blib/lib/DBIO/Replicated/Balancer/Random.pm

filter: Statementstmt 54.5% 12 / 22 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 100% 2 / 2 totaltotal 47.2% 17 / 36 CC 4 SCAR 17.7
CC
4
Cov
43%
next_storage
12.0
new
6.0
_random_number
2.0
CRAP 5.9
« blib/lib/DBIO/InflateColumn.pm ↑ Summary blib/lib/DBIO/Deploy/Base.pm »
1 package DBIO::Replicated::Balancer::Random;
2 # ABSTRACT: Randomly choose an active replicant
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.900007';
8  
9 2 ▶use base 'DBIO::Replicated::Balancer';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 __PACKAGE__->mk_group_accessors(simple => 'master_read_weight');
12  
13  
14 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
15 0 my ($class, %args) = @_;
16 0 my $self = $class->SUPER::new(%args);
17 0 ▶ $self->master_read_weight(exists $args{master_read_weight} ? $args{master_read_weight} : 0);
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'master_read_weight'} ? : 0 0 0
18 0 return $self;
19 }
20  
21  
22 0 ▶sub next_storage {
Subroutine next_storage: not called CC=3 SCAR=24.8
Pod documented
23 0 my $self = shift;
24  
25 0 my @replicants = $self->pool->active_replicants;
26 0 ▶ return if not @replicants;
Branch: 1 branch
BranchTrueFalseTotal
unless @replicants 0 0 0
27  
28 0 my $rnd = $self->_random_number(@replicants + $self->master_read_weight);
29 0 ▶ return $rnd >= @replicants ? $self->master : $replicants[int $rnd];
Branch: 1 branch
BranchTrueFalseTotal
$rnd >= @replicants ? : 0 0 0
30 }
31  
32 0 ▶sub _random_number {
Subroutine _random_number: not called CC=1 SCAR=6.9
33 0 rand($_[1]);
34 }
35  
36 2 1;
37  
38 __END__
« blib/lib/DBIO/InflateColumn.pm ↑ Summary blib/lib/DBIO/Deploy/Base.pm »