Respite/Base.pm

filter: Statementstmt 69.2% 187 / 270 Branchbran 39.1% 94 / 240 Conditioncond 36.4% 77 / 211 MC/DCmcdc 11.4% 14 / 122 Subroutinesub 65.1% 28 / 43 Podpod 68.4% 13 / 19 totaltotal 45.6% 413 / 905 CC 209 SCAR 46.7
CC
209
Cov
50%
run_method
462.0
config
210.0
_decode_utf8_recurse
182.0
CRAP 106.7
« Respite/CommandLine.pm ↑ Summary Respite/Client.pm »
1 package Net::Respite::Base;
2  
3 # Net::Respite::Base - base class for Respite related modules that can be used from a server or commandline
4  
5 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use base 'Net::Respite::Common'; # Default _configs
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use autouse 'Net::Respite::Validate' => qw(validate);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Scalar::Util qw(blessed weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Time::HiRes ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Throw qw(throw);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 5 our $max_recurse = 10;
14  
15 13 ▶sub SHARE {}
Subroutine SHARE: called CC=1 SCAR=0.0
Pod undocumented
16  
17 0 ▶sub config {
Subroutine config: not called CC=14 SCAR=53.5
Pod undocumented
18 0 my ($self, $key, $def, $name) = @_;
19 0 ▶ $name ||= (my $n = $self->base_class || ref($self) || $self || '') =~ /(\w+)$/ ? lc $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
(my $n = $self->base_class || ref $self || $self || '') =~ /(\w+)$/ ? : 0 0 0
Condition0%0/11
$name ||= (my $n = $self->base_class || ref $self || $self || "") =~ /(\w+)$/ ? lc $1 : ""
l!l&&r!l&&!r
000
$self->base_class || ref $self || $self || ''
l!l
00
$self->base_class or ref $self or $self
l!l&&r!l&&!r
000
$self->base_class or ref $self
l!l&&r!l&&!r
000
MC/DC0%0/4
$name ||= (my $n = $self->base_class || ref $self || $self || "") =~ /(\w+)$/ ? lc $1 : ""
$name $self->base_class ref $self $self
Truth table0%0/5
A ||= B or C or D
A= $nameB= $self->base_classC= ref $selfD= $self
ABCDresult
1XXX1
01XX1
001X1
00011
00000
20 0 my $c = $self->_configs($name);
21 return exists($self->{$key}) ? $self->{$key}
22 : exists($c->{"${name}_service_${key}"}) ? $c->{"${name}_service_${key}"}
23 : (ref($c->{"${name}_service"}) && exists $c->{"${name}_service"}->{$key}) ? $c->{"${name}_service"}->{$key}
24 : exists($c->{"${name}_${key}"}) ? $c->{"${name}_${key}"}
25 0 ▶ : (ref($c->{$name}) && exists $c->{$name}->{$key}) ? $c->{$name}->{$key}
Branch: 6 branches
BranchTrueFalseTotal
exists $self->{$key} ? : 0 0 0
exists $$c{"${name}_service_$key"} ? : 0 0 0
ref $$c{"${name}_service"} && exists $$c{"${name}_service"}{$key} ? : 0 0 0
exists $$c{"${name}_$key"} ? : 0 0 0
ref $c->{$name} && exists $c->{$name}{$key} ? : 0 0 0
ref $def eq 'CODE' ? : 0 0 0
Condition0%0/6
ref $$c{"${name}_service"} and exists $$c{"${name}_service"}{$key}
!ll&&!rl&&r
000
ref $c->{$name} and exists $c->{$name}{$key}
!ll&&!rl&&r
000
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 table0%0/3
A and B
A= ref $$c{"${name}_service"}B= exists $$c{"${name}_service"}{$key}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= ref $c->{$name}B= exists $c->{$name}{$key}
ABresult
0X0
100
111
26 : ref($def) eq 'CODE' ? $def->($self) : $def;
27 }
28  
29 ###----------------------------------------------------------------###
30  
31 0 ▶sub run_method {
Subroutine run_method: not called CC=21 SCAR=61.4
Pod undocumented
32 0 my ($self, $meth, $args, $extra) = @_;
33 0 ▶ my $meta = $self->api_meta || {};
Condition0%0/2
$self->api_meta || {}
l!l
00
MC/DC0%0/1
$self->api_meta || {}
$self->api_meta
Truth table0%0/2
A
A= $self->api_meta
Aresult
11
00
34 0 ▶ my $begin = $meta->{'log_prefix'} ? Time::HiRes::time() : undef;
Branch: 1 branch
BranchTrueFalseTotal
$meta->{'log_prefix'} ? : 0 0 0
35 0 $meth =~ tr|/.-|___|;
36 0 ▶ throw "Cannot call method", {class => ref($self), meth => $meth} if $self->_restrict($meth);
Branch: 1 branch
BranchTrueFalseTotal
if $self->_restrict($meth) 0 0 0
37 0 ▶ my $code = $self->find_method($meth) || throw "Invalid Respite method", {class => ref($self), method => $meth};
Condition0%0/3
$self->find_method($meth) || throw('Invalid Respite method', {'class', ref $self, 'method', $meth})
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->find_method($meth) || throw('Invalid Respite method', {'class', ref $self, 'method', $meth})
$self->find_method($meth) throw('Invalid Respite method', {'class', ref $self, 'method', $meth})
Truth table0%0/3
A || B
A= $self->find_method($meth)B= throw('Invalid Respite method', {'class', ref $self, 'method', $meth})
ABresult
1X1
011
000
38 0 my $utf8 = $meta->{'utf8_encoded'};
39 0 ▶ my $enc = $utf8 && (!ref($utf8) || $utf8->{$meth});
Condition0%0/6
$utf8 && (!ref($utf8) || $utf8->{$meth})
!ll&&!rl&&r
000
not ref $utf8 or $utf8->{$meth}
l!l&&r!l&&!r
000
MC/DC0%0/3
$utf8 && (!ref($utf8) || $utf8->{$meth})
$utf8 not ref $utf8 $utf8->{$meth}
Truth table0%0/4
A && not(B) or C
A= $utf8B= not ref $utf8C= $utf8->{$meth}
ABCresult
0XX0
1000
11X1
1011
40 0 ▶ my $trp = $self->{'transport'} || '';
Condition0%0/2
$self->{'transport'} || ''
l!l
00
MC/DC0%0/1
$self->{'transport'} || ''
$self->{'transport'}
Truth table0%0/2
A
A= $self->{'transport'}
Aresult
11
00
41 0 ▶ if ($enc) { # consistently handle args from json, form, or commandline
Branch: 1 branch
BranchTrueFalseTotal
if ($enc) { } 0 0 0
42 0 ▶ _encode_utf8_recurse($args) if $trp eq 'json';
Branch: 1 branch
BranchTrueFalseTotal
if $trp eq "json" 0 0 0
43 } else {
44 0 ▶ _decode_utf8_recurse($args) if $trp && $trp ne 'json';
Branch: 1 branch
BranchTrueFalseTotal
if $trp and $trp ne "json" 0 0 0
Condition0%0/3
$trp and $trp ne "json"
!ll&&!rl&&r
000
MC/DC0%0/2
$trp and $trp ne "json"
$trp $trp ne "json"
Truth table0%0/3
A and B
A= $trpB= $trp ne "json"
ABresult
0X0
100
111
45 }
46 0 ▶ my $resp = eval { $self->$code($args, $extra) } || do {
Condition0%0/3
eval { do { $self->$code($args, $extra) } } || do { my $resp = $@; $resp = eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@ unless ref $resp and $resp->{'error'}; warn $resp if $trp ne 'cmdline'; $resp }
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { $self->$code($args, $extra) } } || do { my $resp = $@; $resp = eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@ unless ref $resp and $resp->{'error'}; warn $resp if $trp ne 'cmdline'; $resp }
eval { do { $self->$code($args, $extra) } } do { my $resp = $@; $resp = eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@ unless ref $resp and $resp->{'error'}; warn $resp if $trp ne 'cmdline'; $resp }
Truth table0%0/3
A || B
A= eval { do { $self->$code($args, $extra) } }B= do { my $resp = $@; $resp = eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@ unless ref $resp and $resp->{'error'}; warn $resp if $trp ne 'cmdline'; $resp }
ABresult
1X1
011
000
47 0 my $resp = $@;
48 0 ▶ $resp = eval { throw 'Trouble dispatching', {method => $meth, msg => $resp} } || $@ if !ref($resp) || !$resp->{'error'};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $resp and $resp->{"error"} 0 0 0
Condition0%0/6
ref $resp and $resp->{"error"}
!ll&&!rl&&r
000
eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $resp and $resp->{"error"}
ref $resp $resp->{"error"}
MC/DC0%0/2
eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } || $@
eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } } $@
Truth table0%0/3
A and B
A= ref $respB= $resp->{"error"}
ABresult
0X0
100
111
Truth table0%0/3
A || B
A= eval { do { throw('Trouble dispatching', {'method', $meth, 'msg', $resp}) } }B= $@
ABresult
1X1
011
000
49 0 ▶ warn $resp if $trp ne 'cmdline';
Branch: 1 branch
BranchTrueFalseTotal
if $trp ne "cmdline" 0 0 0
50 0 $resp;
51 };
52 $self->log_request({
53 method => $meth,
54 request => $args,
55 response => $resp,
56 api_ip => $self->{'api_ip'},
57 api_brand => $self->{'api_brand'},
58 remote_ip => $self->{'remote_ip'},
59 remote_user => $self->{'remote_user'},
60 admin_user => $self->{'admin_user'},
61 0 ▶ caller => $self->{'caller'},
Branch: 1 branch
BranchTrueFalseTotal
if $begin 0 0 0
62 elapsed => (Time::HiRes::time() - $begin),
63 }) if $begin;
64 0 ▶ _decode_utf8_recurse($resp) if ref($resp) eq 'HASH' && exists($resp->{'_utf8_encoded'}) ? delete($resp->{'_utf8_encoded'}) : $enc;
Branch: 2 branches
BranchTrueFalseTotal
if ref $resp eq "HASH" && exists $resp->{"_utf8_encoded"} ? delete $resp->{"_utf8_encoded"} : $enc 0 0 0
ref $resp eq 'HASH' && exists $resp->{'_utf8_encoded'} ? : 0 0 0
Condition0%0/3
ref $resp eq "HASH" and exists $resp->{"_utf8_encoded"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $resp eq "HASH" and exists $resp->{"_utf8_encoded"}
ref $resp eq "HASH" exists $resp->{"_utf8_encoded"}
Truth table0%0/3
A and B
A= ref $resp eq "HASH"B= exists $resp->{"_utf8_encoded"}
ABresult
0X0
100
111
65 0 return $resp;
66 }
67  
68 0 ▶sub _restrict {
Subroutine _restrict: not called CC=2 SCAR=17.9
69 0 my ($class, $meth) = @_;
70 0 ▶ return 0 if __PACKAGE__->SUPER::can($meth); # any of the inherited methods from Net::Respite::Base are not Respite methods
Branch: 1 branch
BranchTrueFalseTotal
if __PACKAGE__->SUPER::can($meth) 0 0 0
71 0 return $meth =~ /^_/;
72 }
73  
74 31 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=6 SCAR=19.1
75 31 my $self = shift;
76 31 ▶ my $meth = $Net::Respite::Base::AUTOLOAD =~ /::(\w+)$/ ? $1 : throw "Invalid method", {method => $Net::Respite::Base::AUTOLOAD};
Branch: 1 branch
BranchTrueFalseTotal
$Net::Respite::Base::AUTOLOAD =~ /::(\w+)$/ ? : 31 0 31
77 31 ▶ throw "Self was not passed while looking up method", {method => $meth, trace => 1} if ! blessed $self;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) 0 31 31
78 31 ▶ local $self->{'_autoload'}->{$meth} = ($self->{'_autoload'}->{$meth} || 0) + 1;
Condition50%1/2
$self->{'_autoload'}{$meth} || 0
l!l
031
MC/DC0%0/1
$self->{'_autoload'}{$meth} || 0
$self->{'_autoload'}{$meth}
Truth table50%1/2
A
A= $self->{'_autoload'}{$meth}
Aresult
11
00
79 31 ▶ throw "Recursive method lookup", {class => ref($self), method => $meth} if $self->{'_autoload'}->{$meth} > $max_recurse;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_autoload"}{$meth} > $Net::Respite::Base::max_recurse 0 31 31
80 31 ▶ my $code = $self->find_method($meth) || throw "Invalid Respite method during AUTOLOAD", {class => ref($self), method => $meth}, 1;
Condition66%2/3
$self->find_method($meth) || throw('Invalid Respite method during AUTOLOAD', {'class', ref $self, 'method', $meth}, 1)
l!l&&r!l&&!r
3010
MC/DC0%0/2
$self->find_method($meth) || throw('Invalid Respite method during AUTOLOAD', {'class', ref $self, 'method', $meth}, 1)
$self->find_method($meth) throw('Invalid Respite method during AUTOLOAD', {'class', ref $self, 'method', $meth}, 1)
Truth table33%1/3
A || B
A= $self->find_method($meth)B= throw('Invalid Respite method during AUTOLOAD', {'class', ref $self, 'method', $meth}, 1)
ABresult
1X1
011
000
81 30 return $self->$code(@_);
82 }
83  
84 0 ▶sub DESTROY {}
Subroutine DESTROY: not called CC=1 SCAR=0.0
85  
86 9 ▶sub api_meta {
Subroutine api_meta: called CC=4 SCAR=15.8
Pod undocumented
87 9 my $self = shift;
88 9 my $ref = ref $self;
89 5 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
90 0 ▶ return ${"${ref}::api_meta"} if ${"${ref}::api_meta"};
Branch: 1 branch
BranchTrueFalseTotal
if ${"${ref}::api_meta";} 0 9 9
91 9 ▶ return $self->{'api_meta'} ||= ($ref eq __PACKAGE__ ? throw "No api_meta defined", {class => $self, type => 'no_meta'} : {});
Branch: 1 branch
BranchTrueFalseTotal
$ref eq __PACKAGE__ ? : 0 0 0
Condition33%1/3
$self->{"api_meta"} ||= $ref eq __PACKAGE__ ? throw("No api_meta defined", {"class", $self, "type", "no_meta"}) : {}
l!l&&r!l&&!r
900
MC/DC0%0/2
$self->{"api_meta"} ||= $ref eq __PACKAGE__ ? throw("No api_meta defined", {"class", $self, "type", "no_meta"}) : {}
$self->{"api_meta"} $ref eq __PACKAGE__ ? throw("No api_meta defined", {"class", $self, "type", "no_meta"}) : {}
Truth table33%1/3
A ||= B
A= $self->{"api_meta"}B= $ref eq __PACKAGE__ ? throw("No api_meta defined", {"class", $self, "type", "no_meta"}) : {}
ABresult
1X1
011
000
92 }
93  
94 0 ▶sub api_preload { shift->find_method; return 1 }
Subroutine api_preload: not called CC=1 SCAR=6.9
Pod documented
95  
96 0 ▶sub _encode_utf8_recurse {
Subroutine _encode_utf8_recurse: not called CC=11 SCAR=48.8
97 0 my $d = shift;
98 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
99 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
100 } elsif (UNIVERSAL::isa($d, 'ARRAY')) {
101 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
102 }
103 }
104  
105 0 ▶sub _decode_utf8_recurse {
Subroutine _decode_utf8_recurse: not called CC=13 SCAR=52.0
106 0 my $d = shift;
107 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
108 0 ▶ return if $seen->{$d}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen->{$d}++ 0 0 0
109 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
110 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
111 } elsif (UNIVERSAL::isa($d, 'ARRAY')) {
112 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
113 }
114 }
115  
116 ###----------------------------------------------------------------###
117  
118 3 ▶sub validate_args {
Subroutine validate_args: called CC=17 SCAR=43.9
Pod documented
119 3 my ($self, $args, $val_hash) = @_;
120 3 ▶ my $sub = (caller(my $n = 1))[3]; $sub = (caller ++$n)[3] while $sub eq '(eval)' || $sub =~ /::validate_args$/;
Branch: 1 branch
BranchTrueFalseTotal
$sub eq "(eval)" || $sub =~ /::validate_args$/ and do { $sub = (caller ++$n)[3] } 0 3 3
Condition33%1/3
$sub eq "(eval)" or $sub =~ /::validate_args$/
l!l&&r!l&&!r
003
MC/DC0%0/2
$sub eq "(eval)" or $sub =~ /::validate_args$/
$sub eq "(eval)" $sub =~ /::validate_args$/
Truth table33%1/3
A or B
A= $sub eq "(eval)"B= $sub =~ /::validate_args$/
ABresult
1X1
011
000
121 3 ▶ if (! $val_hash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val_hash) 3 0 3
122 3 ▶ my $code = $self->can("${sub}__meta") or throw "Could not find meta information.", {method => $sub}, 1;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->can("${sub}__meta") or throw("Could not find meta information.", {"method", $sub}, 1) 3 0 3
123 3 my $meta = $code->($self);
124 3 ▶ $val_hash = $meta->{'args'} || throw "Missing args in meta information", {method => $sub}, 1;
Condition33%1/3
$meta->{'args'} || throw('Missing args in meta information', {'method', $sub}, 1)
l!l&&r!l&&!r
300
MC/DC0%0/2
$meta->{'args'} || throw('Missing args in meta information', {'method', $sub}, 1)
$meta->{'args'} throw('Missing args in meta information', {'method', $sub}, 1)
Truth table33%1/3
A || B
A= $meta->{'args'}B= throw('Missing args in meta information', {'method', $sub}, 1)
ABresult
1X1
011
000
125 0 ▶ if (my $ra = $meta->{'requires_admin'} and (eval { $self->api_meta->{'enforce_requires_admin'} } || do { my $e = $@; die $e if $e && (!ref($e) || $e->{'type'} ne 'no_meta'); 0 })) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $ra = $meta->{"requires_admin"} and eval { do { $self->api_meta->{"enforce_requires_admin"} } } || do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }) 0 3 3
if $e and !ref($e) || $e->{"type"} ne "no_meta" 0 0 0
Condition8%1/12
my $ra = $meta->{"requires_admin"} and eval { do { $self->api_meta->{"enforce_requires_admin"} } } || do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }
!ll&&!rl&&r
300
eval { do { $self->api_meta->{"enforce_requires_admin"} } } or do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }
l!l&&r!l&&!r
000
$e and !ref($e) || $e->{"type"} ne "no_meta"
!ll&&!rl&&r
000
not ref $e or $e->{"type"} ne "no_meta"
l!l&&r!l&&!r
000
MC/DC0%0/3
my $ra = $meta->{"requires_admin"} and eval { do { $self->api_meta->{"enforce_requires_admin"} } } || do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }
my $ra = $meta->{"requires_admin"} eval { do { $self->api_meta->{"enforce_requires_admin"} } } do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }
MC/DC0%0/3
$e and !ref($e) || $e->{"type"} ne "no_meta"
$e not ref $e $e->{"type"} ne "no_meta"
Truth table25%1/4
A and B or C
A= my $ra = $meta->{"requires_admin"}B= eval { do { $self->api_meta->{"enforce_requires_admin"} } }C= do { my $e = $@; die $e if $e and !ref($e) || $e->{"type"} ne "no_meta"; 0 }
ABCresult
0XX0
1000
11X1
1011
Truth table0%0/4
A and not(B) or C
A= $eB= not ref $eC= $e->{"type"} ne "no_meta"
ABCresult
0XX0
1000
11X1
1011
126 0 ▶ $self->require_admin(ref($ra) eq 'CODE' ? $ra->($self, $sub, $args) : ref($ra) eq 'HASH' ? $ra : {$ra => 1, method => $sub});
Branch: 2 branches
BranchTrueFalseTotal
ref $ra eq 'CODE' ? : 0 0 0
ref $ra eq 'HASH' ? : 0 0 0
127 }
128 }
129 3 ▶ my $error_hash = validate($args || {}, $val_hash) || return 1;
Condition75%3/4
validate($args || {}, $val_hash) || (return 1)
l!l
12
$args || {}
l!l
30
MC/DC100%1/1
validate($args || {}, $val_hash) || (return 1)
validate($args || {}, $val_hash)
MC/DC0%0/1
$args || {}
$args
Truth table100%2/2
A
A= validate($args || {}, $val_hash)
Aresult
11
00
Truth table50%1/2
A
A= $args
Aresult
11
00
130 throw "Failed to validate args", {
131 errors => $error_hash,
132 type => 'validation',
133 1 ▶ ($args->{'_no_trace'} ? () : (trace => 1)),
Branch: 1 branch
BranchTrueFalseTotal
$args->{'_no_trace'} ? : 1 0 1
134 }, 1;
135 }
136  
137 1 ▶sub api_ip { $_[0]->{'api_ip'} || ($_[0]->{'base'} ? $_[0]->{'base'}->api_ip : throw "Missing api_ip",0,1) }
Subroutine api_ip: called CC=3 SCAR=16.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"api_ip"} or $_[0]{"base"} ? $_[0]{"base"}->api_ip : throw("Missing api_ip", 0, 1) 1 0 1
$_[0]{'base'} ? : 0 0 0
138 1 ▶sub api_brand { $_[0]->{'api_brand'} || ($_[0]->{'base'} ? $_[0]->{'base'}->api_brand : ($_[0]->is_local && $ENV{'PROV'}) || throw "Missing api_brand",0,1) }
Subroutine api_brand: called CC=5 SCAR=22.0
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"api_brand"} or $_[0]{"base"} ? $_[0]{"base"}->api_brand : $_[0]->is_local && $ENV{"PROV"} || throw("Missing api_brand", 0, 1) 0 1 1
$_[0]{'base'} ? : 0 1 1
Condition33%2/6
$_[0]->is_local and $ENV{"PROV"} or throw("Missing api_brand", 0, 1)
l!l&&r!l&&!r
001
$_[0]->is_local and $ENV{"PROV"}
!ll&&!rl&&r
100
MC/DC0%0/3
$_[0]->is_local and $ENV{"PROV"} or throw("Missing api_brand", 0, 1)
$_[0]->is_local $ENV{"PROV"} throw("Missing api_brand", 0, 1)
Truth table0%0/5
A and B or C
A= $_[0]->is_localB= $ENV{"PROV"}C= throw("Missing api_brand", 0, 1)
ABCresult
11X1
0X11
1011
0X00
1000
139 0 ▶sub remote_ip { $_[0]->{'remote_ip'} || ($_[0]->{'base'} ? $_[0]->{'base'}->remote_ip : throw "Missing remote_ip",0,1) }
Subroutine remote_ip: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"remote_ip"} or $_[0]{"base"} ? $_[0]{"base"}->remote_ip : throw("Missing remote_ip", 0, 1) 0 0 0
$_[0]{'base'} ? : 0 0 0
140 0 ▶sub remote_user { $_[0]->{'remote_user'} || ($_[0]->{'base'} ? $_[0]->{'base'}->remote_user : throw "Missing remote_user",0,1) }
Subroutine remote_user: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"remote_user"} or $_[0]{"base"} ? $_[0]{"base"}->remote_user : throw("Missing remote_user", 0, 1) 0 0 0
$_[0]{'base'} ? : 0 0 0
141  
142 0 ▶sub admin_user { $_[0]->{'admin_user'} || ($_[0]->{'base'} ? $_[0]->{'base'}->admin_user : throw "Not authenticated",0,1) }
Subroutine admin_user: not called CC=3 SCAR=24.8
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"admin_user"} or $_[0]{"base"} ? $_[0]{"base"}->admin_user : throw("Not authenticated", 0, 1) 0 0 0
$_[0]{'base'} ? : 0 0 0
143  
144 1 ▶sub transport { $_[0]->{'transport'} || ($_[0]->{'base'} ? $_[0]->{'base'}->transport : '') }
Subroutine transport: called CC=3 SCAR=12.7
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
$_[0]{"transport"} or $_[0]{"base"} ? $_[0]{"base"}->transport : "" 0 1 1
$_[0]{'base'} ? : 0 1 1
145 0 ▶sub is_server { exists($_[0]->{'is_server'}) ? $_[0]->{'is_server'} : ($_[0]->{'base'} && $_[0]->{'base'}->is_server) }
Subroutine is_server: not called CC=3 SCAR=24.8
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
exists $_[0]{'is_server'} ? : 0 0 0
Condition0%0/3
$_[0]{"base"} and $_[0]{"base"}->is_server
!ll&&!rl&&r
000
MC/DC0%0/2
$_[0]{"base"} and $_[0]{"base"}->is_server
$_[0]{"base"} $_[0]{"base"}->is_server
Truth table0%0/3
A and B
A= $_[0]{"base"}B= $_[0]{"base"}->is_server
ABresult
0X0
100
111
146  
147 0 ▶sub is_authed { eval { shift->admin_user } ? 1 : 0 }
Subroutine is_authed: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
eval { do { (shift())->admin_user } } ? : 0 0 0
148  
149 1 ▶sub is_local { $_[0]->transport =~ /^(?:cmdline|gui)$/ ? 1 : 0 }
Subroutine is_local: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->transport =~ /^(?:cmdline|gui)$/ ? : 0 1 1
150 0 ▶sub who { shift->remote_user }
Subroutine who: not called CC=1 SCAR=6.9
Pod undocumented
151  
152 0 ▶sub base {
Subroutine base: not called CC=6 SCAR=37.4
Pod documented
153 0 my $self = shift;
154 0 ▶ if (! $self->{'base'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"base"}) 0 0 0
155 0 ▶ throw "Could not find base when called_from_base",0,1 if $self->{'called_from_base'};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"called_from_base"} 0 0 0
156 0 ▶ my $class = $self->base_class || throw "Could not find a base_class when accessing base from direct source",0,1;
Condition0%0/3
$self->base_class || throw('Could not find a base_class when accessing base from direct source', 0, 1)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->base_class || throw('Could not find a base_class when accessing base from direct source', 0, 1)
$self->base_class throw('Could not find a base_class when accessing base from direct source', 0, 1)
Truth table0%0/3
A || B
A= $self->base_classB= throw('Could not find a base_class when accessing base from direct source', 0, 1)
ABresult
1X1
011
000
157 0 ▶ return $self if ref($self) eq $class;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq $class 0 0 0
158 0 (my $file = "$class.pm") =~ s|::|/|g;
159 0 ▶ eval { require $file } || throw "Could not load base_class", {msg => $@, class => $class};
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require $file } } or throw("Could not load base_class", {"msg", $@, "class", $class}) 0 0 0
160 0 $self->{'base'} = $class->new({$self->SHARE, map {$_ => $self->{$_}} qw(api_ip api_brand remote_ip remote_user admin_user is_server)});
161 }
162 0 return $self->{'base'};
163 }
164  
165 0 ▶sub base_class { shift->{'base_class'} }
Subroutine base_class: not called CC=1 SCAR=6.9
Pod documented
166  
167 ###----------------------------------------------------------------###
168  
169 40 ▶sub find_method {
Subroutine find_method: called CC=72 SCAR=46.7
Pod undocumented
170 40 my ($self, $meth, $opt) = @_;
171 40 ▶ my $meta = $self->api_meta || {};
Condition50%1/2
$self->api_meta || {}
l!l
400
MC/DC0%0/1
$self->api_meta || {}
$self->api_meta
Truth table50%1/2
A
A= $self->api_meta
Aresult
11
00
172  
173 40 ▶ my $cache = $meta->{'_cache'}->{ref($self)} ||= {%{ $meta->{'methods'} || {} }};
Condition100%4/4
$meta->{"_cache"}{ref $self} ||= {%{$meta->{"methods"} or {};}}
l!l
2713
$meta->{'methods'} || {}
l!l
67
MC/DC100%1/1
$meta->{"_cache"}{ref $self} ||= {%{$meta->{"methods"} or {};}}
$meta->{"_cache"}{ref $self}
MC/DC100%1/1
$meta->{'methods'} || {}
$meta->{'methods'}
Truth table100%2/2
A
A= $meta->{"_cache"}{ref $self}
Aresult
11
00
Truth table100%2/2
A
A= $meta->{'methods'}
Aresult
11
00
174 40 ▶ if ($meth) {
Branch: 2 branches
BranchTrueFalseTotal
if ($meth) { } 31 9 40
elsif (not $cache->{'--load--'}{'builtin'}++) { } 9 0 9
175 31 ▶ return $cache->{$meth} if exists $cache->{$meth};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$meth} 23 8 31
176 8 ▶ return $cache->{$meth} if exists $cache->{$meth};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$meth} 0 8 8
177 8 my $code;
178 0 ▶ return $cache->{$meth} = $code if $code = $self->can($meth) and $code ne \&{__PACKAGE__."::$meth"};
Branch: 1 branch
BranchTrueFalseTotal
if $code = $self->can($meth) and $code ne \&{'Net::Respite::Base' . "::$meth";} 0 8 8
Condition33%1/3
$code = $self->can($meth) and $code ne \&{'Net::Respite::Base' . "::$meth";}
!ll&&!rl&&r
800
MC/DC0%0/2
$code = $self->can($meth) and $code ne \&{'Net::Respite::Base' . "::$meth";}
$code = $self->can($meth) $code ne \&{'Net::Respite::Base' . "::$meth";}
Truth table33%1/3
A and B
A= $code = $self->can($meth)B= $code ne \&{'Net::Respite::Base' . "::$meth";}
ABresult
0X0
100
111
179 8 ▶ return $cache->{$meth} = $code if $code = $self->can("__$meth");
Branch: 1 branch
BranchTrueFalseTotal
if $code = $self->can("__$meth") 3 5 8
180 } elsif (!$cache->{'--load--'}->{'builtin'}++) {
181 5 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
182 9 my @search = ref($self);
183 9 ▶ while (my $pkg = shift @search) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $pkg = shift @search) 16 9 25
184 16 ▶ unshift @search, @{"${pkg}::ISA"} if $pkg ne __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if $pkg ne __PACKAGE__ 7 9 16
185 16 for my $meth (keys %{"${pkg}::"}) {
186 477 ▶ next if ! defined &{"${pkg}::$meth"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${pkg}::$meth";} 148 329 477
187 329 ▶ next if ($pkg eq __PACKAGE__) ? $meth !~ /^__/ : defined &{__PACKAGE__."::$meth"};
Branch: 2 branches
BranchTrueFalseTotal
if $pkg eq __PACKAGE__ ? !($meth =~ /^__/) : defined &{'Net::Respite::Base' . "::$meth";} 275 54 329
$pkg eq __PACKAGE__ ? : 297 32 329
188 54 ▶ next if $pkg =~ /^_[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
if $pkg =~ /^_[a-z]/ 0 54 54
189 54 ▶ next if $meth !~ /__meta$/ && $meth !~ /^__/ && !defined &{"${pkg}::${meth}__meta"};
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";} 0 54 54
Condition83%5/6
$meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";}
l!l&&r!l&&!r
4590
$meth =~ /__meta$/ or $meth =~ /^__/
l!l&&r!l&&!r
27189
MC/DC0%0/3
$meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";}
$meth =~ /__meta$/ $meth =~ /^__/ defined &{"${pkg}::${meth}__meta";}
Truth table75%3/4
A or B or C
A= $meth =~ /__meta$/B= $meth =~ /^__/C= defined &{"${pkg}::${meth}__meta";}
ABCresult
1XX1
01X1
0011
0000
190 54 (my $name = $meth) =~ s/^__//;
191 54 ▶ $cache->{$name} ||= "${pkg}::$meth";
Condition100%2/2
$cache->{$name} ||= "${pkg}::$meth"
l!l
945
MC/DC100%1/1
$cache->{$name} ||= "${pkg}::$meth"
$cache->{$name}
Truth table100%2/2
A
A= $cache->{$name}
Aresult
11
00
192 }
193 }
194 }
195  
196 14 foreach my $type ('namespaces', 'lib_dirs') {
197 24 ▶ my $NS = $meta->{$type} || next;
Condition100%2/2
$meta->{$type} || (next)
l!l
159
MC/DC100%1/1
$meta->{$type} || (next)
$meta->{$type}
Truth table100%2/2
A
A= $meta->{$type}
Aresult
11
00
198 15 ▶ $NS = $cache->{'--load--'}->{'lib_dirs'} ||= $self->_load_lib_dir($NS) if $type eq 'lib_dirs';
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "lib_dirs" 4 11 15
Condition66%2/3
$cache->{"--load--"}{"lib_dirs"} ||= $self->_load_lib_dir($NS)
l!l&&r!l&&!r
130
MC/DC0%0/2
$cache->{"--load--"}{"lib_dirs"} ||= $self->_load_lib_dir($NS)
$cache->{"--load--"}{"lib_dirs"} $self->_load_lib_dir($NS)
Truth table66%2/3
A ||= B
A= $cache->{"--load--"}{"lib_dirs"}B= $self->_load_lib_dir($NS)
ABresult
1X1
011
000
199 15 foreach my $ns (sort keys %$NS) {
200 27 my $opt = $NS->{$ns};
201 27 ▶ $opt = {match => $opt} if ref($opt) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt ne "HASH" 20 7 27
202 27 ▶ my $name = !$meth ? undef : ($meth !~ /^${ns}_*(\w+)$/) ? next : $opt->{'full_name'} ? $meth : $1;
Branch: 3 branches
BranchTrueFalseTotal
!$meth ? : 17 10 27
!($meth =~ /^${ns}_*(\w+)$/) ? : 6 4 10
$opt->{'full_name'} ? : 0 4 4
203 21 ▶ my $pkg = $opt->{'pkg'} || $opt->{'package'} || do { (my $pkg = $ns) =~ s/(?:_|\b)([a-z])/\u$1/g; $pkg };
Condition66%4/6
$opt->{'pkg'} || $opt->{'package'} || do { (my $pkg = $ns) =~ s/(?:_|\b)([a-z])/\u$1/g; $pkg }
l!l&&r!l&&!r
3180
$opt->{"pkg"} or $opt->{"package"}
l!l&&r!l&&!r
3018
MC/DC0%0/3
$opt->{'pkg'} || $opt->{'package'} || do { (my $pkg = $ns) =~ s/(?:_|\b)([a-z])/\u$1/g; $pkg }
$opt->{"pkg"} $opt->{"package"} do { (my $pkg = $ns) =~ s/(?:_|\b)([a-z])/\u$1/g; $pkg }
Truth table50%2/4
A or B || C
A= $opt->{"pkg"}B= $opt->{"package"}C= do { (my $pkg = $ns) =~ s/(?:_|\b)([a-z])/\u$1/g; $pkg }
ABCresult
1XX1
01X1
0011
0000
204 21 ▶ if (! $pkg->can('new')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pkg->can("new")) 1 20 21
205 1 (my $file = "$pkg.pm") =~ s|::|/|g;
206 1 ▶ if (! eval { require ($opt->{'file'} ||= $file) }) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eval { do { require ($opt->{"file"} ||= $file) } }) 0 1 1
Condition33%1/3
$opt->{"file"} ||= $file
l!l&&r!l&&!r
100
MC/DC0%0/2
$opt->{"file"} ||= $file
$opt->{"file"} $file
Truth table33%1/3
A ||= B
A= $opt->{"file"}B= $file
ABresult
1X1
011
000
207 0 warn "Failed to load listed module $pkg ($opt->{'file'}): $@";
208 0 next;
209 }
210 1 ▶ $INC{$file} = $INC{$opt->{'file'}} if $opt->{'file'} ne $file;
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"file"} ne $file 1 0 1
211 }
212  
213 # TODO - faster lookup if we know the method
214 21 ▶ my $qr = $opt->{'match'} || 1;
Condition100%2/2
$opt->{'match'} || 1
l!l
183
MC/DC100%1/1
$opt->{'match'} || 1
$opt->{'match'}
Truth table100%2/2
A
A= $opt->{'match'}
Aresult
11
00
215 21 ▶ $qr = ($qr eq '1' || $qr eq '*') ? qr{.} : qr{^$qr} if $qr && !ref $qr;
Branch: 2 branches
BranchTrueFalseTotal
if $qr and not ref $qr 21 0 21
$qr eq '1' || $qr eq '*' ? : 19 2 21
Condition50%3/6
$qr and not ref $qr
!ll&&!rl&&r
0021
$qr eq 1 or $qr eq "*"
l!l&&r!l&&!r
1902
MC/DC0%0/2
$qr and not ref $qr
$qr not ref $qr
MC/DC50%1/2
$qr eq 1 or $qr eq "*"
$qr eq 1 $qr eq "*"
Truth table33%1/3
A and not(B)
A= $qrB= not ref $qr
ABresult
0X0
100
111
Truth table66%2/3
A or B
A= $qr eq 1B= $qr eq "*"
ABresult
1X1
011
000
216 5 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
217 21 for my $meth (keys %{"${pkg}::"}) {
218 111 ▶ next if ! defined &{"${pkg}::$meth"};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{"${pkg}::$meth";} 58 53 111
219 53 ▶ next if ($pkg eq __PACKAGE__) ? $meth !~ /^__/ : defined &{__PACKAGE__."::$meth"};
Branch: 2 branches
BranchTrueFalseTotal
if $pkg eq __PACKAGE__ ? !($meth =~ /^__/) : defined &{'Net::Respite::Base' . "::$meth";} 4 49 53
$pkg eq __PACKAGE__ ? : 0 53 53
220 49 ▶ next if $meth =~ /^_[a-z]/;
Branch: 1 branch
BranchTrueFalseTotal
if $meth =~ /^_[a-z]/ 0 49 49
221 49 ▶ next if $qr && $meth !~ $qr;
Branch: 1 branch
BranchTrueFalseTotal
if $qr and not $meth =~ /$qr/ 0 49 49
Condition33%1/3
$qr and not $meth =~ /$qr/
!ll&&!rl&&r
0490
MC/DC0%0/2
$qr and not $meth =~ /$qr/
$qr not $meth =~ /$qr/
Truth table33%1/3
A and not(B)
A= $qrB= not $meth =~ /$qr/
ABresult
0X0
100
111
222 49 ▶ next if $meth !~ /__meta$/ && $meth !~ /^__/ && !defined &{"${pkg}::${meth}__meta"};
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";} 16 33 49
Condition100%6/6
$meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";}
l!l&&r!l&&!r
231016
$meth =~ /__meta$/ or $meth =~ /^__/
l!l&&r!l&&!r
101326
MC/DC100%3/3
$meth =~ /__meta$/ or $meth =~ /^__/ or defined &{"${pkg}::${meth}__meta";}
$meth =~ /__meta$/ $meth =~ /^__/ defined &{"${pkg}::${meth}__meta";}
Truth table100%4/4
A or B or C
A= $meth =~ /__meta$/B= $meth =~ /^__/C= defined &{"${pkg}::${meth}__meta";}
ABCresult
1XX1
01X1
0011
0000
223 33 (my $name = $meth) =~ s/^__//;
224 33 ▶ $name = "${ns}_${name}" if !$opt->{'full_name'} && $name !~ /^\Q$ns\E_/;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt->{"full_name"} or $name =~ /^\Q$ns\E_/ 33 0 33
Condition33%1/3
$opt->{"full_name"} or $name =~ /^\Q$ns\E_/
l!l&&r!l&&!r
0033
MC/DC0%0/2
$opt->{"full_name"} or $name =~ /^\Q$ns\E_/
$opt->{"full_name"} $name =~ /^\Q$ns\E_/
Truth table33%1/3
A or B
A= $opt->{"full_name"}B= $name =~ /^\Q$ns\E_/
ABresult
1X1
011
000
225 33 ▶ my $dt = $opt->{'dispatch_type'} || $meta->{'dispatch_type'} || 'new';
Condition100%5/5
$opt->{'dispatch_type'} || $meta->{'dispatch_type'} || 'new'
l!l
2310
$opt->{"dispatch_type"} or $meta->{"dispatch_type"}
l!l&&r!l&&!r
32010
MC/DC100%2/2
$opt->{'dispatch_type'} || $meta->{'dispatch_type'} || 'new'
$opt->{"dispatch_type"} $meta->{"dispatch_type"}
Truth table100%3/3
A or B
A= $opt->{"dispatch_type"}B= $meta->{"dispatch_type"}
ABresult
1X1
011
000
226 4 ▶ $cache->{$name} ||= ($dt eq 'new') ? sub { my $base = shift; $pkg->new({base => $base, called_from_base => 1, $base->SHARE})->$meth(@_) }
Subroutine __ANON__: called CC=1 SCAR=0.0
227 1 ▶ : ($dt eq 'morph') ? sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
228 1 my $base = shift;
229 1 my $prev = ref $base;
230 1 ▶ local $base->{'base'} = $base->{'base'} || $base; weaken($base->{'base'});
Condition33%1/3
$base->{'base'} || $base
l!l&&r!l&&!r
010
MC/DC0%0/2
$base->{'base'} || $base
$base->{'base'} $base
Truth table33%1/3
A || B
A= $base->{'base'}B= $base
ABresult
1X1
011
000
231 1 ▶ my $resp; my $ok = eval { bless $base, $pkg; $resp = $base->$meth(@_); 1 }; my $err = $@; bless $base, $prev; die $err if ! $ok; return $resp;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
232 }
233 13 ▶ : ($dt eq 'cache') ? sub { my $base = shift; ($base->{$pkg} ||= do { my $s = $pkg->new({base => $base, $base->SHARE}); weaken $s->{'base'}; $s })->$meth(@_) }
Subroutine __ANON__: called CC=2 SCAR=7.0
Condition66%2/3
$base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s }
l!l&&r!l&&!r
670
MC/DC0%0/2
$base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s }
$base->{$pkg} do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s }
Truth table66%2/3
A ||= B
A= $base->{$pkg}B= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s }
ABresult
1X1
011
000
234 33 ▶ : throw "Unknown dispatch_type", {dispatch_type => $dt}, 1;
Branch: 3 branches
BranchTrueFalseTotal
$dt eq 'new' ? : 9 22 31
$dt eq 'morph' ? : 1 21 22
$dt eq 'cache' ? : 21 0 21
Condition66%2/3
$cache->{$name} ||= $dt eq "new" ? sub { my $base = shift(); $pkg->new({"base", $base, "called_from_base", 1, $base->SHARE})->$meth(@_); } : ($dt eq "morph" ? sub { my $base = shift(); my $prev = ref $base; local $base->{"base"} = $base->{"base"} || $base; builtin::weaken($base->{"base"}); my $resp; my $ok = eval { do { bless $base, $pkg; $resp = $base->$meth(@_); 1 } }; my $err = $@; bless $base, $prev; die $err unless $ok; return $resp; } : ($dt eq "cache" ? sub { my $base = shift(); ($base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s })->$meth(@_); } : throw("Unknown dispatch_type", {"dispatch_type", $dt}, 1)))
l!l&&r!l&&!r
2310
MC/DC0%0/2
$cache->{$name} ||= $dt eq "new" ? sub { my $base = shift(); $pkg->new({"base", $base, "called_from_base", 1, $base->SHARE})->$meth(@_); } : ($dt eq "morph" ? sub { my $base = shift(); my $prev = ref $base; local $base->{"base"} = $base->{"base"} || $base; builtin::weaken($base->{"base"}); my $resp; my $ok = eval { do { bless $base, $pkg; $resp = $base->$meth(@_); 1 } }; my $err = $@; bless $base, $prev; die $err unless $ok; return $resp; } : ($dt eq "cache" ? sub { my $base = shift(); ($base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s })->$meth(@_); } : throw("Unknown dispatch_type", {"dispatch_type", $dt}, 1)))
$cache->{$name} $dt eq "new" ? sub { my $base = shift(); $pkg->new({"base", $base, "called_from_base", 1, $base->SHARE})->$meth(@_); } : ($dt eq "morph" ? sub { my $base = shift(); my $prev = ref $base; local $base->{"base"} = $base->{"base"} || $base; builtin::weaken($base->{"base"}); my $resp; my $ok = eval { do { bless $base, $pkg; $resp = $base->$meth(@_); 1 } }; my $err = $@; bless $base, $prev; die $err unless $ok; return $resp; } : ($dt eq "cache" ? sub { my $base = shift(); ($base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s })->$meth(@_); } : throw("Unknown dispatch_type", {"dispatch_type", $dt}, 1)))
Truth table66%2/3
A ||= B
A= $cache->{$name}B= $dt eq "new" ? sub { my $base = shift(); $pkg->new({"base", $base, "called_from_base", 1, $base->SHARE})->$meth(@_); } : ($dt eq "morph" ? sub { my $base = shift(); my $prev = ref $base; local $base->{"base"} = $base->{"base"} || $base; builtin::weaken($base->{"base"}); my $resp; my $ok = eval { do { bless $base, $pkg; $resp = $base->$meth(@_); 1 } }; my $err = $@; bless $base, $prev; die $err unless $ok; return $resp; } : ($dt eq "cache" ? sub { my $base = shift(); ($base->{$pkg} ||= do { my $s = $pkg->new({"base", $base, $base->SHARE}); builtin::weaken($s->{"base"}); $s })->$meth(@_); } : throw("Unknown dispatch_type", {"dispatch_type", $dt}, 1)))
ABresult
1X1
011
000
235 }
236 21 ▶ if (($meta->{'allow_nested'} || $opt->{'allow_nested'}) && defined(&{"${pkg}::api_meta"}) && $pkg->can('find_method')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($meta->{"allow_nested"} || $opt->{"allow_nested"} and defined &{"${pkg}::api_meta";} and $pkg->can("find_method")) 2 19 21
Condition66%6/9
$meta->{"allow_nested"} || $opt->{"allow_nested"} and defined &{"${pkg}::api_meta";} and $pkg->can("find_method")
!ll&&!rl&&r
1902
$meta->{"allow_nested"} || $opt->{"allow_nested"} and defined &{"${pkg}::api_meta";}
!ll&&!rl&&r
1902
$meta->{"allow_nested"} or $opt->{"allow_nested"}
l!l&&r!l&&!r
2019
MC/DC25%1/4
$meta->{"allow_nested"} || $opt->{"allow_nested"} and defined &{"${pkg}::api_meta";} and $pkg->can("find_method")
$meta->{"allow_nested"} $opt->{"allow_nested"} defined &{"${pkg}::api_meta";} $pkg->can("find_method")
Truth table28%2/7
A or B and C and D
A= $meta->{"allow_nested"}B= $opt->{"allow_nested"}C= defined &{"${pkg}::api_meta";}D= $pkg->can("find_method")
ABCDresult
00XX0
1X0X0
010X0
1X100
01100
1X111
01111
237 2 my $c2 = $pkg->new({$self->SHARE})->find_method; # TODO - pass them in
238 2 for my $meth (keys %$c2) {
239 18 ▶ next if $qr && $meth !~ $qr;
Branch: 1 branch
BranchTrueFalseTotal
if $qr and not $meth =~ /$qr/ 0 18 18
Condition33%1/3
$qr and not $meth =~ /$qr/
!ll&&!rl&&r
0180
MC/DC0%0/2
$qr and not $meth =~ /$qr/
$qr not $meth =~ /$qr/
Truth table33%1/3
A and not(B)
A= $qrB= not $meth =~ /$qr/
ABresult
0X0
100
111
240 18 ▶ $name = (!$opt->{'full_name'} && $meth !~ /^\Q$ns\E_/) ? "${ns}_${meth}" : $meth;
Branch: 1 branch
BranchTrueFalseTotal
!($opt->{'full_name'} || $meth =~ /^\Q$ns\E_/) ? : 18 0 18
Condition33%1/3
$opt->{'full_name'} || $meth =~ /^\Q$ns\E_/
l!l&&r!l&&!r
0018
MC/DC0%0/2
$opt->{'full_name'} || $meth =~ /^\Q$ns\E_/
$opt->{'full_name'} $meth =~ /^\Q$ns\E_/
Truth table33%1/3
A || B
A= $opt->{'full_name'}B= $meth =~ /^\Q$ns\E_/
ABresult
1X1
011
000
241 18 $cache->{$name} = $c2->{$meth};
242 }
243 }
244 21 ▶ return $cache->{$meth} if $meth && $cache->{$meth};
Branch: 1 branch
BranchTrueFalseTotal
if $meth and $cache->{$meth} 4 17 21
Condition66%2/3
$meth and $cache->{$meth}
!ll&&!rl&&r
1704
MC/DC50%1/2
$meth and $cache->{$meth}
$meth $cache->{$meth}
Truth table66%2/3
A and B
A= $methB= $cache->{$meth}
ABresult
0X0
100
111
245 }
246 }
247  
248 10 ▶ return $cache->{$meth} = 0 if $meth;
Branch: 1 branch
BranchTrueFalseTotal
if $meth 1 9 10
249 9 return $cache;
250 }
251  
252 3 ▶sub _load_lib_dir {
Subroutine _load_lib_dir: called CC=13 SCAR=33.6
253 3 my ($self, $NS) = @_;
254 3 ▶ if ($NS eq '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($NS eq 1) 0 3 3
255 0 ▶ throw "lib_dirs cannot be 1 when accessed from Net::Respite::Base directly" if ref($self) eq __PACKAGE__;
Branch: 1 branch
BranchTrueFalseTotal
if ref $self eq __PACKAGE__ 0 0 0
256 0 (my $file = ref($self).".pm") =~ s|::|/|g;
257 0 ▶ (my $dir = $INC{$file} || '') =~ s|\.pm$|| or throw "Could not determine library path location for lib_dirs", {file => $file};
Branch: 1 branch
BranchTrueFalseTotal
(my $dir = $INC{$file} || "") =~ s/\.pm$// or throw("Could not determine library path location for lib_dirs", {"file", $file}) 0 0 0
Condition0%0/2
$INC{$file} || ''
l!l
00
MC/DC0%0/1
$INC{$file} || ''
$INC{$file}
Truth table0%0/2
A
A= $INC{$file}
Aresult
11
00
258 0 $NS = {$dir => {pkg_prefix => ref($self)}};
259 }
260 3 my %h;
261 3 foreach my $dir (keys %$NS) {
262 0 ▶ opendir my $dh, $dir or do { warn "Failed to opendir $dir: $!"; next };
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or do { warn "Failed to opendir ${dir}: $!"; next } 3 0 3
263 3 my $opt = $NS->{$dir};
264 3 ▶ $opt = {match => $opt} if ref($opt) ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $opt ne "HASH" 3 0 3
265 3 ▶ my $prefix = $opt->{'pkg_prefix'} ? "$opt->{'pkg_prefix'}::" : '';
Branch: 1 branch
BranchTrueFalseTotal
$opt->{'pkg_prefix'} ? : 0 3 3
266 3 foreach my $sub (readdir $dh) {
267 12 ▶ next if $sub !~ /^([a-zA-Z]\w*)\.pm$/; # TODO - possibly handle dirs
Branch: 1 branch
BranchTrueFalseTotal
unless $sub =~ /^([a-zA-Z]\w*)\.pm$/ 9 3 12
268 3 my $pkg = $1;
269 3 ▶ next if $opt->{'pkg_exclude'} && $pkg =~ $opt->{'pkg_exclude'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"pkg_exclude"} and $pkg =~ /$opt->{"pkg_exclude"}/ 0 3 3
Condition33%1/3
$opt->{"pkg_exclude"} and $pkg =~ /$opt->{"pkg_exclude"}/
!ll&&!rl&&r
300
MC/DC0%0/2
$opt->{"pkg_exclude"} and $pkg =~ /$opt->{"pkg_exclude"}/
$opt->{"pkg_exclude"} $pkg =~ /$opt->{"pkg_exclude"}/
Truth table33%1/3
A and B
A= $opt->{"pkg_exclude"}B= $pkg =~ /$opt->{"pkg_exclude"}/
ABresult
0X0
100
111
270 3 (my $name = $pkg) =~ s/(?: (?<=[a-z])(?=[A-Z]) | (?<=[A-Z])(?=[A-Z][a-z]) )/_/xg; # FooBar => Foo_Bar, RespiteUser => Respite_User
271 3 $h{lc $name} = {%$opt, pkg => "$prefix$pkg", file => "$dir/$sub"};
272 }
273 }
274 3 return \%h;
275 }
276  
277 ###----------------------------------------------------------------###
278  
279 3 ▶sub __methods__meta {
Subroutine __methods__meta: called CC=2 SCAR=8.1
280 3 ▶ my $class = ref($_[0]) || $_[0];
Condition33%1/3
ref $_[0] || $_[0]
l!l&&r!l&&!r
300
MC/DC0%0/2
ref $_[0] || $_[0]
ref $_[0] $_[0]
Truth table33%1/3
A || B
A= ref $_[0]B= $_[0]
ABresult
1X1
011
000
281 return {
282 3 desc => "Return a list of all known $class methods. Optionally return all meta information as well",
283 args => {
284 meta => {desc => 'If true, returns all meta information for the method instead of just the description'},
285 method => {desc => 'If passed will be used to filter the available methods - can contain * as a wildcard'},
286 },
287 resp => {methods => 'hashref of available method/description pairs. Will return method/metainfo pairs if meta => 1 is passed.'},
288 };
289 }
290  
291 2 ▶sub __methods {
Subroutine __methods: called CC=14 SCAR=30.2
292 2 my ($self, $args) = @_;
293 5 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
294 2 ▶ my $pkg = ref($self) || $self;
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
200
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
295 2 my %m;
296 0 ▶ my $qr = !$args->{'method'} ? undef : do { (my $p = $args->{'method'}) =~ s/\*/.*/g; qr/^$p$/i };
Branch: 1 branch
BranchTrueFalseTotal
!$args->{'method'} ? : 2 0 2
297 2 my $meths = $self->find_method(); # will load all
298 2 foreach my $meth (keys %$meths) {
299 36 ▶ next if $meth !~ /^(\w+)__meta$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /^(\w+)__meta$/ 22 14 36
300 14 my $name = $1;
301 14 ▶ next if $qr && $name !~ $qr;
Branch: 1 branch
BranchTrueFalseTotal
if $qr and not $name =~ /$qr/ 0 14 14
Condition33%1/3
$qr and not $name =~ /$qr/
!ll&&!rl&&r
1400
MC/DC0%0/2
$qr and not $name =~ /$qr/
$qr not $name =~ /$qr/
Truth table33%1/3
A and not(B)
A= $qrB= not $name =~ /$qr/
ABresult
0X0
100
111
302 14 ▶ my $meta = eval { $self->$meth() } || do { (my $err = $@ || '') =~ s/ at \/.*//s; {desc => "Not documented".($err ? ": $err" : '')} };
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 0 1 1
Condition60%3/5
eval { do { $self->$meth } } || do { (my $err = $@ || '') =~ s[ at /.*][]s; +{'desc', 'Not documented' . ($err ? ": $err" : '')} }
l!l&&r!l&&!r
1310
$@ || ''
l!l
01
MC/DC0%0/2
eval { do { $self->$meth } } || do { (my $err = $@ || '') =~ s[ at /.*][]s; +{'desc', 'Not documented' . ($err ? ": $err" : '')} }
eval { do { $self->$meth } } do { (my $err = $@ || '') =~ s[ at /.*][]s; +{'desc', 'Not documented' . ($err ? ": $err" : '')} }
MC/DC0%0/1
$@ || ''
$@
Truth table66%2/3
A || B
A= eval { do { $self->$meth } }B= do { (my $err = $@ || '') =~ s[ at /.*][]s; +{'desc', 'Not documented' . ($err ? ": $err" : '')} }
ABresult
1X1
011
000
Truth table50%1/2
A
A= $@
Aresult
11
00
303 14 ▶ next if $ENV{'REQUEST_METHOD'} && $meta->{'no_listing'};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"REQUEST_METHOD"} and $meta->{"no_listing"} 0 14 14
Condition33%1/3
$ENV{"REQUEST_METHOD"} and $meta->{"no_listing"}
!ll&&!rl&&r
1400
MC/DC0%0/2
$ENV{"REQUEST_METHOD"} and $meta->{"no_listing"}
$ENV{"REQUEST_METHOD"} $meta->{"no_listing"}
Truth table33%1/3
A and B
A= $ENV{"REQUEST_METHOD"}B= $meta->{"no_listing"}
ABresult
0X0
100
111
304 14 ▶ $m{$name} = $args->{'meta'} ? $meta : $meta->{'no_listing'} ? "(Not listed in Web Respite) $meta->{'desc'}" : $meta->{'desc'};
Branch: 2 branches
BranchTrueFalseTotal
$args->{'meta'} ? : 0 14 14
$meta->{'no_listing'} ? : 0 14 14
305 14 delete $meta->{'api_enum'};
306 }
307 2 return {methods => \%m};
308 }
309  
310 3 ▶sub __hello__meta {
Subroutine __hello__meta: called CC=1 SCAR=0.0
311 return {
312 3 desc => 'Basic call to test connection',
313 args => {test_auth => {validate_if => 'test_auth', enum => ['', 0, 1], desc => 'Optional - if passed it will require authentication'}},
314 resp => {
315 server_time => "Server epoch time",
316 args => "Echo of the passed in args",
317 api_ip => 'IP',
318 api_brand => 'Which brand is in use (if any)',
319 admin_user => 'Returned if test_auth is passed',
320 },
321 };
322 }
323  
324 1 ▶sub __hello {
Subroutine __hello: called CC=6 SCAR=20.7
325 1 my ($self, $args) = @_;
326 1 ▶ sleep $args->{'sleep'} if $args->{'sleep'};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"sleep"} 0 1 1
327 1 ▶ throw delete($args->{'fail'}), {args => $args} if $args->{'fail'};
Branch: 1 branch
BranchTrueFalseTotal
if $args->{"fail"} 0 1 1
328 return {
329 args => $args,
330 server_time => time(),
331 api_ip => $self->api_ip,
332 1 ▶ api_brand => eval { $self->api_brand } || undef,
Branch: 1 branch
BranchTrueFalseTotal
$args->{'test_auth'} && $self->require_admin ? : 0 1 1
Condition33%1/3
$args->{"test_auth"} and $self->require_admin
!ll&&!rl&&r
100
MC/DC0%0/2
$args->{"test_auth"} and $self->require_admin
$args->{"test_auth"} $self->require_admin
Truth table33%1/3
A and B
A= $args->{"test_auth"}B= $self->require_admin
ABresult
0X0
100
111
333 ($args->{'test_auth'} && $self->require_admin ? (
334 admin_user => $self->admin_user,
335 1 ▶ token => $self->{'new_token'},
Condition50%1/2
eval { do { $self->api_brand } } || undef
l!l
01
MC/DC0%0/1
eval { do { $self->api_brand } } || undef
eval { do { $self->api_brand } }
Truth table50%1/2
A
A= eval { do { $self->api_brand } }
Aresult
11
00
336 ) : ()),
337 };
338 }
339  
340 5 1;
« Respite/CommandLine.pm ↑ Summary Respite/Client.pm »