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

filter: Statementstmt 54.3% 163 / 300 Branchbran 41.9% 88 / 210 Conditioncond 31.8% 81 / 254 MC/DCmcdc 18.7% 27 / 144 Subroutinesub 63.6% 14 / 22 Podpod 86.6% 13 / 15 totaltotal 40.8% 386 / 945 CC 216 SCAR 57.7
CC
216
Cov
43%
build
674.6
build
674.6
schema
67.6
CRAP 320.3
« 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 83 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
157 83 ▶use AnyEvent::MCP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
158 83 ▶use AnyEvent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
159 83 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
160 83 ▶use parent "AnyEvent::MCP::Helper";
Subroutine BEGIN: called CC=1 SCAR=0.0
161  
162 88 ▶sub dimension_names {
Subroutine dimension_names: called CC=3 SCAR=15.7
Pod undocumented
163 0 ▶ my ($request) = @_;
Subroutine dimension_names: not called CC=3 SCAR=15.7
Pod undocumented
164 0 ▶ my %remaining = map { $_ => 1 } keys %{$request->{dimensions} || {}};
Condition25%1/4
$request->{'dimensions'} || {}
l!l
880
$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
165 0 ▶ my @first = @{$request->{dimension_order} || []};
Condition25%1/4
$request->{'dimension_order'} || []
l!l
088
$request->{'dimension_order'} || []
l!l
00
MC/DC0%0/1
$request->{'dimension_order'} || []
$request->{'dimension_order'}
MC/DC0%0/1
$request->{'dimension_order'} || []
$request->{'dimension_order'}
Truth table50%1/2
A
A= $request->{'dimension_order'}
Aresult
11
00
Truth table0%0/2
A
A= $request->{'dimension_order'}
Aresult
11
00
166 0 delete @remaining{@first};
167 0 (@first, sort keys %remaining)
168 }
169  
170 80 ▶sub schema {
Subroutine schema: called CC=16 SCAR=42.1
Pod documented
171 0 ▶ my ($request, $stage, $previous) = @_;
Subroutine schema: not called CC=16 SCAR=42.1
Pod documented
172  
173 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
174 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
175  
176 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
177 0 my $chosen = $previous->{decision};
178 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
179 && $chosen =~ /\A(?:allow|deny)-always\z/;
180 0 my $allow = $chosen =~ /\Aallow/;
181 0 my $schema = {
182 type => "object",
183 required => ["decision"],
184 properties => {
185 lifetime => {
186 type => "string",
187 enum => ["indefinite", "900", "57600"],
188 default => "indefinite",
189 title => "Rule lifetime (indefinite, 900 seconds, or 57600 seconds / 16 hours)",
190 },
191 decision => {
192 type => "string",
193 enum => ["back", $chosen],
194 default => $chosen,
195 title => "Save rule or go back",
196 },
197 },
198 };
199 0 ▶ if ($allow) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allow) { } 20 3 23
if ($allow) { } 0 0 0
200 $schema->{properties}{sandbox_grants} = {
201 type => "string",
202 0 default => join (",", @{$request->{sandbox_grants}}),
203 title => "Allowed sandbox grants (comma-separated; empty for none)",
204 };
205 } else {
206 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
207 $schema->{properties}{path} = {
208 0 ▶ type => "string",
Branch: 2 branches
BranchTrueFalseTotal
if @paths 3 0 3
if @paths 0 0 0
209 title => "Deny-always file scope (empty means all paths)",
210 enum => ["", @paths],
211 default => $paths[0],
212 } if @paths;
213 }
214 0 for my $name (dimension_names $request) {
215 0 my $dim = $request->{dimensions}{$name};
216 0 ▶ next if @{$dim->{choices}} == 1;
Branch: 2 branches
BranchTrueFalseTotal
if @{$dim->{"choices"};} == 1 2 21 23
if @{$dim->{"choices"};} == 1 0 0 0
217 $schema->{properties}{"dim_$name"} = {
218 type => "string",
219 title => "$dim->{label} scope",
220 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
221 default => $dim->{default} // $dim->{choices}[0]{match},
222 0 };
223 }
224 0 return $schema
225 }
226  
227 0 my @decisions = qw(allow-once deny-once);
228 0 ▶ push @decisions, qw(allow-always deny-always) if $persistent;
Branch: 2 branches
BranchTrueFalseTotal
if $persistent 57 0 57
if $persistent 0 0 0
229 {
230 type => "object",
231 required => ["decision"],
232 properties => {
233 message => {
234 type => "string",
235 title => "Reason if denied (optional)",
236 maxLength => 2048,
237 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
238 },
239 decision => {
240 type => "string",
241 enum => \@decisions,
242 default => "deny-once",
243 title => "Decision",
244 },
245 },
246 }
247 }
248  
249 59 ▶sub message {
Subroutine message: called CC=8 SCAR=30.7
Pod documented
250 0 ▶ my ($request, $stage) = @_;
Subroutine message: not called CC=8 SCAR=30.7
Pod documented
251  
252 0 my $json = JSON::XS->new;
253 0 my %label = (
254 name => "Server",
255 multibroker_alias => "Multibroker alias",
256 tool => "Tool",
257 action => "Action",
258 action_description => "Action description",
259 sandbox_implementation => "Sandbox",
260 paths => "Paths",
261 );
262  
263 0 my $reason = $request->{reason};
264 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
265 if defined $reason;
266  
267 join "\n",
268 "Permission request",
269 0 "Requested sandbox grants: " . join (", ", @{$request->{sandbox_grants}}),
270 0 ▶ (map { "$label{$_}: " . $json->encode ($request->{$_}) }
Branch: 2 branches
BranchTrueFalseTotal
defined $reason ? : 59 0 59
defined $reason ? : 0 0 0
271 grep defined $request->{$_},
272 qw(name multibroker_alias tool action action_description sandbox_implementation paths)),
273 (defined $reason ? "Reason: $reason" : ()),
274 (map {
275 0 my $dim = $request->{dimensions}{$_};
276 "$dim->{label}: " . $json->encode ($dim->{value})
277 0 } dimension_names ($request)),
278 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
279 ($stage && $stage eq "rule" ? (
280 "Available sandbox grants:",
281 (map {
282 0 my $description = $request->{sandbox_grant_descriptions}{$_};
283 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
284 0 } @{$request->{sandbox_grant_choices}}),
285 (map {
286 0 my $dim = $request->{dimensions}{$_};
287 0 map { " " . $json->encode ($_->{label}) . ": " . $json->encode ($_->{match}) }
288 0 @{$dim->{choices}}
289 } dimension_names ($request))
290 ) : ())
291 }
292  
293 1 ▶sub detail_text {
Subroutine detail_text: called CC=4 SCAR=21.7
Pod documented
294 0 ▶ my ($label, $text) = @_;
Subroutine detail_text: not called CC=4 SCAR=21.7
Pod documented
295  
296 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
297 or die "Invalid permission detail\n";
298  
299 0 my $chars = length $text;
300 0 my $bytes = length AnyEvent::MCP::utf8enc $text;
301 0 my $truncated = $chars > 65536;
302 0 $text = substr $text, 0, 65536;
303 0 $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
304 0 $label =~ s/([\x00-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
305  
306 0 ▶ "$label: $chars characters, $bytes UTF-8 bytes\n\n"
Branch: 2 branches
BranchTrueFalseTotal
$truncated ? : 0 1 1
$truncated ? : 0 0 0
307 . ($truncated ? "WARNING: INCOMPLETE PREVIEW. Additional text is not shown here.\n\n" : "")
308 . $text
309 }
310  
311 90 ▶sub build {
Subroutine build: called CC=54 SCAR=65.1
Pod documented
312 0 ▶ my ($prepared, $answer, $stage, $previous) = @_;
Subroutine build: not called CC=54 SCAR=65.1
Pod documented
313  
314 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
315 die "Invalid permission answer\n" unless ref $answer eq "HASH"
316 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
317  
318 0 my $choice = $answer->{decision};
319 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
320 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
321 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
322 && $choice =~ /-always\z/;
323 } else {
324 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
325 unless $choice =~ /\A(?:allow|deny)-(?:once|always)\z/;
326 }
327  
328 my $message = $choice =~ /\Adeny-/ ? ($stage && $stage eq "rule"
329 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
330 0 ▶ if (defined $message) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $message) 5 84 89
if (defined $message) 0 0 0
331 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
332 || $message =~ /[\r\n]/;
333 0 ▶ undef $message unless $message =~ /\S/;
Branch: 2 branches
BranchTrueFalseTotal
unless $message =~ /\S/u 0 5 5
unless $message =~ /\S/u 0 0 0
334 }
335  
336 # a native MCP "always" choice opens a second form for rule details.
337 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
338 0 ▶ return { decision => $choice, (defined $message ? (message => $message) : ()) };
Branch: 2 branches
BranchTrueFalseTotal
defined $message ? : 3 7 10
defined $message ? : 0 0 0
339 }
340  
341 0 my $allow = $choice =~ /\Aallow-/;
342 0 ▶ my $decision = { decision => $choice, (defined $message ? (message => $message) : ()) };
Branch: 2 branches
BranchTrueFalseTotal
defined $message ? : 2 77 79
defined $message ? : 0 0 0
343 0 ▶ if ($allow) {
Branch: 2 branches
BranchTrueFalseTotal
if ($allow) 66 13 79
if ($allow) 0 0 0
344 0 my $grants = $answer->{sandbox_grants};
345 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
346 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
347 0 my %available = map { $_ => 1 } @{$prepared->{sandbox_grant_choices}};
348 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
349 0 $decision->{sandbox_grants} = [@$grants];
350 }
351  
352 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
353 my $rule = $decision->{rule} = {
354 decision => $allow ? "allow" : "deny",
355 action => $prepared->{action_matcher},
356 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
357 };
358 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
359 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
360 or die "Invalid permission rule lifetime\n";
361 0 $decision->{lifetime} = $lifetime;
362 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
363 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
364 0 my $dim = $prepared->{dimensions}{$name};
365 my $selected = $answer->{"dim_$name"}
366 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
4000
$$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
367 die "Persistent dimension scope was not offered\n"
368 unless defined $selected && !ref $selected
369 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 36 40
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
0436
defined $selected and not ref $selected
!ll&&!rl&&r
0040
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
370 0 $rule->{"match.$name"} = $selected;
371 }
372 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
373 die "Unrequested denial path\n"
374 unless !ref $answer->{path}
375 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
376 0 $rule->{path} = $answer->{path};
377 }
378 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
379 }
380 $decision
381 0 }
382  
383 66 ▶sub decision {
Subroutine decision: called CC=10 SCAR=34.4
Pod documented
384 0 ▶ my ($prepared, $response, $stage, $previous) = @_;
Subroutine decision: not called CC=10 SCAR=34.4
Pod documented
385  
386 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
387 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
388 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
389 0 my %answer = %{$response->{content}};
390 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
391 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
392 $answer{sandbox_grants} = [length $answer{sandbox_grants}
393 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
394 }
395 0 build ($prepared, \%answer, $stage, $previous)
396 }
397  
398 7 ▶sub elicitation {
Subroutine elicitation: called CC=6 SCAR=22.7
Pod documented
399 0 ▶ my ($class, $req, %kv) = @_;
Subroutine elicitation: not called CC=6 SCAR=22.7
Pod documented
400  
401 0 my $meta = $req->{params}{_meta}{"anyevent-mcp/permission"};
402 die "Not a permission elicitation\n" unless $req->{method} eq "elicitation/create"
403 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
404 0 my $stage = $meta->{stage};
405 0 my $job = $class->new (%kv);
406 0 my $old_cancel = $req->{on_cancel};
407 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
408 $job->ask ({
409 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
410 _permission_stage => $stage,
411 _permission_selection => $meta->{selection} || {},
412 7 ▶ }, sub {
Subroutine __ANON__: called CC=12 SCAR=25.3
413 7 my ($success, $decision) = @_;
414  
415 7 ▶ return if $req->{finished};
Branch: 1 branch
BranchTrueFalseTotal
if $req->{"finished"} 0 7 7
416 7 ▶ return $req->error (-32603, $decision) unless $success;
Branch: 1 branch
BranchTrueFalseTotal
unless $success 0 7 7
417 7 my $valid = eval {
418 build ($meta->{request}, {
419 %$decision,
420 (ref $decision->{rule} eq "HASH"
421 2 ▶ ? (map { $_ => $decision->{rule}{$_} } qw(path)) : ()),
Branch: 1 branch
BranchTrueFalseTotal
ref $decision->{'rule'} eq 'HASH' ? : 2 5 7
422 (ref $decision->{rule} eq "HASH"
423 2 ? (map { (my $key = $_) =~ s/^match\./dim_/; $key => $decision->{rule}{$_} }
424 2 grep /^match\./, keys %{$decision->{rule}}) : ()),
425 7 ▶ }, $stage, $meta->{selection});
Branch: 1 branch
BranchTrueFalseTotal
ref $decision->{'rule'} eq 'HASH' ? : 2 5 7
426 };
427 7 ▶ return $req->error (-32603, "Invalid permission helper decision: $@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 7 7
428 $req->reply ({
429 action => "accept",
430 content => {
431 decision => $valid->{decision},
432 (exists $valid->{lifetime} ? (lifetime => $valid->{lifetime}) : ()),
433 (defined $valid->{message} ? (message => $valid->{message}) : ()),
434 (ref $valid->{rule} eq "HASH" && defined $valid->{rule}{path}
435 ? (path => $valid->{rule}{path}) : ()),
436 5 ▶ (exists $valid->{sandbox_grants} ? (sandbox_grants => join (",", @{$valid->{sandbox_grants}})) : ()),
Branch: 1 branch
BranchTrueFalseTotal
ref $valid->{'rule'} eq 'HASH' ? : 2 5 7
437 (ref $valid->{rule} eq "HASH"
438 2 ? (map { (my $key = $_) =~ s/^match\./dim_/; $key => $valid->{rule}{$_} }
439 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
440 },
441 });
442 0 });
443 0 $job
444 }
445  
446 34 ▶sub ask {
Subroutine ask: called CC=3 SCAR=11.2
Pod documented
447 34 my ($self, $prepared, $done) = @_;
448  
449 34 my %input = %$prepared;
450 34 delete $input{rules_file};
451 local $self->{helper} = $self->{helper}
452 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
453 34 $self->SUPER::ask (\%input, $done);
454 }
455  
456 83 1
« bin/mcp-fs ↑ Summary blib/lib/AnyEvent/MCP/IMAP/Providers.pm »