blib/lib/Net/Prometheus/Registry.pm

filter: Statementstmt 100% 27 / 27 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 4 / 4 totaltotal 86.7% 46 / 53 CC 6 SCAR 8.4
CC
6
Cov
87%
unregister
4.6
register
2.0
collectors
2.0
CRAP 2.3
« blib/lib/Net/Prometheus/PerlCollector.pm ↑ Summary blib/lib/Net/Prometheus/ProcessCollector.pm »
1 # You may distribute under the terms of either the GNU General Public License
2 # or the Artistic License (the same terms as Perl itself)
3 #
4 # (C) Paul Evans, 2020-2026 -- leonerd@leonerd.org.uk
5  
6 package Net::Prometheus::Registry 0.16;
7  
8 10 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 10 ▶use feature qw( signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 10 ▶no warnings qw( experimental::signatures );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 =head1 NAME
17  
18 C<Net::Prometheus::Registry> - a collection of metrics collectors
19  
20 =head1 DESCRIPTION
21  
22 This class, or instances of it, acts as a simple storage array for instances
23 derived from L<Net::Prometheus::Metric>, known as "collectors".
24  
25 A single global collection is stored by the module, accessible via the class
26 methods. Additional collections may be made with the constructor and then
27 accessed by instance methods.
28  
29 =cut
30  
31 # These are the global ones
32 10 my @COLLECTORS;
33  
34 =head1 CONSTRUCTOR
35  
36 =for highlighter language=perl
37  
38 =cut
39  
40 =head2 new
41  
42 $registry = Net::Prometheus::Registry->new;
43  
44 Returns a new registry instance.
45  
46 =cut
47  
48 11 ▶sub new ( $class )
Subroutine new: called CC=1 SCAR=0.0
Pod documented
49 {
50 11 return bless [], $class;
51 }
52  
53 =head1 METHODS
54  
55 =cut
56  
57 =head2 register
58  
59 $collector = Net::Prometheus::Registry->register( $collector );
60 $collector = $registry->register( $collector );
61  
62 Adds a new collector to the registry. The collector instance itself is
63 returned, for convenience of chaining method calls on it.
64  
65 =cut
66  
67 21 ▶sub register ( $self, $collector )
Subroutine register: called CC=2 SCAR=7.1
Pod documented
68 {
69 21 ▶ my $collectors = ( ref $self ) ? $self : \@COLLECTORS;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 21 0 21
70  
71 # TODO: ban duplicate registration
72 21 push @$collectors, $collector;
73  
74 21 return $collector;
75 }
76  
77 =head2 unregister
78  
79 Net::Prometheus::Registry->unregister( $collector );
80 $registry->unregister( $collector );
81  
82 Removes a previously-registered collector.
83  
84 =cut
85  
86 2 ▶sub unregister ( $self, $collector )
Subroutine unregister: called CC=4 SCAR=15.2
Pod documented
87 {
88 2 ▶ my $collectors = ( ref $self ) ? $self : \@COLLECTORS;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 2 0 2
89  
90 2 my $found;
91 @$collectors = grep {
92 2 ▶ not( $_ == $collector and ++$found )
Condition33%1/3
$_ == $collector && ++$found
!ll&&!rl&&r
002
MC/DC0%0/2
$_ == $collector && ++$found
$_ == $collector ++$found
Truth table33%1/3
A && B
A= $_ == $collectorB= ++$found
ABresult
0X0
100
111
93 } @$collectors;
94  
95 2 ▶ $found or
Branch: 1 branch
BranchTrueFalseTotal
$found or croak("No such collector") 2 0 2
96 croak "No such collector";
97 }
98  
99 =head2 collectors
100  
101 @collectors = Net::Prometheus::Registry->collectors;
102 @collectors = $registry->collectors;
103  
104 Returns a list of the currently-registered collectors.
105  
106 =cut
107  
108 44 ▶sub collectors ( $self )
Subroutine collectors: called CC=2 SCAR=6.9
Pod documented
109 {
110 44 ▶ my $collectors = ( ref $self ) ? $self : \@COLLECTORS;
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 22 22 44
111 44 return @$collectors;
112 }
113  
114 =head1 AUTHOR
115  
116 Paul Evans <leonerd@leonerd.org.uk>
117  
118 =cut
119  
120 10 0x55AA;
« blib/lib/Net/Prometheus/PerlCollector.pm ↑ Summary blib/lib/Net/Prometheus/ProcessCollector.pm »