From: Dagfinn Ilmari Mannsåker Date: Tue, 1 Apr 2008 15:34:44 +0000 (+0000) Subject: Allow specifying a custom loader_class in loader_options X-Git-Tag: 0.04999_05~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3953cbee8b603198ebe35357210009f2f92284e3;p=dbsrgits%2FDBIx-Class-Schema-Loader.git Allow specifying a custom loader_class in loader_options --- diff --git a/Changes b/Changes index 102bdf5..b741b40 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,7 @@ Revision history for Perl extension DBIx::Class::Schema::Loader Not yet released - Fix limiting table list to the specified schema for DB2 - Default db_schema to the username for DB2 + - Allow specifying a custom loader_class in loader_options 0.04999_04 Wed Mar 12, 2008 - Add is_auto_increment detecton for DB2 diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index a27bc6f..7965299 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -106,7 +106,8 @@ sub _invoke_loader { $args->{dump_directory} ||= $self->dump_to_dir; # XXX this only works for relative storage_type, like ::DBI ... - my $impl = "DBIx::Class::Schema::Loader" . $self->storage_type; + my $impl = $args->{loader_class} + || "DBIx::Class::Schema::Loader" . $self->storage_type; $impl->require or croak qq/Could not load storage_type loader "$impl": / . qq/"$UNIVERSAL::require::ERROR"/; diff --git a/lib/DBIx/Class/Schema/Loader/Base.pm b/lib/DBIx/Class/Schema/Loader/Base.pm index 1d095c0..a45d654 100644 --- a/lib/DBIx/Class/Schema/Loader/Base.pm +++ b/lib/DBIx/Class/Schema/Loader/Base.pm @@ -64,6 +64,13 @@ classes, and implements the common functionality between them. These constructor options are the base options for L. Available constructor options are: +=head2 loader_class + +Use the specified class as the loader instead of +C. This is mostly useful for +subclassing existing loaders or in conjunction with +L. + =head2 skip_relationships Skip setting up relationships. The default is to attempt the loading diff --git a/lib/DBIx/Class/Schema/Loader/DBI.pm b/lib/DBIx/Class/Schema/Loader/DBI.pm index f06cf30..e03aed6 100644 --- a/lib/DBIx/Class/Schema/Loader/DBI.pm +++ b/lib/DBIx/Class/Schema/Loader/DBI.pm @@ -45,7 +45,7 @@ sub new { croak "Failed to require $subclass: $@"; } elsif(!$@) { - bless $self, "DBIx::Class::Schema::Loader::DBI::${driver}"; + bless $self, $subclass unless $self->isa($subclass); } # Set up the default quoting character and name seperators diff --git a/t/24loader_subclass.t b/t/24loader_subclass.t new file mode 100644 index 0000000..43de59b --- /dev/null +++ b/t/24loader_subclass.t @@ -0,0 +1,17 @@ +use strict; +use warnings; +use Test::More; +use lib qw(t/lib); +use make_dbictest_db; + +{ + package DBICTest::Schema; + use base qw/ DBIx::Class::Schema::Loader /; + __PACKAGE__->loader_options( loader_class => 'TestLoaderSubclass' ); +} + +plan tests => 2; + +my $schema = DBICTest::Schema->connect($make_dbictest_db::dsn); +isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite'); +isa_ok($schema->_loader, 'TestLoaderSubclass'); diff --git a/t/lib/TestLoaderSubclass.pm b/t/lib/TestLoaderSubclass.pm new file mode 100644 index 0000000..50c9200 --- /dev/null +++ b/t/lib/TestLoaderSubclass.pm @@ -0,0 +1,7 @@ +package TestLoaderSubclass; + +use strict; +use warnings; +use base qw/DBIx::Class::Schema::Loader::DBI::SQLite/; + +1;