blib/lib/OD/Prometheus/Set.pm

filter: Statementstmt 96.6% 57 / 59 Branchbran 72.2% 13 / 18 Conditioncond 60.0% 6 / 10 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 94.7% 18 / 19 Podpod 0.0% 0 / 8 totaltotal 79.8% 95 / 119 CC 18 SCAR 18.5
CC
18
Cov
87%
find
13.8
each
5.5
value
2.1
CRAP 6.3
« blib/lib/OD/Prometheus/Metric.pm ↑ Summary Build »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package OD::Prometheus::Set;
5 1 $OD::Prometheus::Set::VERSION = '0.005';
6 1 ▶use v5.24;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Scalar::Util qw(looks_like_number reftype);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use OD::Prometheus::Metric;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 =head1 NAME
14  
15 OD::Prometheus::Set - A set of Prometheus metrics
16  
17 =head1 VERSION
18  
19 version 0.005
20  
21 =cut
22  
23 use overload
24 1 ▶ '@{}' => sub { $_[0]->metrics }
Subroutine __ANON__: called CC=1 SCAR=0.0
25 1 ▶;
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 has metrics => (
28 is => 'ro',
29 isa => 'ArrayRef[OD::Prometheus::Metric]',
30 9 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 1 );
32  
33  
34 sub push {
35 5 ▶ push shift->metrics->@*, @_
Subroutine push: called CC=1 SCAR=0.0
Pod undocumented
36 }
37  
38 sub size {
39 11 ▶ scalar $_[0]->metrics->@*
Subroutine size: called CC=1 SCAR=0.0
Pod undocumented
40 }
41  
42 sub is_empty {
43 9 ▶ $_[0]->size == 0
Subroutine is_empty: called CC=1 SCAR=0.0
Pod undocumented
44 }
45  
46 sub pop {
47 0 ▶ pop $_[0]->metrics->@*
Subroutine pop: not called CC=1 SCAR=6.9
Pod undocumented
48 }
49  
50 sub item {
51 1 ▶ $_[0]->metrics->[ $_[1] ]
Subroutine item: called CC=1 SCAR=0.0
Pod undocumented
52 }
53  
54 sub find {
55 8 ▶ my $self = shift // die 'incorrect call';
Subroutine find: called CC=13 SCAR=26.2
Pod undocumented
Condition50%1/2
shift() // die("incorrect call")
l!l
80
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
56 8 ▶ my $metric = shift // die 'incorrect call';
Condition50%1/2
shift() // die("incorrect call")
l!l
80
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
57 8 ▶ my $attrs = shift // {};
Condition100%2/2
shift() // {}
l!l
71
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
58 8 my $value = shift;
59  
60 8 my $rs = OD::Prometheus::Set->new;
61
62 LOOP:
63 8 for my $item ( $self->metrics->@* ) {
64 8 ▶ next LOOP unless $metric eq $item->metric_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $metric eq $item->metric_name 1 7 8
65 7 for my $attr (keys $attrs->%*) {
66 5 ▶ next LOOP unless exists( $item->labels->{ $attr } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $item->labels->{$attr} 1 4 5
67 4 ▶ next LOOP unless $attrs->{ $attr } eq $item->labels->{ $attr }
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs->{$attr} eq $item->labels->{$attr} 1 3 4
68 }
69 5 ▶ if( defined( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 3 5
70 #say STDERR "Comparing ".$value." with ".$item->value;
71 2 ▶ if( looks_like_number( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($value)) { } 2 0 2
72 #say STDERR "Comparing as numbers";
73 2 ▶ next LOOP unless $value == $item->value
Branch: 1 branch
BranchTrueFalseTotal
unless $value == $item->value 1 1 2
74 }
75 else {
76 #say STDERR "Comparing as strings";
77 0 ▶ next LOOP unless $value eq $item->value
Branch: 1 branch
BranchTrueFalseTotal
unless $value eq $item->value 0 0 0
78 }
79 }
80 4 $rs->push( $item )
81 }
82 8 return $rs
83 }
84  
85 sub each {
86 1 ▶ my $self = shift // die 'incorrect call';
Subroutine each: called CC=5 SCAR=17.1
Pod undocumented
Condition50%1/2
shift() // die("incorrect call")
l!l
10
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
87 1 ▶ my $func = shift // die 'incorrect call';
Condition50%1/2
shift() // die("incorrect call")
l!l
10
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
88 1 ▶ die '2nd argument must be a subroutine reference' unless reftype( $func ) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::reftype($func) eq "CODE" 0 1 1
89 1 for ( $self->metrics->@* ) {
90 1 $func->()
91 }
92 }
93  
94 sub value {
95 1 ▶ die 'Please do not call value on a Set that does not have exactly 1 item' unless $_[0]->size == 1;
Subroutine value: called CC=2 SCAR=7.2
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->size == 1 0 1 1
96 1 $_[0]->item(0)->value
97 }
98  
99  
100 1 1;
« blib/lib/OD/Prometheus/Metric.pm ↑ Summary Build »