From: Matt S Trout Date: Tue, 17 Jul 2007 23:18:25 +0000 (+0000) Subject: non-destructive hashref handling for connect_info options X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9a0891be053bee63872959e94da0d790934d48bf;p=dbsrgits%2FDBIx-Class-Historic.git non-destructive hashref handling for connect_info options --- diff --git a/Changes b/Changes index 3d7ef2d..b94d2b5 100644 --- 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 diff --git a/lib/DBIx/Class/Storage/DBI.pm b/lib/DBIx/Class/Storage/DBI.pm index cde6ac5..336ab1f 100644 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@ -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; diff --git a/t/92storage.t b/t/92storage.t index 6eee862..127b66c04 100644 --- a/t/92storage.t +++ b/t/92storage.t @@ -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;