From: Justin Hunter Date: Sun, 23 Jan 2011 14:27:45 +0000 (+0000) Subject: clean up the logic a little bit X-Git-Tag: v1.1.0~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class-Cursor-Cached.git;a=commitdiff_plain;h=a7f2916ab51f759906a6084f4e4d160b6414524c clean up the logic a little bit --- diff --git a/lib/DBIx/Class/Cursor/Cached.pm b/lib/DBIx/Class/Cursor/Cached.pm index 758cf5d..70bd04a 100644 --- a/lib/DBIx/Class/Cursor/Cached.pm +++ b/lib/DBIx/Class/Cursor/Cached.pm @@ -5,6 +5,7 @@ use warnings; use 5.6.1; use Storable (); use Digest::SHA1 (); +use Carp::Clan qw/^DBIx::Class/; use vars qw($VERSION); @@ -52,15 +53,20 @@ sub _build_cache_key { # so the cache key is only affected by what the database sees # and not any other cruft in $attrs my $ref = $storage->_select_args_to_query(@{$args}[0..2], $attrs); - my $connect_info = $storage->_dbi_connect_info; - my ($dbname, $username); - if (ref($connect_info->[0]) eq 'CODE') { - my $dbh = $connect_info->[0]->(); + + my ($connect_info, $dbname, $username); + $connect_info = $storage->_dbi_connect_info; + if (my $dbh = $storage->_dbh) { $dbname = $dbh->{Name}; $username = $dbh->{Username} || ''; - } else { + } elsif (! ref($connect_info->[0]) ) { $dbname = $connect_info->[0]; $username = $connect_info->[1] || ''; + } else { + carp "Invoking connector coderef $connect_info->[0] in order to obtain cache-lookup information"; + my $dbh = $connect_info->[0]->(); + $dbname = $dbh->{Name}; + $username = $dbh->{Username} || ''; } local $Storable::canonical = 1;