X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FStorage%2FDBI%2FReplicated%2FBalancer%2FRandom.pm;h=e90445c9cd1dbae12fc2f2898f7c225cca00a641;hb=c354902c20a8459162b76a4006cb6091af5bf6d4;hp=086ee136e108c52a2c2207d0875ef7e05e9e838f;hpb=64cdad22d9b4022de379ae43174c15ce8dc81b59;p=dbsrgits%2FDBIx-Class.git 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