blib/lib/Net/Statsd/Client/Telegraf.pm

filter: Statementstmt 92.8% 52 / 56 Branchbran 83.3% 10 / 12 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 1 totaltotal 81.7% 76 / 93 CC 9 SCAR 10.7
CC
9
Cov
86%
add_tags
6.1
__ANON__
3.5
__ANON__
2.0
CRAP 2.9
↑ Summary
1 package Net::Statsd::Client::Telegraf;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 our $VERSION = '0.2';
7 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 extends 'Net::Statsd::Client';
10  
11 1 ▶has tags => ( is => 'ro', default => sub { {} }, isa => sub { die 'tags is expecting a hashref' unless ref $_[0] and ref $_[0] eq 'HASH'; } );
Subroutine __ANON__: called CC=1 SCAR=0.5
Subroutine __ANON__: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_[0] and ref $_[0] eq "HASH" 0 2 2
Condition33%1/3
ref $_[0] and ref $_[0] eq "HASH"
!ll&&!rl&&r
002
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "HASH"
ref $_[0] ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
12  
13 3 ▶around increment => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
14 3 my ( $orig, $self, $metric, %opt ) = @_;
15  
16 3 return $self->$orig( $self->add_tags($metric, $opt{tags}), $opt{sample_rate});
17 1 };
18  
19 3 ▶around decrement => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
20 3 my ( $orig, $self, $metric, %opt ) = @_;
21  
22 3 return $self->$orig( $self->add_tags($metric, $opt{tags}), $opt{sample_rate});
23 1 };
24  
25 3 ▶around update => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
26 3 my ( $orig, $self, $metric, $count, %opt ) = @_;
27  
28 3 return $self->$orig( $self->add_tags($metric, $opt{tags}), $count, $opt{sample_rate});
29 1 };
30  
31 6 ▶around timing_ms => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
32 6 my ( $orig, $self, $metric, $time, @others ) = @_;
33  
34 #ugly layer to handle timer method,
35 #Timer method return a timer method which call timing_ms, with the
36 #protocal of Net::Statsd::Client, hence, with a scalar after $time
37 #use Data::Dumper; warn Dumper( \@others );
38 6 ▶ if( scalar( @others ) == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @others == 1) { } 3 3 6
39 3 my $sample_rate = $others[0];
40  
41 3 return $self->$orig( $metric, $time, $sample_rate);
42 } else {
43 3 my %opt = @others;
44 3 return $self->$orig( $self->add_tags($metric, $opt{tags}), $time, $opt{sample_rate});
45 }
46 1 };
47  
48 0 ▶around gauge => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 0 my ( $orig, $self, $metric, $value, %opt ) = @_;
50  
51 0 return $self->$orig( $self->add_tags($metric, $opt{tags}), $value, $opt{sample_rate});
52 1 };
53  
54 0 ▶around set_add => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
55 0 my ( $orig, $self, $metric, $value, %opt ) = @_;
56  
57 0 return $self->$orig( $self->add_tags($metric, $opt{tags}), $value, $opt{sample_rate});
58 1 };
59  
60 3 ▶around timer => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
61 3 my ( $orig, $self, $metric, %opt ) = @_;
62  
63 3 return $self->$orig( $self->add_tags($metric, $opt{tags}), $opt{sample_rate});
64 1 };
65  
66 15 ▶sub add_tags {
Subroutine add_tags: called CC=6 SCAR=18.0
Pod undocumented
67 15 my ($self, $what, $tags) = @_;
68  
69 15 my $t = '';
70 15 ▶ if( defined $tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $tags) 5 10 15
71 5 ▶ die 'tags is expecting a hashref'
Branch: 1 branch
BranchTrueFalseTotal
unless ref $tags and ref $tags eq "HASH" 0 5 5
Condition33%1/3
ref $tags and ref $tags eq "HASH"
!ll&&!rl&&r
005
MC/DC0%0/2
ref $tags and ref $tags eq "HASH"
ref $tags ref $tags eq "HASH"
Truth table33%1/3
A and B
A= ref $tagsB= ref $tags eq "HASH"
ABresult
0X0
100
111
72 unless ref $tags and ref $tags eq 'HASH';
73 5 ▶ while( my ($name, $value) = each %$tags ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$tags) 5 5 10
74 5 $name =~ s/\s/_/g;
75 5 $value =~ s/\s/_/g;
76 5 $t .= ",$name=$value";
77 }
78 }
79 15 ▶ while( my ($name, $value) = each %{$self->tags} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$self->tags;}) 5 15 20
80 5 $name =~ s/\s/_/g;
81 5 $value =~ s/\s/_/g;
82 5 $t .= ",$name=$value";
83 }
84  
85 15 return $what.$t;
86 }
87  
88 1 1;
89 __END__
↑ Summary