[Bast-commits] r4251 - in
branches/DBIx-Class-Schema-Loader/current: .
lib/DBIx/Class/Schema lib/DBIx/Class/Schema/Loader t
ilmari at dev.catalyst.perl.org
ilmari at dev.catalyst.perl.org
Sat Apr 5 01:18:50 BST 2008
Author: ilmari
Date: 2008-04-05 01:18:50 +0100 (Sat, 05 Apr 2008)
New Revision: 4251
Modified:
branches/DBIx-Class-Schema-Loader/current/Changes
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
branches/DBIx-Class-Schema-Loader/current/t/24loader_subclass.t
Log:
- Move loader_class from Schema::Loader::Base to Schema::Loader
- Allow specifying loader_class in the connection info (primariy for make_schema_at)
- Add more tests
Modified: branches/DBIx-Class-Schema-Loader/current/Changes
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/Changes 2008-04-01 15:34:44 UTC (rev 4250)
+++ branches/DBIx-Class-Schema-Loader/current/Changes 2008-04-05 00:18:50 UTC (rev 4251)
@@ -3,7 +3,8 @@
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
+ - Allow specifying a custom loader_class, overriding the
+ storage_type-based detection
0.04999_04 Wed Mar 12, 2008
- Add is_auto_increment detecton for DB2
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2008-04-01 15:34:44 UTC (rev 4250)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader/Base.pm 2008-04-05 00:18:50 UTC (rev 4251)
@@ -62,15 +62,8 @@
=head1 CONSTRUCTOR OPTIONS
These constructor options are the base options for
-L<DBIx::Class::Schema::Loader/loader_opts>. Available constructor options are:
+L<DBIx::Class::Schema::Loader/loader_options>. Available constructor options are:
-=head2 loader_class
-
-Use the specified class as the loader instead of
-C<DBIx::Class::Schema::Loader${storage_type}>. This is mostly useful for
-subclassing existing loaders or in conjunction with
-L<DBIx::Class::Schema::Loader/dump_to_dir>.
-
=head2 skip_relationships
Skip setting up relationships. The default is to attempt the loading
Modified: branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm 2008-04-01 15:34:44 UTC (rev 4250)
+++ branches/DBIx-Class-Schema-Loader/current/lib/DBIx/Class/Schema/Loader.pm 2008-04-05 00:18:50 UTC (rev 4251)
@@ -14,7 +14,7 @@
our $VERSION = '0.04999_04';
__PACKAGE__->mk_classaccessor('_loader_args' => {});
-__PACKAGE__->mk_classaccessors(qw/dump_to_dir _loader_invoked _loader/);
+__PACKAGE__->mk_classaccessors(qw/dump_to_dir _loader_invoked _loader loader_class/);
=head1 NAME
@@ -69,6 +69,16 @@
=head1 METHODS
+=head2 loader_class
+
+Set the loader class to be instantiated when L</connection> is called.
+If the classname starts with "::", "DBIx::Class::Schema::Loader" is
+prepended. Defaults to L<DBIx::Class::Schema/storage_type> (which must
+start with "::" when using L<DBIx::Class::Schema::Loader>).
+
+This is mostly useful for subclassing existing loaders or in conjunction
+with L</dump_to_dir>.
+
=head2 loader_options
Example in Synopsis above demonstrates a few common arguments. For
@@ -106,8 +116,9 @@
$args->{dump_directory} ||= $self->dump_to_dir;
# XXX this only works for relative storage_type, like ::DBI ...
- my $impl = $args->{loader_class}
+ my $impl = $self->loader_class
|| "DBIx::Class::Schema::Loader" . $self->storage_type;
+ $impl = "DBIx::Class::Schema::Loader${impl}" if $impl =~ /^::/;
$impl->require or
croak qq/Could not load storage_type loader "$impl": / .
qq/"$UNIVERSAL::require::ERROR"/;
@@ -123,9 +134,10 @@
See L<DBIx::Class::Schema> for basic usage.
-If the final argument is a hashref, and it contains a key C<loader_options>,
-that key will be deleted, and its value will be used for the loader options,
-just as if set via the L</loader_options> method above.
+If the final argument is a hashref, and it contains the keys C<loader_options>
+or C<loader_class>, those keys will be deleted, and their values value will be
+used for the loader options or class, respectively, just as if set via the
+L</loader_options> or L</loader_class> methods above.
The actual auto-loading operation (the heart of this module) will be invoked
as soon as the connection information is defined.
@@ -136,10 +148,12 @@
my $self = shift;
if($_[-1] && ref $_[-1] eq 'HASH') {
- if(my $loader_opts = delete $_[-1]->{loader_options}) {
- $self->loader_options($loader_opts);
- pop @_ if !keys %{$_[-1]};
+ for my $option (qw/ loader_class loader_options /) {
+ if(my $value = delete $_[-1]->{$option}) {
+ $self->$option($value);
+ }
}
+ pop @_ if !keys %{$_[-1]};
}
$self = $self->next::method(@_);
Modified: branches/DBIx-Class-Schema-Loader/current/t/24loader_subclass.t
===================================================================
--- branches/DBIx-Class-Schema-Loader/current/t/24loader_subclass.t 2008-04-01 15:34:44 UTC (rev 4250)
+++ branches/DBIx-Class-Schema-Loader/current/t/24loader_subclass.t 2008-04-05 00:18:50 UTC (rev 4251)
@@ -4,14 +4,39 @@
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' );
-}
+my %loader_class = ( 'TestLoaderSubclass' => 'TestLoaderSubclass',
+ '::DBI::SQLite' => 'DBIx::Class::Schema::Loader::DBI::SQLite'
+ );
-plan tests => 2;
+my %invocations = (
+ loader_class => sub {
+ package DBICTest::Schema::1;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->loader_class(shift);
+ __PACKAGE__->connect($make_dbictest_db::dsn);
+ },
+ connect_info => sub {
+ package DBICTeset::Schema::2;
+ use base qw/ DBIx::Class::Schema::Loader /;
+ __PACKAGE__->connect($make_dbictest_db::dsn, { loader_class => shift });
+ },
+ make_schema_at => sub {
+ use DBIx::Class::Schema::Loader qw/ make_schema_at /;
+ make_schema_at(
+ 'DBICTeset::Schema::3',
+ { },
+ [ $make_dbictest_db::dsn, { loader_class => shift } ]
+ );
+ }
+);
-my $schema = DBICTest::Schema->connect($make_dbictest_db::dsn);
-isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite');
-isa_ok($schema->_loader, 'TestLoaderSubclass');
+# one test per invocation/class combo
+plan tests => keys(%invocations) * keys(%loader_class);
+
+while (my ($style,$subref) = each %invocations) {
+ while (my ($arg, $class) = each %loader_class) {
+ my $schema = $subref->($arg);
+ $schema = $schema->clone unless ref $schema;
+ isa_ok($schema->_loader, $class, "$style($arg)");
+ }
+}
More information about the Bast-commits
mailing list