| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Perinci::Access; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-12-17'; # DATE |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.44'; # VERSION |
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
20563
|
use 5.010001; |
|
|
1
|
|
|
|
|
4
|
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
34
|
|
|
9
|
1
|
|
|
1
|
|
1130
|
use Log::Any::IfLOG '$log'; |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
6
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
54
|
use Scalar::Util qw(blessed); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
105
|
|
|
12
|
1
|
|
|
1
|
|
667
|
use URI::Split qw(uri_split uri_join); |
|
|
1
|
|
|
|
|
2761
|
|
|
|
1
|
|
|
|
|
709
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $Log_Request = $ENV{LOG_RIAP_REQUEST} // 0; |
|
15
|
|
|
|
|
|
|
our $Log_Response = $ENV{LOG_RIAP_RESPONSE} // 0; |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
|
18
|
0
|
|
|
0
|
1
|
|
my ($class, %opts) = @_; |
|
19
|
|
|
|
|
|
|
|
|
20
|
0
|
|
0
|
|
|
|
$opts{riap_version} //= 1.1; |
|
21
|
0
|
|
0
|
|
|
|
$opts{handlers} //= {}; |
|
22
|
0
|
|
0
|
|
|
|
$opts{handlers}{''} //= 'Perinci::Access::Schemeless'; |
|
23
|
0
|
|
0
|
|
|
|
$opts{handlers}{pl} //= 'Perinci::Access::Perl'; |
|
24
|
0
|
|
0
|
|
|
|
$opts{handlers}{http} //= 'Perinci::Access::HTTP::Client'; |
|
25
|
0
|
|
0
|
|
|
|
$opts{handlers}{https} //= 'Perinci::Access::HTTP::Client'; |
|
26
|
0
|
|
0
|
|
|
|
$opts{handlers}{'riap+tcp'} //= 'Perinci::Access::Simple::Client'; |
|
27
|
0
|
|
0
|
|
|
|
$opts{handlers}{'riap+unix'} //= 'Perinci::Access::Simple::Client'; |
|
28
|
0
|
|
0
|
|
|
|
$opts{handlers}{'riap+pipe'} //= 'Perinci::Access::Simple::Client'; |
|
29
|
|
|
|
|
|
|
|
|
30
|
0
|
|
0
|
|
|
|
$opts{_handler_objs} //= {}; |
|
31
|
0
|
|
|
|
|
|
bless \%opts, $class; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _request_or_parse_url { |
|
35
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
36
|
0
|
|
|
|
|
|
my $which = shift; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my ($action, $uri, $extra, $copts); |
|
39
|
0
|
0
|
|
|
|
|
if ($which eq 'request') { |
|
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
|
|
0
|
|
|
|
$sch //= ""; |
|
47
|
0
|
0
|
|
|
|
|
die "Can't handle scheme '$sch' in URL" unless $self->{handlers}{$sch}; |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# convert riap://perl/Foo/Bar to pl:/Foo/Bar/ as Perl only accepts pl |
|
50
|
0
|
0
|
|
|
|
|
if ($sch eq 'riap') { |
|
51
|
0
|
|
0
|
|
|
|
$auth //= ''; |
|
52
|
0
|
0
|
|
|
|
|
die "Unsupported auth '$auth' in riap: scheme, ". |
|
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
|
0
|
|
|
|
|
unless ($self->{_handler_objs}{$sch}) { |
|
60
|
0
|
0
|
|
|
|
|
if (blessed($self->{handlers}{$sch})) { |
|
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"; |
|
|
0
|
|
|
|
|
|
|
|
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
|
|
0
|
|
|
|
%{ $self->{handler_args} // {}}); |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
} |
|
71
|
|
|
|
|
|
|
} |
|
72
|
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $res; |
|
74
|
0
|
0
|
|
|
|
|
if ($which eq 'request') { |
|
75
|
0
|
0
|
0
|
|
|
|
if ($Log_Request && $log->is_trace) { |
|
76
|
|
|
|
|
|
|
$log->tracef( |
|
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
|
0
|
0
|
|
|
|
if ($Log_Response && $log->is_trace) { |
|
84
|
0
|
|
|
|
|
|
$log->tracef("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
|
|
|
|
|
|
|
sub request { |
|
93
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
94
|
0
|
|
|
|
|
|
$self->_request_or_parse_url('request', @_); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub parse_url { |
|
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
99
|
0
|
|
|
|
|
|
$self->_request_or_parse_url('parse_url', @_); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |
|
103
|
|
|
|
|
|
|
# ABSTRACT: Wrapper for Perinci Riap clients |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
__END__ |