podcoverage test now requires minimum 0.19 version for Pod::Coverage and changed...
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Replicated / Balancer / Random.pm
index e37b291..6f786d3 100644 (file)
@@ -1,12 +1,11 @@
 package DBIx::Class::Storage::DBI::Replicated::Balancer::Random;
 
-use List::Util qw(shuffle);
 use Moose;
 with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
 
 =head1 NAME
 
-DBIx::Class::Storage::DBI::Replicated::Balancer::Random; A 'random' Balancer
+DBIx::Class::Storage::DBI::Replicated::Balancer::Random - A 'random' Balancer
 
 =head1 SYNOPSIS
 
@@ -40,7 +39,12 @@ 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;
+  my $random_replicant = int(rand($count_active_replicants));
+  
+  return $active_replicants[$random_replicant];
 }
 
 =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