Schemeless.pm

filter: Statementstmt 82.5% 507 / 614 Branchbran 60.5% 178 / 294 Conditioncond 71.9% 87 / 121 MC/DCmcdc 59.0% 39 / 66 Subroutinesub 84.7% 78 / 92 Podpod 72.0% 31 / 43 totaltotal 74.8% 920 / 1230 CC 287 SCAR 28.6
CC
287
Cov
75%
_pre_tx_action
182.0
action_complete_arg_elem
42.0
get_meta
30.1
CRAP 17.5
↑ Summary Perl.pm »
1 package Perinci::Access::Schemeless;
2  
3 5 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Log::ger;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 5 ▶use parent qw(Perinci::Access::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 5 ▶use List::Util qw(first);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 5 ▶use Perinci::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 5 ▶use Perinci::Sub::Normalize qw(normalize_function_metadata);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 5 ▶use Perinci::Sub::Util qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use Module::Installed::Tiny qw(module_source);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Package::Util::Lite qw(package_exists);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Tie::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use URI::Split qw(uri_split uri_join);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 5 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
21 5 our $DATE = '2023-10-24'; # DATE
22 5 our $DIST = 'Perinci-Access-Perl'; # DIST
23 5 our $VERSION = '0.900'; # VERSION
24  
25 5 our $re_perl_package =
26 qr/\A[A-Za-z_][A-Za-z_0-9]*(::[A-Za-z_0-9][A-Za-z_0-9]*)*\z/;
27  
28 36 ▶sub new {
Subroutine new: called CC=14 SCAR=26.6
Pod documented
29 36 require Class::Inspector;
30  
31 36 my $class = shift;
32 36 my $self = $class->SUPER::new(@_);
33  
34 # build a list of supported actions for each type of entity
35 36 my %typeacts = (
36 package => [],
37 function => [],
38 variable => [],
39 ); # key = type, val = [[ACTION, META], ...]
40  
41 36 my @comacts;
42 36 for my $meth (@{Class::Inspector->methods(ref $self)}) {
43 2846 ▶ next unless $meth =~ /^actionmeta_(.+)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $meth =~ /^actionmeta_(.+)/ 2161 685 2846
44 685 my $act = $1;
45 685 my $meta = $self->$meth();
46 685 $self->{_actionmetas}{$act} = $meta;
47 685 for my $type (@{$meta->{applies_to}}) {
48 685 ▶ if ($type eq '*') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq '*') { } 469 216 685
49 469 push @comacts, [$act, $meta];
50 } else {
51 216 push @{$typeacts{$type}}, [$act, $meta];
52 }
53 }
54 }
55 36 for my $type (keys %typeacts) {
56 1623 $typeacts{$type} = { map {$_->[0] => $_->[1]}
57 108 @{$typeacts{$type}}, @comacts };
58 }
59 36 $self->{_typeacts} = \%typeacts;
60  
61 36 ▶ $self->{cache_size} //= 100; # for caching metadata & code
Condition50%1/2
$self->{"cache_size"} //= 100
l!l
036
MC/DC0%0/1
$self->{"cache_size"} //= 100
$self->{"cache_size"}
Truth table50%1/2
A
A= $self->{"cache_size"}
Aresult
11
00
62 #$self->{use_tx} //= 0;
63 36 ▶ $self->{wrap} //= 1;
Condition100%2/2
$self->{"wrap"} //= 1
l!l
432
MC/DC100%1/1
$self->{"wrap"} //= 1
$self->{"wrap"}
Truth table100%2/2
A
A= $self->{"wrap"}
Aresult
11
00
64 #$self->{custom_tx_manager} //= undef;
65 36 ▶ $self->{load} //= 1;
Condition50%1/2
$self->{"load"} //= 1
l!l
036
MC/DC0%0/1
$self->{"load"} //= 1
$self->{"load"}
Truth table50%1/2
A
A= $self->{"load"}
Aresult
11
00
66 36 ▶ $self->{normalize_metadata} //= 1;
Condition100%2/2
$self->{"normalize_metadata"} //= 1
l!l
135
MC/DC100%1/1
$self->{"normalize_metadata"} //= 1
$self->{"normalize_metadata"}
Truth table100%2/2
A
A= $self->{"normalize_metadata"}
Aresult
11
00
67 #$self->{after_load}
68 #$self->{allow_paths}
69 #$self->{deny_paths}
70 #$self->{allow_schemes}
71 #$self->{deny_schemes}
72 #$self->{package_prefix}
73 36 ▶ $self->{debug} //= $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG} // 0;
Condition50%2/4
$self->{"debug"} //= $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} // 0
l!l
036
$ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} // 0
l!l
036
MC/DC0%0/1
$self->{"debug"} //= $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} // 0
$self->{"debug"}
Truth table50%1/2
A
A= $self->{"debug"}
Aresult
11
00
74 36 ▶ $self->{accept_argv} //= 1;
Condition50%1/2
$self->{"accept_argv"} //= 1
l!l
036
MC/DC0%0/1
$self->{"accept_argv"} //= 1
$self->{"accept_argv"}
Truth table50%1/2
A
A= $self->{"accept_argv"}
Aresult
11
00
75  
76 36 ▶ if ($self->{cache_size} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_size"} > 0) 36 0 36
77 36 my %metacache;
78 36 tie %metacache, 'Tie::Cache', $self->{cache_size};
79 36 $self->{_meta_cache} = \%metacache;
80 36 my %codecache;
81 36 tie %codecache, 'Tie::Cache', $self->{cache_size};
82 36 $self->{_code_cache} = \%codecache;
83 }
84  
85 36 $self;
86 }
87  
88 # for older Perinci::Access::Base 0.28-, to remove later
89 0 ▶sub _init {}
Subroutine _init: not called CC=1 SCAR=0.0
90  
91 # if paths=/a/b, will match /a/b as well as /a/b/c
92 30 ▶sub __match_paths {
Subroutine __match_paths: called CC=11 SCAR=24.0
93 30 my ($path, $paths) = @_;
94  
95 30 ▶ my $pathslash = $path =~ m!/\z! ? $path : "$path/";
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[/\z] ? : 15 15 30
96  
97 30 ▶ for (ref($paths) eq 'ARRAY' ? @$paths : $paths) {
Branch: 1 branch
BranchTrueFalseTotal
ref $paths eq 'ARRAY' ? : 0 30 30
98 30 ▶ if (ref($_) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'Regexp') { } 8 22 30
99 8 ▶ return 1 if $path =~ $_;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ /$_/ 4 4 8
100 } else {
101 22 ▶ if (m!/\z!) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[/\z]) { } 10 12 22
102 10 ▶ return 1 if $_ eq $pathslash || index($pathslash, $_) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $pathslash or index($pathslash, $_) == 0 5 5 10
Condition100%3/3
$_ eq $pathslash or index($pathslash, $_) == 0
l!l&&r!l&&!r
415
MC/DC100%2/2
$_ eq $pathslash or index($pathslash, $_) == 0
$_ eq $pathslash index($pathslash, $_) == 0
Truth table100%3/3
A or B
A= $_ eq $pathslashB= index($pathslash, $_) == 0
ABresult
1X1
011
000
103 } else {
104 12 my $p = "$_/";
105 12 ▶ return 1 if $p eq $path || index($pathslash, $p) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $p eq $path or index($pathslash, $p) == 0 6 6 12
Condition100%3/3
$p eq $path or index($pathslash, $p) == 0
l!l&&r!l&&!r
246
MC/DC100%2/2
$p eq $path or index($pathslash, $p) == 0
$p eq $path index($pathslash, $p) == 0
Truth table100%3/3
A or B
A= $p eq $pathB= index($pathslash, $p) == 0
ABresult
1X1
011
000
106 }
107 }
108 }
109 15 0;
110 }
111  
112 # if paths=/a/b, will match /a/b as well as /a/b/c AS WELL AS /a and /. only
113 # suitable for 'list' action, e.g. allow_path is '/a/b' but we can do 'list /'
114 # and 'list /a' too (but not 'list /c').
115 476 ▶sub __match_paths2 {
Subroutine __match_paths2: called CC=12 SCAR=24.9
116 476 my ($path, $paths) = @_;
117  
118 476 ▶ my $pathslash = $path =~ m!/\z! ? $path : "$path/";
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[/\z] ? : 398 78 476
119  
120 476 ▶ for (ref($paths) eq 'ARRAY' ? @$paths : $paths) {
Branch: 1 branch
BranchTrueFalseTotal
ref $paths eq 'ARRAY' ? : 0 476 476
121 476 ▶ if (ref($_) eq 'Regexp') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'Regexp') { } 54 422 476
122 # we can't match a regex against a string, so we just pass here
123 54 return 1;
124 } else {
125 422 ▶ if (m!/\z!) {
Branch: 1 branch
BranchTrueFalseTotal
if (m[/\z]) { } 10 412 422
126 10 ▶ return 1 if $_ eq $pathslash || index($_, $pathslash) == 0 ||
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq $pathslash or index($_, $pathslash) == 0 or index($pathslash, $_) == 0 9 1 10
Condition100%6/6
$_ eq $pathslash or index($_, $pathslash) == 0 or index($pathslash, $_) == 0
l!l&&r!l&&!r
811
$_ eq $pathslash or index($_, $pathslash) == 0
l!l&&r!l&&!r
442
MC/DC100%3/3
$_ eq $pathslash or index($_, $pathslash) == 0 or index($pathslash, $_) == 0
$_ eq $pathslash index($_, $pathslash) == 0 index($pathslash, $_) == 0
Truth table100%4/4
A or B or C
A= $_ eq $pathslashB= index($_, $pathslash) == 0C= index($pathslash, $_) == 0
ABCresult
1XX1
01X1
0011
0000
127 index($pathslash, $_) == 0;
128 } else {
129 412 my $p = "$_/";
130 412 ▶ return 1 if $p eq $path || index($p, $pathslash) == 0 ||
Branch: 1 branch
BranchTrueFalseTotal
if $p eq $path or index($p, $pathslash) == 0 or index($pathslash, $p) == 0 70 342 412
Condition100%6/6
$p eq $path or index($p, $pathslash) == 0 or index($pathslash, $p) == 0
l!l&&r!l&&!r
1456342
$p eq $path or index($p, $pathslash) == 0
l!l&&r!l&&!r
59398
MC/DC100%3/3
$p eq $path or index($p, $pathslash) == 0 or index($pathslash, $p) == 0
$p eq $path index($p, $pathslash) == 0 index($pathslash, $p) == 0
Truth table100%4/4
A or B or C
A= $p eq $pathB= index($p, $pathslash) == 0C= index($pathslash, $p) == 0
ABCresult
1XX1
01X1
0011
0000
131 index($pathslash, $p) == 0 ;
132 }
133 }
134 }
135 343 0;
136 }
137  
138 84 ▶sub _parse_uri {
Subroutine _parse_uri: called CC=20 SCAR=30.3
139 84 my ($self, $req) = @_;
140  
141 84 my $path = $req->{-uri_path};
142 84 ▶ if (defined $self->{allow_paths}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"allow_paths"}) 5 79 84
143 5 my $allow;
144 5 ▶ if ($self->{_actionmetas}{$req->{action}}{allow_request_parent_path}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_actionmetas'}{$req->{'action'}}{'allow_request_parent_path'}) { } 4 1 5
145 4 $allow = __match_paths2($path, $self->{allow_paths});
146 } else {
147 1 $allow = __match_paths($path, $self->{allow_paths});
148 }
149 5 ▶ return err(403, "Forbidden uri path (does not match allow_paths)")
Branch: 1 branch
BranchTrueFalseTotal
unless $allow 1 4 5
150 unless $allow;
151 }
152 83 ▶ if (defined($self->{deny_paths}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"deny_paths"} and __match_paths($path, $self->{"deny_paths"})) 1 82 83
Condition100%3/3
defined $self->{"deny_paths"} and __match_paths($path, $self->{"deny_paths"})
!ll&&!rl&&r
8021
MC/DC100%2/2
defined $self->{"deny_paths"} and __match_paths($path, $self->{"deny_paths"})
defined $self->{"deny_paths"} __match_paths($path, $self->{"deny_paths"})
Truth table100%3/3
A and B
A= defined $self->{"deny_paths"}B= __match_paths($path, $self->{"deny_paths"})
ABresult
0X0
100
111
153 __match_paths($path, $self->{deny_paths})) {
154 1 return err(403, "Forbidden uri path (matches deny_paths)");
155 }
156  
157 82 ▶ my $sch = $req->{-uri_scheme} // "";
Condition100%2/2
$req->{"-uri_scheme"} // ""
l!l
577
MC/DC100%1/1
$req->{"-uri_scheme"} // ""
$req->{"-uri_scheme"}
Truth table100%2/2
A
A= $req->{"-uri_scheme"}
Aresult
11
00
158 82 ▶ if (defined($self->{allow_schemes}) && !(grep { $_ eq $sch } @{ $self->{allow_schemes} })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"allow_schemes"} and not grep({$_ eq $sch;} @{$$self{"allow_schemes"};})) 3 79 82
Condition100%3/3
defined $self->{"allow_schemes"} and not grep({$_ eq $sch;} @{$$self{"allow_schemes"};})
!ll&&!rl&&r
7633
MC/DC100%2/2
defined $self->{"allow_schemes"} and not grep({$_ eq $sch;} @{$$self{"allow_schemes"};})
defined $self->{"allow_schemes"} not grep({$_ eq $sch;} @{$$self{"allow_schemes"};})
Truth table100%3/3
A and not(B)
A= defined $self->{"allow_schemes"}B= not grep({$_ eq $sch;} @{$$self{"allow_schemes"};})
ABresult
0X0
100
111
159 3 return err(501,
160 "Unsupported uri scheme (does not match allow_schemes)");
161 }
162 79 ▶ if (defined($self->{deny_schemes}) && (grep { $_ eq $sch } @{ $self->{deny_schemes} })) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"deny_schemes"} and grep {$_ eq $sch;} @{$$self{"deny_schemes"};}) 1 78 79
Condition100%3/3
defined $self->{"deny_schemes"} and grep {$_ eq $sch;} @{$$self{"deny_schemes"};}
!ll&&!rl&&r
7711
MC/DC100%2/2
defined $self->{"deny_schemes"} and grep {$_ eq $sch;} @{$$self{"deny_schemes"};}
defined $self->{"deny_schemes"} grep {$_ eq $sch;} @{$$self{"deny_schemes"};}
Truth table100%3/3
A and B
A= defined $self->{"deny_schemes"}B= grep {$_ eq $sch;} @{$$self{"deny_schemes"};}
ABresult
0X0
100
111
163 1 return err(501, "Unsupported uri scheme (matches deny_schemes)");
164 }
165  
166 78 my ($dir, $leaf, $perl_package);
167 78 ▶ if ($path =~ m!(.*)/(.*)!) {
Branch: 1 branch
BranchTrueFalseTotal
if ($path =~ m[(.*)/(.*)]) { } 78 0 78
168 78 $dir = $1;
169 78 $leaf = $2;
170 } else {
171 0 $dir = $path;
172 0 $leaf = '';
173 }
174 78 for ($perl_package) {
175 78 $_ = $dir;
176 78 s!^/+!!;
177 78 s!/+!::!g;
178 78 ▶ if (defined $self->{package_prefix}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"package_prefix"}) 0 78 78
179 0 ▶ $_ = $self->{package_prefix} . (length($_) ? "::":"") . $_;
Branch: 1 branch
BranchTrueFalseTotal
length $_ ? : 0 0 0
180 }
181 }
182 78 ▶ return err(400, "Invalid perl package name: $perl_package")
Branch: 1 branch
BranchTrueFalseTotal
if $perl_package and not $perl_package =~ /$Perinci::Access::Schemeless::re_perl_package/ 0 78 78
Condition66%2/3
$perl_package and not $perl_package =~ /$Perinci::Access::Schemeless::re_perl_package/
!ll&&!rl&&r
8700
MC/DC0%0/2
$perl_package and not $perl_package =~ /$Perinci::Access::Schemeless::re_perl_package/
$perl_package not $perl_package =~ /$Perinci::Access::Schemeless::re_perl_package/
Truth table66%2/3
A and not(B)
A= $perl_packageB= not $perl_package =~ /$Perinci::Access::Schemeless::re_perl_package/
ABresult
0X0
100
111
183 if $perl_package && $perl_package !~ $re_perl_package;
184  
185 78 my $type;
186 78 ▶ if (length $leaf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $leaf) { } 43 35 78
187 43 ▶ if ($leaf =~ /^[%\@\$]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($leaf =~ /^[%\@\$]/) { } 2 41 43
188 2 $type = 'variable';
189 } else {
190 41 $type = 'function';
191 }
192 } else {
193 35 $type = 'package';
194 # make sure path ends in /, to ease processing
195 35 ▶ $req->{-uri_path} .= "/" unless $path =~ m!/\z!;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ m[/\z] 0 35 35
196 }
197  
198 78 $req->{-uri_dir} = $dir;
199 78 $req->{-uri_leaf} = $leaf;
200 78 $req->{-perl_package} = $perl_package;
201 78 $req->{-type} = $type;
202  
203 #$log->tracef("TMP: req=%s", $req);
204 78 return;
205 }
206  
207 # key = module_p, val = error resp or undef if successful
208 5 my %loadcache;
209 5 tie %loadcache, 'Tie::Cache', 200;
210  
211 65 ▶sub _load_module {
Subroutine _load_module: called CC=17 SCAR=28.7
212 65 my ($self, $req) = @_;
213  
214 65 my $pkg = $req->{-perl_package};
215  
216 # skip there is no module to load
217 65 ▶ return if !$pkg;
Branch: 1 branch
BranchTrueFalseTotal
unless $pkg 1 64 65
218  
219 # if we are instructed not to load any module, we just check via existence
220 # of packages
221 64 ▶ unless ($self->{load}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"load"}) 0 64 64
222 0 ▶ return if package_exists($pkg);
Branch: 1 branch
BranchTrueFalseTotal
if package_exists($pkg) 0 0 0
223 0 return err(500, "Package $pkg does not exist");
224 }
225  
226 64 my $module_p = $pkg;
227 64 $module_p =~ s!::!/!g;
228 64 $module_p .= ".pm";
229  
230 # module has been required before and successfully loaded
231 64 ▶ return if $INC{$module_p};
Branch: 1 branch
BranchTrueFalseTotal
if $INC{$module_p} 18 46 64
232  
233 # module has been required before and failed
234 return err(500, "Module $pkg has failed to load previously" .
235 $loadcache{$module_p} ?
236 ": $loadcache{$module_p}[0] - $loadcache{$module_p}[1]" :
237 "")
238 46 ▶ if exists($INC{$module_p});
Branch: 2 branches
BranchTrueFalseTotal
if exists $INC{$module_p} 0 46 46
"Module $pkg has failed to load previously" . $loadcache{$module_p} ? : 0 0 0
239  
240 # use cache result (for caching errors, or packages like 'main' and 'CORE'
241 # where no modules for such packages exist)
242 46 ▶ return $loadcache{$module_p} if exists $loadcache{$module_p};
Branch: 1 branch
BranchTrueFalseTotal
if exists $loadcache{$module_p} 5 41 46
243  
244 # load and cache negative result
245 41 my $res;
246 {
247 41 my ($source, $fullpath);
248 41 eval { ($source, $fullpath) = module_source($pkg, {die=>1, find_prefix=>1}) };
249 41 my $err = $@;
250  
251 # when the module path does not exist, but the package does, we can
252 # ignore this error. for example: main, CORE, etc.
253 41 my $pkg_exists = package_exists($pkg);
254  
255 41 ▶ if (!defined($source)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $source) 37 4 41
256 37 ▶ last if $pkg_exists;
Branch: 1 branch
BranchTrueFalseTotal
if $pkg_exists 36 1 37
257 1 ▶ $res = [404, "Can't find source for module $pkg".($fullpath && $fullpath !~ /\.pm$/ ? " (but can find prefix for it at $fullpath)" : "").": $err"];
Branch: 1 branch
BranchTrueFalseTotal
$fullpath && !($fullpath =~ /\.pm$/) ? : 0 1 1
Condition33%1/3
$fullpath and not $fullpath =~ /\.pm$/
!ll&&!rl&&r
100
MC/DC0%0/2
$fullpath and not $fullpath =~ /\.pm$/
$fullpath not $fullpath =~ /\.pm$/
Truth table33%1/3
A and not(B)
A= $fullpathB= not $fullpath =~ /\.pm$/
ABresult
0X0
100
111
258 1 last;
259 }
260 4 ▶ eval $source; ## no critic: BuiltinFunctions::ProhibitStringyEval
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
261 4 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 3 4
262 1 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 1 1
263 1 $res = [500, "Can't load module $pkg (probably compile error): $@"];
264 1 last;
265 }
266 # load is successful
267 3 $INC{$module_p} = $fullpath;
268 3 ▶ if ($self->{after_load}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"after_load"}) 1 2 3
269 1 eval { $self->{after_load}($self, module=>$pkg) };
270 1 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 1 1
271 0 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 0 0
272 0 log_error("after_load for package $pkg dies: $@");
273 }
274 }
275 }
276 41 $loadcache{$module_p} = $res;
277 41 return $res;
278 }
279  
280 44 ▶sub __inject_entity_v_date {
Subroutine __inject_entity_v_date: called CC=5 SCAR=16.1
281 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
282  
283 44 my ($req, $meta) = @_;
284  
285 44 my $pkg = $req->{-perl_package};
286 44 ▶ unless (defined $meta->{entity_v}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"entity_v"}) 38 6 44
287 38 my $ver = ${"$pkg\::VERSION"};
288 38 ▶ if (defined $ver) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ver) 25 13 38
289 25 $meta->{entity_v} = $ver;
290 }
291 }
292 44 ▶ unless (defined $meta->{entity_date}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $meta->{"entity_date"}) 41 3 44
293 41 my $date = ${"$pkg\::DATE"};
294 41 ▶ if (defined $date) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $date) 13 28 41
295 13 $meta->{entity_date} = $date;
296 }
297 }
298 }
299  
300 64 ▶sub get_meta {
Subroutine get_meta: called CC=24 SCAR=34.1
Pod documented
301 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
302  
303 64 my ($self, $req) = @_;
304  
305 64 my $pkg = $req->{-perl_package};
306 64 my $leaf = $req->{-uri_leaf};
307 64 my $type = $req->{-type};
308 64 ▶ if (!length($pkg)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $pkg) 5 59 64
309 5 ▶ if (length $leaf) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $leaf) { } 3 4 7
310 # 404 for all non-subpackage entity directly under /
311 1 ▶ return [404, "No metadata for ::$leaf (".
Branch: 1 branch
BranchTrueFalseTotal
package_exists($pkg) ? : 0 3 3
312 (package_exists($pkg) ? "package '$pkg' exists, perhaps you mentioned '$pkg' somewhere without actually loading the module, or perhaps '$leaf' is a typo?" :
313 "package '$pkg' doesn't exist, perhaps '$pkg' or '$leaf' is a typo?").
314 ")"
315 ];
316 } else {
317 # empty metadata for root (/)
318 4 $req->{-meta} = {v=>1.1};
319 4 return;
320 }
321 }
322  
323 59 my $name = "$pkg\::$leaf";
324 59 ▶ if ($self->{_meta_cache}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_meta_cache"}{$name}) 17 42 59
325 17 $req->{-meta} = $self->{_meta_cache}{$name};
326 $req->{-orig_meta} = $self->{_orig_meta_cache}{$name}
327 17 ▶ if $self->{_orig_meta_cache}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_orig_meta_cache"}{$name} 0 17 17
328 17 return;
329 }
330  
331 43 my $res = $self->_load_module($req);
332 # missing module (but existing prefix) is okay for package, we construct an
333 # empty package metadata for it
334 43 ▶ return $res if $res && !($type eq 'package' && $res->[0] == 405);
Branch: 1 branch
BranchTrueFalseTotal
if $res and not $type eq "package" && $res->[0] == 405 6 36 42
Condition50%3/6
$res and not $type eq "package" && $res->[0] == 405
!ll&&!rl&&r
3606
$type eq 'package' && $res->[0] == 405
!ll&&!rl&&r
060
MC/DC33%1/3
$res and not $type eq "package" && $res->[0] == 405
$res $type eq 'package' $res->[0] == 405
Truth table50%2/4
A and not(B && C)
A= $resB= $type eq 'package'C= $res->[0] == 405
ABCresult
0XX0
1110
10X1
1101
335  
336 36 my $meta;
337 36 my $metas = \%{"$pkg\::SPEC"};
338 36 ▶ $meta = $metas->{ $leaf || ":package" };
Condition100%2/2
$leaf || ':package'
l!l
2412
MC/DC100%1/1
$leaf || ':package'
$leaf
Truth table100%2/2
A
A= $leaf
Aresult
11
00
339  
340 36 ▶ if (!$meta && $type eq 'package') {
Branch: 1 branch
BranchTrueFalseTotal
if (not $meta and $type eq "package") 6 30 36
Condition100%3/3
not $meta and $type eq "package"
!ll&&!rl&&r
2736
MC/DC100%2/2
not $meta and $type eq "package"
not $meta $type eq "package"
Truth table100%3/3
not(A) and B
A= not $metaB= $type eq "package"
ABresult
0X0
100
111
341 6 $meta = {v=>1.1};
342 }
343  
344 36 ▶ return err(404,
Branch: 1 branch
BranchTrueFalseTotal
unless $meta 3 33 36
345 join("",
346 "No metadata for $name (package '$pkg' exists, ",
347 "perhaps you mentioned '$pkg' ",
348 "somewhere without actually loading the module, or ",
349 "perhaps '$leaf' is a typo?)",
350 )) unless $meta;
351  
352 33 ▶ if ($res) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res) 0 33 33
353 0 ▶ if ($res->[0] == 405) {
Branch: 2 branches
BranchTrueFalseTotal
if ($res->[0] == 405) { } 0 0 0
elsif ($res->[0] != 200) { } 0 0 0
354 0 $meta = {v=>1.1}; # empty package metadata for dir
355 } elsif ($res->[0] != 200) {
356 0 return $res;
357 }
358 }
359  
360 # normalize has only been implemented for function
361 33 ▶ if ($type eq 'function' && $self->{normalize_metadata}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "function" and $self->{"normalize_metadata"}) 18 15 33
Condition100%3/3
$type eq "function" and $self->{"normalize_metadata"}
!ll&&!rl&&r
14118
MC/DC100%2/2
$type eq "function" and $self->{"normalize_metadata"}
$type eq "function" $self->{"normalize_metadata"}
Truth table100%3/3
A and B
A= $type eq "function"B= $self->{"normalize_metadata"}
ABresult
0X0
100
111
362 18 eval { $meta = normalize_function_metadata($meta) };
363 20 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 18 18
364 2 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 0 0
365 2 return [500, "Can't normalize function metadata: $@"];
366 }
367  
368 20 ▶ $meta->{args} //= {};
Condition66%2/3
$meta->{"args"} //= {}
l!l
1080
MC/DC100%1/1
$meta->{"args"} //= {}
$meta->{"args"}
Truth table100%2/2
A
A= $meta->{"args"}
Aresult
11
00
369 20 $meta->{_orig_args_as} = $meta->{args_as};
370 24 $meta->{args_as} = 'hash';
371 20 $meta->{_orig_result_naked} = $meta->{result_naked};
372 18 $meta->{result_naked} = 0;
373 18 my $sfp = $self->{set_function_properties};
374 18 ▶ if ($sfp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sfp) 0 18 18
375 0 for (keys %$sfp) {
376 0 $meta->{"_orig_$_"} = $meta->{$_};
377 0 $meta->{$_} = $sfp->{$_};
378 }
379 }
380 }
381  
382 33 __inject_entity_v_date($req, $meta);
383  
384 33 ▶ if ($self->{cache_size} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_size"} > 0) 33 0 33
385 33 $self->{_meta_cache}{$name} = $meta;
386 }
387  
388 33 $req->{-meta} = $meta;
389 33 return;
390 }
391  
392 19 ▶sub get_code {
Subroutine get_code: called CC=14 SCAR=26.9
Pod documented
393 19 my ($self, $req) = @_;
394  
395 # because we're lazy, we assume here that type is already function. it
396 # should be okay since get_code() is only called by action_call().
397  
398 19 my $name = $req->{-perl_package} . "::" . $req->{-uri_leaf};
399 19 ▶ if ($self->{_code_cache}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_code_cache"}{$name}) 6 13 19
400 6 $req->{-code} = $self->{_code_cache}{$name};
401 6 return;
402 }
403  
404 13 my $res = $self->_load_module($req);
405 13 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 13 13
406  
407 return err(404, "Can't find function $req->{-uri_leaf} in ".
408 "module $req->{-perl_package}")
409 13 ▶ unless defined &{$name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined &{$name;} 0 13 13
410  
411 # we get our own meta and not use get_meta() because we want to get the
412 # original metadata
413 13 my $meta;
414 {
415 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
416 13 my $metas = \%{"$req->{-perl_package}::SPEC"};
417 13 ▶ $meta = $metas->{ $req->{-uri_leaf} || ":package" };
Condition50%1/2
$req->{'-uri_leaf'} || ':package'
l!l
130
MC/DC0%0/1
$req->{'-uri_leaf'} || ':package'
$req->{'-uri_leaf'}
Truth table50%1/2
A
A= $req->{'-uri_leaf'}
Aresult
11
00
418 }
419  
420 13 ▶ return err(404, "Can't find function metadata $req->{-uri_leaf} in ".
Branch: 1 branch
BranchTrueFalseTotal
unless $meta 0 13 13
421 "module $req->{-perl_package}")
422 unless $meta;
423  
424 13 my $code;
425 GET_CODE:
426 {
427 # we don't need to wrap
428 13 ▶ if (!$self->{wrap} ||
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"wrap"} or $meta->{"x.perinci.sub.wrapper.logs"} and &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})) 2 11 13
Condition83%5/6
not $self->{"wrap"} or $meta->{"x.perinci.sub.wrapper.logs"} and &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})
l!l&&r!l&&!r
1111
$meta->{"x.perinci.sub.wrapper.logs"} and &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})
!ll&&!rl&&r
1101
MC/DC66%2/3
not $self->{"wrap"} or $meta->{"x.perinci.sub.wrapper.logs"} and &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})
not $self->{"wrap"} $meta->{"x.perinci.sub.wrapper.logs"} &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})
Truth table75%3/4
not(A) or B and C
A= not $self->{"wrap"}B= $meta->{"x.perinci.sub.wrapper.logs"}C= &first(sub { $_->{"validate_args"}; } , @{$$meta{"x.perinci.sub.wrapper.logs"};})
ABCresult
1XX1
0111
00X0
0100
429 $meta->{"x.perinci.sub.wrapper.logs"} &&
430 1 ▶ (first {$_->{validate_args}}
Subroutine __ANON__: called CC=1 SCAR=0.0
431 1 @{ $meta->{"x.perinci.sub.wrapper.logs"} })
432 ) {
433 2 $code = \&{$name};
434 2 last GET_CODE;
435 }
436  
437 11 require Perinci::Sub::Wrapper;
438 11 my $sfp = $self->{set_function_properties};
439  
440 11 ▶ my $wrapres = Perinci::Sub::Wrapper::wrap_sub(
Branch: 1 branch
BranchTrueFalseTotal
$sfp ? : 0 11 11
441 sub_name=>$name, meta=>$meta,
442 convert=>{args_as=>'hash', result_naked=>0,
443 ($sfp ? %$sfp : ())
444 });
445 11 ▶ return err(500, "Can't wrap function", $wrapres)
Branch: 1 branch
BranchTrueFalseTotal
unless $wrapres->[0] == 200 0 11 11
446 unless $wrapres->[0] == 200;
447 11 $code = $wrapres->[2]{sub};
448  
449 11 ▶ if ($self->{cache_size} > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"cache_size"} > 0) 11 0 11
450 11 $self->{_code_cache}{$name} = $code;
451 # also put wrapper-generated meta in the cache, so further meta
452 # request can use this. the metadata from wrapper contains wrapper
453 # logs (x.perinci.sub.wrapper.logs) which can be helpful hint for
454 # some uses.
455 11 my $newmeta = $wrapres->[2]{meta};
456 11 $newmeta->{_orig_result_naked} = $meta->{result_naked};
457 11 $newmeta->{_orig_args_as} = $meta->{args_as};
458 11 ▶ if ($sfp) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sfp) 0 11 11
459 0 for (keys %$sfp) {
460 0 $newmeta->{"_orig_$_"} = $meta->{$_};
461 }
462 }
463 11 __inject_entity_v_date($req, $newmeta);
464 11 $self->{_meta_cache}{$name} = $newmeta;
465 }
466 }
467  
468 13 $req->{-code} = $code;
469 13 return;
470 }
471  
472 85 ▶sub request {
Subroutine request: called CC=10 SCAR=23.5
Pod documented
473 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
474  
475 85 my ($self, $action, $uri, $extra) = @_;
476  
477 85 ▶ return err(400, "Please specify URI") unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 85 85
478  
479 87 ▶ my $req = { action=>$action, uri=>$uri, %{$extra // {}} };
Condition100%2/2
$extra // {}
l!l
2065
MC/DC100%1/1
$extra // {}
$extra
Truth table100%2/2
A
A= $extra
Aresult
11
00
480 85 my $res = $self->check_request($req);
481 85 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 85 85
482  
483 85 ▶ return err(501, "Action '$action' not implemented")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can("actionmeta_$action") 1 84 85
484 unless $self->can("actionmeta_$action");
485  
486 84 my $am = $self->${\("actionmeta_$action")};
487  
488 84 $res = $self->_parse_uri($req);
489 84 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 6 78 84
490  
491 return err(501, "Action '$action' not implemented for ".
492 "'$req->{-type}' entity")
493 unless $am->{applies_to}[0] eq '*' ||
494 78 ▶ (grep { $_ eq $req->{-type} } @{ $am->{applies_to} });
Branch: 1 branch
BranchTrueFalseTotal
unless $am->{"applies_to"}[0] eq "*" or grep {$_ eq $req->{"-type"};} @{$$am{"applies_to"};} 2 76 78
Condition100%3/3
$am->{"applies_to"}[0] eq "*" or grep {$_ eq $req->{"-type"};} @{$$am{"applies_to"};}
l!l&&r!l&&!r
42342
MC/DC100%2/2
$am->{"applies_to"}[0] eq "*" or grep {$_ eq $req->{"-type"};} @{$$am{"applies_to"};}
$am->{"applies_to"}[0] eq "*" grep {$_ eq $req->{"-type"};} @{$$am{"applies_to"};}
Truth table100%3/3
A or B
A= $am->{"applies_to"}[0] eq "*"B= grep {$_ eq $req->{"-type"};} @{$$am{"applies_to"};}
ABresult
1X1
011
000
495  
496 76 my $meth = "action_$action";
497 # check transaction
498  
499 76 $res = $self->$meth($req);
500 76 ▶ if ($self->{debug}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"debug"}) 0 76 76
501 0 ▶ $res->[3] //= {};
Condition0%0/2
$res->[3] //= {}
l!l
00
MC/DC0%0/1
$res->[3] //= {}
$res->[3]
Truth table0%0/2
A
A= $res->[3]
Aresult
11
00
502 $res->[3]{debug} = {
503 0 req => $req,
504 };
505 }
506 76 $res;
507 }
508  
509 2 ▶sub parse_url {
Subroutine parse_url: called CC=2 SCAR=7.0
Pod documented
510 2 my ($self, $uri) = @_;
511 2 ▶ die "Please specify url" unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 2 2
512 2 my ($sch, $auth, $path) = uri_split($uri);
513 return {
514 # to mark that we are schemeless
515 2 proto=>'',
516 path=>$path,
517 };
518 }
519  
520 45 ▶sub actionmeta_info { +{
Subroutine actionmeta_info: called CC=1 SCAR=0.0
Pod documented
521 45 applies_to => ['*'],
522 summary => "Get general information on code entity",
523 needs_meta => 0,
524 needs_code => 0,
525 } }
526  
527 7 ▶sub action_info {
Subroutine action_info: called CC=2 SCAR=6.9
Pod documented
528 7 my ($self, $req) = @_;
529  
530 7 my $mres = $self->get_meta($req);
531 7 ▶ return $mres if $mres;
Branch: 1 branch
BranchTrueFalseTotal
if $mres 1 6 7
532  
533 my $res = {
534 uri => $req->{uri},
535 type => $req->{-type},
536 6 };
537  
538 6 [200, "OK (info action)", $res];
539 }
540  
541 44 ▶sub actionmeta_actions { +{
Subroutine actionmeta_actions: called CC=1 SCAR=0.0
Pod documented
542 44 applies_to => ['*'],
543 summary => "List available actions for code entity",
544 needs_meta => 0,
545 needs_code => 0,
546 } }
547  
548 8 ▶sub action_actions {
Subroutine action_actions: called CC=4 SCAR=14.0
Pod documented
549 8 my ($self, $req) = @_;
550  
551 8 my $mres = $self->get_meta($req);
552 8 ▶ return $mres if $mres;
Branch: 1 branch
BranchTrueFalseTotal
if $mres 4 4 8
553  
554 4 my @res;
555 4 for my $k (sort keys %{ $self->{_typeacts}{$req->{-type}} }) {
556 60 my $v = $self->{_typeacts}{$req->{-type}}{$k};
557 60 ▶ if ($req->{detail}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{'detail'}) { } 0 60 60
558 0 push @res, {name=>$k, summary=>$v->{summary}};
559 } else {
560 60 push @res, $k;
561 }
562 }
563 4 [200, "OK (actions action)", \@res];
564 }
565  
566 46 ▶sub actionmeta_list { +{
Subroutine actionmeta_list: called CC=1 SCAR=0.0
Pod documented
567 46 applies_to => ['package'],
568 summary => "List code entities inside this package code entity",
569 # this means, even if allow_path is '/a/b', we allow request on '/a' or '/'.
570 allow_request_parent_path => 1,
571 } }
572  
573 10 ▶sub action_list {
Subroutine action_list: called CC=19 SCAR=29.7
Pod documented
574 10 require Module::List;
575  
576 10 my ($self, $req) = @_;
577 10 my $detail = $req->{detail};
578 10 ▶ my $f_type = $req->{type} || "";
Condition50%1/2
$req->{'type'} || ''
l!l
010
MC/DC0%0/1
$req->{'type'} || ''
$req->{'type'}
Truth table50%1/2
A
A= $req->{'type'}
Aresult
11
00
579  
580 10 my @res;
581  
582 555 ▶ my $filter_path = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
583 554 my $path = shift;
584 554 ▶ if (defined($self->{allow_paths}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"allow_paths"} and not __match_paths2($path, $self->{"allow_paths"})) 340 214 554
Condition100%3/3
defined $self->{"allow_paths"} and not __match_paths2($path, $self->{"allow_paths"})
!ll&&!rl&&r
15856340
MC/DC100%2/2
defined $self->{"allow_paths"} and not __match_paths2($path, $self->{"allow_paths"})
defined $self->{"allow_paths"} not __match_paths2($path, $self->{"allow_paths"})
Truth table100%3/3
A and not(B)
A= defined $self->{"allow_paths"}B= not __match_paths2($path, $self->{"allow_paths"})
ABresult
0X0
100
111
585 !__match_paths2($path, $self->{allow_paths})) {
586 340 return 0;
587 }
588 214 ▶ if (defined($self->{deny_paths}) &&
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"deny_paths"} and __match_paths2($path, $self->{"deny_paths"})) 50 164 214
Condition66%2/3
defined $self->{"deny_paths"} and __match_paths2($path, $self->{"deny_paths"})
!ll&&!rl&&r
164050
MC/DC50%1/2
defined $self->{"deny_paths"} and __match_paths2($path, $self->{"deny_paths"})
defined $self->{"deny_paths"} __match_paths2($path, $self->{"deny_paths"})
Truth table66%2/3
A and B
A= defined $self->{"deny_paths"}B= __match_paths2($path, $self->{"deny_paths"})
ABresult
0X0
100
111
589 __match_paths2($path, $self->{deny_paths})) {
590 50 return 0;
591 }
592 164 1;
593 10 };
594  
595 10 my %mem;
596  
597 # get submodules
598 10 ▶ unless ($f_type && $f_type ne 'package') {
Branch: 1 branch
BranchTrueFalseTotal
unless ($f_type and $f_type ne "package") 10 0 10
Condition33%1/3
$f_type and $f_type ne "package"
!ll&&!rl&&r
1000
MC/DC0%0/2
$f_type and $f_type ne "package"
$f_type $f_type ne "package"
Truth table33%1/3
A and B
A= $f_typeB= $f_type ne "package"
ABresult
0X0
100
111
599 my $lres = Module::List::list_modules(
600 10 ▶ $req->{-perl_package} ? "$req->{-perl_package}\::" : "",
Branch: 1 branch
BranchTrueFalseTotal
$req->{'-perl_package'} ? : 9 1 10
601 {list_modules=>1, list_prefixes=>1});
602 10 my $dir = $req->{-uri_dir};
603 10 for my $m (sort keys %$lres) {
604 425 $m =~ s!::$!!;
605 425 $m =~ s!.+::!!;
606 425 my $path = "$dir/$m/";
607 425 ▶ next unless $filter_path->($path);
Branch: 1 branch
BranchTrueFalseTotal
unless &$filter_path($path) 360 65 425
608 65 ▶ next if $mem{$path}++;
Branch: 1 branch
BranchTrueFalseTotal
if $mem{$path}++ 4 61 65
609 61 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 19 42 61
610 19 push @res, {uri=>"$m/", type=>"package"};
611 } else {
612 42 push @res, "$m/";
613 }
614 }
615 }
616  
617 10 my $res = $self->_load_module($req);
618 10 ▶ return $res if $res && $res->[0] != 405;
Branch: 1 branch
BranchTrueFalseTotal
if $res and $res->[0] != 405 1 9 10
Condition66%2/3
$res and $res->[0] != 405
!ll&&!rl&&r
901
MC/DC50%1/2
$res and $res->[0] != 405
$res $res->[0] != 405
Truth table66%2/3
A and B
A= $resB= $res->[0] != 405
ABresult
0X0
100
111
619  
620 # get all entities from this module
621 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
622 9 my $spec = \%{"$req->{-perl_package}\::SPEC"};
623 9 my $dir = $req->{-uri_dir};
624 9 for my $e (sort keys %$spec) {
625 135 ▶ next if $e =~ /^:/;
Branch: 1 branch
BranchTrueFalseTotal
if $e =~ /^:/ 6 129 135
626 129 my $path = "$dir/$e";
627 129 ▶ next unless $filter_path->($path);
Branch: 1 branch
BranchTrueFalseTotal
unless &$filter_path($path) 30 99 129
628 99 ▶ next if $mem{$path}++;
Branch: 1 branch
BranchTrueFalseTotal
if $mem{$path}++ 0 99 99
629 99 ▶ my $t = $e =~ /^[%\@\$]/ ? 'variable' : 'function';
Branch: 1 branch
BranchTrueFalseTotal
$e =~ /^[%\@\$]/ ? : 4 95 99
630 99 ▶ next if $f_type && $f_type ne $t;
Branch: 1 branch
BranchTrueFalseTotal
if $f_type and $f_type ne $t 0 99 99
Condition33%1/3
$f_type and $f_type ne $t
!ll&&!rl&&r
9900
MC/DC0%0/2
$f_type and $f_type ne $t
$f_type $f_type ne $t
Truth table33%1/3
A and B
A= $f_typeB= $f_type ne $t
ABresult
0X0
100
111
631 99 ▶ if ($detail) {
Branch: 1 branch
BranchTrueFalseTotal
if ($detail) { } 30 69 99
632 30 push @res, {
633 uri=>$e, type=>$t,
634 };
635 } else {
636 69 push @res, $e;
637 }
638 }
639  
640 9 [200, "OK (list action)", \@res];
641 }
642  
643 66 ▶sub actionmeta_meta { +{
Subroutine actionmeta_meta: called CC=1 SCAR=0.0
Pod documented
644 66 applies_to => ['*'],
645 summary => "Get metadata",
646 } }
647  
648 26 ▶sub action_meta {
Subroutine action_meta: called CC=2 SCAR=6.9
Pod documented
649 26 my ($self, $req) = @_;
650  
651 26 my $res = $self->get_meta($req);
652 26 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 5 21 26
653  
654 21 [200, "OK (meta action)", $req->{-meta}];
655 }
656  
657 56 ▶sub actionmeta_call { +{
Subroutine actionmeta_call: called CC=1 SCAR=0.0
Pod documented
658 56 applies_to => ['function'],
659 summary => "Call function",
660 } }
661  
662 19 ▶sub action_call {
Subroutine action_call: called CC=22 SCAR=33.2
Pod documented
663 19 require UUID::Random;
664  
665 19 my ($self, $req) = @_;
666  
667 19 my $res;
668  
669 my $tm; # = does client mention tx_id?
670 19 ▶ if (defined $req->{tx_id}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $req->{"tx_id"}) 0 19 19
671 0 $res = $self->_pre_tx_action($req);
672 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
673 0 $tm = $self->{_tx_manager};
674 0 $tm->{_tx_id} = $req->{tx_id};
675 }
676  
677 19 $res = $self->get_meta($req);
678 19 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 19 19
679 19 $res = $self->get_code($req);
680 19 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 19 19
681  
682 19 my %args;
683  
684 # try to convert from argv if given argv
685 19 ▶ if (exists($req->{argv}) && $self->{accept_argv}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $req->{'argv'} and $self->{'accept_argv'}) { } 2 17 19
Condition66%2/3
exists $req->{"argv"} and $self->{"accept_argv"}
!ll&&!rl&&r
1702
MC/DC50%1/2
exists $req->{"argv"} and $self->{"accept_argv"}
exists $req->{"argv"} $self->{"accept_argv"}
Truth table66%2/3
A and B
A= exists $req->{"argv"}B= $self->{"accept_argv"}
ABresult
0X0
100
111
686 2 require Perinci::Sub::GetArgs::Argv;
687 $res = Perinci::Sub::GetArgs::Argv::get_args_from_argv(
688 2 argv => [@{ $req->{argv} }],
689 meta => $req->{-meta},
690 2 );
691 2 ▶ return err(400, "Can't parse argv", $res) unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 1 1 2
692 1 %args = %{ $res->[2] };
693 } else {
694 17 ▶ %args = %{ $req->{args} // {} };
Condition66%2/3
$req->{"args"} // {}
l!l
3140
MC/DC100%1/1
$req->{"args"} // {}
$req->{"args"}
Truth table100%2/2
A
A= $req->{"args"}
Aresult
11
00
695 }
696  
697 18 my $risub = risub($req->{-meta});
698  
699 18 ▶ if ($req->{dry_run}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"dry_run"}) 3 15 18
700 3 ▶ return err(412, "Function does not support dry run")
Branch: 1 branch
BranchTrueFalseTotal
unless $risub->can_dry_run 1 2 3
701 unless $risub->can_dry_run;
702 2 ▶ if ($risub->feature('dry_run')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($risub->feature('dry_run')) { } 1 1 2
703 1 $args{-dry_run} = 1;
704 } else {
705 1 $args{-dry_run} = 1;
706 1 $args{-tx_action} = 'check_state';
707 1 $args{-tx_action_id} = UUID::Random::generate();
708 1 undef $tm;
709 }
710 }
711  
712 17 ▶ if ($risub->feature('progress')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($risub->feature("progress")) 1 16 17
713 1 require Progress::Any;
714 1 $args{-progress} = Progress::Any->get_indicator();
715 }
716  
717 17 ▶ if ($tm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tm) { } 0 17 17
718 $res = $tm->action(
719 f => "$req->{-perl_package}::$req->{-uri_leaf}", args=>\%args,
720 confirm => $req->{confirm},
721 0 );
722 0 ▶ $tm->{_tx_id} = undef if $tm;
Branch: 1 branch
BranchTrueFalseTotal
if $tm 0 0 0
723 } else {
724 17 ▶ $args{-confirm} = 1 if $req->{confirm};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"confirm"} 1 16 17
725 17 eval { $res = $req->{-code}->(%args) };
726 17 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 16 17
727 1 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 1 1
728 1 $res = err(500, "Function died: $@");
729 }
730 }
731  
732 # add hint that result is binary
733 17 ▶ if (defined $res->[2]) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $res->[2]) 7 10 17
734 7 ▶ if ($req->{-meta}{result} && $req->{-meta}{result}{schema} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($req->{"-meta"}{"result"} and $req->{"-meta"}{"result"}{"schema"} and $req->{"-meta"}{"result"}{"schema"}[0] eq "buf") 0 7 7
Condition66%4/6
$req->{"-meta"}{"result"} and $req->{"-meta"}{"result"}{"schema"} and $req->{"-meta"}{"result"}{"schema"}[0] eq "buf"
!ll&&!rl&&r
430
$req->{"-meta"}{"result"} and $req->{"-meta"}{"result"}{"schema"}
!ll&&!rl&&r
403
MC/DC0%0/3
$req->{"-meta"}{"result"} and $req->{"-meta"}{"result"}{"schema"} and $req->{"-meta"}{"result"}{"schema"}[0] eq "buf"
$req->{"-meta"}{"result"} $req->{"-meta"}{"result"}{"schema"} $req->{"-meta"}{"result"}{"schema"}[0] eq "buf"
Truth table50%2/4
A and B and C
A= $req->{"-meta"}{"result"}B= $req->{"-meta"}{"result"}{"schema"}C= $req->{"-meta"}{"result"}{"schema"}[0] eq "buf"
ABCresult
0XX0
10X0
1100
1111
735 $req->{-meta}{result}{schema}[0] eq 'buf') {
736 0 $res->[3]{'x.hint.result_binary'} = 1;
737 }
738 }
739  
740 17 $res;
741 }
742  
743 43 ▶sub actionmeta_complete_arg_val { +{
Subroutine actionmeta_complete_arg_val: called CC=1 SCAR=0.0
Pod documented
744 41 applies_to => ['function'],
745 summary => "Complete function's argument value"
746 } }
747  
748 5 ▶sub action_complete_arg_val {
Subroutine action_complete_arg_val: called CC=5 SCAR=16.2
Pod documented
749 5 require Perinci::Sub::Complete;
750  
751 5 my ($self, $req) = @_;
752 5 ▶ my $arg = $req->{arg} or return err(400, "Please specify arg");
Branch: 1 branch
BranchTrueFalseTotal
my $arg = $req->{"arg"} or return err(400, "Please specify arg") 4 1 5
753 4 ▶ my $word = $req->{word} // "";
Condition66%2/3
$req->{"word"} // ""
l!l
310
MC/DC100%1/1
$req->{"word"} // ""
$req->{"word"}
Truth table100%2/2
A
A= $req->{"word"}
Aresult
11
00
754 4 my $ci = $req->{ci};
755  
756 4 my $res = $self->get_meta($req);
757 4 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 4 4
758 [200, "OK (complete_arg_val action)",
759 4 ▶ Perinci::Sub::Complete::complete_arg_val(meta=>$req->{-meta}, word=>$word,
Condition100%2/2
Perinci::Sub::Complete::complete_arg_val("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci) // []
l!l
31
MC/DC100%1/1
Perinci::Sub::Complete::complete_arg_val("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci) // []
Perinci::Sub::Complete::complete_arg_val("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci)
Truth table100%2/2
A
A= Perinci::Sub::Complete::complete_arg_val("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci)
Aresult
11
00
760 arg=>$arg, ci=>$ci) // []];
761 }
762  
763 36 ▶sub actionmeta_complete_arg_elem { +{
Subroutine actionmeta_complete_arg_elem: called CC=1 SCAR=0.0
Pod documented
764 36 applies_to => ['function'],
765 summary => "Complete function's argument element value"
766 } }
767  
768 0 ▶sub action_complete_arg_elem {
Subroutine action_complete_arg_elem: not called CC=6 SCAR=37.4
Pod documented
769 0 require Perinci::Sub::Complete;
770  
771 0 my ($self, $req) = @_;
772 0 ▶ my $arg = $req->{arg} or return err(400, "Please specify arg");
Branch: 1 branch
BranchTrueFalseTotal
my $arg = $req->{"arg"} or return err(400, "Please specify arg") 0 0 0
773 defined(my $index = $req->{index})
774 0 ▶ or return err(400, "Please specify index");
Branch: 1 branch
BranchTrueFalseTotal
defined(my $index = $req->{"index"}) or return err(400, "Please specify index") 0 0 0
775 0 ▶ my $word = $req->{word} // "";
Condition0%0/2
$req->{"word"} // ""
l!l
00
MC/DC0%0/1
$req->{"word"} // ""
$req->{"word"}
Truth table0%0/2
A
A= $req->{"word"}
Aresult
11
00
776 0 my $ci = $req->{ci};
777  
778 0 my $res = $self->get_meta($req);
779 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
780 [200, "OK (complete_arg_elem action)",
781 Perinci::Sub::Complete::complete_arg_elem(
782 0 ▶ meta=>$req->{-meta}, word=>$word, arg=>$arg, ci=>$ci, index=>$index,
Condition0%0/2
Perinci::Sub::Complete::complete_arg_elem("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci, "index", $index) // []
l!l
00
MC/DC0%0/1
Perinci::Sub::Complete::complete_arg_elem("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci, "index", $index) // []
Perinci::Sub::Complete::complete_arg_elem("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci, "index", $index)
Truth table0%0/2
A
A= Perinci::Sub::Complete::complete_arg_elem("meta", $req->{"-meta"}, "word", $word, "arg", $arg, "ci", $ci, "index", $index)
Aresult
11
00
783 ) // []];
784 }
785  
786 37 ▶sub actionmeta_child_metas { +{
Subroutine actionmeta_child_metas: called CC=1 SCAR=0.0
Pod documented
787 37 applies_to => ['package'],
788 summary => "Get metadata of all child entities",
789 } }
790  
791 1 ▶sub action_child_metas {
Subroutine action_child_metas: called CC=4 SCAR=14.0
Pod documented
792 1 my ($self, $req) = @_;
793  
794 1 my $res = $self->action_list($req);
795 1 ▶ return $res unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 1 1
796 1 my $ents = $res->[2];
797  
798 1 my %res;
799 my %om;
800 my $base = uri_join(
801 1 $req->{-uri_scheme}, $req->{-uri_auth}, $req->{-uri_dir});
802  
803 1 for my $ent (@$ents) {
804 6 $res = $self->request(meta => "$base/$ent");
805 # ignore failed request
806 6 ▶ next unless $res->[0] == 200;
Branch: 1 branch
BranchTrueFalseTotal
unless $res->[0] == 200 0 6 6
807 6 $res{$ent} = $res->[2];
808 }
809 1 [200, "OK (child_metas action)", \%res];
810 }
811  
812 38 ▶sub actionmeta_get { +{
Subroutine actionmeta_get: called CC=1 SCAR=0.0
Pod documented
813 36 applies_to => ['variable'],
814 summary => "Get value of variable",
815 } }
816  
817 0 ▶sub action_get {
Subroutine action_get: not called CC=5 SCAR=30.3
Pod documented
818 5 ▶ no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
Subroutine BEGIN: called CC=1 SCAR=0.0
819  
820 0 my ($self, $req) = @_;
821 0 local $req->{-uri_leaf} = $req->{-uri_leaf};
822  
823 # extract prefix
824 0 ▶ $req->{-uri_leaf} =~ s/^([%\@\$])//
Branch: 1 branch
BranchTrueFalseTotal
$req->{"-uri_leaf"} =~ s/^([%\@\$])// or return err(500, "BUG: Unknown variable prefix") 0 0 0
825 or return err(500, "BUG: Unknown variable prefix");
826 0 my $prefix = $1;
827 0 my $name = $req->{-perl_package} . "::" . $req->{-uri_leaf};
828 my $res =
829 0 ▶ $prefix eq '$' ? ${$name} :
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '@' ? : 0 0 0
830 0 ▶ $prefix eq '@' ? \@{$name} :
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '%' ? : 0 0 0
831 0 ▶ $prefix eq '%' ? \%{$name} :
Branch: 1 branch
BranchTrueFalseTotal
$prefix eq '$' ? : 0 0 0
832 undef;
833 0 [200, "OK (get action)", $res];
834 }
835  
836 0 ▶sub _pre_tx_action {
Subroutine _pre_tx_action: not called CC=13 SCAR=52.0
837 0 my ($self, $req) = @_;
838  
839 return err(501, "Transaction not supported by server")
840 0 ▶ unless $self->{use_tx};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"use_tx"} 0 0 0
841  
842 # instantiate custom tx manager, per request if necessary
843 0 ▶ if (ref($self->{custom_tx_manager}) eq 'CODE') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'custom_tx_manager'} eq 'CODE') { } 0 0 0
elsif (not builtin::blessed($self->{'_tx_manager'})) { } 0 0 0
844 0 eval {
845 0 $self->{_tx_manager} = $self->{custom_tx_manager}->($self);
846 0 ▶ die $self->{_tx_manager} unless blessed($self->{_tx_manager});
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->{"_tx_manager"}) 0 0 0
847 };
848 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
849 0 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 0 0
850 0 return err(500, "Can't initialize custom tx manager: ".
851 "$self->{_tx_manager}: $@");
852 }
853 } elsif (!blessed($self->{_tx_manager})) {
854 0 ▶ my $tm_cl = $self->{custom_tx_manager} // "Perinci::Tx::Manager";
Condition0%0/2
$self->{"custom_tx_manager"} // "Perinci::Tx::Manager"
l!l
00
MC/DC0%0/1
$self->{"custom_tx_manager"} // "Perinci::Tx::Manager"
$self->{"custom_tx_manager"}
Truth table0%0/2
A
A= $self->{"custom_tx_manager"}
Aresult
11
00
855 0 my $tm_cl_p = $tm_cl; $tm_cl_p =~ s!::!/!g; $tm_cl_p .= ".pm";
856 0 eval {
857 0 require $tm_cl_p;
858 0 $self->{_tx_manager} = $tm_cl->new(pa => $self);
859 0 ▶ die $self->{_tx_manager} unless blessed($self->{_tx_manager});
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self->{"_tx_manager"}) 0 0 0
860 };
861 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
862 0 ▶ die if $ENV{PERINCI_ACCESS_SCHEMELESS_DEBUG};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"PERINCI_ACCESS_SCHEMELESS_DEBUG"} 0 0 0
863 0 return err(500, "Can't initialize tx manager ($tm_cl): $@");
864 }
865 # we just want to force newer version, we currently can't specify this
866 # in Makefile.PL because peritm's tests use us. this might be rectified
867 # in the future.
868 0 ▶ if ($tm_cl eq 'Perinci::Tx::Manager') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tm_cl eq "Perinci::Tx::Manager") 0 0 0
869 0 ▶ $Perinci::Tx::Manager::VERSION >= 0.29
Branch: 1 branch
BranchTrueFalseTotal
$Perinci::Tx::Manager::VERSION >= "0.29" or die "Your Perinci::Tx::Manager is too old, please install v0.29 or later" 0 0 0
870 or die "Your Perinci::Tx::Manager is too old, ".
871 "please install v0.29 or later";
872 }
873 }
874  
875 0 return;
876 }
877  
878 36 ▶sub actionmeta_begin_tx { +{
Subroutine actionmeta_begin_tx: called CC=1 SCAR=0.0
Pod documented
879 36 applies_to => ['*'],
880 summary => "Start a new transaction",
881 } }
882  
883 0 ▶sub action_begin_tx {
Subroutine action_begin_tx: not called CC=2 SCAR=17.9
Pod documented
884 0 my ($self, $req) = @_;
885 0 my $res = $self->_pre_tx_action($req);
886 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
887  
888 $self->{_tx_manager}->begin(
889 tx_id => $req->{tx_id},
890 summary => $req->{summary},
891 0 );
892 }
893  
894 36 ▶sub actionmeta_commit_tx { +{
Subroutine actionmeta_commit_tx: called CC=1 SCAR=0.0
Pod documented
895 36 applies_to => ['*'],
896 summary => "Commit a transaction",
897 } }
898  
899 0 ▶sub action_commit_tx {
Subroutine action_commit_tx: not called CC=2 SCAR=17.9
Pod documented
900 0 my ($self, $req) = @_;
901 0 my $res = $self->_pre_tx_action($req);
902 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
903  
904 $self->{_tx_manager}->commit(
905 tx_id => $req->{tx_id},
906 0 );
907 }
908  
909 36 ▶sub actionmeta_savepoint_tx { +{
Subroutine actionmeta_savepoint_tx: called CC=1 SCAR=0.0
Pod documented
910 36 applies_to => ['*'],
911 summary => "Create a savepoint in a transaction",
912 } }
913  
914 0 ▶sub action_savepoint_tx {
Subroutine action_savepoint_tx: not called CC=2 SCAR=17.9
Pod documented
915 0 my ($self, $req) = @_;
916 0 my $res = $self->_pre_tx_action($req);
917 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
918  
919 $self->{_tx_manager}->savepoint(
920 tx_id => $req->{tx_id},
921 sp => $req->{tx_spid},
922 0 );
923 }
924  
925 36 ▶sub actionmeta_release_tx_savepoint { +{
Subroutine actionmeta_release_tx_savepoint: called CC=1 SCAR=0.0
Pod documented
926 36 applies_to => ['*'],
927 summary => "Release a transaction savepoint",
928 } }
929  
930 0 ▶sub action_release_tx_savepoint {
Subroutine action_release_tx_savepoint: not called CC=2 SCAR=17.9
Pod documented
931 0 my ($self, $req) =\ @_;
932 0 my $res = $self->_pre_tx_action($req);
933 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
934  
935 $self->{_tx_manager}->release_savepoint(
936 tx_id => $req->{tx_id},
937 sp => $req->{tx_spid},
938 0 );
939 }
940  
941 36 ▶sub actionmeta_rollback_tx { +{
Subroutine actionmeta_rollback_tx: called CC=1 SCAR=0.0
Pod undocumented
942 36 applies_to => ['*'],
943 summary => "Rollback a transaction (optionally to a savepoint)",
944 } }
945  
946 0 ▶sub action_rollback_tx {
Subroutine action_rollback_tx: not called CC=2 SCAR=17.9
Pod undocumented
947 0 my ($self, $req) = @_;
948 0 my $res = $self->_pre_tx_action($req);
949 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
950  
951 $self->{_tx_manager}->rollback(
952 tx_id => $req->{tx_id},
953 sp => $req->{tx_spid},
954 0 );
955 }
956  
957 36 ▶sub actionmeta_list_txs { +{
Subroutine actionmeta_list_txs: called CC=1 SCAR=0.0
Pod undocumented
958 36 applies_to => ['*'],
959 summary => "List transactions",
960 } }
961  
962 0 ▶sub action_list_txs {
Subroutine action_list_txs: not called CC=2 SCAR=17.9
Pod undocumented
963 0 my ($self, $req) = @_;
964 0 my $res = $self->_pre_tx_action($req);
965 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
966  
967 $self->{_tx_manager}->list(
968 detail => $req->{detail},
969 tx_status => $req->{tx_status},
970 tx_id => $req->{tx_id},
971 0 );
972 }
973  
974 36 ▶sub actionmeta_undo { +{
Subroutine actionmeta_undo: called CC=1 SCAR=0.0
Pod undocumented
975 36 applies_to => ['*'],
976 summary => "Undo a committed transaction",
977 } }
978  
979 0 ▶sub action_undo {
Subroutine action_undo: not called CC=2 SCAR=17.9
Pod undocumented
980 0 my ($self, $req) = @_;
981 0 my $res = $self->_pre_tx_action($req);
982 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
983  
984 $self->{_tx_manager}->undo(
985 tx_id => $req->{tx_id},
986 confirm => $req->{confirm},
987 0 );
988 }
989  
990 36 ▶sub actionmeta_redo { +{
Subroutine actionmeta_redo: called CC=1 SCAR=0.0
Pod undocumented
991 36 applies_to => ['*'],
992 summary => "Redo an undone committed transaction",
993 } }
994  
995 0 ▶sub action_redo {
Subroutine action_redo: not called CC=2 SCAR=17.9
Pod undocumented
996 0 my ($self, $req) = @_;
997 0 my $res = $self->_pre_tx_action($req);
998 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
999  
1000 $self->{_tx_manager}->redo(
1001 tx_id => $req->{tx_id},
1002 confirm => $req->{confirm},
1003 0 );
1004 }
1005  
1006 36 ▶sub actionmeta_discard_tx { +{
Subroutine actionmeta_discard_tx: called CC=1 SCAR=0.0
Pod undocumented
1007 36 applies_to => ['*'],
1008 summary => "Discard (forget) a committed transaction",
1009 } }
1010  
1011 0 ▶sub action_discard_tx {
Subroutine action_discard_tx: not called CC=2 SCAR=17.9
Pod undocumented
1012 0 my ($self, $req) = @_;
1013 0 my $res = $self->_pre_tx_action($req);
1014 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
1015  
1016 $self->{_tx_manager}->discard(
1017 tx_id => $req->{tx_id},
1018 0 );
1019 }
1020  
1021 36 ▶sub actionmeta_discard_all_txs { +{
Subroutine actionmeta_discard_all_txs: called CC=1 SCAR=0.0
Pod undocumented
1022 36 applies_to => ['*'],
1023 summary => "Discard (forget) all committed transactions",
1024 } }
1025  
1026 0 ▶sub action_discard_all_txs {
Subroutine action_discard_all_txs: not called CC=2 SCAR=17.9
Pod undocumented
1027 0 my ($self, $req) = @_;
1028 0 my $res = $self->_pre_tx_action($req);
1029 0 ▶ return $res if $res;
Branch: 1 branch
BranchTrueFalseTotal
if $res 0 0 0
1030  
1031 $self->{_tx_manager}->discard_all(
1032 # XXX select client
1033 0 );
1034 }
1035  
1036 5 1;
1037 # ABSTRACT: Base class for Perinci::Access::Perl
1038  
1039 __END__
↑ Summary Perl.pm »