- Allow specifying loader_class in the connection info (primariy for make_schema_at)
- Add more tests
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
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
=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
$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"/;
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.
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(@_);
=head1 CONSTRUCTOR OPTIONS
These constructor options are the base options for
-L<DBIx::Class::Schema::Loader/loader_opts>. 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>.
+L<DBIx::Class::Schema::Loader/loader_options>. Available constructor options are:
=head2 skip_relationships
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'
+ );
+
+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 } ]
+ );
+ }
+);
-plan tests => 2;
+# one test per invocation/class combo
+plan tests => keys(%invocations) * keys(%loader_class);
-my $schema = DBICTest::Schema->connect($make_dbictest_db::dsn);
-isa_ok($schema->storage, 'DBIx::Class::Storage::DBI::SQLite');
-isa_ok($schema->_loader, 'TestLoaderSubclass');
+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)");
+ }
+}