[Bast-commits] r7448 - DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated

caelum at dev.catalyst.perl.org caelum at dev.catalyst.perl.org
Mon Aug 31 15:30:37 GMT 2009


Author: caelum
Date: 2009-08-31 15:30:37 +0000 (Mon, 31 Aug 2009)
New Revision: 7448

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm
Log:
fix case where repelicant coderef dsn does not connect

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2009-08-31 02:58:43 UTC (rev 7447)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2009-08-31 15:30:37 UTC (rev 7448)
@@ -138,6 +138,16 @@
   },
 );
 
+has next_unknown_replicant_id => (
+  is => 'rw',
+  metaclass => 'Counter',
+  isa => Int,
+  default => 1,
+  provides => {
+    inc => 'inc_unknown_replicant_id'
+  },
+);
+
 =head1 METHODS
 
 This class defines the following methods.
@@ -166,7 +176,8 @@
 
     my $dsn;
     my $replicant = do {
-# yes this is evil, but it only usually happens once
+# yes this is evil, but it only usually happens once (for coderefs)
+# this will fail if the coderef does not actually DBI::connect
       no warnings 'redefine';
       my $connect = \&DBI::connect;
       local *DBI::connect = sub {
@@ -176,15 +187,27 @@
       $self->connect_replicant($schema, $connect_info);
     };
 
-    if (!$dsn && !$connect_coderef) {
-      $dsn = $connect_info->[0];
-      $dsn = $dsn->{dsn} if (reftype($dsn)||'') eq 'HASH';
+    my $key;
+
+    if (!$dsn) {
+      if (!$connect_coderef) {
+        $dsn = $connect_info->[0];
+        $dsn = $dsn->{dsn} if (reftype($dsn)||'') eq 'HASH';
+      }
+      else {
+        # all attempts to get the DSN failed
+        $key = "UNKNOWN_" . $self->next_unknown_replicant_id;
+        $self->inc_unknown_replicant_id;
+      }
     }
-    $replicant->dsn($dsn);
+    if ($dsn) {
+      $replicant->dsn($dsn);
+      ($key) = ($dsn =~ m/^dbi\:.+\:(.+)$/i);
+    }
 
-    my ($key) = ($dsn =~ m/^dbi\:.+\:(.+)$/i);
+    $replicant->id($key);
+    $self->set_replicant($key => $replicant);  
 
-    $self->set_replicant($key => $replicant);  
     push @newly_created, $replicant;
   }
 

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm	2009-08-31 02:58:43 UTC (rev 7447)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/Replicant.pm	2009-08-31 15:30:37 UTC (rev 7448)
@@ -52,10 +52,8 @@
   default=>1,
 );
 
-has dsn => (
-  is => 'rw',
-  isa => Str,
-);
+has dsn => (is => 'rw', isa => Str);
+has id  => (is => 'rw', isa => Str);
 
 =head1 METHODS
 

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm	2009-08-31 02:58:43 UTC (rev 7447)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Storage/DBI/Replicated/WithDSN.pm	2009-08-31 15:30:37 UTC (rev 7448)
@@ -41,6 +41,9 @@
     if ((reftype($dsn)||'') ne 'CODE') {
       "$op [DSN_$storage_type=$dsn]$rest";
     }
+    elsif (my $id = eval { $self->id }) {
+      "$op [$storage_type=$id]$rest";
+    }
     else {
       "$op [$storage_type]$rest";
     }




More information about the Bast-commits mailing list