Respite/Client.pm

filter: Statementstmt 63.2% 131 / 207 Branchbran 36.4% 59 / 162 Conditioncond 23.1% 32 / 138 MC/DCmcdc 2.5% 2 / 78 Subroutinesub 52.6% 20 / 38 Podpod 20.0% 1 / 5 totaltotal 39.0% 245 / 628 CC 135 SCAR 42.9
CC
135
Cov
44%
_decode_utf8_recurse
182.0
_remote_call
142.3
_encode_utf8_recurse
132.0
CRAP 72.8
« Respite/Base.pm ↑ Summary Respite/Server/Test.pm »
1 package Net::Respite::Client;
2  
3 # Net::Respite::Client - Generic class for running remote services
4  
5 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use base 'Net::Respite::Common'; # Default _configs
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use IO::Socket::SSL ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use Time::HiRes qw(sleep);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=16.2
13 4 ▶ if (! eval { require Throw }) {
Branch: 1 branch
BranchTrueFalseTotal
if (not eval { do { require Throw } }) { } 0 4 4
14 0 ▶ *Throw_::TO_JSON = sub { +{%{$_[0]}} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
15 0 ▶ *Throw_::_str = sub { my ($s) = @_; my ($e,$p) = delete(@$s{qw(error _pretty)}); $e||="throw"; $e .= ': '.($p||$Throw::pretty?jsop():json())->encode($s) if %$s; "$e\n" };
Subroutine __ANON__: not called CC=5 SCAR=34.0
Branch: 2 branches
BranchTrueFalseTotal
if %$s 0 0 0
$p || $Throw::pretty ? : 0 0 0
Condition0%0/5
$e ||= "throw"
l!l
00
$p or $Throw::pretty
l!l&&r!l&&!r
000
MC/DC0%0/1
$e ||= "throw"
$e
MC/DC0%0/2
$p or $Throw::pretty
$p $Throw::pretty
Truth table0%0/2
A
A= $e
Aresult
11
00
Truth table0%0/3
A or B
A= $pB= $Throw::pretty
ABresult
1X1
011
000
16 0 ▶ *throw = *Throw_::throw = sub { my ($m,$a,$l)=@_; $a=ref($m) ? $m : {%{$a||{}}, error => $m};
Subroutine __ANON__: not called CC=7 SCAR=40.3
Branch: 1 branch
BranchTrueFalseTotal
ref $m ? : 0 0 0
Condition0%0/2
$a || {}
l!l
00
MC/DC0%0/1
$a || {}
$a
Truth table0%0/2
A
A= $a
Aresult
11
00
17 0 ▶ do {my$i=$l||0;$i++while __PACKAGE__ eq caller$i; $a->{'trace'}=sprintf "%s at %s line %s\n",(caller$i)[3,1,2]} if $a->{'trace'}||$l; die bless $a, 'Throw_' };
Branch: 2 branches
BranchTrueFalseTotal
if ($a->{"trace"} or $l) 0 0 0
__PACKAGE__ eq caller $i and do { ++$i } 0 0 0
Condition0%0/5
$a->{"trace"} or $l
l!l&&r!l&&!r
000
$l || 0
l!l
00
MC/DC0%0/2
$a->{"trace"} or $l
$a->{"trace"} $l
MC/DC0%0/1
$l || 0
$l
Truth table0%0/3
A or B
A= $a->{"trace"}B= $l
ABresult
1X1
011
000
Truth table0%0/2
A
A= $l
Aresult
11
00
18 0 overload::OVERLOAD('Throw_', '""' => \&Throw_::_str, fallback => 1);
19 4 } else { Throw->import('throw') }
20 }
21  
22 14 ▶sub service_name { $_[0]->{'service_name'} || $_[0]->{'service'} || throw "Missing service_name" }
Subroutine service_name: called CC=3 SCAR=14.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"service_name"} or $_[0]{"service"} or throw("Missing service_name") 14 0 14
Condition33%1/3
$_[0]{"service_name"} or $_[0]{"service"}
l!l&&r!l&&!r
0140
MC/DC0%0/2
$_[0]{"service_name"} or $_[0]{"service"}
$_[0]{"service_name"} $_[0]{"service"}
Truth table33%1/3
A or B
A= $_[0]{"service_name"}B= $_[0]{"service"}
ABresult
1X1
011
000
23  
24 7 ▶sub run_method {
Subroutine run_method: called CC=21 SCAR=40.7
Pod undocumented
25 7 my $self = shift;
26 7 my $name = $self->service_name;
27 7 ▶ my $method = shift || throw "Missing $name service method", undef, 1;
Condition33%1/3
shift() || throw("Missing $name service method", undef, 1)
l!l&&r!l&&!r
700
MC/DC0%0/2
shift() || throw("Missing $name service method", undef, 1)
shift() throw("Missing $name service method", undef, 1)
Truth table33%1/3
A || B
A= shift()B= throw("Missing $name service method", undef, 1)
ABresult
1X1
011
000
28 7 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
70
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
29 7 ▶ throw "Invalid $name service args", {method => $method, args => $args}, 1 if ref($args) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args ne "HASH" 0 7 7
30 7 ▶ local $args->{'_i'} = $self->{'remote_ip'} || $ENV{'REMOTE_ADDR'} || (($ENV{'REALUSER'} || $ENV{'SUDO_USER'}) ? 'sudo' : 'cmdline');
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'REALUSER'} || $ENV{'SUDO_USER'} ? : 0 7 7
Condition33%3/9
$self->{'remote_ip'} || $ENV{'REMOTE_ADDR'} || ($ENV{'REALUSER'} || $ENV{'SUDO_USER'} ? 'sudo' : 'cmdline')
l!l&&r!l&&!r
070
$self->{"remote_ip"} or $ENV{"REMOTE_ADDR"}
l!l&&r!l&&!r
007
$ENV{"REALUSER"} or $ENV{"SUDO_USER"}
l!l&&r!l&&!r
007
MC/DC0%0/4
$self->{'remote_ip'} || $ENV{'REMOTE_ADDR'} || ($ENV{'REALUSER'} || $ENV{'SUDO_USER'} ? 'sudo' : 'cmdline')
$self->{"remote_ip"} $ENV{"REMOTE_ADDR"} $ENV{"REALUSER"} $ENV{"SUDO_USER"}
Truth table20%1/5
A or B || C or D
A= $self->{"remote_ip"}B= $ENV{"REMOTE_ADDR"}C= $ENV{"REALUSER"}D= $ENV{"SUDO_USER"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
31 7 ▶ local $args->{'_w'} = $self->{'remote_user'} || $ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid($<))[0] || '-unknown-';
Condition35%6/17
$self->{'remote_user'} || $ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid $<)[0] || '-unknown-'
l!l
70
$self->{"remote_user"} or $ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"} or $ENV{"USER"} or (getpwuid $<)[0]
l!l&&r!l&&!r
070
$self->{"remote_user"} or $ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"} or $ENV{"USER"}
l!l&&r!l&&!r
007
$self->{"remote_user"} or $ENV{"REALUSER"} or $ENV{"SUDO_USER"} or $ENV{"REMOTE_USER"}
l!l&&r!l&&!r
007
$self->{"remote_user"} or $ENV{"REALUSER"} or $ENV{"SUDO_USER"}
l!l&&r!l&&!r
007
$self->{"remote_user"} or $ENV{"REALUSER"}
l!l&&r!l&&!r
007
MC/DC0%0/6
$self->{'remote_user'} || $ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid $<)[0] || '-unknown-'
$self->{"remote_user"} $ENV{"REALUSER"} $ENV{"SUDO_USER"} $ENV{"REMOTE_USER"} $ENV{"USER"} (getpwuid $<)[0]
Truth table14%1/7
A or B or C or D or E or F
A= $self->{"remote_user"}B= $ENV{"REALUSER"}C= $ENV{"SUDO_USER"}D= $ENV{"REMOTE_USER"}E= $ENV{"USER"}F= (getpwuid $<)[0]
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
32 7 ▶ local $args->{'_t'} = $self->{'token'} if !$args->{'_t'} && $self->{'token'};
Branch: 1 branch
BranchTrueFalseTotal
if not $args->{"_t"} and $self->{"token"} 0 7 7
Condition33%1/3
not $args->{"_t"} and $self->{"token"}
!ll&&!rl&&r
070
MC/DC0%0/2
not $args->{"_t"} and $self->{"token"}
not $args->{"_t"} $self->{"token"}
Truth table33%1/3
not(A) and B
A= not $args->{"_t"}B= $self->{"token"}
ABresult
0X0
100
111
33 7 ▶ local $args->{'_c'} = do {my $i = my $c = 0; $c = [(caller $i++)[0..3]] while !$i || $c->[0]->isa(__PACKAGE__); join '; ', @$c} if ! $self->config(no_trace => undef, $name);
Branch: 2 branches
BranchTrueFalseTotal
unless $self->config("no_trace", undef, $name) 7 0 7
!$i || $c->[0]->isa(__PACKAGE__) and do { $c = [(caller $i++)[0..3]] } 21 7 28
Condition100%3/3
not $i or $c->[0]->isa(__PACKAGE__)
l!l&&r!l&&!r
7147
MC/DC100%2/2
not $i or $c->[0]->isa(__PACKAGE__)
not $i $c->[0]->isa(__PACKAGE__)
Truth table100%3/3
not(A) or B
A= not $iB= $c->[0]->isa(__PACKAGE__)
ABresult
1X1
011
000
34 7 ▶ local $self->{'flat'} = exists($args->{'_flat'}) ? delete($args->{'_flat'}) : $self->config(flat => undef, $name);
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'_flat'} ? : 0 7 7
35 7 ▶ return $self->_remote_call($method, $args) if $self->_needs_remote($method);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_needs_remote($method) 7 0 7
36 0 return $self->_local_call( $method, $args);
37 }
38  
39 14 ▶sub _needs_remote {
Subroutine _needs_remote: called CC=1 SCAR=0.0
40 14 my ($self, $method) = @_;
41 14 return $method !~ /(^local_|_local$)/;
42 }
43  
44 0 ▶sub _local_call {
Subroutine _local_call: not called CC=6 SCAR=37.4
45 0 my ($self, $method, $args) = @_;
46 0 my $name = $self->service_name;
47 0 ▶ local $self->{'brand'} ||= $self->api_brand($name);
Condition0%0/3
local $self->{"brand"} ||= $self->api_brand($name)
l!l&&r!l&&!r
000
MC/DC0%0/2
local $self->{"brand"} ||= $self->api_brand($name)
local $self->{"brand"} $self->api_brand($name)
Truth table0%0/3
A ||= B
A= local $self->{"brand"}B= $self->api_brand($name)
ABresult
1X1
011
000
48 my $hash = eval {
49 0 ▶ my $code = $self->can("__$method") || throw "Invalid $name service method", {method => $method}, 1;
Condition0%0/3
$self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1)
$self->can("__$method") throw("Invalid $name service method", {'method', $method}, 1)
Truth table0%0/3
A || B
A= $self->can("__$method")B= throw("Invalid $name service method", {'method', $method}, 1)
ABresult
1X1
011
000
50 0 ▶ return $code->($self, $args);
Branch: 1 branch
BranchTrueFalseTotal
ref $@ eq 'HASH' && $@->{'error'} ? : 0 0 0
Condition0%0/3
ref $@ eq "HASH" and $@->{"error"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ eq "HASH" and $@->{"error"}
ref $@ eq "HASH" $@->{"error"}
Truth table0%0/3
A and B
A= ref $@ eq "HASH"B= $@->{"error"}
ABresult
0X0
100
111
51 0 ▶ } || (ref($@) eq 'HASH' && $@->{'error'} ? $@ : {error => "Trouble running $name service method", service => $name});
Condition0%0/3
eval { do { my $code = $self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1); return &$code($self, $args) } } || (ref $@ eq 'HASH' && $@->{'error'} ? $@ : {'error', "Trouble running $name service method", 'service', $name})
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { my $code = $self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1); return &$code($self, $args) } } || (ref $@ eq 'HASH' && $@->{'error'} ? $@ : {'error', "Trouble running $name service method", 'service', $name})
eval { do { my $code = $self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1); return &$code($self, $args) } } (ref $@ eq 'HASH' && $@->{'error'} ? $@ : {'error', "Trouble running $name service method", 'service', $name})
Truth table0%0/3
A || B
A= eval { do { my $code = $self->can("__$method") || throw("Invalid $name service method", {'method', $method}, 1); return &$code($self, $args) } }B= (ref $@ eq 'HASH' && $@->{'error'} ? $@ : {'error', "Trouble running $name service method", 'service', $name})
ABresult
1X1
011
000
52 0 return $self->_result({method => $method, args => $args, data => $hash, service => $name, url => 'local'});
53 }
54  
55 109 ▶sub config {
Subroutine config: called CC=10 SCAR=28.0
Pod undocumented
56 109 my ($self, $key, $def, $name) = @_;
57 109 ▶ $name ||= $self->service_name;
Condition33%1/3
$name ||= $self->service_name
l!l&&r!l&&!r
10900
MC/DC0%0/2
$name ||= $self->service_name
$name $self->service_name
Truth table33%1/3
A ||= B
A= $nameB= $self->service_name
ABresult
1X1
011
000
58 109 my $c = $self->_configs($name);
59 return exists($self->{$key}) ? $self->{$key}
60 : exists($c->{"${name}_service_${key}"}) ? $c->{"${name}_service_${key}"}
61 : (ref($c->{"${name}_service"}) && exists $c->{"${name}_service"}->{$key}) ? $c->{"${name}_service"}->{$key}
62 : exists($c->{"${name}_${key}"}) ? $c->{"${name}_${key}"}
63 109 ▶ : (ref($c->{$name}) && exists $c->{$name}->{$key}) ? $c->{$name}->{$key}
Branch: 6 branches
BranchTrueFalseTotal
exists $self->{$key} ? : 55 54 109
exists $$c{"${name}_service_$key"} ? : 0 54 54
ref $$c{"${name}_service"} && exists $$c{"${name}_service"}{$key} ? : 0 54 54
exists $$c{"${name}_$key"} ? : 0 54 54
ref $c->{$name} && exists $c->{$name}{$key} ? : 0 54 54
ref $def eq 'CODE' ? : 7 47 54
Condition33%2/6
ref $$c{"${name}_service"} and exists $$c{"${name}_service"}{$key}
!ll&&!rl&&r
5400
ref $c->{$name} and exists $c->{$name}{$key}
!ll&&!rl&&r
5400
MC/DC0%0/2
ref $$c{"${name}_service"} and exists $$c{"${name}_service"}{$key}
ref $$c{"${name}_service"} exists $$c{"${name}_service"}{$key}
MC/DC0%0/2
ref $c->{$name} and exists $c->{$name}{$key}
ref $c->{$name} exists $c->{$name}{$key}
Truth table33%1/3
A and B
A= ref $$c{"${name}_service"}B= exists $$c{"${name}_service"}{$key}
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= ref $c->{$name}B= exists $c->{$name}{$key}
ABresult
0X0
100
111
64 : ref($def) eq 'CODE' ? $def->($self) : $def;
65 }
66  
67 7 ▶sub api_brand {
Subroutine api_brand: called CC=3 SCAR=17.3
Pod undocumented
68 7 my ($self, $name) = @_;
69 7 ▶ $name ||= $self->service_name;
Condition33%1/3
$name ||= $self->service_name
l!l&&r!l&&!r
700
MC/DC0%0/2
$name ||= $self->service_name
$name $self->service_name
Truth table33%1/3
A ||= B
A= $nameB= $self->service_name
ABresult
1X1
011
000
70 7 ▶ return undef if $self->config(no_brand => undef, $name); ## no critic (ProhibitExplicitReturnUndef)
Branch: 1 branch
BranchTrueFalseTotal
if $self->config("no_brand", undef, $name) 0 7 7
71 0 ▶ $self->config(brand => sub { eval { config::provider() } || $self->_configs->{'provider'} || do { warn "Missing $name brand"; '-' } }, $name);
Subroutine __ANON__: not called CC=3 SCAR=22.6
Branch: 1 branch
BranchTrueFalseTotal
eval { do { config::provider() } } or $self->_configs->{"provider"} or do { warn "Missing $name brand"; "-" } 0 0 0
Condition0%0/3
eval { do { config::provider() } } or $self->_configs->{"provider"}
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { config::provider() } } or $self->_configs->{"provider"}
eval { do { config::provider() } } $self->_configs->{"provider"}
Truth table0%0/3
A or B
A= eval { do { config::provider() } }B= $self->_configs->{"provider"}
ABresult
1X1
011
000
72 }
73  
74 7 ▶sub _remote_call {
Subroutine _remote_call: called CC=43 SCAR=49.6
75 7 my ($self, $method, $args) = @_;
76 7 my $begin = Time::HiRes::time();
77 7 my $name = $self->service_name;
78 7 my $brand = $self->api_brand($name);
79 7 ▶ my $val = sub { my ($key, $def) = @_; $self->config($key, $def, $name) };
Subroutine __ANON__: called CC=1 SCAR=0.0
80 7 my $no_ssl = $val->(no_ssl => undef);
81 0 ▶ my $host = $val->(host => sub {throw "Missing $name service host",undef,1});
Subroutine __ANON__: not called CC=1 SCAR=1.2
82 7 ▶ my $port = $val->(port => ($no_ssl ? 80 : 443));
Branch: 1 branch
BranchTrueFalseTotal
$no_ssl ? : 7 0 7
83 7 ▶ my $path = $val->(path => sub { $name =~ /^(\w+)_service/ ? $1 : $name });
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$name =~ /^(\w+)_service/ ? : 0 7 7
84 7 ▶ my $pass = $val->(no_sign => undef) ? undef : $val->(pass => undef); # rely on the server to tell us if a password is necessary
Branch: 1 branch
BranchTrueFalseTotal
&$val('no_sign', undef) ? : 0 7 7
85 7 ▶ my $utf8 = exists($args->{'_utf8_encoded'}) ? delete($args->{'_utf8_encoded'}) : $val->(utf8_encoded => undef);
Branch: 1 branch
BranchTrueFalseTotal
exists $args->{'_utf8_encoded'} ? : 0 7 7
86 7 ▶ my $enc = $utf8 && (!ref($utf8) || $utf8->{$method});
Condition16%1/6
$utf8 && (!ref($utf8) || $utf8->{$method})
!ll&&!rl&&r
700
not ref $utf8 or $utf8->{$method}
l!l&&r!l&&!r
000
MC/DC0%0/3
$utf8 && (!ref($utf8) || $utf8->{$method})
$utf8 not ref $utf8 $utf8->{$method}
Truth table25%1/4
A && not(B) or C
A= $utf8B= not ref $utf8C= $utf8->{$method}
ABCresult
0XX0
1000
11X1
1011
87 7 my $retry = $val->(retry => undef);
88 7 my $ns = $val->(ns => undef);
89 7 ▶ $method = "${ns}_${method}" if $ns;
Branch: 1 branch
BranchTrueFalseTotal
if $ns 0 7 7
90 7 ▶ my $url = "/$path/$method".($brand ? "/$brand" : '');
Branch: 1 branch
BranchTrueFalseTotal
$brand ? : 7 0 7
91 7 my $cookie = $val->(cookie => undef);
92  
93 7 my $req;
94 0 ▶ local $SIG{'ALRM'} = sub { die "Timeout on $name\n" };
Subroutine __ANON__: not called CC=1 SCAR=1.2
95 7 ▶ my $old = alarm($args->{'_timeout'} || $val->(timeout => 120)) || 0;
Condition40%2/5
alarm($args->{'_timeout'} || &$val('timeout', 120)) || 0
l!l
07
$args->{'_timeout'} || &$val('timeout', 120)
l!l&&r!l&&!r
070
MC/DC0%0/2
alarm($args->{'_timeout'} || &$val('timeout', 120)) || 0
$args->{'_timeout'} &$val('timeout', 120)
Truth table33%1/3
A || B
A= $args->{'_timeout'}B= &$val('timeout', 120)
ABresult
1X1
011
000
96 7 my %head;
97 my $hash = eval {
98 7 ▶ _decode_utf8_recurse($args) if $enc;
Branch: 1 branch
BranchTrueFalseTotal
if $enc 0 7 7
99 7 ▶ $req = eval { $self->json->encode($args) } || throw "Trouble encoding $name service json", {msg => $@}, 1;
Condition33%1/3
eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1)
l!l&&r!l&&!r
700
MC/DC0%0/2
eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1)
eval { do { $self->json->encode($args) } } throw("Trouble encoding $name service json", {'msg', $@}, 1)
Truth table33%1/3
A || B
A= eval { do { $self->json->encode($args) } }B= throw("Trouble encoding $name service json", {'msg', $@}, 1)
ABresult
1X1
011
000
100 7 ▶ my $sign = defined($pass) ? do { my $t = int $begin; "X-Respite-Auth: ".($val->('md5_pass') ? md5_hex($pass) : md5_hex("$pass:$t:$url:".md5_hex($req)).":$t")."\r\n" } : '';
Branch: 2 branches
BranchTrueFalseTotal
defined $pass ? : 4 3 7
&$val('md5_pass') ? : 0 4 4
101 7 ▶ $cookie = $cookie ? "Cookie: $cookie\r\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
$cookie ? : 0 7 7
102  
103 7 my $sock;
104 7 my $i = 0;
105 7 ▶ while (++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if (++$i) 7 0 7
106 # Note SSL verify may not work as expected on IO::Socket::SSL versions below v1.46
107 7 ▶ $sock = $no_ssl ? IO::Socket::INET->new("$host:$port")
Branch: 1 branch
BranchTrueFalseTotal
$no_ssl ? : 7 0 7
108 : IO::Socket::SSL->new(PeerAddr => $host, PeerPort => $port, SSL_verify_mode => $val->(ssl_verify_mode => 0));
109 7 ▶ last if $sock || !$retry || (Time::HiRes::time() - $begin > 3);
Branch: 1 branch
BranchTrueFalseTotal
if $sock or not $retry or &Time::HiRes::time() - $begin > 3 7 0 7
Condition33%2/6
$sock or not $retry or &Time::HiRes::time() - $begin > 3
l!l&&r!l&&!r
700
$sock or not $retry
l!l&&r!l&&!r
700
MC/DC0%0/3
$sock or not $retry or &Time::HiRes::time() - $begin > 3
$sock not $retry &Time::HiRes::time() - $begin > 3
Truth table25%1/4
A or not(B) or C
A= $sockB= not $retryC= &Time::HiRes::time() - $begin > 3
ABCresult
1XX1
01X1
0011
0000
110 0 sleep 0.5;
111 }
112 7 ▶ if (!$sock) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sock) 0 7 7
113 0 ▶ throw "Could not connect to $name service", {
Condition0%0/6
!$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!)
!ll&&!rl&&r
000
$IO::Socket::SSL::SSL_ERROR or $!
l!l&&r!l&&!r
000
MC/DC0%0/3
!$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!)
!$no_ssl $IO::Socket::SSL::SSL_ERROR $!
Truth table0%0/4
not(A) && B or C
A= !$no_sslB= $IO::Socket::SSL::SSL_ERRORC= $!
ABCresult
0XX0
1000
11X1
1011
114 host => $host, port => $port, url => $url,
115 msg => (!$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!)), detail => "$@", ssl => !$no_ssl, tries => $i,
116 };
117 }
118  
119 7 my $out = "POST $url HTTP/1.0\r\n${cookie}${sign}Host: $host\r\nContent-length: ".length($req)."\r\nContent-type: application/json\r\n\r\n$req";
120 7 ▶ warn "DEBUG_Respite: Connected to http".($no_ssl?'':'s')."://$host:$port/\n$out\n" if $ENV{'DEBUG_Respite'};
Branch: 2 branches
BranchTrueFalseTotal
if $ENV{"DEBUG_Respite"} 0 7 7
$no_ssl ? : 0 0 0
121 7 print $sock $out;
122 7 my ($len, $type, $line);
123 7 ▶ throw "Got non-200 status from $name service", {status => $line, url => $url} if !($line = <$sock>) || $line !~ m{^HTTP/\S+ 200\b};
Branch: 1 branch
BranchTrueFalseTotal
unless $line = readline $sock and $line =~ m[^HTTP/\S+ 200\b] 0 7 7
Condition33%1/3
$line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]
!ll&&!rl&&r
007
MC/DC0%0/2
$line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]
$line = readline $sock $line =~ m[^HTTP/\S+ 200\b]
Truth table33%1/3
A and B
A= $line = readline $sockB= $line =~ m[^HTTP/\S+ 200\b]
ABresult
0X0
100
111
124 7 ▶ while (defined($line = <$sock>)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($line = readline $sock)) 42 0 42
125 42 ▶ $line =~ s/\r?\n$// || throw "Failed to find line termination", {line => $line};
Branch: 1 branch
BranchTrueFalseTotal
$line =~ s/\r?\n$// or throw("Failed to find line termination", {"line", $line}) 42 0 42
126 42 ▶ last if $line eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 7 35 42
127 35 my ($key, $val) = split /\s*:\s*/, $line, 2;
128 0 ▶ $head{$key} = $head{$key} ? ref($head{$key}) ? [@{$head{$key}}, $val] : [$head{$key}, $val] : $val;
Branch: 2 branches
BranchTrueFalseTotal
$head{$key} ? : 0 35 35
ref $head{$key} ? : 0 0 0
129 35 ▶ $len = ($val =~ /^\d+$/) ? $val : throw "Invalid content length", {h => \%head} if lc($key) eq 'content-length';
Branch: 2 branches
BranchTrueFalseTotal
if lc $key eq "content-length" 7 28 35
$val =~ /^\d+$/ ? : 7 0 7
130 }
131 7 ▶ throw "Failed to find content length in $name service response" if ! $len;
Branch: 1 branch
BranchTrueFalseTotal
unless $len 0 7 7
132 7 ▶ throw "Content too large in $name service", {length => $len} if $len > 100_000_000;
Branch: 1 branch
BranchTrueFalseTotal
if $len > 100000000 0 7 7
133 7 my $data = '';
134 7 while (1) {
135 7 ▶ read($sock, $data, $len, length $data) || throw "Failed to read bytes", {needed => $len, got => length($data)};
Branch: 1 branch
BranchTrueFalseTotal
read $sock, $data, $len, length $data or throw("Failed to read bytes", {"needed", $len, "got", length $data}) 7 0 7
136 7 ▶ last if length $data >= $len;
Branch: 1 branch
BranchTrueFalseTotal
if length $data >= $len 7 0 7
137 }
138 7 close $sock;
139 7 alarm($old);
140  
141 7 ▶ throw "Invalid $name service json object string" if $data !~ /^\s*\{/;
Branch: 1 branch
BranchTrueFalseTotal
unless $data =~ /^\s*\{/ 0 7 7
142 7 ▶ my $resp = eval { $self->json->decode($data) } || throw "Failed to decode $name service json response data", {msg => $@};
Condition33%1/3
eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@})
l!l&&r!l&&!r
700
MC/DC0%0/2
eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@})
eval { do { $self->json->decode($data) } } throw("Failed to decode $name service json response data", {'msg', $@})
Truth table33%1/3
A || B
A= eval { do { $self->json->decode($data) } }B= throw("Failed to decode $name service json response data", {'msg', $@})
ABresult
1X1
011
000
143 7 ▶ _encode_utf8_recurse($resp) if $enc;
Branch: 1 branch
BranchTrueFalseTotal
if $enc 0 7 7
144 7 $resp;
145 0 ▶ } || do { alarm($old); {error => "Failed to get valid $name service response: $@"} };
Condition33%1/3
eval { do { _decode_utf8_recurse($args) if $enc; $req = eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1); my $sign = defined $pass ? do { my $t = int $begin; 'X-Respite-Auth: ' . (&$val('md5_pass') ? md5_hex($pass) : md5_hex("${pass}:${t}:${url}:" . md5_hex($req)) . ":$t") . "\r\n" } : ''; $cookie = $cookie ? "Cookie: $cookie\r\n" : ''; my $sock; my $i = 0; while (++$i) { $sock = $no_ssl ? 'IO::Socket::INET'->new("${host}:$port") : 'IO::Socket::SSL'->new('PeerAddr', $host, 'PeerPort', $port, 'SSL_verify_mode', &$val('ssl_verify_mode', 0)); last if $sock or not $retry or &Time::HiRes::time() - $begin > 3; &Net::Respite::Client::sleep(0.5); } ; unless ($sock) { throw("Could not connect to $name service", {'host', $host, 'port', $port, 'url', $url, 'msg', !$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!), 'detail', "$@", 'ssl', !$no_ssl, 'tries', $i}); } ; my $out = "POST $url HTTP/1.0\r\n$cookie${sign}Host: $host\r\nContent-length: " . length($req) . "\r\nContent-type: application/json\r\n\r\n$req"; warn 'DEBUG_Respite: Connected to http' . ($no_ssl ? '' : 's') . "://${host}:$port/\n$out\n" if $ENV{'DEBUG_Respite'}; print $sock $out; my($len, $type, $line); throw("Got non-200 status from $name service", {'status', $line, 'url', $url}) unless $line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]; while (defined($line = readline $sock)) { $line =~ s/\r?\n$// or throw('Failed to find line termination', {'line', $line}); last if $line eq ''; () = split(/\s*:\s*/, $line, 2); $head{$key} = $head{$key} ? ref $head{$key} ? [@{$head{$key};}, $val] : [$head{$key}, $val] : $val; $len = $val =~ /^\d+$/ ? $val : throw('Invalid content length', {'h', \%head}) if lc $key eq 'content-length'; } ; throw("Failed to find content length in $name service response") unless $len; throw("Content too large in $name service", {'length', $len}) if $len > 100000000; my $data = ''; while (1) { read $sock, $data, $len, length $data or throw('Failed to read bytes', {'needed', $len, 'got', length $data}); last if length $data >= $len; } ; close $sock; alarm $old; throw("Invalid $name service json object string") unless $data =~ /^\s*\{/; my $resp = eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@}); _encode_utf8_recurse($resp) if $enc; $resp } } || do { alarm $old; +{'error', "Failed to get valid $name service response: $@"} }
l!l&&r!l&&!r
700
MC/DC0%0/2
eval { do { _decode_utf8_recurse($args) if $enc; $req = eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1); my $sign = defined $pass ? do { my $t = int $begin; 'X-Respite-Auth: ' . (&$val('md5_pass') ? md5_hex($pass) : md5_hex("${pass}:${t}:${url}:" . md5_hex($req)) . ":$t") . "\r\n" } : ''; $cookie = $cookie ? "Cookie: $cookie\r\n" : ''; my $sock; my $i = 0; while (++$i) { $sock = $no_ssl ? 'IO::Socket::INET'->new("${host}:$port") : 'IO::Socket::SSL'->new('PeerAddr', $host, 'PeerPort', $port, 'SSL_verify_mode', &$val('ssl_verify_mode', 0)); last if $sock or not $retry or &Time::HiRes::time() - $begin > 3; &Net::Respite::Client::sleep(0.5); } ; unless ($sock) { throw("Could not connect to $name service", {'host', $host, 'port', $port, 'url', $url, 'msg', !$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!), 'detail', "$@", 'ssl', !$no_ssl, 'tries', $i}); } ; my $out = "POST $url HTTP/1.0\r\n$cookie${sign}Host: $host\r\nContent-length: " . length($req) . "\r\nContent-type: application/json\r\n\r\n$req"; warn 'DEBUG_Respite: Connected to http' . ($no_ssl ? '' : 's') . "://${host}:$port/\n$out\n" if $ENV{'DEBUG_Respite'}; print $sock $out; my($len, $type, $line); throw("Got non-200 status from $name service", {'status', $line, 'url', $url}) unless $line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]; while (defined($line = readline $sock)) { $line =~ s/\r?\n$// or throw('Failed to find line termination', {'line', $line}); last if $line eq ''; () = split(/\s*:\s*/, $line, 2); $head{$key} = $head{$key} ? ref $head{$key} ? [@{$head{$key};}, $val] : [$head{$key}, $val] : $val; $len = $val =~ /^\d+$/ ? $val : throw('Invalid content length', {'h', \%head}) if lc $key eq 'content-length'; } ; throw("Failed to find content length in $name service response") unless $len; throw("Content too large in $name service", {'length', $len}) if $len > 100000000; my $data = ''; while (1) { read $sock, $data, $len, length $data or throw('Failed to read bytes', {'needed', $len, 'got', length $data}); last if length $data >= $len; } ; close $sock; alarm $old; throw("Invalid $name service json object string") unless $data =~ /^\s*\{/; my $resp = eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@}); _encode_utf8_recurse($resp) if $enc; $resp } } || do { alarm $old; +{'error', "Failed to get valid $name service response: $@"} }
eval { do { _decode_utf8_recurse($args) if $enc; $req = eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1); my $sign = defined $pass ? do { my $t = int $begin; 'X-Respite-Auth: ' . (&$val('md5_pass') ? md5_hex($pass) : md5_hex("${pass}:${t}:${url}:" . md5_hex($req)) . ":$t") . "\r\n" } : ''; $cookie = $cookie ? "Cookie: $cookie\r\n" : ''; my $sock; my $i = 0; while (++$i) { $sock = $no_ssl ? 'IO::Socket::INET'->new("${host}:$port") : 'IO::Socket::SSL'->new('PeerAddr', $host, 'PeerPort', $port, 'SSL_verify_mode', &$val('ssl_verify_mode', 0)); last if $sock or not $retry or &Time::HiRes::time() - $begin > 3; &Net::Respite::Client::sleep(0.5); } ; unless ($sock) { throw("Could not connect to $name service", {'host', $host, 'port', $port, 'url', $url, 'msg', !$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!), 'detail', "$@", 'ssl', !$no_ssl, 'tries', $i}); } ; my $out = "POST $url HTTP/1.0\r\n$cookie${sign}Host: $host\r\nContent-length: " . length($req) . "\r\nContent-type: application/json\r\n\r\n$req"; warn 'DEBUG_Respite: Connected to http' . ($no_ssl ? '' : 's') . "://${host}:$port/\n$out\n" if $ENV{'DEBUG_Respite'}; print $sock $out; my($len, $type, $line); throw("Got non-200 status from $name service", {'status', $line, 'url', $url}) unless $line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]; while (defined($line = readline $sock)) { $line =~ s/\r?\n$// or throw('Failed to find line termination', {'line', $line}); last if $line eq ''; () = split(/\s*:\s*/, $line, 2); $head{$key} = $head{$key} ? ref $head{$key} ? [@{$head{$key};}, $val] : [$head{$key}, $val] : $val; $len = $val =~ /^\d+$/ ? $val : throw('Invalid content length', {'h', \%head}) if lc $key eq 'content-length'; } ; throw("Failed to find content length in $name service response") unless $len; throw("Content too large in $name service", {'length', $len}) if $len > 100000000; my $data = ''; while (1) { read $sock, $data, $len, length $data or throw('Failed to read bytes', {'needed', $len, 'got', length $data}); last if length $data >= $len; } ; close $sock; alarm $old; throw("Invalid $name service json object string") unless $data =~ /^\s*\{/; my $resp = eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@}); _encode_utf8_recurse($resp) if $enc; $resp } } do { alarm $old; +{'error', "Failed to get valid $name service response: $@"} }
Truth table33%1/3
A || B
A= eval { do { _decode_utf8_recurse($args) if $enc; $req = eval { do { $self->json->encode($args) } } || throw("Trouble encoding $name service json", {'msg', $@}, 1); my $sign = defined $pass ? do { my $t = int $begin; 'X-Respite-Auth: ' . (&$val('md5_pass') ? md5_hex($pass) : md5_hex("${pass}:${t}:${url}:" . md5_hex($req)) . ":$t") . "\r\n" } : ''; $cookie = $cookie ? "Cookie: $cookie\r\n" : ''; my $sock; my $i = 0; while (++$i) { $sock = $no_ssl ? 'IO::Socket::INET'->new("${host}:$port") : 'IO::Socket::SSL'->new('PeerAddr', $host, 'PeerPort', $port, 'SSL_verify_mode', &$val('ssl_verify_mode', 0)); last if $sock or not $retry or &Time::HiRes::time() - $begin > 3; &Net::Respite::Client::sleep(0.5); } ; unless ($sock) { throw("Could not connect to $name service", {'host', $host, 'port', $port, 'url', $url, 'msg', !$no_ssl && ($IO::Socket::SSL::SSL_ERROR || $!), 'detail', "$@", 'ssl', !$no_ssl, 'tries', $i}); } ; my $out = "POST $url HTTP/1.0\r\n$cookie${sign}Host: $host\r\nContent-length: " . length($req) . "\r\nContent-type: application/json\r\n\r\n$req"; warn 'DEBUG_Respite: Connected to http' . ($no_ssl ? '' : 's') . "://${host}:$port/\n$out\n" if $ENV{'DEBUG_Respite'}; print $sock $out; my($len, $type, $line); throw("Got non-200 status from $name service", {'status', $line, 'url', $url}) unless $line = readline $sock and $line =~ m[^HTTP/\S+ 200\b]; while (defined($line = readline $sock)) { $line =~ s/\r?\n$// or throw('Failed to find line termination', {'line', $line}); last if $line eq ''; () = split(/\s*:\s*/, $line, 2); $head{$key} = $head{$key} ? ref $head{$key} ? [@{$head{$key};}, $val] : [$head{$key}, $val] : $val; $len = $val =~ /^\d+$/ ? $val : throw('Invalid content length', {'h', \%head}) if lc $key eq 'content-length'; } ; throw("Failed to find content length in $name service response") unless $len; throw("Content too large in $name service", {'length', $len}) if $len > 100000000; my $data = ''; while (1) { read $sock, $data, $len, length $data or throw('Failed to read bytes', {'needed', $len, 'got', length $data}); last if length $data >= $len; } ; close $sock; alarm $old; throw("Invalid $name service json object string") unless $data =~ /^\s*\{/; my $resp = eval { do { $self->json->decode($data) } } || throw("Failed to decode $name service json response data", {'msg', $@}); _encode_utf8_recurse($resp) if $enc; $resp } }B= do { alarm $old; +{'error', "Failed to get valid $name service response: $@"} }
ABresult
1X1
011
000
146  
147 return $self->_result({
148 service => $name,
149 method => $method,
150 args => $args,
151 data => $hash,
152 headers => \%head,
153 url => $url, host => $host, port => $port,
154 brand => $brand,
155 elapsed => sprintf('%.05f', Time::HiRes::time() - $begin),
156 7 ▶ ($self->{'pretty'} ? (pretty => 1) : ()),
Branch: 1 branch
BranchTrueFalseTotal
$self->{'pretty'} ? : 0 7 7
157 });
158 }
159  
160 7 ▶sub _result {
Subroutine _result: called CC=5 SCAR=17.8
161 7 my ($self, $args) = @_;
162 7 ▶ if ($self->{'flat'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"flat"}) 7 0 7
163 7 my $data = $args->{'data'};
164 7 ▶ throw {_service => $args->{'service'} || $self->service_name, %$data, ($args->{'pretty'} ? (_pretty => 1) : ())} if $data->{'error'};
Branch: 2 branches
BranchTrueFalseTotal
if $data->{"error"} 2 5 7
$args->{'pretty'} ? : 0 2 2
Condition33%1/3
$args->{'service'} || $self->service_name
l!l&&r!l&&!r
200
MC/DC0%0/2
$args->{'service'} || $self->service_name
$args->{'service'} $self->service_name
Truth table33%1/3
A || B
A= $args->{'service'}B= $self->service_name
ABresult
1X1
011
000
165 5 return $data;
166 }
167 0 return bless $args, $self->_result_class;
168 }
169  
170 0 ▶sub _result_class { shift->{'result_class'} || 'Net::Respite::Client::Result' }
Subroutine _result_class: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
+(shift())->{"result_class"} or "Net::Respite::Client::Result" 0 0 0
171  
172 0 ▶sub _encode_utf8_recurse {
Subroutine _encode_utf8_recurse: not called CC=11 SCAR=48.8
173 0 my $d = shift;
174 0 ▶ if (UNIVERSAL::isa($d, 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($d, 'HASH')) { } 0 0 0
elsif (UNIVERSAL::isa($d, 'ARRAY')) { } 0 0 0
175 0 ▶ for my $k (keys %$d) { my $v = $d->{$k}; (ref $v) ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v) and utf8::encode($d->{$k}) }
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v) and utf8::encode($d->{$k}) 0 0 0
ref $v ? : 0 0 0
Condition0%0/3
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
ref $v ? _encode_utf8_recurse($v) : $v utf8::is_utf8($v)
Truth table0%0/3
A and B
A= ref $v ? _encode_utf8_recurse($v) : $vB= utf8::is_utf8($v)
ABresult
0X0
100
111
176 } elsif (UNIVERSAL::isa($d, 'ARRAY')) {
177 0 ▶ for my $v (@$d) { (ref $v) ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v) and utf8::encode($v) }
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v) and utf8::encode($v) 0 0 0
ref $v ? : 0 0 0
Condition0%0/3
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
ref $v ? _encode_utf8_recurse($v) : $v utf8::is_utf8($v)
Truth table0%0/3
A and B
A= ref $v ? _encode_utf8_recurse($v) : $vB= utf8::is_utf8($v)
ABresult
0X0
100
111
178 }
179 }
180  
181 0 ▶sub _decode_utf8_recurse {
Subroutine _decode_utf8_recurse: not called CC=13 SCAR=52.0
182 0 my $d = shift;
183 0 ▶ my $seen = shift || {};
Condition0%0/2
shift() || {}
l!l
00
MC/DC0%0/1
shift() || {}
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
184 0 ▶ return if $seen->{$d}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$d}++ 0 0 0
185 0 ▶ if (UNIVERSAL::isa($d, 'HASH')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($d, 'HASH')) { } 0 0 0
elsif (UNIVERSAL::isa($d, 'ARRAY')) { } 0 0 0
186 0 ▶ for my $k (keys %$d) { my $v = $d->{$k}; (ref $v) ? _decode_utf8_recurse($v, $seen) : $v and !utf8::is_utf8($v) and utf8::decode($d->{$k}) }
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v) and utf8::decode($d->{$k}) 0 0 0
ref $v ? : 0 0 0
Condition0%0/3
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)
ref $v ? _decode_utf8_recurse($v, $seen) : $v not utf8::is_utf8($v)
Truth table0%0/3
A and not(B)
A= ref $v ? _decode_utf8_recurse($v, $seen) : $vB= not utf8::is_utf8($v)
ABresult
0X0
100
111
187 } elsif (UNIVERSAL::isa($d, 'ARRAY')) {
188 0 ▶ for my $v (@$d) { (ref $v) ? _decode_utf8_recurse($v, $seen) : $v and !utf8::is_utf8($v) and utf8::decode($v) }
Branch: 2 branches
BranchTrueFalseTotal
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v) and utf8::decode($v) 0 0 0
ref $v ? : 0 0 0
Condition0%0/3
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)
!ll&&!rl&&r
000
MC/DC0%0/2
ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)
ref $v ? _decode_utf8_recurse($v, $seen) : $v not utf8::is_utf8($v)
Truth table0%0/3
A and not(B)
A= ref $v ? _decode_utf8_recurse($v, $seen) : $vB= not utf8::is_utf8($v)
ABresult
0X0
100
111
189 }
190 }
191  
192 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=7 SCAR=21.3
193 7 my $self = shift;
194 7 ▶ my $args = shift || {};
Condition50%1/2
shift() || {}
l!l
07
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
195 7 ▶ my $meth = $Net::Respite::Client::AUTOLOAD =~ /::(\w+)$/ ? $1 : throw "Invalid method\n";
Branch: 1 branch
BranchTrueFalseTotal
$Net::Respite::Client::AUTOLOAD =~ /::(\w+)$/ ? : 7 0 7
196 7 ▶ throw "Self was not passed while looking up method", {method => $meth, trace => 1} if ! ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 7 7
197 7 ▶ throw "Invalid ".$self->service_name." method \"$meth\"", {trace => 1} if !$self->_needs_remote($meth) && ! $self->can("__${meth}");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_needs_remote($meth) or $self->can("__$meth") 0 7 7
Condition33%1/3
$self->_needs_remote($meth) or $self->can("__$meth")
l!l&&r!l&&!r
700
MC/DC0%0/2
$self->_needs_remote($meth) or $self->can("__$meth")
$self->_needs_remote($meth) $self->can("__$meth")
Truth table33%1/3
A or B
A= $self->_needs_remote($meth)B= $self->can("__$meth")
ABresult
1X1
011
000
198 7 ▶ my $code = sub { $_[0]->run_method($meth => $_[1]) };
Subroutine __ANON__: called CC=1 SCAR=0.0
199 4 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
200 0 ▶ *{ref($self)."::$meth"} = $code if __PACKAGE__ ne ref($self);
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__ ne ref $self 0 7 7
201 7 return $self->$code($args);
202 }
203  
204 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
205  
206 0 ▶sub run_commandline {
Subroutine run_commandline: not called CC=3 SCAR=24.8
Pod undocumented
207 0 my $class = shift;
208 0 ▶ my $args = ref($_[0]) ? shift : {@_};
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 0 0 0
209 0 ▶ my $self = ref($class) ? $class : $class->new({%$args});
Branch: 1 branch
BranchTrueFalseTotal
ref $class ? : 0 0 0
210 0 require Net::Respite::CommandLine;
211 0 ▶ Net::Respite::CommandLine->run({dispatch_factory => sub { $self }});
Subroutine __ANON__: not called CC=1 SCAR=6.9
212 }
213  
214 ###----------------------------------------------------------------###
215  
216 {
217 package Net::Respite::Client::Result;
218 0 ▶ use overload 'bool' => sub { ! shift->error }, '""' => \&as_string, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
219 0 ▶ sub error { shift->data->{'error'} }
Subroutine error: not called CC=1 SCAR=6.9
220 0 ▶ sub TO_JSON { return {%{$_[0]}} }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
221 0 ▶ sub as_string {
Subroutine as_string: not called CC=5 SCAR=34.0
222 0 my $self = shift;
223 0 ▶ if (my $err = $self->error) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $err = $self->error) 0 0 0
224 0 my $data = $self->data;
225 0 ▶ my $p = defined($Net::Respite::Client::pretty) ? $Net::Respite::Client::pretty : $self->{'pretty'};
Branch: 1 branch
BranchTrueFalseTotal
defined $Net::Respite::Client::pretty ? : 0 0 0
226 0 local $data->{'error'}; delete $data->{'error'};
227 0 ▶ return !scalar keys %$self ? $err : "$err: ".($p ? Net::Respite::Client::jsop():Net::Respite::Client::json())->encode({%$data});
Branch: 2 branches
BranchTrueFalseTotal
!scalar(keys %$self) ? : 0 0 0
$p ? : 0 0 0
228 }
229 0 return "Called $self->{'service'} service method $self->{'method'}";
230 }
231 0 ▶ sub data { shift->{'data'} ||= {} }
Subroutine data: not called CC=2 SCAR=17.9
Condition0%0/2
+(shift())->{"data"} ||= {}
l!l
00
MC/DC0%0/1
+(shift())->{"data"} ||= {}
+(shift())->{"data"}
Truth table0%0/2
A
A= +(shift())->{"data"}
Aresult
11
00
232 }
233  
234 4 1;
« Respite/Base.pm ↑ Summary Respite/Server/Test.pm »