X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader.pm;h=8d8d181592ffd7091cca1b1f2ad5b643355ece36;hb=b327622ba07a243c4b5e10b0b7dbd17c20d75b34;hp=7965299f8b1c062029acac53c79e24b4a6c94556;hpb=3953cbee8b603198ebe35357210009f2f92284e3;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 7965299..8d8d181 100644 --- a/lib/DBIx/Class/Schema/Loader.pm +++ b/lib/DBIx/Class/Schema/Loader.pm @@ -11,10 +11,10 @@ use Scalar::Util qw/ weaken /; # Always remember to do all digits for the version even if they're 0 # i.e. first release of 0.XX *must* be 0.XX000. This avoids fBSD ports # brain damage and presumably various other packaging systems too -our $VERSION = '0.04999_04'; +our $VERSION = '0.04999_05'; __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 @@ the road. =head1 METHODS +=head2 loader_class + +Set the loader class to be instantiated when L is called. +If the classname starts with "::", "DBIx::Class::Schema::Loader" is +prepended. Defaults to L (which must +start with "::" when using L). + +This is mostly useful for subclassing existing loaders or in conjunction +with L. + =head2 loader_options Example in Synopsis above demonstrates a few common arguments. For @@ -106,8 +116,9 @@ sub _invoke_loader { $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 @@ sub _invoke_loader { See L for basic usage. -If the final argument is a hashref, and it contains a key C, -that key will be deleted, and its value will be used for the loader options, -just as if set via the L method above. +If the final argument is a hashref, and it contains the keys C +or C, 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 or L 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 @@ sub connection { 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(@_);