From: Rafael Kitover Date: Mon, 31 Aug 2009 02:58:43 +0000 (+0000) Subject: make replicant dsn detection a bit nicer X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c91f8249ba6525712f09c341c9a92f4bd18f512;p=dbsrgits%2FDBIx-Class-Historic.git make replicant dsn detection a bit nicer --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm index c31cd4d..ac943f6 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm @@ -159,19 +159,13 @@ sub connect_replicants { $connect_info = [ $connect_info ] if reftype $connect_info ne 'ARRAY'; - my $replicant = $self->connect_replicant($schema, $connect_info); - my $connect_coderef = (reftype($connect_info->[0])||'') eq 'CODE' ? $connect_info->[0] : (reftype($connect_info->[0])||'') eq 'HASH' && $connect_info->[0]->{dbh_maker}; my $dsn; - if (not $connect_coderef) { - $dsn = $connect_info->[0]; - $dsn = $dsn->{dsn} if (reftype($dsn)||'') eq 'HASH'; - } - else { + my $replicant = do { # yes this is evil, but it only usually happens once no warnings 'redefine'; my $connect = \&DBI::connect; @@ -179,9 +173,15 @@ sub connect_replicants { $dsn = $_[1]; goto $connect; }; - $connect_coderef->(); + $self->connect_replicant($schema, $connect_info); + }; + + if (!$dsn && !$connect_coderef) { + $dsn = $connect_info->[0]; + $dsn = $dsn->{dsn} if (reftype($dsn)||'') eq 'HASH'; } $replicant->dsn($dsn); + my ($key) = ($dsn =~ m/^dbi\:.+\:(.+)$/i); $self->set_replicant($key => $replicant);