blib/lib/AnyEvent/MCP/Permissions/Ask.pm

filter: Statementstmt 54.4% 158 / 290 Branchbran 41.9% 88 / 210 Conditioncond 31.7% 82 / 258 MC/DCmcdc 18.4% 27 / 146 Subroutinesub 65.0% 13 / 20 Podpod 100% 13 / 13 totaltotal 40.6% 381 / 937 CC 218 SCAR 57.8
CC
218
Cov
43%
build
674.6
build
674.6
schema
76.4
CRAP 323.2
« bin/mcp-fs ↑ Summary blib/lib/AnyEvent/MCP/IMAP/Providers.pm »
1 =head1 NAME
2  
3 AnyEvent::MCP::Permissions::Ask - pluggable external permission prompts
4  
5 =head1 DESCRIPTION
6  
7 An MCP tool may need to ask a human for permission, but its server should not
8 have to know whether the answer comes from a terminal, a graphical dialog or
9 a desktop service. This module runs a separate permission helper so the
10 prompting mechanism can be changed without changing the tool.
11  
12 The helper receives one UTF-8 JSON request on stdin, terminated by EOF,
13 and writes one JSON decision to stdout. C<helper> is an executable or an
14 argument array. C<timeout> limits elapsed time; C<max_size> limits output,
15 defaulting to 1 MiB. C<PERL_ANYEVENT_MCP_PERMISSION_HELPER> selects the
16 default executable.
17  
18 C<ask ($prepared, $done)> calls C<$done-E<gt>($success, $decision)> once.
19 C<cancel> terminates the helper and completes with failure. Helpers are reaped
20 by AnyEvent::Util even after cancellation.
21  
22 The default helper tries YAD, letting GTK select its display backend,
23 and asks on C</dev/tty> if YAD cannot start. If neither is available,
24 the request is denied rather than silently allowed. Applications can substitute a desktop-daemon client.
25 Rule management is available separately via C<anyevent-mcp manage-rules NAME>.
26  
27 C<< AnyEvent::MCP::Permissions::Ask->elicitation ($req, %config) >> handles
28 a permission-tagged Client::Request with the external helper and replies to it.
29 Use this in the client's C<on_request> callback for local permission dialogs.
30 It preserves cancellation and validates the selected C<sandbox_grants>
31 and all named dimension scopes.
32  
33 The functions C<schema>, C<message>, C<decision> and C<build> implement the
34 shared form/helper representation. The initial form offers allow/deny,
35 once/always, and an optional denial C<message>. Persistent choices are omitted
36 if any requested dimension has no available persistent scope. Approval never
37 attaches that message to a successful tool result. Only the C<always>
38 choices lead to a second form for persistent rule grants, scopes and lifetime;
39 C<back> returns to the first form. The local graphical helper can
40 complete this two-screen flow without a network round-trip; the terminal
41 helper offers a C<m> shortcut to edit the denial reason. A dimension with only
42 one possible scope is saved automatically without asking the user to select it.
43 Decisions are validated again by the permission engine before use.
44  
45 The typical place to use C<elicitation> is in an
46 L<AnyEvent::MCP::Client/on_request> callback:
47  
48 on_request => sub {
49 my ($client, $req) = @_;
50 AnyEvent::MCP::Permissions::Ask->elicitation ($req);
51 },
52  
53 Load this module before using the callback. It handles
54 permission-tagged requests; the application must route or reject
55 unrelated form requests. The server-side authorization logic lives in
56 L<AnyEvent::MCP::Server::Permissions>.
57  
58 =head1 METHODS
59  
60 =over
61  
62 =item $ask = AnyEvent::MCP::Permissions::Ask->new (%config)
63  
64 Create a helper runner with these options:
65  
66 =over
67  
68 =item helper => $executable
69  
70 =item helper => [$executable, $arg...]
71  
72 Executable or argument array, not a shell command. Defaults to
73 C<PERL_ANYEVENT_MCP_PERMISSION_HELPER> or C<anyevent-mcp-askpermission>.
74  
75 =item timeout => $seconds
76  
77 Maximum elapsed time for a prompt, defaulting to 300 seconds. Zero
78 also selects the default; it does not disable the timer.
79  
80 =item max_size => $bytes
81  
82 Maximum helper output size, defaulting to 1 MiB.
83  
84 =back
85  
86 =item $ask->ask ($prepared, $done->($success, $decision))
87  
88 Send a prepared permission request to the external helper. C<$done> receives
89 the decoded decision hash on successful completion, or an error message
90 when C<$success> is false. Process success does not mean permission was
91 granted: the permission engine validates the decision separately.
92 Only one request may be active per runner.
93  
94 =item $ask->cancel ($reason)
95  
96 Terminate an active helper, completing its callback with failure.
97 C<$reason> is optional. The child is reaped asynchronously.
98  
99 =item $job = AnyEvent::MCP::Permissions::Ask->elicitation ($req, %config)
100  
101 Handle a permission-tagged C<elicitation/create> Client::Request using the
102 local helper. C<%config> is passed to the runner constructor. Cancellation
103 of C<$req> cancels the helper. Other elicitation requests are rejected.
104  
105 =back
106  
107 =head1 FORM UTILITIES
108  
109 These functions are called with fully qualified names, not as methods.
110 C<$prepared> is the prepared request returned by the permission engine.
111 C<$stage> is C<choice> for the initial form or C<rule> for persistent rule
112 details. C<$previous> holds the selection from the preceding form.
113  
114 =over
115  
116 =item $schema = AnyEvent::MCP::Permissions::Ask::schema $prepared, $stage, $previous
117  
118 Returns the JSON Schema hash reference for the selected form stage.
119  
120 =item $text = AnyEvent::MCP::Permissions::Ask::message $prepared, $stage
121  
122 Formats the request and, for the rule stage, available grants and scopes
123 as readable text.
124  
125 =item $text = AnyEvent::MCP::Permissions::Ask::detail_text $label, $text
126  
127 Formats one display-only detail with its size and a preview of at most
128 65536 Unicode characters. Control and bidi characters are visibly escaped;
129 tabs and newlines are preserved. Longer text carries an explicit warning.
130  
131 =item $decision = AnyEvent::MCP::Permissions::Ask::build $prepared, $answer, $stage, $previous
132  
133 Validates an answer hash and constructs a decision hash. An initial
134 always choice selects the next stage; the rule stage completes it or
135 returns C<back>. Grant selections here are arrays, unlike the
136 comma-separated grant string in the native MCP form. Persistent answers may
137 select C<lifetime>: C<indefinite> (the default), C<900> or C<57600>, all
138 strings. A finite lifetime produces an absolute C<expires> Unix timestamp
139 in the rule; the selected lifetime is retained when forwarding native forms.
140 Each named dimension is selected as C<dim_NAME> from the matchers offered in
141 C<dimensions-E<gt>{NAME}{choices}>; the rule saves it as C<match.NAME>.
142  
143 =item $decision = AnyEvent::MCP::Permissions::Ask::decision $prepared, $response, $stage, $previous
144  
145 Converts the MCP elicitation response hash to a decision, including
146 decoding its grant string. A declined or cancelled form becomes deny-once.
147 Invalid answers die. The permission engine still validates and resolves
148 the decision against its current policy.
149  
150 =back
151  
152 =cut
153  
154 package AnyEvent::MCP::Permissions::Ask;
155  
156 82 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 82 ▶use AnyEvent::MCP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
158 82 ▶use AnyEvent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
159 82 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
160 82 ▶use parent "AnyEvent::MCP::Helper";
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 80 ▶sub schema {
Subroutine schema: called CC=17 SCAR=43.4
Pod documented
163 0 ▶ my ($request, $stage, $previous) = @_;
Subroutine schema: not called CC=17 SCAR=43.4
Pod documented
164  
165 0 ▶ $previous ||= {};
Condition50%2/4
$previous ||= {}
l!l
2456
$previous ||= {}
l!l
00
MC/DC100%1/1
$previous ||= {}
$previous
MC/DC0%0/1
$previous ||= {}
$previous
Truth table100%2/2
A
A= $previous
Aresult
11
00
Truth table0%0/2
A
A= $previous
Aresult
11
00
166 0 ▶ my $persistent = !grep !@{$_->{choices}}, values %{$request->{dimensions} || {}};
Condition25%1/4
$request->{'dimensions'} || {}
l!l
800
$request->{'dimensions'} || {}
l!l
00
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
Truth table50%1/2
A
A= $request->{'dimensions'}
Aresult
11
00
Truth table0%0/2
A
A= $request->{'dimensions'}
Aresult
11
00
167  
168 0 ▶ if ($stage && $stage eq "rule") {
Branch: 2 branches
BranchTrueFalseTotal
if ($stage and $stage eq "rule") 23 57 80
if ($stage and $stage eq "rule") 0 0 0
Condition50%3/6
$stage and $stage eq "rule"
!ll&&!rl&&r
45323
$stage and $stage eq "rule"
!ll&&!rl&&r
000
MC/DC100%2/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
MC/DC0%0/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
Truth table100%3/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
169 0 my $chosen = $previous->{decision};
170 0 ▶ die "Invalid persistent decision\n" unless $persistent
Branch: 2 branches
BranchTrueFalseTotal
unless $persistent and $chosen =~ /\A(?:allow|deny)-always\z/u 0 23 23
unless $persistent and $chosen =~ /\A(?:allow|deny)-always\z/u 0 0 0
Condition16%1/6
$persistent and $chosen =~ /\A(?:allow|deny)-always\z/u
!ll&&!rl&&r
0023
$persistent and $chosen =~ /\A(?:allow|deny)-always\z/u
!ll&&!rl&&r
000
MC/DC0%0/2
$persistent and $chosen =~ /\A(?:allow|deny)-always\z/u
$persistent $chosen =~ /\A(?:allow|deny)-always\z/u
MC/DC0%0/2
$persistent and $chosen =~ /\A(?:allow|deny)-always\z/u
$persistent $chosen =~ /\A(?:allow|deny)-always\z/u
Truth table33%1/3
A and B
A= $persistentB= $chosen =~ /\A(?:allow|deny)-always\z/u
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $persistentB= $chosen =~ /\A(?:allow|deny)-always\z/u
ABresult
0X0
100
111
171 && $chosen =~ /\A(?:allow|deny)-always\z/;
172 0 my $allow = $chosen =~ /\Aallow/;
173 0 my $schema = {
174 type => "object",
175 required => ["decision"],
176 properties => {
177 lifetime => {
178 type => "string",
179 enum => ["indefinite", "900", "57600"],
180 default => "indefinite",
181 title => "Rule lifetime (indefinite, 900 seconds, or 57600 seconds / 16 hours)",
182 },
183 decision => {
184 type => "string",
185 enum => ["back", $chosen],
186 default => $chosen,
187 title => "Save rule or go back",
188 },
189 },
190 };
191 0 ▶ if ($allow) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allow) { } 20 3 23
if ($allow) { } 0 0 0
192 $schema->{properties}{sandbox_grants} = {
193 type => "string",
194 0 default => join (",", @{$request->{sandbox_grants}}),
195 title => "Allowed sandbox grants (comma-separated; empty for none)",
196 };
197 } else {
198 0 ▶ my @paths = grep defined && !ref, @{$request->{paths} || []};
Condition20%2/10
defined $_ && !ref($_)
!ll&&!rl&&r
003
$request->{'paths'} || []
l!l
30
defined $_ && !ref($_)
!ll&&!rl&&r
000
$request->{'paths'} || []
l!l
00
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
MC/DC0%0/1
$request->{'paths'} || []
$request->{'paths'}
MC/DC0%0/2
defined $_ && !ref($_)
defined $_ !ref($_)
MC/DC0%0/1
$request->{'paths'} || []
$request->{'paths'}
Truth table33%1/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
Truth table50%1/2
A
A= $request->{'paths'}
Aresult
11
00
Truth table0%0/3
A && not(B)
A= defined $_B= !ref($_)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $request->{'paths'}
Aresult
11
00
199 $schema->{properties}{path} = {
200 0 ▶ type => "string",
Branch: 2 branches
BranchTrueFalseTotal
if @paths 3 0 3
if @paths 0 0 0
201 title => "Deny-always file scope (empty means all paths)",
202 enum => ["", @paths],
203 default => $paths[0],
204 } if @paths;
205 }
206 0 ▶ for my $name (sort keys %{$request->{dimensions} || {}}) {
Condition25%1/4
$request->{'dimensions'} || {}
l!l
230
$request->{'dimensions'} || {}
l!l
00
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
Truth table50%1/2
A
A= $request->{'dimensions'}
Aresult
11
00
Truth table0%0/2
A
A= $request->{'dimensions'}
Aresult
11
00
207 0 my $dim = $request->{dimensions}{$name};
208 0 ▶ next if @{$dim->{choices}} == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @{$dim->{"choices"};} == 1 2 21 23
if @{$dim->{"choices"};} == 1 0 0 0
209 $schema->{properties}{"dim_$name"} = {
210 type => "string",
211 title => "$dim->{label} scope",
212 0 ▶ enum => [map $_->{match}, @{$dim->{choices}}],
Condition33%2/6
$dim->{"default"} // $dim->{"choices"}[0]{"match"}
l!l&&r!l&&!r
9120
$dim->{"default"} // $dim->{"choices"}[0]{"match"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$dim->{"default"} // $dim->{"choices"}[0]{"match"}
$dim->{"default"} $dim->{"choices"}[0]{"match"}
MC/DC0%0/2
$dim->{"default"} // $dim->{"choices"}[0]{"match"}
$dim->{"default"} $dim->{"choices"}[0]{"match"}
Truth table66%2/3
A // B
A= $dim->{"default"}B= $dim->{"choices"}[0]{"match"}
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $dim->{"default"}B= $dim->{"choices"}[0]{"match"}
ABresult
1X1
011
000
213 default => $dim->{default} // $dim->{choices}[0]{match},
214 0 };
215 }
216 0 return $schema
217 }
218  
219 0 my @decisions = qw(allow-once deny-once);
220 0 ▶ push @decisions, qw(allow-always deny-always) if $persistent;
Branch: 2 branches
BranchTrueFalseTotal
if $persistent 57 0 57
if $persistent 0 0 0
221 {
222 type => "object",
223 required => ["decision"],
224 properties => {
225 message => {
226 type => "string",
227 title => "Reason if denied (optional)",
228 maxLength => 2048,
229 0 ▶ default => $previous->{message} // "",
Condition50%2/4
$previous->{"message"} // ""
l!l
156
$previous->{"message"} // ""
l!l
00
MC/DC100%1/1
$previous->{"message"} // ""
$previous->{"message"}
MC/DC0%0/1
$previous->{"message"} // ""
$previous->{"message"}
Truth table100%2/2
A
A= $previous->{"message"}
Aresult
11
00
Truth table0%0/2
A
A= $previous->{"message"}
Aresult
11
00
230 },
231 decision => {
232 type => "string",
233 enum => \@decisions,
234 default => "deny-once",
235 title => "Decision",
236 },
237 },
238 }
239 }
240  
241 59 ▶sub message {
Subroutine message: called CC=10 SCAR=34.8
Pod documented
242 0 ▶ my ($request, $stage) = @_;
Subroutine message: not called CC=10 SCAR=34.8
Pod documented
243  
244 0 my $json = JSON::XS->new;
245 0 my %label = (
246 name => "Server",
247 multibroker_alias => "Multibroker alias",
248 tool => "Tool",
249 action => "Action",
250 action_description => "Action description",
251 sandbox_implementation => "Sandbox",
252 paths => "Paths",
253 );
254  
255 0 my $reason = $request->{reason};
256 0 ▶ $reason =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge
Branch: 2 branches
BranchTrueFalseTotal
if defined $reason 59 0 59
if defined $reason 0 0 0
257 if defined $reason;
258  
259 join "\n",
260 "Permission request",
261 0 "Requested sandbox grants: " . join (", ", @{$request->{sandbox_grants}}),
262 0 ▶ (map { "$label{$_}: " . $json->encode ($request->{$_}) }
Branch: 2 branches
BranchTrueFalseTotal
defined $reason ? : 59 0 59
defined $reason ? : 0 0 0
263 grep defined $request->{$_},
264 qw(name multibroker_alias tool action action_description sandbox_implementation paths)),
265 (defined $reason ? "Reason: $reason" : ()),
266 (map {
267 0 my $dim = $request->{dimensions}{$_};
268 "$dim->{label}: " . $json->encode ($dim->{value})
269 0 ▶ } sort keys %{$request->{dimensions} || {}}),
Condition25%1/4
$request->{'dimensions'} || {}
l!l
590
$request->{'dimensions'} || {}
l!l
00
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
Truth table50%1/2
A
A= $request->{'dimensions'}
Aresult
11
00
Truth table0%0/2
A
A= $request->{'dimensions'}
Aresult
11
00
270 0 ▶ (map { detail_text ($_, $request->{details}{$_}) } sort keys %{$request->{details} || {}}),
Branch: 2 branches
BranchTrueFalseTotal
$stage && $stage eq 'rule' ? : 6 53 59
$stage && $stage eq 'rule' ? : 0 0 0
Condition40%4/10
$request->{'details'} || {}
l!l
158
$stage and $stage eq "rule"
!ll&&!rl&&r
5306
$request->{'details'} || {}
l!l
00
$stage and $stage eq "rule"
!ll&&!rl&&r
000
MC/DC100%1/1
$request->{'details'} || {}
$request->{'details'}
MC/DC50%1/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
MC/DC0%0/1
$request->{'details'} || {}
$request->{'details'}
MC/DC0%0/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
Truth table100%2/2
A
A= $request->{'details'}
Aresult
11
00
Truth table66%2/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
Truth table0%0/2
A
A= $request->{'details'}
Aresult
11
00
Truth table0%0/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
271 ($stage && $stage eq "rule" ? (
272 "Available sandbox grants:",
273 (map {
274 0 my $description = $request->{sandbox_grant_descriptions}{$_};
275 0 ▶ " $_" . (defined $description && length $description ? " - $description" : "")
Branch: 2 branches
BranchTrueFalseTotal
defined $description && length $description ? : 0 12 12
defined $description && length $description ? : 0 0 0
Condition16%1/6
defined $description and length $description
!ll&&!rl&&r
1200
defined $description and length $description
!ll&&!rl&&r
000
MC/DC0%0/2
defined $description and length $description
defined $description length $description
MC/DC0%0/2
defined $description and length $description
defined $description length $description
Truth table33%1/3
A and B
A= defined $descriptionB= length $description
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= defined $descriptionB= length $description
ABresult
0X0
100
111
276 0 } @{$request->{sandbox_grant_choices}}),
277 (map {
278 0 my $dim = $request->{dimensions}{$_};
279 0 map { " " . $json->encode ($_->{label}) . ": " . $json->encode ($_->{match}) }
280 0 @{$dim->{choices}}
281 0 ▶ } sort keys %{$request->{dimensions} || {}})
Condition25%1/4
$request->{'dimensions'} || {}
l!l
60
$request->{'dimensions'} || {}
l!l
00
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
MC/DC0%0/1
$request->{'dimensions'} || {}
$request->{'dimensions'}
Truth table50%1/2
A
A= $request->{'dimensions'}
Aresult
11
00
Truth table0%0/2
A
A= $request->{'dimensions'}
Aresult
11
00
282 ) : ())
283 }
284  
285 1 ▶sub detail_text {
Subroutine detail_text: called CC=4 SCAR=21.7
Pod documented
286 0 ▶ my ($label, $text) = @_;
Subroutine detail_text: not called CC=4 SCAR=21.7
Pod documented
287  
288 0 ▶ defined $text && !ref $text
Branch: 2 branches
BranchTrueFalseTotal
defined $text and not ref $text or die "Invalid permission detail\n" 1 0 1
defined $text and not ref $text or die "Invalid permission detail\n" 0 0 0
Condition16%1/6
defined $text and not ref $text
!ll&&!rl&&r
001
defined $text and not ref $text
!ll&&!rl&&r
000
MC/DC0%0/2
defined $text and not ref $text
defined $text not ref $text
MC/DC0%0/2
defined $text and not ref $text
defined $text not ref $text
Truth table33%1/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
Truth table0%0/3
A and not(B)
A= defined $textB= not ref $text
ABresult
0X0
100
111
289 or die "Invalid permission detail\n";
290  
291 0 my $chars = length $text;
292 0 my $bytes = length AnyEvent::MCP::utf8enc $text;
293 0 my $truncated = $chars > 65536;
294 0 $text = substr $text, 0, 65536;
295 0 $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
296 0 $label =~ s/([\x00-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
297  
298 0 ▶ "$label: $chars characters, $bytes UTF-8 bytes\n\n"
Branch: 2 branches
BranchTrueFalseTotal
$truncated ? : 0 1 1
$truncated ? : 0 0 0
299 . ($truncated ? "WARNING: INCOMPLETE PREVIEW. Additional text is not shown here.\n\n" : "")
300 . $text
301 }
302  
303 90 ▶sub build {
Subroutine build: called CC=54 SCAR=65.1
Pod documented
304 0 ▶ my ($prepared, $answer, $stage, $previous) = @_;
Subroutine build: not called CC=54 SCAR=65.1
Pod documented
305  
306 0 ▶ $previous ||= {};
Condition50%2/4
$previous ||= {}
l!l
5535
$previous ||= {}
l!l
00
MC/DC100%1/1
$previous ||= {}
$previous
MC/DC0%0/1
$previous ||= {}
$previous
Truth table100%2/2
A
A= $previous
Aresult
11
00
Truth table0%0/2
A
A= $previous
Aresult
11
00
307 die "Invalid permission answer\n" unless ref $answer eq "HASH"
308 0 ▶ && defined $answer->{decision} && !ref $answer->{decision};
Branch: 2 branches
BranchTrueFalseTotal
unless ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"} 0 90 90
unless ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"} 0 0 0
Condition16%2/12
ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"}
!ll&&!rl&&r
0090
ref $answer eq "HASH" and defined $answer->{"decision"}
!ll&&!rl&&r
0090
ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"}
!ll&&!rl&&r
000
ref $answer eq "HASH" and defined $answer->{"decision"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"}
ref $answer eq "HASH" defined $answer->{"decision"} not ref $answer->{"decision"}
MC/DC0%0/3
ref $answer eq "HASH" and defined $answer->{"decision"} and not ref $answer->{"decision"}
ref $answer eq "HASH" defined $answer->{"decision"} not ref $answer->{"decision"}
Truth table25%1/4
A and B and not(C)
A= ref $answer eq "HASH"B= defined $answer->{"decision"}C= not ref $answer->{"decision"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and not(C)
A= ref $answer eq "HASH"B= defined $answer->{"decision"}C= not ref $answer->{"decision"}
ABCresult
0XX0
10X0
1100
1111
309  
310 0 my $choice = $answer->{decision};
311 0 ▶ if ($stage && $stage eq "rule") {
Branch: 2 branches
BranchTrueFalseTotal
if ($stage and $stage eq 'rule') { } 20 70 90
if ($stage and $stage eq 'rule') { } 0 0 0
Condition50%3/6
$stage and $stage eq "rule"
!ll&&!rl&&r
333720
$stage and $stage eq "rule"
!ll&&!rl&&r
000
MC/DC100%2/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
MC/DC0%0/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
Truth table100%3/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
312 0 ▶ return { decision => "back" } if $choice eq "back";
Branch: 2 branches
BranchTrueFalseTotal
if $choice eq "back" 1 19 20
if $choice eq "back" 0 0 0
313 0 ▶ die "Invalid rule decision\n" unless $choice eq ($previous->{decision} // "")
Branch: 2 branches
BranchTrueFalseTotal
unless $choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u 0 19 19
unless $choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u 0 0 0
Condition20%2/10
$choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u
!ll&&!rl&&r
0019
$previous->{"decision"} // ""
l!l
190
$choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u
!ll&&!rl&&r
000
$previous->{"decision"} // ""
l!l
00
MC/DC0%0/2
$choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u
$choice eq ($previous->{"decision"} // "") $choice =~ /-always\z/u
MC/DC0%0/1
$previous->{"decision"} // ""
$previous->{"decision"}
MC/DC0%0/2
$choice eq ($previous->{"decision"} // "") and $choice =~ /-always\z/u
$choice eq ($previous->{"decision"} // "") $choice =~ /-always\z/u
MC/DC0%0/1
$previous->{"decision"} // ""
$previous->{"decision"}
Truth table33%1/3
A and B
A= $choice eq ($previous->{"decision"} // "")B= $choice =~ /-always\z/u
ABresult
0X0
100
111
Truth table50%1/2
A
A= $previous->{"decision"}
Aresult
11
00
Truth table0%0/3
A and B
A= $choice eq ($previous->{"decision"} // "")B= $choice =~ /-always\z/u
ABresult
0X0
100
111
Truth table0%0/2
A
A= $previous->{"decision"}
Aresult
11
00
314 && $choice =~ /-always\z/;
315 } else {
316 0 ▶ die "Invalid permission decision\n"
Branch: 2 branches
BranchTrueFalseTotal
unless $choice =~ /\A(?:allow|deny)-(?:once|always)\z/u 0 70 70
unless $choice =~ /\A(?:allow|deny)-(?:once|always)\z/u 0 0 0
317 unless $choice =~ /\A(?:allow|deny)-(?:once|always)\z/;
318 }
319  
320 my $message = $choice =~ /\Adeny-/ ? ($stage && $stage eq "rule"
321 0 ▶ ? $previous->{message} : $answer->{message}) : undef;
Branch: 4 branches
BranchTrueFalseTotal
$choice =~ /\Adeny-/u ? : 16 73 89
$stage && $stage eq 'rule' ? : 5 11 16
$choice =~ /\Adeny-/u ? : 0 0 0
$stage && $stage eq 'rule' ? : 0 0 0
Condition50%3/6
$stage and $stage eq "rule"
!ll&&!rl&&r
835
$stage and $stage eq "rule"
!ll&&!rl&&r
000
MC/DC100%2/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
MC/DC0%0/2
$stage and $stage eq "rule"
$stage $stage eq "rule"
Truth table100%3/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $stageB= $stage eq "rule"
ABresult
0X0
100
111
322 0 ▶ if (defined $message) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $message) 5 84 89
if (defined $message) 0 0 0
323 0 ▶ die "Invalid permission message\n" if ref $message || length $message > 2048
Branch: 2 branches
BranchTrueFalseTotal
if ref $message or length $message > 2048 or $message =~ /[\r\n]/u 0 5 5
if ref $message or length $message > 2048 or $message =~ /[\r\n]/u 0 0 0
Condition16%2/12
ref $message or length $message > 2048 or $message =~ /[\r\n]/u
l!l&&r!l&&!r
005
ref $message or length $message > 2048
l!l&&r!l&&!r
005
ref $message or length $message > 2048 or $message =~ /[\r\n]/u
l!l&&r!l&&!r
000
ref $message or length $message > 2048
l!l&&r!l&&!r
000
MC/DC0%0/3
ref $message or length $message > 2048 or $message =~ /[\r\n]/u
ref $message length $message > 2048 $message =~ /[\r\n]/u
MC/DC0%0/3
ref $message or length $message > 2048 or $message =~ /[\r\n]/u
ref $message length $message > 2048 $message =~ /[\r\n]/u
Truth table25%1/4
A or B or C
A= ref $messageB= length $message > 2048C= $message =~ /[\r\n]/u
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/4
A or B or C
A= ref $messageB= length $message > 2048C= $message =~ /[\r\n]/u
ABCresult
1XX1
01X1
0011
0000
324 || $message =~ /[\r\n]/;
325 0 ▶ undef $message unless $message =~ /\S/;
Branch: 2 branches
BranchTrueFalseTotal
unless $message =~ /\S/u 0 5 5
unless $message =~ /\S/u 0 0 0
326 }
327  
328 # a native MCP "always" choice opens a second form for rule details.
329 0 ▶ if ($stage && $stage eq "choice" && $choice =~ /-always\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($stage and $stage eq "choice" and $choice =~ /-always\z/u) 10 79 89
if ($stage and $stage eq "choice" and $choice =~ /-always\z/u) 0 0 0
Condition50%6/12
$stage and $stage eq "choice" and $choice =~ /-always\z/u
!ll&&!rl&&r
522710
$stage and $stage eq "choice"
!ll&&!rl&&r
331937
$stage and $stage eq "choice" and $choice =~ /-always\z/u
!ll&&!rl&&r
000
$stage and $stage eq "choice"
!ll&&!rl&&r
000
MC/DC100%3/3
$stage and $stage eq "choice" and $choice =~ /-always\z/u
$stage $stage eq "choice" $choice =~ /-always\z/u
MC/DC0%0/3
$stage and $stage eq "choice" and $choice =~ /-always\z/u
$stage $stage eq "choice" $choice =~ /-always\z/u
Truth table100%4/4
A and B and C
A= $stageB= $stage eq "choice"C= $choice =~ /-always\z/u
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and B and C
A= $stageB= $stage eq "choice"C= $choice =~ /-always\z/u
ABCresult
0XX0
10X0
1100
1111
330 0 ▶ return { decision => $choice, (defined $message ? (message => $message) : ()) };
Branch: 2 branches
BranchTrueFalseTotal
defined $message ? : 3 7 10
defined $message ? : 0 0 0
331 }
332  
333 0 my $allow = $choice =~ /\Aallow-/;
334 0 ▶ my $decision = { decision => $choice, (defined $message ? (message => $message) : ()) };
Branch: 2 branches
BranchTrueFalseTotal
defined $message ? : 2 77 79
defined $message ? : 0 0 0
335 0 ▶ if ($allow) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allow) 66 13 79
if ($allow) 0 0 0
336 0 my $grants = $answer->{sandbox_grants};
337 0 ▶ $grants = $prepared->{sandbox_grants} if !defined $grants && $choice eq "allow-once";
Branch: 2 branches
BranchTrueFalseTotal
if not defined $grants and $choice eq "allow-once" 6 60 66
if not defined $grants and $choice eq "allow-once" 0 0 0
Condition33%2/6
not defined $grants and $choice eq "allow-once"
!ll&&!rl&&r
6006
not defined $grants and $choice eq "allow-once"
!ll&&!rl&&r
000
MC/DC50%1/2
not defined $grants and $choice eq "allow-once"
not defined $grants $choice eq "allow-once"
MC/DC0%0/2
not defined $grants and $choice eq "allow-once"
not defined $grants $choice eq "allow-once"
Truth table66%2/3
not(A) and B
A= not defined $grantsB= $choice eq "allow-once"
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not defined $grantsB= $choice eq "allow-once"
ABresult
0X0
100
111
338 0 ▶ die "Permission answer needs sandbox grants\n" unless ref $grants eq "ARRAY";
Branch: 2 branches
BranchTrueFalseTotal
unless ref $grants eq "ARRAY" 0 66 66
unless ref $grants eq "ARRAY" 0 0 0
339 0 my %available = map { $_ => 1 } @{$prepared->{sandbox_grant_choices}};
340 0 ▶ die "Unknown selected sandbox grant\n" if grep !$available{$_}, @$grants;
Branch: 2 branches
BranchTrueFalseTotal
if grep((!$available{$_}), @$grants) 0 66 66
if grep((!$available{$_}), @$grants) 0 0 0
341 0 $decision->{sandbox_grants} = [@$grants];
342 }
343  
344 0 ▶ if ($choice =~ /-always\z/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($choice =~ /-always\z/u) 43 36 79
if ($choice =~ /-always\z/u) 0 0 0
345 my $rule = $decision->{rule} = {
346 decision => $allow ? "allow" : "deny",
347 action => $prepared->{action_matcher},
348 0 ▶ "sandbox-grants" => join (",", @{$allow ? $decision->{sandbox_grants} : $prepared->{sandbox_grants}}),
Branch: 4 branches
BranchTrueFalseTotal
$allow ? : 30 13 43
$allow ? : 30 13 43
$allow ? : 0 0 0
$allow ? : 0 0 0
349 };
350 0 ▶ my $lifetime = exists $answer->{lifetime} ? $answer->{lifetime} : "indefinite";
Branch: 2 branches
BranchTrueFalseTotal
exists $answer->{'lifetime'} ? : 15 28 43
exists $answer->{'lifetime'} ? : 0 0 0
351 0 ▶ defined $lifetime && !ref $lifetime && $lifetime =~ /\A(?:indefinite|900|57600)\z/
Branch: 2 branches
BranchTrueFalseTotal
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u or die "Invalid permission rule lifetime\n" 39 4 43
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u or die "Invalid permission rule lifetime\n" 0 0 0
Condition41%5/12
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u
!ll&&!rl&&r
1339
defined $lifetime and not ref $lifetime
!ll&&!rl&&r
0142
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u
!ll&&!rl&&r
000
defined $lifetime and not ref $lifetime
!ll&&!rl&&r
000
MC/DC66%2/3
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u
defined $lifetime not ref $lifetime $lifetime =~ /\A(?:indefinite|900|57600)\z/u
MC/DC0%0/3
defined $lifetime and not ref $lifetime and $lifetime =~ /\A(?:indefinite|900|57600)\z/u
defined $lifetime not ref $lifetime $lifetime =~ /\A(?:indefinite|900|57600)\z/u
Truth table75%3/4
A and not(B) and C
A= defined $lifetimeB= not ref $lifetimeC= $lifetime =~ /\A(?:indefinite|900|57600)\z/u
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $lifetimeB= not ref $lifetimeC= $lifetime =~ /\A(?:indefinite|900|57600)\z/u
ABCresult
0XX0
10X0
1100
1111
352 or die "Invalid permission rule lifetime\n";
353 0 $decision->{lifetime} = $lifetime;
354 0 ▶ $rule->{expires} = time + $lifetime unless $lifetime eq "indefinite";
Branch: 2 branches
BranchTrueFalseTotal
unless $lifetime eq "indefinite" 7 32 39
unless $lifetime eq "indefinite" 0 0 0
355 0 ▶ for my $name (keys %{$prepared->{dimensions} || {}}) {
Condition25%1/4
$prepared->{'dimensions'} || {}
l!l
390
$prepared->{'dimensions'} || {}
l!l
00
MC/DC0%0/1
$prepared->{'dimensions'} || {}
$prepared->{'dimensions'}
MC/DC0%0/1
$prepared->{'dimensions'} || {}
$prepared->{'dimensions'}
Truth table50%1/2
A
A= $prepared->{'dimensions'}
Aresult
11
00
Truth table0%0/2
A
A= $prepared->{'dimensions'}
Aresult
11
00
356 0 my $dim = $prepared->{dimensions}{$name};
357 my $selected = $answer->{"dim_$name"}
358 0 ▶ // (@{$dim->{choices}} == 1 ? $dim->{choices}[0]{match} : undef);
Branch: 2 branches
BranchTrueFalseTotal
@{$dim->{'choices'};} == 1 ? : 0 0 0
@{$dim->{'choices'};} == 1 ? : 0 0 0
Condition16%1/6
$$answer{"dim_$name"} // (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
l!l&&r!l&&!r
3900
$$answer{"dim_$name"} // (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
l!l&&r!l&&!r
000
MC/DC0%0/2
$$answer{"dim_$name"} // (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
$$answer{"dim_$name"} (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
MC/DC0%0/2
$$answer{"dim_$name"} // (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
$$answer{"dim_$name"} (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
Truth table33%1/3
A // B
A= $$answer{"dim_$name"}B= (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
ABresult
1X1
011
000
Truth table0%0/3
A // B
A= $$answer{"dim_$name"}B= (@{$dim->{"choices"};} == 1 ? $dim->{"choices"}[0]{"match"} : undef)
ABresult
1X1
011
000
359 die "Persistent dimension scope was not offered\n"
360 unless defined $selected && !ref $selected
361 0 ▶ && grep $_->{match} eq $selected, @{$dim->{choices}};
Branch: 2 branches
BranchTrueFalseTotal
unless defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};}) 4 35 39
unless defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};}) 0 0 0
Condition25%3/12
defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
!ll&&!rl&&r
0435
defined $selected and not ref $selected
!ll&&!rl&&r
0039
defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
!ll&&!rl&&r
000
defined $selected and not ref $selected
!ll&&!rl&&r
000
MC/DC33%1/3
defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
defined $selected not ref $selected grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
MC/DC0%0/3
defined $selected and not ref $selected and grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
defined $selected not ref $selected grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
Truth table50%2/4
A and not(B) and C
A= defined $selectedB= not ref $selectedC= grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
A and not(B) and C
A= defined $selectedB= not ref $selectedC= grep(($_->{"match"} eq $selected), @{$$dim{"choices"};})
ABCresult
0XX0
10X0
1100
1111
362 0 $rule->{"match.$name"} = $selected;
363 }
364 0 ▶ if (!$allow && defined $answer->{path} && length $answer->{path}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $allow and defined $answer->{"path"} and length $answer->{"path"}) 3 32 35
if (not $allow and defined $answer->{"path"} and length $answer->{"path"}) 0 0 0
Condition41%5/12
not $allow and defined $answer->{"path"} and length $answer->{"path"}
!ll&&!rl&&r
3203
not $allow and defined $answer->{"path"}
!ll&&!rl&&r
2663
not $allow and defined $answer->{"path"} and length $answer->{"path"}
!ll&&!rl&&r
000
not $allow and defined $answer->{"path"}
!ll&&!rl&&r
000
MC/DC66%2/3
not $allow and defined $answer->{"path"} and length $answer->{"path"}
not $allow defined $answer->{"path"} length $answer->{"path"}
MC/DC0%0/3
not $allow and defined $answer->{"path"} and length $answer->{"path"}
not $allow defined $answer->{"path"} length $answer->{"path"}
Truth table75%3/4
not(A) and B and C
A= not $allowB= defined $answer->{"path"}C= length $answer->{"path"}
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/4
not(A) and B and C
A= not $allowB= defined $answer->{"path"}C= length $answer->{"path"}
ABCresult
0XX0
10X0
1100
1111
365 die "Unrequested denial path\n"
366 unless !ref $answer->{path}
367 0 ▶ && grep !ref $_ && $_ eq $answer->{path}, @{$prepared->{paths} || []};
Branch: 2 branches
BranchTrueFalseTotal
unless not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];}) 1 2 3
unless not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];}) 0 0 0
Condition31%5/16
not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
!ll&&!rl&&r
012
!ref($_) && $_ eq $answer->{'path'}
!ll&&!rl&&r
012
$prepared->{'paths'} || []
l!l
30
not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
!ll&&!rl&&r
000
!ref($_) && $_ eq $answer->{'path'}
!ll&&!rl&&r
000
$prepared->{'paths'} || []
l!l
00
MC/DC50%1/2
not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
not ref $answer->{"path"} grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
MC/DC50%1/2
!ref($_) && $_ eq $answer->{'path'}
!ref($_) $_ eq $answer->{'path'}
MC/DC0%0/1
$prepared->{'paths'} || []
$prepared->{'paths'}
MC/DC0%0/2
not ref $answer->{"path"} and grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
not ref $answer->{"path"} grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
MC/DC0%0/2
!ref($_) && $_ eq $answer->{'path'}
!ref($_) $_ eq $answer->{'path'}
MC/DC0%0/1
$prepared->{'paths'} || []
$prepared->{'paths'}
Truth table66%2/3
not(A) and B
A= not ref $answer->{"path"}B= grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
ABresult
0X0
100
111
Truth table66%2/3
not(A) && B
A= !ref($_)B= $_ eq $answer->{'path'}
ABresult
0X0
100
111
Truth table50%1/2
A
A= $prepared->{'paths'}
Aresult
11
00
Truth table0%0/3
not(A) and B
A= not ref $answer->{"path"}B= grep((!ref($_) && $_ eq $answer->{"path"}), @{$prepared->{"paths"} or [];})
ABresult
0X0
100
111
Truth table0%0/3
not(A) && B
A= !ref($_)B= $_ eq $answer->{'path'}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $prepared->{'paths'}
Aresult
11
00
368 0 $rule->{path} = $answer->{path};
369 }
370 0 ▶ $rule->{message} = $message if !$allow && defined $message;
Branch: 2 branches
BranchTrueFalseTotal
if not $allow and defined $message 2 32 34
if not $allow and defined $message 0 0 0
Condition50%3/6
not $allow and defined $message
!ll&&!rl&&r
2662
not $allow and defined $message
!ll&&!rl&&r
000
MC/DC100%2/2
not $allow and defined $message
not $allow defined $message
MC/DC0%0/2
not $allow and defined $message
not $allow defined $message
Truth table100%3/3
not(A) and B
A= not $allowB= defined $message
ABresult
0X0
100
111
Truth table0%0/3
not(A) and B
A= not $allowB= defined $message
ABresult
0X0
100
111
371 }
372 $decision
373 0 }
374  
375 66 ▶sub decision {
Subroutine decision: called CC=10 SCAR=34.4
Pod documented
376 0 ▶ my ($prepared, $response, $stage, $previous) = @_;
Subroutine decision: not called CC=10 SCAR=34.4
Pod documented
377  
378 0 ▶ die "Invalid elicitation response\n" unless ref $response eq "HASH";
Branch: 2 branches
BranchTrueFalseTotal
unless ref $response eq "HASH" 0 66 66
unless ref $response eq "HASH" 0 0 0
379 0 ▶ return { decision => "deny-once" } if $response->{action} eq "decline" || $response->{action} eq "cancel";
Branch: 2 branches
BranchTrueFalseTotal
if $response->{"action"} eq "decline" or $response->{"action"} eq "cancel" 20 46 66
if $response->{"action"} eq "decline" or $response->{"action"} eq "cancel" 0 0 0
Condition33%2/6
$response->{"action"} eq "decline" or $response->{"action"} eq "cancel"
l!l&&r!l&&!r
20046
$response->{"action"} eq "decline" or $response->{"action"} eq "cancel"
l!l&&r!l&&!r
000
MC/DC50%1/2
$response->{"action"} eq "decline" or $response->{"action"} eq "cancel"
$response->{"action"} eq "decline" $response->{"action"} eq "cancel"
MC/DC0%0/2
$response->{"action"} eq "decline" or $response->{"action"} eq "cancel"
$response->{"action"} eq "decline" $response->{"action"} eq "cancel"
Truth table66%2/3
A or B
A= $response->{"action"} eq "decline"B= $response->{"action"} eq "cancel"
ABresult
1X1
011
000
Truth table0%0/3
A or B
A= $response->{"action"} eq "decline"B= $response->{"action"} eq "cancel"
ABresult
1X1
011
000
380 0 ▶ die "Invalid elicitation action\n" unless $response->{action} eq "accept" && ref $response->{content} eq "HASH";
Branch: 2 branches
BranchTrueFalseTotal
unless $response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH" 0 46 46
unless $response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH" 0 0 0
Condition16%1/6
$response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH"
!ll&&!rl&&r
0046
$response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH"
$response->{"action"} eq "accept" ref $response->{"content"} eq "HASH"
MC/DC0%0/2
$response->{"action"} eq "accept" and ref $response->{"content"} eq "HASH"
$response->{"action"} eq "accept" ref $response->{"content"} eq "HASH"
Truth table33%1/3
A and B
A= $response->{"action"} eq "accept"B= ref $response->{"content"} eq "HASH"
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $response->{"action"} eq "accept"B= ref $response->{"content"} eq "HASH"
ABresult
0X0
100
111
381 0 my %answer = %{$response->{content}};
382 0 ▶ if ($answer{decision} =~ /\Aallow-/ && defined $answer{sandbox_grants}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}) 27 19 46
if ($answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}) 0 0 0
Condition50%3/6
$answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}
!ll&&!rl&&r
91027
$answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}
!ll&&!rl&&r
000
MC/DC100%2/2
$answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}
$answer{"decision"} =~ /\Aallow-/u defined $answer{"sandbox_grants"}
MC/DC0%0/2
$answer{"decision"} =~ /\Aallow-/u and defined $answer{"sandbox_grants"}
$answer{"decision"} =~ /\Aallow-/u defined $answer{"sandbox_grants"}
Truth table100%3/3
A and B
A= $answer{"decision"} =~ /\Aallow-/uB= defined $answer{"sandbox_grants"}
ABresult
0X0
100
111
Truth table0%0/3
A and B
A= $answer{"decision"} =~ /\Aallow-/uB= defined $answer{"sandbox_grants"}
ABresult
0X0
100
111
383 0 ▶ die "Invalid sandbox-grants answer\n" if ref $answer{sandbox_grants};
Branch: 2 branches
BranchTrueFalseTotal
if ref $answer{"sandbox_grants"} 0 27 27
if ref $answer{"sandbox_grants"} 0 0 0
384 $answer{sandbox_grants} = [length $answer{sandbox_grants}
385 0 ▶ ? split /\s*,\s*/, $answer{sandbox_grants}, -1 : ()];
Branch: 2 branches
BranchTrueFalseTotal
length $answer{'sandbox_grants'} ? : 21 6 27
length $answer{'sandbox_grants'} ? : 0 0 0
386 }
387 0 build ($prepared, \%answer, $stage, $previous)
388 }
389  
390 7 ▶sub elicitation {
Subroutine elicitation: called CC=6 SCAR=22.7
Pod documented
391 0 ▶ my ($class, $req, %kv) = @_;
Subroutine elicitation: not called CC=6 SCAR=22.7
Pod documented
392  
393 0 my $meta = $req->{params}{_meta}{"anyevent-mcp/permission"};
394 die "Not a permission elicitation\n" unless $req->{method} eq "elicitation/create"
395 0 ▶ && ref $meta eq "HASH" && $meta->{version} == 1 && ref $meta->{request} eq "HASH";
Branch: 2 branches
BranchTrueFalseTotal
unless $req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH" 0 7 7
unless $req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH" 0 0 0
Condition16%3/18
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH"
!ll&&!rl&&r
007
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1
!ll&&!rl&&r
007
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH"
!ll&&!rl&&r
007
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH"
!ll&&!rl&&r
000
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1
!ll&&!rl&&r
000
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/4
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH"
$req->{"method"} eq "elicitation/create" ref $meta eq "HASH" $meta->{"version"} == 1 ref $meta->{"request"} eq "HASH"
MC/DC0%0/4
$req->{"method"} eq "elicitation/create" and ref $meta eq "HASH" and $meta->{"version"} == 1 and ref $meta->{"request"} eq "HASH"
$req->{"method"} eq "elicitation/create" ref $meta eq "HASH" $meta->{"version"} == 1 ref $meta->{"request"} eq "HASH"
Truth table20%1/5
A and B and C and D
A= $req->{"method"} eq "elicitation/create"B= ref $meta eq "HASH"C= $meta->{"version"} == 1D= ref $meta->{"request"} eq "HASH"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
Truth table0%0/5
A and B and C and D
A= $req->{"method"} eq "elicitation/create"B= ref $meta eq "HASH"C= $meta->{"version"} == 1D= ref $meta->{"request"} eq "HASH"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
396 0 my $stage = $meta->{stage};
397 0 my $job = $class->new (%kv);
398 0 my $old_cancel = $req->{on_cancel};
399 0 ▶ $req->{on_cancel} = sub { $job->cancel; $old_cancel->(@_) if $old_cancel };
Subroutine __ANON__: not called CC=2 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if $old_cancel 0 0 0
400 $job->ask ({
401 0 ▶ %{$meta->{request}},
Condition25%1/4
$meta->{'selection'} || {}
l!l
70
$meta->{'selection'} || {}
l!l
00
MC/DC0%0/1
$meta->{'selection'} || {}
$meta->{'selection'}
MC/DC0%0/1
$meta->{'selection'} || {}
$meta->{'selection'}
Truth table50%1/2
A
A= $meta->{'selection'}
Aresult
11
00
Truth table0%0/2
A
A= $meta->{'selection'}
Aresult
11
00
402 _permission_stage => $stage,
403 _permission_selection => $meta->{selection} || {},
404 7 ▶ }, sub {
Subroutine __ANON__: called CC=12 SCAR=25.3
405 7 my ($success, $decision) = @_;
406  
407 7 ▶ return if $req->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"finished"} 0 7 7
408 7 ▶ return $req->error (-32603, $decision) unless $success;
Branch: 1 branch
BranchTrueFalseTotal
unless $success 0 7 7
409 7 my $valid = eval {
410 build ($meta->{request}, {
411 %$decision,
412 (ref $decision->{rule} eq "HASH"
413 2 ▶ ? (map { $_ => $decision->{rule}{$_} } qw(path)) : ()),
Branch: 1 branch
BranchTrueFalseTotal
ref $decision->{'rule'} eq 'HASH' ? : 2 5 7
414 (ref $decision->{rule} eq "HASH"
415 2 ? (map { (my $key = $_) =~ s/^match\./dim_/; $key => $decision->{rule}{$_} }
416 2 grep /^match\./, keys %{$decision->{rule}}) : ()),
417 7 ▶ }, $stage, $meta->{selection});
Branch: 1 branch
BranchTrueFalseTotal
ref $decision->{'rule'} eq 'HASH' ? : 2 5 7
418 };
419 7 ▶ return $req->error (-32603, "Invalid permission helper decision: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
420 $req->reply ({
421 action => "accept",
422 content => {
423 decision => $valid->{decision},
424 (exists $valid->{lifetime} ? (lifetime => $valid->{lifetime}) : ()),
425 (defined $valid->{message} ? (message => $valid->{message}) : ()),
426 (ref $valid->{rule} eq "HASH" && defined $valid->{rule}{path}
427 ? (path => $valid->{rule}{path}) : ()),
428 5 ▶ (exists $valid->{sandbox_grants} ? (sandbox_grants => join (",", @{$valid->{sandbox_grants}})) : ()),
Branch: 1 branch
BranchTrueFalseTotal
ref $valid->{'rule'} eq 'HASH' ? : 2 5 7
429 (ref $valid->{rule} eq "HASH"
430 2 ? (map { (my $key = $_) =~ s/^match\./dim_/; $key => $valid->{rule}{$_} }
431 7 ▶ grep /^match\./, keys %{$valid->{rule}}) : ()),
Branch: 4 branches
BranchTrueFalseTotal
exists $valid->{'lifetime'} ? : 2 5 7
defined $valid->{'message'} ? : 0 7 7
ref $valid->{'rule'} eq 'HASH' && defined $valid->{'rule'}{'path'} ? : 0 7 7
exists $valid->{'sandbox_grants'} ? : 5 2 7
Condition66%2/3
ref $valid->{"rule"} eq "HASH" and defined $valid->{"rule"}{"path"}
!ll&&!rl&&r
520
MC/DC0%0/2
ref $valid->{"rule"} eq "HASH" and defined $valid->{"rule"}{"path"}
ref $valid->{"rule"} eq "HASH" defined $valid->{"rule"}{"path"}
Truth table66%2/3
A and B
A= ref $valid->{"rule"} eq "HASH"B= defined $valid->{"rule"}{"path"}
ABresult
0X0
100
111
432 },
433 });
434 0 });
435 0 $job
436 }
437  
438 34 ▶sub ask {
Subroutine ask: called CC=3 SCAR=11.2
Pod documented
439 34 my ($self, $prepared, $done) = @_;
440  
441 34 my %input = %$prepared;
442 34 delete $input{rules_file};
443 local $self->{helper} = $self->{helper}
444 34 ▶ || $ENV{PERL_ANYEVENT_MCP_PERMISSION_HELPER} || "anyevent-mcp-askpermission";
Condition60%3/5
$self->{'helper'} || $ENV{'PERL_ANYEVENT_MCP_PERMISSION_HELPER'} || 'anyevent-mcp-askpermission'
l!l
340
$self->{"helper"} or $ENV{"PERL_ANYEVENT_MCP_PERMISSION_HELPER"}
l!l&&r!l&&!r
3130
MC/DC0%0/2
$self->{'helper'} || $ENV{'PERL_ANYEVENT_MCP_PERMISSION_HELPER'} || 'anyevent-mcp-askpermission'
$self->{"helper"} $ENV{"PERL_ANYEVENT_MCP_PERMISSION_HELPER"}
Truth table66%2/3
A or B
A= $self->{"helper"}B= $ENV{"PERL_ANYEVENT_MCP_PERMISSION_HELPER"}
ABresult
1X1
011
000
445 34 $self->SUPER::ask (\%input, $done);
446 }
447  
448 82 1
« bin/mcp-fs ↑ Summary blib/lib/AnyEvent/MCP/IMAP/Providers.pm »