X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FSchema%2FLoader.pm;h=2d9a52fcebd83c292845418e7b7cf993efc59c40;hb=41ef22da3417549e4b5eedd025cca17278bd1d72;hp=2b33b0f56f9eef90aa48e9d0b55bcb6f75bac260;hpb=85f65df633434e4aece7aacbadbf2ecbf7be3f62;p=dbsrgits%2FDBIx-Class-Schema-Loader.git diff --git a/lib/DBIx/Class/Schema/Loader.pm b/lib/DBIx/Class/Schema/Loader.pm index 2b33b0f..2d9a52f 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.03999_01'; +our $VERSION = '0.04999_06'; __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 @@ -45,16 +45,17 @@ L by scanning database table definitions and setting up the columns, primary keys, and relationships. DBIx::Class::Schema::Loader currently supports only the DBI storage type. -It has explicit support for L, L, L, and -L. Other DBI drivers may function to a greater or lesser -degree with this loader, depending on how much of the DBI spec they -implement, and how standard their implementation is. Patches to make -other DBDs work correctly welcome. +It has explicit support for L, L, L, +L, and L. Other DBI drivers may function to +a greater or lesser degree with this loader, depending on how much of the +DBI spec they implement, and how standard their implementation is. + +Patches to make other DBDs work correctly welcome. See L for notes on writing your own vendor-specific subclass for an unsupported DBD driver. -This module requires L 0.06 or later, and obsoletes +This module requires L 0.07006 or later, and obsoletes the older L. This module is designed more to get you up and running quickly against @@ -68,16 +69,39 @@ the road. =head1 METHODS +=head2 loader_class + +=over 4 + +=item Argument: $loader_class + +=back + +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 +=over 4 + +=item Argument: \%loader_options + +=back + Example in Synopsis above demonstrates a few common arguments. For detailed information on all of the arguments, most of which are only useful in fairly complex scenarios, see the L documentation. -One must call C before any connection is made, -or embed the C in the connection information itself -as shown below. Setting C after the connection has +If you intend to use C, you must call +C before any connection is made, or embed the +C in the connection information itself as shown +below. Setting C after the connection has already been made is useless. =cut @@ -104,7 +128,9 @@ 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 = $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"/; @@ -118,11 +144,20 @@ sub _invoke_loader { =head2 connection -See L for basic usage. +=over 4 + +=item Arguments: @args + +=item Return Value: $new_schema -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. +=back + +See L for basic usage. + +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. @@ -133,10 +168,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(@_); @@ -151,7 +188,7 @@ sub connection { =head2 clone -See L. +See L. =cut @@ -170,7 +207,11 @@ sub clone { =head2 dump_to_dir -Argument: directory name. +=over 4 + +=item Argument: $directory + +=back Calling this as a class method on either L or any derived schema class will cause all affected schemas to dump @@ -236,6 +277,14 @@ sub import { =head2 make_schema_at +=over 4 + +=item Arguments: $schema_name, \%loader_options, \@connect_info + +=item Return Value: $schema_name + +=back + This simple function allows one to create a Loader-based schema in-memory on the fly without any on-disk class files of any kind. When used with the C option, you can @@ -285,6 +334,12 @@ sub make_schema_at { =head2 rescan +=over 4 + +=item Return Value: @new_monikers + +=back + Re-scans the database for newly added tables since the initial load, and adds them to the schema at runtime, including relationships, etc. Does not process drops or changes.