[Bast-commits] r7433 - in
DBIx-Class/0.08/branches/connect_info_hash:
lib/DBIx/Class/Storage t/storage
caelum at dev.catalyst.perl.org
caelum at dev.catalyst.perl.org
Sun Aug 30 01:14:36 GMT 2009
Author: caelum
Date: 2009-08-30 01:14:36 +0000 (Sun, 30 Aug 2009)
New Revision: 7433
Modified:
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:
add dbh_maker option to connect_info hash
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 00:53:21 UTC (rev 7432)
+++ DBIx-Class/0.08/branches/connect_info_hash/lib/DBIx/Class/Storage/DBI.pm 2009-08-30 01:14:36 UTC (rev 7433)
@@ -125,6 +125,9 @@
</connect_info>
</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>.
+
=back
Please note that the L<DBI> docs recommend that you always explicitly
@@ -337,6 +340,12 @@
# Connect via subref
->connect_info([ sub { DBI->connect(...) } ]);
+ # Connect via subref in hashref
+ ->connect_info([{
+ dbh_maker => sub { DBI->connect(...) },
+ on_connect_do => 'alter session ...',
+ }]);
+
# A bit more complicated
->connect_info(
[
@@ -407,9 +416,16 @@
elsif (ref $args[0] eq 'HASH') { # single hashref (i.e. Catalyst config)
%attrs = %{$args[0]};
@args = ();
- for (qw/password user dsn/) {
- unshift @args, delete $attrs{$_};
+ 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';
+ }
}
+ else {
+ @args = delete @attrs{qw/dsn user password/};
+ }
}
else { # otherwise assume dsn/user/password + \%attrs + \%extra_attrs
%attrs = (
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 00:53:21 UTC (rev 7432)
+++ DBIx-Class/0.08/branches/connect_info_hash/t/storage/base.t 2009-08-30 01:14:36 UTC (rev 7433)
@@ -33,7 +33,7 @@
}
}
-plan tests => 17;
+plan tests => 21;
my $schema = DBICTest->init_schema( sqlite_use_file => 1 );
@@ -145,6 +145,16 @@
},
],
},
+ 'connect_info ([ \%attr_with_coderef ])' => {
+ args => [ {
+ dbh_maker => $coderef,
+ on_connect_do => [qw/a b c/],
+ on_disconnect_do => [qw/d e f/],
+ } ],
+ dbi_connect_info => [
+ $coderef
+ ],
+ },
};
for my $type (keys %$invocations) {
More information about the Bast-commits
mailing list