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