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

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Wed May 20 21:47:05 GMT 2009


Author: ribasushi
Date: 2009-05-20 21:47:05 +0000 (Wed, 20 May 2009)
New Revision: 6356

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
   DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t
Log:
on_connect_do now accepts a single string like it does an arrayref (patch by prema)

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm	2009-05-20 21:00:13 UTC (rev 6355)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI.pm	2009-05-20 21:47:05 UTC (rev 6356)
@@ -153,6 +153,10 @@
 
 =over
 
+=item a scalar
+
+This contains one SQL statement to execute.
+
 =item an array reference
 
 This contains SQL statements to execute in order.  Each element contains
@@ -626,19 +630,25 @@
   $self->_conn_tid(threads->tid) if $INC{'threads.pm'};
 
   my $connection_do = $self->on_connect_do;
-  $self->_do_connection_actions($connection_do) if ref($connection_do);
+  $self->_do_connection_actions($connection_do) if $connection_do;
 }
 
 sub _do_connection_actions {
   my $self = shift;
   my $connection_do = shift;
 
-  if (ref $connection_do eq 'ARRAY') {
+  if (!ref $connection_do) {
+    $self->_do_query($connection_do);
+  }
+  elsif (ref $connection_do eq 'ARRAY') {
     $self->_do_query($_) foreach @$connection_do;
   }
   elsif (ref $connection_do eq 'CODE') {
     $connection_do->($self);
   }
+  else {
+    $self->throw_exception (sprintf ("Don't know how to process conection actions of type '%s'", ref $connection_do) );
+  }
 
   return $self;
 }

Modified: DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t
===================================================================
--- DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t	2009-05-20 21:00:13 UTC (rev 6355)
+++ DBIx-Class/0.08/trunk/t/92storage_on_connect_do.t	2009-05-20 21:47:05 UTC (rev 6356)
@@ -1,7 +1,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 10;
+use Test::More tests => 12;
 
 use lib qw(t/lib);
 use base 'DBICTest';
@@ -11,7 +11,23 @@
     no_connect  => 1,
     no_deploy   => 1,
 );
+
 ok $schema->connection(
+  DBICTest->_database,
+  {
+    on_connect_do => 'CREATE TABLE TEST_empty (id INTEGER)',
+  },
+), 'connection()';
+
+is_deeply (
+  $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
+  [],
+  'string version on_connect_do() worked'
+);
+
+$schema->storage->disconnect;
+
+ok $schema->connection(
     DBICTest->_database,
     {
         on_connect_do       => [
@@ -24,10 +40,11 @@
     },
 ), 'connection()';
 
-is_deeply
+is_deeply (
   $schema->storage->dbh->selectall_arrayref('SELECT * FROM TEST_empty'),
   [ [ 2 ], [ 3 ], [ 7 ] ],
-  'on_connect_do() worked';
+  'on_connect_do() worked'
+);
 eval { $schema->storage->dbh->do('SELECT 1 FROM TEST_nonexistent'); };
 ok $@, 'Searching for nonexistent table dies';
 




More information about the Bast-commits mailing list