Version bump for release
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader.pm
index bbc8fd3..8d8d181 100644 (file)
@@ -2,8 +2,7 @@ package DBIx::Class::Schema::Loader;
 
 use strict;
 use warnings;
-use base qw/DBIx::Class::Schema/;
-use base qw/Class::Data::Accessor/;
+use base qw/DBIx::Class::Schema Class::Data::Accessor/;
 use Carp::Clan qw/^DBIx::Class/;
 use UNIVERSAL::require;
 use Class::C3;
@@ -12,11 +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_05';
 
-__PACKAGE__->mk_classaccessor('dump_to_dir');
 __PACKAGE__->mk_classaccessor('_loader_args' => {});
-__PACKAGE__->mk_classaccessor('_loader_invoked');
+__PACKAGE__->mk_classaccessors(qw/dump_to_dir _loader_invoked _loader loader_class/);
 
 =head1 NAME
 
@@ -47,16 +45,17 @@ L<DBIx::Class::Schema> 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<DBD::Pg>, L<DBD::mysql>, L<DBD::DB2>, and
-L<DBD::SQLite>.  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<DBD::Pg>, L<DBD::mysql>, L<DBD::DB2>,
+L<DBD::SQLite>, and L<DBD::Oracle>.  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<DBIx::Class::Schema::Loader::DBI::Writing> for notes on writing
 your own vendor-specific subclass for an unsupported DBD driver.
 
-This module requires L<DBIx::Class> 0.06 or later, and obsoletes
+This module requires L<DBIx::Class> 0.07006 or later, and obsoletes
 the older L<DBIx::Class::Loader>.
 
 This module is designed more to get you up and running quickly against
@@ -70,6 +69,16 @@ the road.
 
 =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
@@ -77,9 +86,10 @@ detailed information on all of the arguments, most of which are
 only useful in fairly complex scenarios, see the
 L<DBIx::Class::Schema::Loader::Base> documentation.
 
-One must call C<loader_options> before any connection is made,
-or embed the C<loader_options> in the connection information itself
-as shown below.  Setting C<loader_options> after the connection has
+If you intend to use C<loader_options>, you must call
+C<loader_options> before any connection is made, or embed the
+C<loader_options> in the connection information itself as shown
+below.  Setting C<loader_options> after the connection has
 already been made is useless.
 
 =cut
@@ -106,12 +116,15 @@ 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"/;
 
-    $impl->new(%$args)->load;
+    $self->_loader($impl->new(%$args));
+    $self->_loader->load;
     $self->_loader_invoked(1);
 
     $self;
@@ -121,9 +134,10 @@ sub _invoke_loader {
 
 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.
@@ -134,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(@_);
@@ -284,6 +300,18 @@ sub make_schema_at {
     $target->connection(@$connect_info);
 }
 
+=head2 rescan
+
+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.
+
+Returns a list of the new monikers added.
+
+=cut
+
+sub rescan { my $self = shift; $self->_loader->rescan($self) }
+
 =head1 EXAMPLE
 
 Using the example in L<DBIx::Class::Manual::ExampleSchema> as a basis