| 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")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 48 | 8 | ▶ | my $metric = shift // die 'incorrect call'; | ||||||||||
|
Condition50%1/2
shift() // die("incorrect call")
MC/DC0%0/1
shift() // die("incorrect call")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||
| 49 | 8 | ▶ | my $attrs = shift // {}; | ||||||||||
|
Condition100%2/2
shift() // {}
MC/DC100%1/1
shift() // {}
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 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
| |||||||||||||
| 57 | 7 | for my $attr (keys $attrs->%*) { | |||||||||||
| 58 | 5 | ▶ | next LOOP unless exists( $item->labels->{ $attr } ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | 4 | ▶ | next LOOP unless $attrs->{ $attr } eq $item->labels->{ $attr } | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | } | ||||||||||||
| 61 | 5 | ▶ | if( defined( $value ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 62 | #say STDERR "Comparing ".$value." with ".$item->value; | ||||||||||||
| 63 | 2 | ▶ | if( looks_like_number( $value ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 64 | #say STDERR "Comparing as numbers"; | ||||||||||||
| 65 | 2 | ▶ | next LOOP unless $value == $item->value | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 66 | } | ||||||||||||
| 67 | else { | ||||||||||||
| 68 | #say STDERR "Comparing as strings"; | ||||||||||||
| 69 | 0 | ▶ | next LOOP unless $value eq $item->value | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 70 | } | ||||||||||||
| 71 | } | ||||||||||||
| 72 | 4 | $rs->push( $item ) | |||||||||||
| 73 | } | ||||||||||||
| 74 | 8 | return $rs | |||||||||||
| 75 | } | ||||||||||||
| 76 | |||||||||||||
| 77 | |||||||||||||
| 78 | 1 | 1; | |||||||||||