| 1 | package DataDog::DogStatsd::Helper; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | our $VERSION = '0.07'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use base qw( Exporter ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | our @EXPORT_OK = qw/stats_inc stats_dec stats_timing stats_gauge stats_count stats_histogram stats_event stats_timed/; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use DataDog::DogStatsd; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Time::HiRes qw(tv_interval gettimeofday); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | ## no critic (Subroutines::RequireFinalReturn) | ||||||||||||||||||||||||||||
| 14 | 6 | ▶ | sub stats_inc { | ||||||||||||||||||||||||||
|
Subroutine
stats_inc: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 15 | 6 | my @args = @_; | |||||||||||||||||||||||||||
| 16 | # support stats_inc('test.blabla', 0.1); as well | ||||||||||||||||||||||||||||
| 17 | 6 | ▶ | if (@args > 1 and $args[1] =~ /^[\d\.]+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args > 1 and $args[1] =~ /^[\d\.]+$/
MC/DC100%2/2
@args > 1 and $args[1] =~ /^[\d\.]+$/
@args > 1
$args[1] =~ /^[\d\.]+$/
Truth table100%3/3
A and B
A= @args > 1B= $args[1] =~ /^[\d\.]+$/
| |||||||||||||||||||||||||||||
| 18 | # actually ppl wants stats_count | ||||||||||||||||||||||||||||
| 19 | 1 | ▶ | warn "stats_inc sample_rate makes no sense for more than 1\n" if $args[1] > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | 1 | $args[1] = {sample_rate => $args[1]}; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 6 | get_dogstatsd()->increment(@args); | |||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||
| 24 | 4 | ▶ | sub stats_dec { get_dogstatsd()->decrement(@_); } | ||||||||||||||||||||||||||
|
Subroutine
stats_dec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 5 | ▶ | sub stats_timing { | ||||||||||||||||||||||||||
|
Subroutine
stats_timing: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 27 | 5 | my @args = @_; | |||||||||||||||||||||||||||
| 28 | # support stats_timing('connection_time', 1000 * $interval, 0.1); as well | ||||||||||||||||||||||||||||
| 29 | 5 | ▶ | if (@args > 2 and $args[2] =~ /^[\d\.]+$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args > 2 and $args[2] =~ /^[\d\.]+$/
MC/DC100%2/2
@args > 2 and $args[2] =~ /^[\d\.]+$/
@args > 2
$args[2] =~ /^[\d\.]+$/
Truth table100%3/3
A and B
A= @args > 2B= $args[2] =~ /^[\d\.]+$/
| |||||||||||||||||||||||||||||
| 30 | # actually ppl wants stats_count | ||||||||||||||||||||||||||||
| 31 | 1 | ▶ | warn "stats_timing sample_rate makes no sense for more than 1\n" if $args[2] > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | $args[2] = {sample_rate => $args[2]}; | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 5 | get_dogstatsd()->timing(@args); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 4 | ▶ | sub stats_timed (&@) { ## no critic (ProhibitSubroutinePrototypes, Subroutines::RequireArgUnpacking) | ||||||||||||||||||||||||||
|
Subroutine
stats_timed: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 38 | 4 | my ($sub, $what, $opts) = splice @_, 0, 3; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | my $start = [gettimeofday]; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 4 | my (@res, $no_ex); | |||||||||||||||||||||||||||
| 43 | 4 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 44 | 1 | $no_ex = eval { @res = $sub->(@_); 1; }; | |||||||||||||||||||||||||||
| 45 | } elsif (defined wantarray) { | ||||||||||||||||||||||||||||
| 46 | 1 | $no_ex = eval { $res[0] = $sub->(@_); 1; }; | |||||||||||||||||||||||||||
| 47 | } else { | ||||||||||||||||||||||||||||
| 48 | 0 | $no_ex = eval { $sub->(@_); 1; }; | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 4 | ▶ | if ($no_ex) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 2 | get_dogstatsd()->timing($what, 1000 * tv_interval($start), $opts); | |||||||||||||||||||||||||||
| 53 | } else { | ||||||||||||||||||||||||||||
| 54 | 2 | get_dogstatsd()->increment("$what.failure", $opts); | |||||||||||||||||||||||||||
| 55 | 2 | die $@; ## no critic (Variables::ProhibitEvilVariables) | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 2 | ▶ | return wantarray ? @res : $res[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 4 | ▶ | sub stats_gauge { get_dogstatsd()->gauge(@_); } | ||||||||||||||||||||||||||
|
Subroutine
stats_gauge: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 62 | 1 | ▶ | sub stats_count { get_dogstatsd()->count(@_); } | ||||||||||||||||||||||||||
|
Subroutine
stats_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | sub stats_histogram { get_dogstatsd()->histogram(@_); } | ||||||||||||||||||||||||||
|
Subroutine
stats_histogram: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub stats_event { get_dogstatsd()->event(@_); } | ||||||||||||||||||||||||||
|
Subroutine
stats_event: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 3 | my $DOGSTATSD; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 27 | ▶ | sub get_dogstatsd { | ||||||||||||||||||||||||||
|
Subroutine
get_dogstatsd: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | $DOGSTATSD ||= DataDog::DogStatsd->new( | ||||||||||||||||||||||||||||
| 70 | host => $ENV{DATADOG_AGENT_HOST}, | ||||||||||||||||||||||||||||
| 71 | port => $ENV{DATADOG_AGENT_PORT}, | ||||||||||||||||||||||||||||
| 72 | 27 | ▶ | namespace => $ENV{DATADOG_AGENT_NAMESPACE}); | ||||||||||||||||||||||||||
|
Condition66%2/3
$DOGSTATSD ||= "DataDog::DogStatsd"->new("host", $ENV{"DATADOG_AGENT_HOST"}, "port", $ENV{"DATADOG_AGENT_PORT"}, "namespace", $ENV{"DATADOG_AGENT_NAMESPACE"})
MC/DC0%0/2
$DOGSTATSD ||= "DataDog::DogStatsd"->new("host", $ENV{"DATADOG_AGENT_HOST"}, "port", $ENV{"DATADOG_AGENT_PORT"}, "namespace", $ENV{"DATADOG_AGENT_NAMESPACE"})
$DOGSTATSD
"DataDog::DogStatsd"->new("host", $ENV{"DATADOG_AGENT_HOST"}, "port", $ENV{"DATADOG_AGENT_PORT"}, "namespace", $ENV{"DATADOG_AGENT_NAMESPACE"})
Truth table66%2/3
A ||= B
A= $DOGSTATSDB= "DataDog::DogStatsd"->new("host", $ENV{"DATADOG_AGENT_HOST"}, "port", $ENV{"DATADOG_AGENT_PORT"}, "namespace", $ENV{"DATADOG_AGENT_NAMESPACE"})
| |||||||||||||||||||||||||||||
| 73 | 27 | return $DOGSTATSD; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | ▶ | sub set_dogstatsd { | ||||||||||||||||||||||||||
|
Subroutine
set_dogstatsd: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 1 | $DOGSTATSD = pop; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 3 | 1; | |||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||