blib/lib/Perinci/Access.pm

filter: Statementstmt 30.9% 22 / 71 Branchbran 0.0% 0 / 18 Conditioncond 5.5% 2 / 36 MC/DCmcdc 0.0% 0 / 19 Subroutinesub 60.0% 6 / 10 Podpod 100% 3 / 3 totaltotal 21.0% 33 / 157 CC 25 SCAR 50.0
CC
25
Cov
19%
_request_or_parse_url
240.0
new
132.0
request
2.0
CRAP 148.9
↑ Summary
1 package Perinci::Access;
2  
3 2 our $DATE = '2017-07-10'; # DATE
4 2 our $VERSION = '0.45'; # VERSION
5  
6 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use URI::Split qw(uri_split uri_join);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 ▶our $Log_Request = $ENV{LOG_RIAP_REQUEST} // 0;
Condition50%1/2
$ENV{"LOG_RIAP_REQUEST"} // 0
l!l
02
MC/DC0%0/1
$ENV{"LOG_RIAP_REQUEST"} // 0
$ENV{"LOG_RIAP_REQUEST"}
Truth table50%1/2
A
A= $ENV{"LOG_RIAP_REQUEST"}
Aresult
11
00
15 2 ▶our $Log_Response = $ENV{LOG_RIAP_RESPONSE} // 0;
Condition50%1/2
$ENV{"LOG_RIAP_RESPONSE"} // 0
l!l
02
MC/DC0%0/1
$ENV{"LOG_RIAP_RESPONSE"} // 0
$ENV{"LOG_RIAP_RESPONSE"}
Truth table50%1/2
A
A= $ENV{"LOG_RIAP_RESPONSE"}
Aresult
11
00
16  
17 0 ▶sub new {
Subroutine new: not called CC=11 SCAR=48.8
Pod documented
18 0 my ($class, %opts) = @_;
19  
20 0 ▶ $opts{riap_version} //= 1.1;
Condition0%0/2
$opts{"riap_version"} //= "1.1"
l!l
00
MC/DC0%0/1
$opts{"riap_version"} //= "1.1"
$opts{"riap_version"}
Truth table0%0/2
A
A= $opts{"riap_version"}
Aresult
11
00
21 0 ▶ $opts{handlers} //= {};
Condition0%0/2
$opts{"handlers"} //= {}
l!l
00
MC/DC0%0/1
$opts{"handlers"} //= {}
$opts{"handlers"}
Truth table0%0/2
A
A= $opts{"handlers"}
Aresult
11
00
22 0 ▶ $opts{handlers}{''} //= 'Perinci::Access::Schemeless';
Condition0%0/2
$opts{"handlers"}{""} //= "Perinci::Access::Schemeless"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{""} //= "Perinci::Access::Schemeless"
$opts{"handlers"}{""}
Truth table0%0/2
A
A= $opts{"handlers"}{""}
Aresult
11
00
23 0 ▶ $opts{handlers}{pl} //= 'Perinci::Access::Perl';
Condition0%0/2
$opts{"handlers"}{"pl"} //= "Perinci::Access::Perl"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"pl"} //= "Perinci::Access::Perl"
$opts{"handlers"}{"pl"}
Truth table0%0/2
A
A= $opts{"handlers"}{"pl"}
Aresult
11
00
24 0 ▶ $opts{handlers}{http} //= 'Perinci::Access::HTTP::Client';
Condition0%0/2
$opts{"handlers"}{"http"} //= "Perinci::Access::HTTP::Client"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"http"} //= "Perinci::Access::HTTP::Client"
$opts{"handlers"}{"http"}
Truth table0%0/2
A
A= $opts{"handlers"}{"http"}
Aresult
11
00
25 0 ▶ $opts{handlers}{https} //= 'Perinci::Access::HTTP::Client';
Condition0%0/2
$opts{"handlers"}{"https"} //= "Perinci::Access::HTTP::Client"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"https"} //= "Perinci::Access::HTTP::Client"
$opts{"handlers"}{"https"}
Truth table0%0/2
A
A= $opts{"handlers"}{"https"}
Aresult
11
00
26 0 ▶ $opts{handlers}{'riap+tcp'} //= 'Perinci::Access::Simple::Client';
Condition0%0/2
$opts{"handlers"}{"riap+tcp"} //= "Perinci::Access::Simple::Client"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"riap+tcp"} //= "Perinci::Access::Simple::Client"
$opts{"handlers"}{"riap+tcp"}
Truth table0%0/2
A
A= $opts{"handlers"}{"riap+tcp"}
Aresult
11
00
27 0 ▶ $opts{handlers}{'riap+unix'} //= 'Perinci::Access::Simple::Client';
Condition0%0/2
$opts{"handlers"}{"riap+unix"} //= "Perinci::Access::Simple::Client"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"riap+unix"} //= "Perinci::Access::Simple::Client"
$opts{"handlers"}{"riap+unix"}
Truth table0%0/2
A
A= $opts{"handlers"}{"riap+unix"}
Aresult
11
00
28 0 ▶ $opts{handlers}{'riap+pipe'} //= 'Perinci::Access::Simple::Client';
Condition0%0/2
$opts{"handlers"}{"riap+pipe"} //= "Perinci::Access::Simple::Client"
l!l
00
MC/DC0%0/1
$opts{"handlers"}{"riap+pipe"} //= "Perinci::Access::Simple::Client"
$opts{"handlers"}{"riap+pipe"}
Truth table0%0/2
A
A= $opts{"handlers"}{"riap+pipe"}
Aresult
11
00
29  
30 0 ▶ $opts{_handler_objs} //= {};
Condition0%0/2
$opts{"_handler_objs"} //= {}
l!l
00
MC/DC0%0/1
$opts{"_handler_objs"} //= {}
$opts{"_handler_objs"}
Truth table0%0/2
A
A= $opts{"_handler_objs"}
Aresult
11
00
31 0 bless \%opts, $class;
32 }
33  
34 0 ▶sub _request_or_parse_url {
Subroutine _request_or_parse_url: not called CC=15 SCAR=54.8
35 0 my $self = shift;
36 0 my $which = shift;
37  
38 0 my ($action, $uri, $extra, $copts);
39 0 ▶ if ($which eq 'request') {
Branch: 1 branch
BranchTrueFalseTotal
if ($which eq 'request') { } 0 0 0
40 0 ($action, $uri, $extra, $copts) = @_;
41 } else {
42 0 ($uri, $copts) = @_;
43 }
44  
45 0 my ($sch, $auth, $path, $query, $frag) = uri_split($uri);
46 0 ▶ $sch //= "";
Condition0%0/2
$sch //= ""
l!l
00
MC/DC0%0/1
$sch //= ""
$sch
Truth table0%0/2
A
A= $sch
Aresult
11
00
47 0 ▶ die "Can't handle scheme '$sch' in URL" unless $self->{handlers}{$sch};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"handlers"}{$sch} 0 0 0
48  
49 # convert riap://perl/Foo/Bar to pl:/Foo/Bar/ as Perl only accepts pl
50 0 ▶ if ($sch eq 'riap') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sch eq "riap") 0 0 0
51 0 ▶ $auth //= '';
Condition0%0/2
$auth //= ""
l!l
00
MC/DC0%0/1
$auth //= ""
$auth
Truth table0%0/2
A
A= $auth
Aresult
11
00
52 0 ▶ die "Unsupported auth '$auth' in riap: scheme, ".
Branch: 1 branch
BranchTrueFalseTotal
unless $auth eq "perl" 0 0 0
53 "only 'perl' is supported" unless $auth eq 'perl';
54 0 $sch = 'pl';
55 0 $auth = undef;
56 0 $uri = uri_join($sch, $auth, $path, $query, $frag);
57 }
58  
59 0 ▶ unless ($self->{_handler_objs}{$sch}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_handler_objs"}{$sch}) 0 0 0
60 0 ▶ if (blessed($self->{handlers}{$sch})) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($self->{'handlers'}{$sch})) { } 0 0 0
61 0 $self->{_handler_objs}{$sch} = $self->{handlers}{$sch};
62 } else {
63 0 my $modp = $self->{handlers}{$sch};
64 0 $modp =~ s!::!/!g; $modp .= ".pm";
65 0 require $modp;
66 #$log->tracef("TMP: Creating Riap client object for schema %s with args %s", $sch, $self->{handler_args});
67 $self->{_handler_objs}{$sch} = $self->{handlers}{$sch}->new(
68 riap_version => $self->{riap_version},
69 0 ▶ %{ $self->{handler_args} // {}});
Condition0%0/2
$self->{"handler_args"} // {}
l!l
00
MC/DC0%0/1
$self->{"handler_args"} // {}
$self->{"handler_args"}
Truth table0%0/2
A
A= $self->{"handler_args"}
Aresult
11
00
70 }
71 }
72  
73 0 my $res;
74 0 ▶ if ($which eq 'request') {
Branch: 1 branch
BranchTrueFalseTotal
if ($which eq 'request') { } 0 0 0
75 0 ▶ if ($Log_Request && log_is_trace()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Perinci::Access::Log_Request and log_is_trace()) 0 0 0
Condition0%0/3
$Perinci::Access::Log_Request and log_is_trace()
!ll&&!rl&&r
000
MC/DC0%0/2
$Perinci::Access::Log_Request and log_is_trace()
$Perinci::Access::Log_Request log_is_trace()
Truth table0%0/3
A and B
A= $Perinci::Access::Log_RequestB= log_is_trace()
ABresult
0X0
100
111
76 log_trace(
77 "Riap request (%s): %s -> %s (%s)",
78 0 ref($self->{_handler_objs}{$sch}),
79 $action, $uri, $extra, $copts);
80 }
81 0 $res = $self->{_handler_objs}{$sch}->request(
82 $action, $uri, $extra, $copts);
83 0 ▶ if ($Log_Response && log_is_trace()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Perinci::Access::Log_Response and log_is_trace()) 0 0 0
Condition0%0/3
$Perinci::Access::Log_Response and log_is_trace()
!ll&&!rl&&r
000
MC/DC0%0/2
$Perinci::Access::Log_Response and log_is_trace()
$Perinci::Access::Log_Response log_is_trace()
Truth table0%0/3
A and B
A= $Perinci::Access::Log_ResponseB= log_is_trace()
ABresult
0X0
100
111
84 0 log_trace("Riap response: %s", $res);
85 }
86 } else {
87 0 $res = $self->{_handler_objs}{$sch}->parse_url($uri, $copts);
88 }
89 0 $res;
90 }
91  
92 0 ▶sub request {
Subroutine request: not called CC=1 SCAR=6.9
Pod documented
93 0 my $self = shift;
94 0 $self->_request_or_parse_url('request', @_);
95 }
96  
97 0 ▶sub parse_url {
Subroutine parse_url: not called CC=1 SCAR=6.9
Pod documented
98 0 my $self = shift;
99 0 $self->_request_or_parse_url('parse_url', @_);
100 }
101  
102 2 1;
103 # ABSTRACT: Wrapper for Perinci Riap clients
104  
105 __END__
↑ Summary