connect_info replaces dsn/user/password/options
Brandon Black [Sat, 18 Feb 2006 23:15:17 +0000 (23:15 +0000)]
Changes
lib/DBIx/Class/Schema/Loader.pm
lib/DBIx/Class/Schema/Loader/Generic.pm
t/lib/dbixcsl_common_tests.pm

diff --git a/Changes b/Changes
index 8dbdd06..8cf5e7f 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension DBIx::Class::Schema::Loader
 
+0.02003 Not yet released
+        - Deprecated arguments: dsn, user, password, options
+        - New argument: connect_info
+
 0.02002 Sat Feb 18 19:53:12 UTC 2006
         - Added moniker_map and inflect_map
 
index 633c34f..d93ed3a 100644 (file)
@@ -10,7 +10,7 @@ use UNIVERSAL::require;
 # 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.02002';
+our $VERSION = '0.02003';
 
 __PACKAGE__->mk_classaccessor('loader');
 
@@ -30,9 +30,11 @@ DBIx::Class::Schema::Loader - Dynamic definition of a DBIx::Class::Schema
   }
 
   __PACKAGE__->load_from_connection(
-    dsn                     => "dbi:mysql:dbname",
-    user                    => "root",
-    password                => "",
+    connect_info            => [ "dbi:mysql:dbname",
+                                 "root",
+                                 "mypassword",
+                                 { AutoCommit => 1 },
+                               ],
     additional_classes      => [qw/DBIx::Class::Foo/],
     additional_base_classes => [qw/My::Stuff/],
     left_base_classes       => [qw/DBIx::Class::Bar/],
@@ -110,11 +112,25 @@ L<DBIx::Class::Schema::Loader::Generic> documentation.
 
 =cut
 
+# XXX this is DBI-specific, as it peers into the dsn to determine
+# the vendor class to use...
 sub load_from_connection {
     my ( $class, %args ) = @_;
 
-    croak 'dsn argument is required' if ! $args{dsn};
-    my $dsn = $args{dsn};
+    my $dsn;
+
+    if($args{connect_info} && $args{connect_info}->[0]) {
+        $dsn = $args{connect_info}->[0];
+    }
+    elsif($args{dsn}) {
+        warn "dsn argument is deprecated, please use connect_info instead";
+        $dsn = $args{dsn};
+    }
+    else {
+        croak 'connect_info arrayref argument with valid '
+              . 'first element is required';
+    }
+
     my ($driver) = $dsn =~ m/^dbi:(\w*?)(?:\((.*?)\))?:/i;
     $driver = 'SQLite' if $driver eq 'SQLite2';
     my $impl = "DBIx::Class::Schema::Loader::" . $driver;
index bdb5d95..9a4533f 100644 (file)
@@ -14,10 +14,7 @@ require DBIx::Class;
 
 __PACKAGE__->mk_ro_accessors(qw/
                                 schema
-                                dsn
-                                user
-                                password
-                                options
+                                connect_info
                                 exclude
                                 constraint
                                 additional_classes
@@ -53,6 +50,16 @@ classes, and implements the common functionality between them.
 
 Available constructor options are:
 
+=head2 connect_info
+
+Identical to the connect_info arguments to C<connect> and C<connection>
+that are mentioned in L<DBIx::Class::Schema>.
+
+An arrayref of connection information.  For DBI-based Schemas,
+this takes the form:
+
+  connect_info => [ $dsn, $user, $pass, { AutoCommit => 1 } ],
+
 =head2 additional_base_classes
 
 List of additional base classes your table classes will use.
@@ -89,14 +96,6 @@ Exclude tables matching regex.
 
 Enable debug messages.
 
-=head2 dsn
-
-DBI Data Source Name.
-
-=head2 password
-
-Password.
-
 =head2 relationships
 
 Try to automatically detect/setup has_a and has_many relationships.
@@ -121,10 +120,32 @@ Deprecated.  Equivalent to L</inflect_map>, but previously only took
 a hashref argument, not a coderef.  If you set C<inflect> to anything,
 that setting will be copied to L</inflect_map>.
 
+=head2 dsn
+
+DEPRECATED, use L</connect_info> instead.
+
+DBI Data Source Name.
+
 =head2 user
 
+DEPRECATED, use L</connect_info> instead.
+
 Username.
 
+=head2 password
+
+DEPRECATED, use L</connect_info> instead.
+
+Password.
+
+=head2 options
+
+DEPRECATED, use L</connect_info> instead.
+
+DBI connection options hashref, like:
+
+  { AutoCommit => 1 }
+
 =head1 METHODS
 
 =cut
@@ -161,7 +182,8 @@ sub new {
                                additional_base_classes
                                left_base_classes
                                components
-                               resultset_components/);
+                               resultset_components
+                               connect_info/);
 
     push(@{$self->{components}}, 'ResultSetManager')
         if @{$self->{resultset_components}};
@@ -172,6 +194,13 @@ sub new {
     # Support deprecated argument name
     $self->{inflect_map} ||= $self->{inflect};
 
+    # Support deprecated connect_info args, even mixed
+    #  with a valid partially-filled connect_info
+    $self->{connect_info}->[0] ||= $self->{dsn};
+    $self->{connect_info}->[1] ||= $self->{user};
+    $self->{connect_info}->[2] ||= $self->{password};
+    $self->{connect_info}->[3] ||= $self->{options};
+
     $self;
 }
 
@@ -185,8 +214,7 @@ L<DBIx::Class::Schema::Loader> right after object construction.
 sub load {
     my $self = shift;
 
-    $self->schema->connection($self->dsn, $self->user,
-                              $self->password, $self->options);
+    $self->schema->connection(@{$self->connect_info});
 
     warn qq/\### START DBIx::Class::Schema::Loader dump ###\n/
         if $self->debug;
index ca96d45..9e3fb5c 100644 (file)
@@ -52,9 +52,8 @@ sub run_tests {
     my $debug = ($self->{verbose} > 1) ? 1 : 0;
 
     my %loader_opts = (
-        dsn                     => $self->{dsn},
-        user                    => $self->{user},
-        password                => $self->{password},
+        connect_info            => [ $self->{dsn}, $self->{user},
+                                     $self->{password} ],
         constraint              => '^(?:\S+\.)?(?i:loader_test)[0-9]+$',
         relationships           => 1,
         additional_classes      => 'TestAdditional',