Skip to content

Instantly share code, notes, and snippets.

@hatyuki
Created January 17, 2010 15:52
Show Gist options
  • Save hatyuki/279429 to your computer and use it in GitHub Desktop.
Save hatyuki/279429 to your computer and use it in GitHub Desktop.
package MyApp::Model;
use DBIx::Skinny;
{
# 再定義したときの警告がでないようにするためのオマジナイ
no warnings 'redefine';
# row クラスを作成しているメソッドを再定義
*_mk_row_class = sub {
my ($class, $key, $table) = @_;
$table ||= $class->_guess_table_name($key)||'';
my $attr = $class->attribute;
my $base_row_class = $attr->{row_class_map}->{$table} || '';
if ( $base_row_class eq 'DBIx::Skinny::Row' ) {
return $class->_mk_anon_row_class($key, $base_row_class);
} elsif ($base_row_class) {
return $base_row_class;
} elsif ($table) {
# ここら辺いじった
# ($table の use を試みた後に 'BASE_ROW' の use を試みる)
for my $row_name (_camelize($table), 'BASE_ROW') {
my $tmp_base_row_class = join '::', $attr->{klass}, 'Row', $row_name;
eval "use $tmp_base_row_class"; ## no critic
# use できればそのクラスを利用する
unless ($@) {
$attr->{row_class_map}->{$table} = $tmp_base_row_class;
return $tmp_base_row_class;
}
}
# use できなければ anon row class
$attr->{row_class_map}->{$table} = 'DBIx::Skinny::Row';
return $class->_mk_anon_row_class($key, $attr->{row_class_map}->{$table});
} else {
return $class->_mk_anon_row_class($key, 'DBIx::Skinny::Row');
}
};
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment