blib/lib/BenchmarkAnything/Reporter.pm

filter: Statementstmt 56.6% 17 / 30 Branchbran 10.0% 1 / 10 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 62.5% 5 / 8 Podpod 100% 2 / 2 totaltotal 41.6% 25 / 60 CC 8 SCAR 32.9
CC
8
Cov
39%
report
56.0
new
2.0
_get_user_agent
2.0
CRAP 26.9
↑ Summary
1 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 package BenchmarkAnything::Reporter;
5 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 $BenchmarkAnything::Reporter::AUTHORITY = 'cpan:SCHWIGON';
7 }
8 # ABSTRACT: Handle result reporting to a BenchmarkAnything HTTP/REST API
9 2 $BenchmarkAnything::Reporter::VERSION = '0.003';
10  
11 sub new
12 2 ▶{
Subroutine new: called CC=2 SCAR=7.0
Pod documented
13 2 my $class = shift;
14 2 my $self = bless { @_ }, $class;
15  
16 2 require BenchmarkAnything::Config;
17 2 ▶ $self->{config} = BenchmarkAnything::Config->new unless $self->{config};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"config"} 2 0 2
18  
19 2 return $self;
20 }
21  
22  
23 sub report
24 0 ▶{
Subroutine report: not called CC=7 SCAR=40.3
Pod documented
25 0 my ($self, $data) = @_;
26  
27 # --- validate ---
28 0 ▶ if (not $data)
Branch: 1 branch
BranchTrueFalseTotal
unless ($data) 0 0 0
29 {
30 0 die "benchmarkanything: no input data provided.\n";
31 }
32  
33 0 my $ua = $self->_get_user_agent;
34 0 my $url = $self->_get_base_url."/api/v1/add";
35 0 ▶ print "Report data...\n" if $self->{verbose} or $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} or $self->{"debug"} 0 0 0
Condition0%0/3
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"verbose"} or $self->{"debug"}
$self->{"verbose"} $self->{"debug"}
Truth table0%0/3
A or B
A= $self->{"verbose"}B= $self->{"debug"}
ABresult
1X1
011
000
36 0 my $res = $ua->post($url => json => $data)->res;
37 0 ▶ print "Done.\n" if $self->{verbose} or $self->{debug};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} or $self->{"debug"} 0 0 0
Condition0%0/3
$self->{"verbose"} or $self->{"debug"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"verbose"} or $self->{"debug"}
$self->{"verbose"} $self->{"debug"}
Truth table0%0/3
A or B
A= $self->{"verbose"}B= $self->{"debug"}
ABresult
1X1
011
000
38  
39 0 ▶ die "benchmarkanything: ".$res->error->{message}." ($url)\n" if $res->error;
Branch: 1 branch
BranchTrueFalseTotal
if $res->error 0 0 0
40  
41 0 return $self;
42 }
43  
44 sub _get_user_agent
45 0 ▶{
Subroutine _get_user_agent: not called CC=1 SCAR=6.9
46 0 require Mojo::UserAgent;
47 0 return Mojo::UserAgent->new;
48 }
49  
50 sub _get_base_url
51 0 ▶{
Subroutine _get_base_url: not called CC=1 SCAR=6.9
52 0 $_[0]->{config}{benchmarkanything}{backends}{http}{base_url};
53 }
54  
55 2 1;
56 2 3
57  
58 __END__
↑ Summary