From: Brandon L. Black Date: Tue, 22 May 2007 01:40:14 +0000 (+0000) Subject: Merge 'trunk' into 'DBIx-Class-current' X-Git-Tag: v0.08010~150^2~57 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=541df64afe67cde2a5cd2c48c1cb419298452a1f Merge 'trunk' into 'DBIx-Class-current' r30913@brandon-blacks-computer (orig r3263): matthewt | 2007-05-06 11:52:36 -0500 patch from soulchild (thanks!) r31140@brandon-blacks-computer (orig r3318): castaway | 2007-05-17 07:56:49 -0500 Applied patch from Pedro Melo to fix order of components in the example r31938@brandon-blacks-computer (orig r3348): ilmari | 2007-05-21 15:23:36 -0500 Copy the working mk_hash from HashRefInflator in -current into Cookbook r31946@brandon-blacks-computer (orig r3355): blblack | 2007-05-21 20:21:42 -0500 connect_info should return the same data it was given --- 541df64afe67cde2a5cd2c48c1cb419298452a1f diff --cc lib/DBIx/Class/Storage/DBI.pm index 860cc36,bc66144..7e86c00 --- a/lib/DBIx/Class/Storage/DBI.pm +++ b/lib/DBIx/Class/Storage/DBI.pm @@@ -10,14 -10,7 +10,14 @@@ use SQL::Abstract::Limit use DBIx::Class::Storage::DBI::Cursor; use DBIx::Class::Storage::Statistics; use IO::File; -use Carp::Clan qw/DBIx::Class/; +use Scalar::Util 'blessed'; + - __PACKAGE__->mk_group_accessors( - 'simple' => - qw/_connect_info _dbh _sql_maker _sql_maker_opts _conn_pid _conn_tid - disable_sth_caching cursor on_connect_do transaction_depth/ ++__PACKAGE__->mk_group_accessors('simple' => ++ qw/_connect_info _dbi_connect_info _dbh _sql_maker _sql_maker_opts ++ _conn_pid _conn_tid disable_sth_caching cursor on_connect_do ++ transaction_depth/ +); + BEGIN { package DBIC::SQL::Abstract; # Would merge upstream, but nate doesn't reply :( @@@ -453,58 -448,6 +453,61 @@@ Examples ] ); +=cut + +sub connect_info { + my ($self, $info_arg) = @_; + + return $self->_connect_info if !$info_arg; + + # Kill sql_maker/_sql_maker_opts, so we get a fresh one with only + # the new set of options + $self->_sql_maker(undef); + $self->_sql_maker_opts({}); ++ $self->_connect_info($info_arg); + - my $info = [ @$info_arg ]; # copy because we can alter it - my $last_info = $info->[-1]; ++ my $dbi_info = [@$info_arg]; # copy for DBI ++ my $last_info = $dbi_info->[-1]; + if(ref $last_info eq 'HASH') { + for my $storage_opt (qw/on_connect_do disable_sth_caching/) { + if(my $value = delete $last_info->{$storage_opt}) { + $self->$storage_opt($value); + } + } + for my $sql_maker_opt (qw/limit_dialect quote_char name_sep/) { + if(my $opt_val = delete $last_info->{$sql_maker_opt}) { + $self->_sql_maker_opts->{$sql_maker_opt} = $opt_val; + } + } + + # Get rid of any trailing empty hashref - pop(@$info) if !keys %$last_info; ++ pop(@$dbi_info) if !keys %$last_info; + } + - if(ref $info->[0] ne 'CODE') { ++ $self->_dbi_connect_info($dbi_info); ++ ++ if(ref $dbi_info->[0] ne 'CODE') { + # Extend to 3 arguments with undefs, if necessary - while(scalar(@$info) < 3) { push(@$info, undef) } ++ while(scalar(@$dbi_info) < 3) { push(@$dbi_info, undef) } + + # Complain if 4th argument is defined and is not a HASH - if(defined $info->[3] && ref $info->[3] ne 'HASH') { ++ if(defined $dbi_info->[3] && ref $dbi_info->[3] ne 'HASH') { + warn "4th argument of DBI connect info is defined " + . " but is not a hashref!"; + } + + # Set AutoCommit to 1 if not specified manually + else { - $info->[3] ||= {}; - if(!defined $info->[3]->{AutoCommit}) { - $info->[3]->{AutoCommit} = 1; ++ $dbi_info->[3] ||= {}; ++ if(!defined $dbi_info->[3]->{AutoCommit}) { ++ $dbi_info->[3]->{AutoCommit} = 1; + } + } + } + - $self->_connect_info($info); ++ $self->_connect_info; +} + =head2 on_connect_do This method is deprecated in favor of setting via L. @@@ -723,15 -591,43 +726,15 @@@ sub sql_maker return $self->_sql_maker; } -sub connect_info { - my ($self, $info_arg) = @_; - - if($info_arg) { - # Kill sql_maker/_sql_maker_opts, so we get a fresh one with only - # the new set of options - $self->_sql_maker(undef); - $self->_sql_maker_opts({}); - $self->_connect_info($info_arg); - - my $dbi_info = [@$info_arg]; # copy for DBI - my $last_info = $dbi_info->[-1]; - if(ref $last_info eq 'HASH') { - if(my $on_connect_do = delete $last_info->{on_connect_do}) { - $self->on_connect_do($on_connect_do); - } - for my $sql_maker_opt (qw/limit_dialect quote_char name_sep/) { - if(my $opt_val = delete $last_info->{$sql_maker_opt}) { - $self->_sql_maker_opts->{$sql_maker_opt} = $opt_val; - } - } - - # Get rid of any trailing empty hashref - pop(@$dbi_info) if !keys %$last_info; - } - - $self->_dbi_connect_info($dbi_info); - } - - $self->_connect_info; -} - sub _populate_dbh { my ($self) = @_; - my @info = @{$self->_connect_info || []}; + my @info = @{$self->_dbi_connect_info || []}; $self->_dbh($self->_connect(@info)); + # Always set the transaction depth on connect, since + # there is no transaction in progress by definition + $self->{transaction_depth} = $self->_dbh->{AutoCommit} ? 0 : 1; + if(ref $self eq 'DBIx::Class::Storage::DBI') { my $driver = $self->_dbh->{Driver}->{Name}; if ($self->load_optional_class("DBIx::Class::Storage::DBI::${driver}")) {