From: Rafael Kitover Date: Fri, 26 Mar 2010 18:30:10 +0000 (-0400) Subject: don't rebless with custom loader_class X-Git-Tag: 0.06000~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=71a6e88a3c8774abfd058d2b87e1be00b6d75a4a;p=dbsrgits%2FDBIx-Class-Schema-Loader.git don't rebless with custom loader_class --- diff --git a/Changes b/Changes index 45e2605..ab320be 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader + - do not try to detect driver and rebless when used with a custom + loader_class - suppress 'bad table or view' warnings for filtered tables/views - croak if several tables reduce to an identical moniker (ribasushi) - better type info for Sybase ASE diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index fa161f1..3d85da8 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -163,11 +163,15 @@ sub _invoke_loader { $args->{use_namespaces} = $self->use_namespaces if $self->use_namespaces; # XXX this only works for relative storage_type, like ::DBI ... - my $impl = $self->loader_class - || "DBIx::Class::Schema::Loader" . $self->storage_type; - $impl = "DBIx::Class::Schema::Loader${impl}" if $impl =~ /^::/; + my $loader_class = $self->loader_class; + if ($loader_class) { + $loader_class = "DBIx::Class::Schema::Loader${loader_class}" if $loader_class =~ /^::/; + $args->{loader_class} = $loader_class; + }; + + my $impl = $loader_class || "DBIx::Class::Schema::Loader" . $self->storage_type; eval { $self->ensure_class_loaded($impl) }; - croak qq/Could not load storage_type loader "$impl": "$@"/ if $@; + croak qq/Could not load loader class "$impl": "$@"/ if $@; $self->_loader($impl->new(%$args)); $self->_loader->load; @@ -370,6 +374,8 @@ sub make_schema_at { @{$target . '::ISA'} = qw/DBIx::Class::Schema::Loader/; } + eval { $target->_loader_invoked(0) }; + $target->loader_options($opts); $target->connection(@$connect_info); } @@ -518,3 +524,4 @@ L, L =cut 1; +# vim:et sts=4 sw=4 tw=0: diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index a2a7147..42f3990 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -62,6 +62,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/ datetime_timezone datetime_locale config_file + loader_class /); diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index fc07b22..e5c0332 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -35,14 +35,17 @@ things. sub new { my $self = shift->next::method(@_); - # rebless to vendor-specific class if it exists and loads - my $dbh = $self->schema->storage->dbh; - my $driver = $dbh->{Driver}->{Name}; - - my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver; - if ($self->load_optional_class($subclass)) { - bless $self, $subclass unless $self->isa($subclass); - $self->_rebless; + # rebless to vendor-specific class if it exists and loads and we're not in a + # custom class. + if (not $self->loader_class) { + my $dbh = $self->schema->storage->dbh; + my $driver = $dbh->{Driver}->{Name}; + + my $subclass = 'DBIx::Class::Schema::Loader::DBI::' . $driver; + if ($self->load_optional_class($subclass)) { + bless $self, $subclass unless $self->isa($subclass); + $self->_rebless; + } } # Set up the default quoting character and name seperators diff --git a/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm b/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm index efad039..d052e27 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm @@ -50,7 +50,8 @@ sub _tables_list { =head1 SEE ALSO L, -L, +L, +L, L, L, L diff --git a/t/24loader_subclass.t b/t/24loader_subclass.t index 66d24df..78a5535 100644 --- a/t/24loader_subclass.t +++ b/t/24loader_subclass.t @@ -4,9 +4,11 @@ use Test::More; use lib qw(t/lib); use make_dbictest_db; -my %loader_class = ( 'TestLoaderSubclass' => 'TestLoaderSubclass', - '::DBI::SQLite' => 'DBIx::Class::Schema::Loader::DBI::SQLite' - ); +my %loader_class = ( + 'TestLoaderSubclass' => 'TestLoaderSubclass', + 'TestLoaderSubclass_NoRebless' => 'TestLoaderSubclass_NoRebless', + '::DBI::SQLite' => 'DBIx::Class::Schema::Loader::DBI::SQLite' +); my %invocations = ( loader_class => sub { diff --git a/t/lib/TestLoaderSubclass_NoRebless.pm b/t/lib/TestLoaderSubclass_NoRebless.pm new file mode 100644 index 0000000..b93fd59 --- /dev/null +++ b/t/lib/TestLoaderSubclass_NoRebless.pm @@ -0,0 +1,7 @@ +package TestLoaderSubclass_NoRebless; + +use strict; +use warnings; +use base qw/DBIx::Class::Schema::Loader::DBI/; + +1;