Condition Coverage

blib/lib/Respite/Client.pm
Criterion Covered Total %
condition 20 82 24.3


and 3 conditions

line !l l&&!r l&&r condition
32 0 5 0 not $args->{'_t'} and $self->{'token'}
63 44 0 0 ref $$c{"${name}_service"} && exists $$c{"${name}_service"}{$key}
44 0 0 ref $c->{$name} && exists $c->{$name}{$key}
86 5 0 0 $utf8 && (!ref($utf8) || $utf8->{$method})
175 0 0 0 ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
177 0 0 0 ref $v ? _encode_utf8_recurse($v) : $v and utf8::is_utf8($v)
186 0 0 0 ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)
188 0 0 0 ref $v ? _decode_utf8_recurse($v, $seen) : $v and not utf8::is_utf8($v)

or 2 conditions

line l !l condition
15 0 0 $e ||= "throw"
17 0 0 $l || 0
28 5 0 shift() || {}
31 5 0 $self->{'remote_user'} || $ENV{'REALUSER'} || $ENV{'SUDO_USER'} || $ENV{'REMOTE_USER'} || $ENV{'USER'} || (getpwuid $<)[0] || '-unknown-'
95 0 5 alarm($args->{'_timeout'} || &$val('timeout', 120)) || 0
183 0 0 shift() || {}
194 0 5 shift() || {}
231 0 0 +(shift())->{'data'} ||= {}

or 3 conditions

line l !l&&r !l&&!r condition
15 0 0 0 $p || $Throw::pretty
17 0 0 0 $a->{'trace'} or $l
22 0 10 0 $_[0]{'service_name'} or $_[0]{'service'}
27 5 0 0 shift() || throw("Missing $name service method", undef, 1)
30 0 5 0 $self->{'remote_ip'} || $ENV{'REMOTE_ADDR'} || ($ENV{'REALUSER'} || $ENV{'SUDO_USER'} ? 'sudo' : 'cmdline')
33 5 10 5 not $i or $c->[0]->isa(__PACKAGE__)
47 0 0 0 local $self->{'brand'} ||= $self->api_brand($name)
51 0 0 0 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})
57 78 0 0 $name ||= $self->service_name
69 5 0 0 $name ||= $self->service_name
71 0 0 5 eval { do { config::provider() } } or $self->_configs->{'provider'}
145 5 0 0 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; &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)) { throw('Failed to find line termination', {'line', $line}) unless $line =~ s/\r?\n$//; last if $line eq ''; my($key, $val) = 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) { throw('Failed to read bytes', {'needed', $len, 'got', length $data}) unless read $sock, $data, $len, 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: $@"} }
164 2 0 0 $args->{'service'} || $self->service_name
197 5 0 0 $self->_needs_remote($meth) or $self->can("__$meth")