package DBIx::Class::Storage::DBI::Replicated::Balancer::Random;
-use List::Util qw(shuffle);
use Moose;
-extends 'DBIx::Class::Storage::DBI::Replicated::Balancer';
+with 'DBIx::Class::Storage::DBI::Replicated::Balancer';
+use namespace::clean -except => 'meta';
=head1 NAME
-DBIx::Class::Storage::DBI::Replicated::Balancer; A Software Load Balancer
+DBIx::Class::Storage::DBI::Replicated::Balancer::Random - A 'random' Balancer
=head1 SYNOPSIS
=cut
sub next_storage {
- my $self = shift @_;
- my $next = (shuffle($self->pool->active_replicants))[0];
- return $next ? $next : $self->master;
+ 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
=cut
-1;
\ No newline at end of file
+__PACKAGE__->meta->make_immutable;
+
+1;