[Bast-commits] r7434 - in DBIx-Class/0.08/branches/connect_info_hash: . lib/DBIx/Class/Storage t/storage

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sun Aug 30 06:51:14 GMT 2009


Author: ribasushi
Date: 2009-08-30 06:51:14 +0000 (Sun, 30 Aug 2009)
New Revision: 7434

Modified:
   DBIx-Class/0.08/branches/connect_info_hash/Makefile.PL
   DBIx-Class/0.08/branches/connect_info_hash/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/branches/connect_info_hash/t/storage/base.t
Log:
Minor cleanup and test enhancement

Modified: DBIx-Class/0.08/branches/connect_info_hash/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/connect_info_hash/Makefile.PL	2009-08-30 01:14:36 UTC (rev 7433)
+++ DBIx-Class/0.08/branches/connect_info_hash/Makefile.PL	2009-08-30 06:51:14 UTC (rev 7434)
@@ -14,7 +14,7 @@
 test_requires 'Test::Deep'          => 0;
 test_requires 'Test::Exception'     => 0;
 test_requires 'Test::More'          => 0.92;
-test_requires 'Test::Warn'          => 0.11;
+test_requires 'Test::Warn'          => 0.21;
 
 test_requires 'File::Temp'          => 0.22;
 

Modified: DBIx-Class/0.08/branches/connect_info_hash/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/connect_info_hash/lib/DBIx/Class/Storage/DBI.pm	2009-08-30 01:14:36 UTC (rev 7433)
+++ DBIx-Class/0.08/branches/connect_info_hash/lib/DBIx/Class/Storage/DBI.pm	2009-08-30 06:51:14 UTC (rev 7434)
@@ -112,6 +112,12 @@
     %extra_attributes,
   }];
 
+  $connect_info_args = [{
+    dbh_maker => sub { DBI->connect (...) },
+    %dbi_attributes,
+    %extra_attributes,
+  }];
+
 This is particularly useful for L<Catalyst> based applications, allowing the
 following config (L<Config::General> style):
 
@@ -126,7 +132,8 @@
   </Model::DB>
 
 The C<dsn>/C<user>/C<password> combination can be substituted by the
-C<dbh_maker> key whose value is a coderef that returns the C<$dbh>.
+C<dbh_maker> key whose value is a coderef that returns a connected
+L<DBI database handle|DBI/connect>
 
 =back
 
@@ -418,9 +425,15 @@
     @args = ();
     if (my $code = delete $attrs{dbh_maker}) {
       @args = $code;
-      if (delete @attrs{qw/dsn user password/}) {
-        warn 'dsn/user/password ignored when dbh_maker coderef used in ' .
-             'connect_info';
+
+      my @ignored = grep { delete $attrs{$_} } (qw/dsn user password/);
+      if (@ignored) {
+        carp sprintf (
+            'Attribute(s) %s in connect_info were ignored, as they can not be applied '
+          . "to the result of 'dbh_maker'",
+
+          join (', ', map { "'$_'" } (@ignored) ),
+        );
       }
     }
     else {

Modified: DBIx-Class/0.08/branches/connect_info_hash/t/storage/base.t
===================================================================
--- DBIx-Class/0.08/branches/connect_info_hash/t/storage/base.t	2009-08-30 01:14:36 UTC (rev 7433)
+++ DBIx-Class/0.08/branches/connect_info_hash/t/storage/base.t	2009-08-30 06:51:14 UTC (rev 7434)
@@ -1,7 +1,8 @@
 use strict;
-use warnings;  
+use warnings;
 
 use Test::More;
+use Test::Warn;
 use lib qw(t/lib);
 use DBICTest;
 use Data::Dumper;
@@ -33,8 +34,6 @@
     }
 }
 
-plan tests => 21;
-
 my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
 
 is( ref($schema->storage), 'DBIx::Class::Storage::DBI::SQLite',
@@ -148,12 +147,15 @@
   'connect_info ([ \%attr_with_coderef ])' => {
       args => [ {
         dbh_maker => $coderef,
+        dsn => 'blah',
+        user => 'bleh',
         on_connect_do => [qw/a b c/],
         on_disconnect_do => [qw/d e f/],
       } ],
       dbi_connect_info => [
         $coderef
       ],
+      warn => qr/Attribute\(s\) 'dsn', 'user' in connect_info were ignored/,
   },
 };
 
@@ -164,11 +166,16 @@
   local $Data::Dumper::Sortkeys = 1;
   my $arg_dump = Dumper ($invocations->{$type}{args});
 
-  $storage->connect_info ($invocations->{$type}{args});
+  my $do = sub {  };
 
+  warnings_exist (
+    sub { $storage->connect_info ($invocations->{$type}{args}) },
+     $invocations->{$type}{warn} || (),
+    'Warned about ignored attributes',
+  );
+
   is ($arg_dump, Dumper ($invocations->{$type}{args}), "$type didn't modify passed arguments");
 
-
   is_deeply ($storage->_dbi_connect_info, $invocations->{$type}{dbi_connect_info}, "$type produced correct _dbi_connect_info");
   ok ( (not $storage->auto_savepoint and not $storage->unsafe), "$type correctly ignored extra hashref");
 
@@ -179,4 +186,6 @@
   );
 }
 
+done_testing;
+
 1;




More information about the Bast-commits mailing list