lib/IO/K8s/Role/Loadbalanced.pm

filter: Statementstmt 100% 17 / 17 Branchbran 75.0% 3 / 4 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 3 / 3 Podpod 100% 2 / 2 totaltotal 89.6% 26 / 29 CC 5 SCAR 11.0
CC
5
Cov
91%
set_weighted
4.0
mirror_to
2.0
BEGIN
1.0
CRAP 3.0
« lib/IO/K8s/Role/NetworkPolicy.pm ↑ Summary lib/IO/K8s/ApiextensionsApiserver/Pkg/Apis/Apiextensions/V1/JSONSchemaPropsOrStringArray.pm »
1 package IO::K8s::Role::Loadbalanced;
2 # ABSTRACT: Role for traffic distribution (weighted backends, mirroring)
3 7 our $VERSION = '1.112';
4 7 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 # The fluent setters below build the spec through IO::K8s::Role::SpecBuilder
7 # rather than by hand, so that role is a hard dependency of this one (k103).
8 # IO::K8s::Role::APIObject composes SpecBuilder for every top-level Kind, so
9 # these are satisfied for anything built with IO::K8s::APIObject; a class
10 # that composes this role without them now fails at composition time,
11 # naming the missing method, instead of at the first setter call.
12 7 requires qw( spec_array spec_get spec_push spec_set );
13  
14  
15 7 ▶sub set_weighted {
Subroutine set_weighted: called CC=4 SCAR=13.9
Pod documented
16 7 my ($self, $name, $weight) = @_;
17 7 my $services = $self->spec_array('weighted.services');
18 7 for my $i (0 .. $#$services) {
19 4 ▶ next unless ($self->spec_get("weighted.services.$i.name") // '') eq $name;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->spec_get("weighted.services.$i.name") // "") eq $name 2 2 4
Condition50%1/2
$self->spec_get("weighted.services.$i.name") // ""
l!l
40
MC/DC0%0/1
$self->spec_get("weighted.services.$i.name") // ""
$self->spec_get("weighted.services.$i.name")
Truth table50%1/2
A
A= $self->spec_get("weighted.services.$i.name")
Aresult
11
00
20 2 $self->spec_set("weighted.services.$i.weight", $weight);
21 2 return $self;
22 }
23 5 $self->spec_push('weighted.services', { name => $name, weight => $weight });
24 5 return $self;
25 }
26  
27  
28 2 ▶sub mirror_to {
Subroutine mirror_to: called CC=2 SCAR=7.1
Pod documented
29 2 my ($self, $name, %opts) = @_;
30 $self->spec_push('mirroring.mirrors', {
31 name => $name,
32 2 ▶ $opts{percent} ? (percent => $opts{percent}) : (),
Branch: 1 branch
BranchTrueFalseTotal
$opts{'percent'} ? : 2 0 2
33 });
34 2 return $self;
35 }
36  
37 7 1;
38  
39 __END__
« lib/IO/K8s/Role/NetworkPolicy.pm ↑ Summary lib/IO/K8s/ApiextensionsApiserver/Pkg/Apis/Apiextensions/V1/JSONSchemaPropsOrStringArray.pm »