use BUILDARGS intead of wrapping new, added make_immutable, removed unnneeded test...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Balancer / Random.pm
index 086ee13..e90445c 100644 (file)
@@ -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