From: John Napiorkowski Date: Wed, 9 Jul 2008 17:35:06 +0000 (+0000) Subject: use BUILDARGS intead of wrapping new, added make_immutable, removed unnneeded test... X-Git-Tag: v0.08240~402^2~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c354902c;p=dbsrgits%2FDBIx-Class.git use BUILDARGS intead of wrapping new, added make_immutable, removed unnneeded test, added some docs --- diff --git a/lib/DBIx/Class/Storage/DBI/Replicated.pm b/lib/DBIx/Class/Storage/DBI/Replicated.pm index d711f84..4790f9a 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated.pm @@ -287,7 +287,7 @@ has 'write_handler' => ( This class defines the following methods. -=head2 new +=head2 BUILDARGS L 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 @@ bits get put into the correct places. =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 @@ You may distribute this code under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; + 1; diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm index 9ccc406..7c7ac6c 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/First.pm @@ -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 @@ You may distribute this code under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; + 1; \ No newline at end of file diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm index 086ee13..e90445c 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Balancer/Random.pm @@ -40,7 +40,11 @@ be requested several times in a row. =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 @@ You may distribute this code under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; + 1; \ No newline at end of file diff --git a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm index 9d314c0..6fe7046 100644 --- a/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm +++ b/lib/DBIx/Class/Storage/DBI/Replicated/Pool.pm @@ -271,4 +271,6 @@ You may distribute this code under the same terms as Perl itself. =cut +__PACKAGE__->meta->make_immutable; + 1; diff --git a/t/93storage_replication.t b/t/93storage_replication.t index 46c2295..854841b 100644 --- a/t/93storage_replication.t +++ b/t/93storage_replication.t @@ -9,7 +9,7 @@ BEGIN { 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 @@ $replicated [ 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;