don't rebless with custom loader_class
Rafael Kitover [Fri, 26 Mar 2010 18:30:10 +0000 (14:30 -0400)]
Changes
lib/DBIx/Class/Schema/Loader.pm
lib/DBIx/Class/Schema/Loader/Base.pm
lib/DBIx/Class/Schema/Loader/DBI.pm
lib/DBIx/Class/Schema/Loader/DBI/ODBC.pm
t/24loader_subclass.t
t/lib/TestLoaderSubclass_NoRebless.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index 45e2605..ab320be 100644 (file)
--- 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
index fa161f1..3d85da8 100644 (file)
@@ -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<DBIx::Class>, L<DBIx::Class::Manual::ExampleSchema>
 =cut
 
 1;
+# vim:et sts=4 sw=4 tw=0:
index a2a7147..42f3990 100644 (file)
@@ -62,6 +62,7 @@ __PACKAGE__->mk_group_ro_accessors('simple', qw/
                                 datetime_timezone
                                 datetime_locale
                                 config_file
+                                loader_class
 /);
 
 
index fc07b22..e5c0332 100644 (file)
@@ -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
index efad039..d052e27 100644 (file)
@@ -50,7 +50,8 @@ sub _tables_list {
 =head1 SEE ALSO
 
 L<DBIx::Class::Schema::Loader::DBI::ODBC::Microsoft_SQL_Server>,
-L<DBIx::Class::Schema::Loader::DBI::MSSQL>,
+L<DBIx::Class::Schema::Loader::DBI::ODBC::SQL_Anywhere>,
+L<DBIx::Class::Schema::Loader::DBI::ODBC::Firebird>,
 L<DBIx::Class::Schema::Loader>, L<DBIx::Class::Schema::Loader::Base>,
 L<DBIx::Class::Schema::Loader::DBI>
 
index 66d24df..78a5535 100644 (file)
@@ -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 (file)
index 0000000..b93fd59
--- /dev/null
@@ -0,0 +1,7 @@
+package TestLoaderSubclass_NoRebless;
+
+use strict;
+use warnings;
+use base qw/DBIx::Class::Schema::Loader::DBI/;
+
+1;