[Bast-commits] r3705 - in DBIx-Class/0.08/trunk: lib/DBIx/Class/Storage t

tomboh at dev.catalyst.perl.org tomboh at dev.catalyst.perl.org
Wed Aug 22 11:28:58 GMT 2007


Author: tomboh
Date: 2007-08-22 11:28:58 +0100 (Wed, 22 Aug 2007)
New Revision: 3705

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t
Log:
Fix the behaviour of code refs within array refs for on_(dis)?connect_do
and enhance tests to spot the previous mistake.


Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm	2007-08-21 19:56:43 UTC (rev 3704)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm	2007-08-22 10:28:58 UTC (rev 3705)
@@ -366,7 +366,7 @@
 
 =item on_disconnect_do
 
-Takes arguments in the same for as L<on_connect_do> and executes them
+Takes arguments in the same form as L<on_connect_do> and executes them
 immediately before disconnecting from the database.
 
 Note, this only runs if you explicitly call L<disconnect> on the
@@ -792,7 +792,8 @@
   my ($self, $action) = @_;
 
   if (ref $action eq 'CODE') {
-    $action->($self);
+    $action = $action->($self);
+    $self->_do_query($_) foreach @$action;
   }
   else {
     my @to_run = (ref $action eq 'ARRAY') ? (@$action) : ($action);

Modified: DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t
===================================================================
--- DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t	2007-08-21 19:56:43 UTC (rev 3704)
+++ DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t	2007-08-22 10:28:58 UTC (rev 3705)
@@ -17,6 +17,7 @@
         on_connect_do       => [
             'CREATE TABLE TEST_empty (id INTEGER)',
             [ 'INSERT INTO TEST_empty VALUES (?)', {}, 2 ],
+            \&insert_from_subref,
         ],
         on_disconnect_do    =>
             [\&check_exists, 'DROP TABLE TEST_empty', \&check_dropped],
@@ -25,7 +26,7 @@
 
 is_deeply
   $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
-  [ [ 2 ] ],
+  [ [ 2 ], [ 3 ], [ 7 ] ],
   'on_connect_do() worked';
 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
 ok $@, 'Searching for nonexistent table dies';
@@ -50,10 +51,20 @@
 sub check_exists {
     my $storage = shift;
     ok $storage->dbh->do('SELECT 1 FROM TEST_empty'), 'Table still exists';
+    return;
 }
 
 sub check_dropped {
     my $storage = shift;
     eval { $storage->dbh->do('SELECT 1 FROM TEST_empty'); };
     ok $@, 'Reading from dropped table fails';
+    return;
 }
+
+sub insert_from_subref {
+    my $storage = shift;
+    return [
+        [ 'INSERT INTO TEST_empty VALUES (?)', {}, 3 ],
+        'INSERT INTO TEST_empty VALUES (7)',
+    ];
+}




More information about the Bast-commits mailing list