| 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
MC/DC0%0/1
$ENV{"LOG_RIAP_REQUEST"} // 0
$ENV{"LOG_RIAP_REQUEST"}
Truth table50%1/2
A
A= $ENV{"LOG_RIAP_REQUEST"}
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | our $Log_Response = $ENV{LOG_RIAP_RESPONSE} // 0; | ||||||||||||||||||||||||||
|
Condition50%1/2
$ENV{"LOG_RIAP_RESPONSE"} // 0
MC/DC0%0/1
$ENV{"LOG_RIAP_RESPONSE"} // 0
$ENV{"LOG_RIAP_RESPONSE"}
Truth table50%1/2
A
A= $ENV{"LOG_RIAP_RESPONSE"}
| |||||||||||||||||||||||||||||
| 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"
MC/DC0%0/1
$opts{"riap_version"} //= "1.1"
$opts{"riap_version"}
Truth table0%0/2
A
A= $opts{"riap_version"}
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | $opts{handlers} //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"} //= {}
MC/DC0%0/1
$opts{"handlers"} //= {}
$opts{"handlers"}
Truth table0%0/2
A
A= $opts{"handlers"}
| |||||||||||||||||||||||||||||
| 22 | 0 | ▶ | $opts{handlers}{''} //= 'Perinci::Access::Schemeless'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{""} //= "Perinci::Access::Schemeless"
MC/DC0%0/1
$opts{"handlers"}{""} //= "Perinci::Access::Schemeless"
$opts{"handlers"}{""}
Truth table0%0/2
A
A= $opts{"handlers"}{""}
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $opts{handlers}{pl} //= 'Perinci::Access::Perl'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"pl"} //= "Perinci::Access::Perl"
MC/DC0%0/1
$opts{"handlers"}{"pl"} //= "Perinci::Access::Perl"
$opts{"handlers"}{"pl"}
Truth table0%0/2
A
A= $opts{"handlers"}{"pl"}
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | $opts{handlers}{http} //= 'Perinci::Access::HTTP::Client'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"http"} //= "Perinci::Access::HTTP::Client"
MC/DC0%0/1
$opts{"handlers"}{"http"} //= "Perinci::Access::HTTP::Client"
$opts{"handlers"}{"http"}
Truth table0%0/2
A
A= $opts{"handlers"}{"http"}
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $opts{handlers}{https} //= 'Perinci::Access::HTTP::Client'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"https"} //= "Perinci::Access::HTTP::Client"
MC/DC0%0/1
$opts{"handlers"}{"https"} //= "Perinci::Access::HTTP::Client"
$opts{"handlers"}{"https"}
Truth table0%0/2
A
A= $opts{"handlers"}{"https"}
| |||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $opts{handlers}{'riap+tcp'} //= 'Perinci::Access::Simple::Client'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"riap+tcp"} //= "Perinci::Access::Simple::Client"
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"}
| |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | $opts{handlers}{'riap+unix'} //= 'Perinci::Access::Simple::Client'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"riap+unix"} //= "Perinci::Access::Simple::Client"
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"}
| |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | $opts{handlers}{'riap+pipe'} //= 'Perinci::Access::Simple::Client'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"handlers"}{"riap+pipe"} //= "Perinci::Access::Simple::Client"
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"}
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $opts{_handler_objs} //= {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opts{"_handler_objs"} //= {}
MC/DC0%0/1
$opts{"_handler_objs"} //= {}
$opts{"_handler_objs"}
Truth table0%0/2
A
A= $opts{"_handler_objs"}
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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 //= ""
MC/DC0%0/1
$sch //= ""
$sch
Truth table0%0/2
A
A= $sch
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | die "Can't handle scheme '$sch' in URL" unless $self->{handlers}{$sch}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $auth //= ''; | ||||||||||||||||||||||||||
|
Condition0%0/2
$auth //= ""
MC/DC0%0/1
$auth //= ""
$auth
Truth table0%0/2
A
A= $auth
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | die "Unsupported auth '$auth' in riap: scheme, ". | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (blessed($self->{handlers}{$sch})) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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"} // {}
MC/DC0%0/1
$self->{"handler_args"} // {}
$self->{"handler_args"}
Truth table0%0/2
A
A= $self->{"handler_args"}
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | my $res; | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ($which eq 'request') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if ($Log_Request && log_is_trace()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Perinci::Access::Log_Request and log_is_trace()
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()
| |||||||||||||||||||||||||||||
| 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
Condition0%0/3
$Perinci::Access::Log_Response and log_is_trace()
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()
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||