blib/lib/OD/Prometheus/Set.pm

filter: Statementstmt 98.0% 49 / 50 Branchbran 78.5% 11 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 15 / 15 Podpod 0.0% 0 / 4 totaltotal 86.9% 80 / 92 CC 13 SCAR 19.7
CC
13
Cov
91%
find
13.8
BEGIN
1.0
BEGIN
1.0
CRAP 7.2
« 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.004';
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);
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.004
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 10 ▶ 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 find {
47 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
48 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
49 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
50 8 my $value = shift;
51  
52 8 my $rs = OD::Prometheus::Set->new;
53
54 LOOP:
55 8 for my $item ( $self->metrics->@* ) {
56 8 ▶ next LOOP unless $metric eq $item->metric_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $metric eq $item->metric_name 1 7 8
57 7 for my $attr (keys $attrs->%*) {
58 5 ▶ next LOOP unless exists( $item->labels->{ $attr } );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $item->labels->{$attr} 1 4 5
59 4 ▶ next LOOP unless $attrs->{ $attr } eq $item->labels->{ $attr }
Branch: 1 branch
BranchTrueFalseTotal
unless $attrs->{$attr} eq $item->labels->{$attr} 1 3 4
60 }
61 5 ▶ if( defined( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 2 3 5
62 #say STDERR "Comparing ".$value." with ".$item->value;
63 2 ▶ if( looks_like_number( $value ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&looks_like_number($value)) { } 2 0 2
64 #say STDERR "Comparing as numbers";
65 2 ▶ next LOOP unless $value == $item->value
Branch: 1 branch
BranchTrueFalseTotal
unless $value == $item->value 1 1 2
66 }
67 else {
68 #say STDERR "Comparing as strings";
69 0 ▶ next LOOP unless $value eq $item->value
Branch: 1 branch
BranchTrueFalseTotal
unless $value eq $item->value 0 0 0
70 }
71 }
72 4 $rs->push( $item )
73 }
74 8 return $rs
75 }
76  
77  
78 1 1;
« blib/lib/OD/Prometheus/Metric.pm ↑ Summary Build »