schema-loader does multi-column FKs now, needs a bit of cleanup/refactor work
[dbsrgits/DBIx-Class-Schema-Loader.git] / lib / DBIx / Class / Schema / Loader.pm
index 75318cf..51b2792 100644 (file)
@@ -1,9 +1,16 @@
 package DBIx::Class::Schema::Loader;
 
 use strict;
+use warnings;
+
+use vars qw($VERSION @ISA);
 use UNIVERSAL::require;
 
-our $VERSION = '0.01';
+# 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
+
+$VERSION = '0.01000';
 
 =head1 NAME
 
@@ -11,13 +18,13 @@ DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
 
 =head1 SYNOPSIS
 
-  use DBIx::Class::Schema::Loader;
+  package My::Schema;
+  use base qw/DBIx::Class::Schema::Loader/;
 
-  my $loader = DBIx::Class::Schema::Loader->new(
+  __PACKAGE__->load_from_connection(
     dsn                     => "dbi:mysql:dbname",
     user                    => "root",
     password                => "",
-    namespace               => "Data",
     additional_classes      => [qw/DBIx::Class::Foo/],
     additional_base_classes => [qw/My::Stuff/],
     left_base_classes       => [qw/DBIx::Class::Bar/],
@@ -28,34 +35,18 @@ DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
     debug                   => 1,
   );
 
-  my $conn = $loader->connection($dsn, $user, $password); #
-  my $conn = $loader->connection(); # uses same dsn as ->new();
-
-use with mod_perl
+  # in seperate application code ...
 
-in your startup.pl
-
-  # load all tables
-  use DBIx::Class::Loader;
-  my $loader = DBIx::Class::Loader->new(
-    dsn       => "dbi:mysql:dbname",
-    user      => "root",
-    password  => "",
-    namespace => "Data",
-  );
+  use My::Schema;
 
-in your web application.
-
-  use strict;
-
-  # you can use Data::Film directly
-  my $conn = $loader->connection();
-  my $film_moniker = $loader->moniker('film');
-  my $a_film = $conn->resultset($film_moniker)->find($id);
+  my $schema1 = My::Schema->connect( $dsn, $user, $password, $attrs);
+  # -or-
+  my $schema1 = "My::Schema";
+  # ^^ defaults to dsn/user/pass from load_from_connection()
 
 =head1 DESCRIPTION
 
-DBIx::Class::Schema::Loader automate the definition of a
+DBIx::Class::Schema::Loader automates the definition of a
 DBIx::Class::Schema by scanning table schemas and setting up
 columns and primary keys.
 
@@ -64,14 +55,14 @@ L<DBIx::Class::Schema::Loader::Generic> for more, and
 L<DBIx::Class::Schema::Loader::Writing> for notes on writing your own
 db-specific subclass for an unsupported db.
 
-L<Class::DBI::Loader>, L<Class::DBI>, and L<DBIx::Class::Loader> are now
-obsolete, use L<DBIx::Class> and this module instead. ;)
+This module obsoletes L<DBIx::Class::Loader> for L<DBIx::Class> version 0.5
+and later.
 
 =cut
 
 =head1 METHODS
 
-=head2 new
+=head2 load_from_connection
 
 Example in Synopsis above demonstrates the available arguments.  For
 detailed information on the arguments, see the
@@ -79,14 +70,10 @@ L<DBIx::Class::Schema::Loader::Generic> documentation.
 
 =cut
 
-sub new {
+sub load_from_connection {
     my ( $class, %args ) = @_;
 
-    foreach (qw/namespace dsn/) {
-       die qq/Argument $_ is required/ if ! $args{$_};
-    }
-
-    $args{namespace} =~ s/(.*)::$/$1/;
+    die qq/dsn argument is required/ if ! $args{dsn};
 
     my $dsn = $args{dsn};
     my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
@@ -94,14 +81,18 @@ sub new {
     my $impl = "DBIx::Class::Schema::Loader::" . $driver;
 
     $impl->require or
-    die qq/Couldn't require loader class "$impl", "$UNIVERSAL::require::ERROR"/;
+      die qq/Couldn't require loader class "$impl",/ .
+          qq/"$UNIVERSAL::require::ERROR"/;
 
-    return $impl->new(%args);
+    push(@ISA, $impl);
+    $class->_load_from_connection(%args);
 }
 
 =head1 AUTHOR
 
-Sebastian Riedel, C<sri@oook.de>
+Brandon Black, C<bblack@gmail.com>
+
+Sebastian Riedel, C<sri@oook.de> (DBIx::Class::Loader, which this module is branched from)
 
 Based upon the work of IKEBE Tomohiro