[Bast-commits] r4562 - in DBIx-Class/0.08/branches/replication_dedux: lib/DBIx/Class/Storage/DBI lib/DBIx/Class/Storage/DBI/Replicated lib/DBIx/Class/Storage/DBI/Replicated/Balancer t

jnapiorkowski at dev.catalyst.perl.org jnapiorkowski at dev.catalyst.perl.org
Wed Jul 9 18:35:06 BST 2008


Author: jnapiorkowski
Date: 2008-07-09 18:35:06 +0100 (Wed, 09 Jul 2008)
New Revision: 4562

Modified:
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
   DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
   DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
Log:
use BUILDARGS intead of wrapping new, added make_immutable, removed unnneeded test, added some docs

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm	2008-07-09 16:11:10 UTC (rev 4561)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm	2008-07-09 17:35:06 UTC (rev 4562)
@@ -1,6 +1,5 @@
 package DBIx::Class::Storage::DBI::Replicated::Balancer::First;
 
-use List::Util qw(shuffle);
 use Moose;
 with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
 
@@ -49,4 +48,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 1;
\ No newline at end of file

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2008-07-09 16:11:10 UTC (rev 4561)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm	2008-07-09 17:35:06 UTC (rev 4562)
@@ -40,7 +40,11 @@
 =cut
 
 sub next_storage {
-  return  (shuffle(shift->pool->active_replicants))[0];
+  my $self = shift @_;
+  my @active_replicants = $self->pool->active_replicants;
+  my $count_active_replicants = $#active_replicants +1;
+  
+  return $active_replicants[int(rand($count_active_replicants +1))];
 }
 
 =head1 AUTHOR
@@ -53,4 +57,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 1;
\ No newline at end of file

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-07-09 16:11:10 UTC (rev 4561)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm	2008-07-09 17:35:06 UTC (rev 4562)
@@ -271,4 +271,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 1;

Modified: DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-07-09 16:11:10 UTC (rev 4561)
+++ DBIx-Class/0.08/branches/replication_dedux/lib/DBIx/Class/Storage/DBI/Replicated.pm	2008-07-09 17:35:06 UTC (rev 4562)
@@ -287,7 +287,7 @@
 
 This class defines the following methods.
 
-=head2 new
+=head2 BUILDARGS
 
 L<DBIx::Class::Schema> when instantiating it's storage passed itself as the
 first argument.  So we need to massage the arguments a bit so that all the
@@ -295,10 +295,15 @@
 
 =cut
 
-around 'new' => sub {
-  my ($new, $self, $schema, $storage_type_args, @args) = @_;
-  return $self->$new(schema=>$schema, %$storage_type_args, @args);
-};
+sub BUILDARGS {
+  my ($class, $schema, $storage_type_args, @args) = @_;	
+  
+  return {
+  	schema=>$schema, 
+  	%$storage_type_args,
+  	@args
+  }
+}
 
 =head2 _build_master
 
@@ -691,4 +696,6 @@
 
 =cut
 
+__PACKAGE__->meta->make_immutable;
+
 1;

Modified: DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t
===================================================================
--- DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-07-09 16:11:10 UTC (rev 4561)
+++ DBIx-Class/0.08/branches/replication_dedux/t/93storage_replication.t	2008-07-09 17:35:06 UTC (rev 4562)
@@ -9,7 +9,7 @@
     eval "use Moose; use Test::Moose";
     plan $@
         ? ( skip_all => 'needs Moose for testing' )
-        : ( tests => 80 );
+        : ( tests => 79 );
 }
 
 use_ok 'DBIx::Class::Storage::DBI::Replicated::Pool';
@@ -270,20 +270,6 @@
         [ 7, "Watergate"],
     ]);
 
-SKIP: {
-    ## We can't do this test if we have a custom replicants, since we assume
-    ## if there are custom one that you are trying to test a real replicating
-    ## system.  See docs above for more.
-    
-    skip 'Cannot test inconsistent replication since you have a real replication system', 1
-     if DBICTest->has_custom_dsn && $ENV{"DBICTEST_SLAVE0_DSN"};
-    
-	## Alright, the database 'cluster' is not in a consistent state.  When we do
-	## a read now we expect bad news    
-    is $replicated->schema->resultset('Artist')->find(5), undef
-    => 'read after disconnect fails because it uses a replicant which we have neglected to "replicate" yet'; 
-}
-
 ## Make sure all the slaves have the table definitions
 $replicated->replicate;
 




More information about the Bast-commits mailing list