non-destructive hashref handling for connect_info options
Matt S Trout [Tue, 17 Jul 2007 23:18:25 +0000 (23:18 +0000)]
Changes
lib/DBIx/Class/Storage/DBI.pm
t/92storage.t

diff --git a/Changes b/Changes
index 3d7ef2d..b94d2b5 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 Revision history for DBIx::Class
 
+        - non-destructive hashref handling for connect_info options
         - count no longer returns negative values after slice
           (report and test from JOHANL)
         - rebless before building datetime_parser
index cde6ac5..336ab1f 100644 (file)
@@ -479,6 +479,7 @@ sub connect_info {
 
   my $last_info = $dbi_info->[-1];
   if(ref $last_info eq 'HASH') {
+    $last_info = { %$last_info }; # so delete is non-destructive
     for my $storage_opt (qw/on_connect_do disable_sth_caching unsafe/) {
       if(my $value = delete $last_info->{$storage_opt}) {
         $self->$storage_opt($value);
@@ -489,6 +490,8 @@ sub connect_info {
         $self->_sql_maker_opts->{$sql_maker_opt} = $opt_val;
       }
     }
+    # re-insert modified hashref
+    $dbi_info->[-1] = $last_info;
 
     # Get rid of any trailing empty hashref
     pop(@$dbi_info) if !keys %$last_info;
index 6eee862..127b66c 100644 (file)
@@ -32,7 +32,7 @@ use DBICTest;
     }
 }
 
-plan tests => 5;
+plan tests => 6;
 
 my $schema = DBICTest->init_schema();
 
@@ -64,5 +64,10 @@ is($@, "", "Exploding \$sth->execute was caught");
 is(1, $schema->resultset('Artist')->search({name => "Exploding Sheep" })->count,
   "And the STH was retired");
 
+my $info = { on_connect_do => [] };
+
+$storage->connect_info(['foo','bar','baz',$info]);
+
+ok(exists($info->{on_connect_do}), q{Didn't kill key passed to storage});
 
 1;