line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
our $DATE = '2021-08-01'; # DATE |
3
|
|
|
|
|
|
|
our $VERSION = '0.897'; # VERSION |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
use 5.010001; |
6
|
1
|
|
|
1
|
|
3133
|
use strict; |
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
8
|
1
|
|
|
1
|
|
3
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
9
|
|
|
|
|
|
|
use URI::Split qw(uri_split); |
10
|
1
|
|
|
1
|
|
337
|
|
|
1
|
|
|
|
|
2325
|
|
|
1
|
|
|
|
|
67
|
|
11
|
|
|
|
|
|
|
use parent qw(Perinci::Access::Schemeless); |
12
|
1
|
|
|
1
|
|
377
|
|
|
1
|
|
|
|
|
254
|
|
|
1
|
|
|
|
|
5
|
|
13
|
|
|
|
|
|
|
my $class = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
1
|
3227
|
my $self = $class->SUPER::new(@_); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
9
|
# The pl: uri scheme has a 1:1 mapping between Perl package and path, so |
18
|
|
|
|
|
|
|
# /Foo/Bar/ must mean the Foo::Bar package. We don't allow package_prefix or |
19
|
|
|
|
|
|
|
# anything fancy like that. |
20
|
|
|
|
|
|
|
delete $self->{package_prefix}; |
21
|
|
|
|
|
|
|
|
22
|
1
|
|
|
|
|
3
|
$self->{allow_schemes} = ['pl', '']; |
23
|
|
|
|
|
|
|
$self->{deny_schemes} = undef; |
24
|
1
|
|
|
|
|
3
|
|
25
|
1
|
|
|
|
|
3
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
4
|
|
28
|
|
|
|
|
|
|
my ($self, $uri) = @_; |
29
|
|
|
|
|
|
|
die "Please specify url" unless $uri; |
30
|
|
|
|
|
|
|
|
31
|
2
|
|
|
2
|
1
|
9105
|
my ($sch, $auth, $path) = uri_split($uri); |
32
|
2
|
50
|
|
|
|
8
|
$sch //= ""; |
33
|
|
|
|
|
|
|
|
34
|
2
|
|
|
|
|
6
|
die "Only pl uri scheme is supported" unless $sch eq 'pl'; |
35
|
2
|
|
100
|
|
|
25
|
{proto=>"pl", path=>$path}; |
36
|
|
|
|
|
|
|
} |
37
|
2
|
100
|
|
|
|
16
|
|
38
|
1
|
|
|
|
|
10
|
1; |
39
|
|
|
|
|
|
|
# ABSTRACT: Access Perl module, functions, variables through Riap |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=pod |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=encoding UTF-8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perinci::Access::Perl - Access Perl module, functions, variables through Riap |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 VERSION |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
This document describes version 0.897 of Perinci::Access::Perl (from Perl distribution Perinci-Access-Perl), released on 2021-08-01. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 SYNOPSIS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
First write your code and add Rinci metadata to them: |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
package MyMod::MySubMod; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
our %SPEC; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$SPEC{':package'} = { |
63
|
|
|
|
|
|
|
v => 1.1, |
64
|
|
|
|
|
|
|
summary => 'This package is blah blah', |
65
|
|
|
|
|
|
|
}; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$SPEC{'$var1'} = { |
68
|
|
|
|
|
|
|
v => 1.1, |
69
|
|
|
|
|
|
|
summary => 'This variable is blah blah', |
70
|
|
|
|
|
|
|
}; |
71
|
|
|
|
|
|
|
our $var1; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$SPEC{func1} = { |
74
|
|
|
|
|
|
|
v => 1.1, |
75
|
|
|
|
|
|
|
summary => 'This function does blah blah', |
76
|
|
|
|
|
|
|
args => { |
77
|
|
|
|
|
|
|
a => { schema => 'int', req => 1 }, |
78
|
|
|
|
|
|
|
b => { schema => 'int' }, |
79
|
|
|
|
|
|
|
}, |
80
|
|
|
|
|
|
|
}; |
81
|
|
|
|
|
|
|
sub func1 { |
82
|
|
|
|
|
|
|
... |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
then access them through Riap: |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
use Perinci::Access::Perl; |
89
|
|
|
|
|
|
|
my $pa = Perinci::Access::Perl->new; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# call function |
92
|
|
|
|
|
|
|
$res = $pa->request(call => '/MyMod/MySubMod/func1', {args=>{a=>1, b=>2}}); |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# get variables |
95
|
|
|
|
|
|
|
$res = $pa->request(get => '/MyMod/MySubMod/$var1'); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 DESCRIPTION |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
This class allows you to access Perl modules, functions, and variables through |
100
|
|
|
|
|
|
|
Riap. Only those which have L<Rinci> metadata are accessible. The metadata is |
101
|
|
|
|
|
|
|
put in C<%SPEC> package variables, with function names as keys, or C<:package> |
102
|
|
|
|
|
|
|
for package metadata, or C<$NAME> for variables. Functions will be wrapped |
103
|
|
|
|
|
|
|
before executed (unless you pass C<< wrap => 0 >> to the constructor). |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
You should probably use this through L<Perinci::Access>. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head1 CONTRIBUTOR |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=for stopwords Steven Haryanto |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Steven Haryanto <sharyanto@cpan.org> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 FUNCTIONS |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 new(%opts) => OBJ |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Constructor. For a list of options, see superclass |
118
|
|
|
|
|
|
|
L<Perinci::Access::Schemeless> except for C<package_prefix> which are not |
119
|
|
|
|
|
|
|
recognized by this class. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 $pa->request($action, $uri, \%extras) => RESP |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 $pa->parse_url($url) => HASH |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 FAQ |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head2 Why C<%SPEC> (instead of C<%META>, C<%METADATA>, C<%RINCI>, etc)? |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
The name was first chosen during Sub::Spec era (see BackPAN) in 2011, it stuck. |
130
|
|
|
|
|
|
|
By that time I already had had a lot of code written using C<%SPEC>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head2 Why wrap? |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
The wrapping process accomplishes several things, among others: checking of |
135
|
|
|
|
|
|
|
metadata, normalization of schemas in metadata, also argument validation and |
136
|
|
|
|
|
|
|
exception trapping in function. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
The function wrapping introduces a small overhead when performing a sub call |
139
|
|
|
|
|
|
|
(typically around several to tens of microseconds on an Intel Core i5 1.7GHz |
140
|
|
|
|
|
|
|
notebook). This is usually smaller than the overhead of Perinci::Access::Perl |
141
|
|
|
|
|
|
|
itself (typically in the range of 100 microseconds). But if you are concerned |
142
|
|
|
|
|
|
|
about the wrapping overhead, see the C<< wrap => 0 >> option. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=head1 HOMEPAGE |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Access-Perl>. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head1 SOURCE |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Source repository is at L<https://github.com/perlancar/perl-Perinci-Access-Perl>. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 BUGS |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=Perinci-Access-Perl> |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
When submitting a bug or request, please include a test-file or a |
157
|
|
|
|
|
|
|
patch to an existing test-file that illustrates the bug or desired |
158
|
|
|
|
|
|
|
feature. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head1 SEE ALSO |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
L<Perinci::Access::Schemeless> |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
L<Perinci::Access> |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
L<Riap> |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 AUTHOR |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
perlancar <perlancar@cpan.org> |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
This software is copyright (c) 2021, 2020, 2019, 2017, 2016, 2015, 2014, 2013, 2012 by perlancar@cpan.org. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
177
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |