}
## Get a replicant, or the master if none
- my $next = $self->$next_storage(@args);
- return $next ? $next:$self->master;
+ if(my $next = $self->$next_storage(@args)) {
+ return $next;
+ } else {
+ return $self->master;
+ }
};
=head2 increment_storage
my ($select_single, $self, @args) = @_;
if (my $forced_pool = $args[-1]->{force_pool}) {
- delete $args[-1]->{force_pool};
- return $self->_get_forced_pool($forced_pool)->select_single(@args);
+ delete $args[-1]->{force_pool};
+ return $self->_get_forced_pool($forced_pool)->select_single(@args);
} else {
- $self->increment_storage;
+ $self->increment_storage;
return $self->$select_single(@args);
}
};
package DBIx::Class::Storage::DBI::Replicated::Balancer::Random;
-use List::Util qw(shuffle);
use Moose;
with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
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[int(rand($count_active_replicants +1))];
+ return $active_replicants[$random_replicant];
}
=head1 AUTHOR