[Bast-commits] r6655 - in DBIx-Class/0.08/branches/on_connect_call: . lib/DBIx/Class/Storage t

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Sat Jun 13 00:28:07 GMT 2009


Author: caelum
Date: 2009-06-13 00:28:06 +0000 (Sat, 13 Jun 2009)
New Revision: 6655

Added:
   DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t
Modified:
   DBIx-Class/0.08/branches/on_connect_call/Makefile.PL
   DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
Log:
finished up on_connect_call stuff

Modified: DBIx-Class/0.08/branches/on_connect_call/Makefile.PL
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/Makefile.PL	2009-06-12 23:54:57 UTC (rev 6654)
+++ DBIx-Class/0.08/branches/on_connect_call/Makefile.PL	2009-06-13 00:28:06 UTC (rev 6655)
@@ -81,6 +81,9 @@
   'DateTime::Format::MySQL'   => 0,
   'DateTime::Format::Pg'      => 0,
 
+  # t/73oracle.t
+  'DateTime::Format::Oracle'  => 0,
+
   # t/96_is_deteministic_value.t
   'DateTime::Format::Strptime' => 0,
 

Modified: DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm	2009-06-12 23:54:57 UTC (rev 6654)
+++ DBIx-Class/0.08/branches/on_connect_call/lib/DBIx/Class/Storage/DBI.pm	2009-06-13 00:28:06 UTC (rev 6655)
@@ -221,6 +221,26 @@
 Executes a SQL string or a code reference that returns a SQL string. This is
 what L</on_connect_do> and L</on_disconnect_do> use.
 
+It can take:
+
+=over
+
+=item a scalar
+
+Will execute the scalar as SQL.
+
+=item an arrayref
+
+Taken to be arguments to L<DBI/do>, the SQL string optionally followed by the
+attributes hashref and bind values.
+
+=item a code reference
+
+Will execute C<< $code->($storage) >> and execute the return array refs as
+above.
+
+=back
+
 =item set_datetime_format
 
 Execute any statements necessary to initialize the database session to return

Added: DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t
===================================================================
--- DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/on_connect_call/t/92storage_on_connect_call.t	2009-06-13 00:28:06 UTC (rev 6655)
@@ -0,0 +1,67 @@
+use strict;
+use warnings;
+no warnings qw/once redefine/;
+
+use lib qw(t/lib);
+require DBICTest;
+
+use Test::More tests => 9;
+
+my $schema = DBICTest->init_schema(
+  no_connect  => 1,
+  no_deploy   => 1,
+);
+
+local *DBIx::Class::Storage::DBI::connect_call_foo = sub {
+  isa_ok $_[0], 'DBIx::Class::Storage::DBI',
+    'got storage in connect_call method';
+  is $_[1], 'bar', 'got param in connect_call method';
+};
+
+local *DBIx::Class::Storage::DBI::disconnect_call_foo = sub {
+  isa_ok $_[0], 'DBIx::Class::Storage::DBI',
+    'got storage in disconnect_call method';
+};
+
+ok $schema->connection(
+  DBICTest->_database,
+  {
+    on_connect_call => [
+        [ do_sql => 'create table test1 (id integer)' ],
+        [ do_sql => [ 'insert into test1 values (?)', {}, 1 ] ],
+        [ do_sql => sub { ['insert into test1 values (2)'] } ],
+        [ sub { $_[0]->dbh->do($_[1]) }, 'insert into test1 values (3)' ],
+        [ foo => 'bar' ],
+    ],
+    on_connect_do => 'insert into test1 values (4)',
+    on_disconnect_call => 'foo',
+  },
+), 'connection()';
+
+is_deeply (
+  $schema->storage->dbh->selectall_arrayref('select * from test1'),
+  [ [ 1 ], [ 2 ], [ 3 ], [ 4 ] ],
+  'on_connect_call/do actions worked'
+);
+
+local *DBIx::Class::Storage::DBI::connect_call_foo = sub {
+  isa_ok $_[0], 'DBIx::Class::Storage::DBI',
+    'got storage in connect_call method';
+};
+
+local *DBIx::Class::Storage::DBI::connect_call_bar = sub {
+  isa_ok $_[0], 'DBIx::Class::Storage::DBI',
+    'got storage in connect_call method';
+};
+
+$schema->storage->disconnect;
+
+ok $schema->connection(
+  DBICTest->_database,
+  {
+    # method list form
+    on_connect_call => [ 'foo', sub { ok 1, "coderef in list form" }, 'bar' ],
+  },
+), 'connection()';
+
+$schema->storage->ensure_connected;




More information about the Bast-commits mailing list