bin/anyevent-mcp-form-elicitation

filter: Statementstmt 75.6% 183 / 242 Branchbran 60.9% 106 / 174 Conditioncond 48.6% 88 / 181 MC/DCmcdc 15.3% 15 / 98 Subroutinesub 89.4% 17 / 19 Podpod n/a totaltotal 57.2% 409 / 714 CC 162 SCAR 50.3
CC
162
Cov
63%
terminal
567.7
fields
189.4
value
35.3
CRAP 152.4
« blib/lib/AnyEvent/MCP/Server/Simple.pm ↑ Summary blib/lib/AnyEvent/MCP/Server/Permissions.pm »
1 #!/opt/bin/perl
2  
3 =head1 NAME
4  
5 anyevent-mcp-form-elicitation - display an MCP elicitation form using YAD or a terminal
6  
7 =head1 SYNOPSIS
8  
9 anyevent-mcp-form-elicitation <request.json >response.json
10  
11 =head1 DESCRIPTION
12  
13 Reads one UTF-8 JSON object containing MCP form elicitation parameters:
14 C<mode> (optional, C<form>), C<message> and C<requestedSchema>. It displays
15 the form using YAD, or uses C</dev/tty> if YAD cannot start. It writes one
16 ordinary MCP response to stdout:
17  
18 {"action":"accept","content":{"answer":"Some text"}}
19 {"action":"decline"}
20 {"action":"cancel"}
21  
22 Exit status zero means a valid response, including decline or cancel.
23 Nonzero means invalid input or a helper failure; diagnostics go to stderr.
24 Closing a working dialog cancels the question and does not open another
25 prompt. Without YAD or a terminal the helper fails rather than inventing
26 an answer.
27  
28 Forms contain at most 32 fields. Supported field types are strings,
29 single-select string enums (C<enum> or titled C<oneOf> values), booleans,
30 numbers and integers. Titles, descriptions, defaults, required fields,
31 string length limits and numeric bounds are supported. Unsupported schema
32 features, including string formats, nested objects, multi-select arrays and
33 URL elicitation, produce an error.
34  
35 Text fields accept multiline answers. Optional unselected choices,
36 booleans and blank numbers are omitted; empty text is returned as an empty
37 string. In a terminal, enter C<<< << >>> to start multiline text, ending
38 with a line containing only C<.>. C<:cancel> and C<:decline> leave the form;
39 C<:omit> omits an optional field. Prefix a literal colon command with another
40 colon. A final confirmation lets you submit or edit the entered answers.
41  
42 The helper does not speak an MCP transport or maintain continuation tokens.
43 It can be used directly from shell scripts or replaced by another executable
44 with the same stdin/stdout contract. MCP callers use
45 C<PERL_ANYEVENT_MCP_ELICITATION_HELPER> to select an alternative.
46  
47 =head1 OPTIONS
48  
49 =over
50  
51 =item --tty
52  
53 Display form on C</dev/tty>, never try YAD. Fails when terminal unavailable.
54 Cannot combine with C<--yad>.
55  
56 =item --yad
57  
58 Display form with YAD only; fails when unavailable. No terminal fallback.
59 Cannot combine with C<--tty>.
60  
61 =item --help
62  
63 Print short usage synopsis and exit.
64  
65 =back
66  
67 =cut
68  
69 31 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71 31 ▶use Getopt::Long ();
Subroutine BEGIN: called CC=1 SCAR=0.0
72 31 ▶use JSON::XS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
73 31 ▶use Scalar::Util qw(looks_like_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
74 31 ▶use Text::ParseWords ();
Subroutine BEGIN: called CC=1 SCAR=0.0
75  
76 31 ▶use AnyEvent::MCP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78 Getopt::Long::GetOptions
79 "tty" => \my $tty_only,
80 "yad" => \my $yad_only,
81 "help" => \my $help,
82 or exit 2;
83  
84 !@ARGV or die "Unexpected arguments\n";
85 !($tty_only && $yad_only) or die "--tty and --yad are mutually exclusive\n";
86  
87 if ($help) {
88 print "usage: $0 [--tty | --yad] <request.json >response.json\n";
89 exit;
90 }
91  
92 binmode STDIN;
93 binmode STDOUT;
94 my $json = JSON::XS->new->canonical;
95 my $input = "";
96 while (read STDIN, my $chunk, 8192) {
97 $input .= $chunk;
98 length $input <= 1 << 20 or die "Form request exceeds 1 MiB\n";
99 }
100  
101 my $params = JSON::XS::decode_json $input;
102  
103 40 ▶sub value {
Subroutine value: called CC=23 SCAR=35.6
104 40 my ($field, $value) = @_;
105  
106 40 my $name = $field->{name};
107 40 ▶ if ($field->{type} eq "boolean") {
Branch: 2 branches
BranchTrueFalseTotal
if ($field->{'type'} eq 'boolean') { } 8 32 40
elsif ($field->{'type'} eq 'string') { } 23 9 32
108 8 ▶ JSON::XS::is_bool ($value) or die "$name: expected a boolean\n";
Branch: 1 branch
BranchTrueFalseTotal
&JSON::XS::is_bool($value) or die "${name}: expected a boolean\n" 8 0 8
109 } elsif ($field->{type} eq "string") {
110 23 ▶ defined $value && !ref $value or die "$name: expected text\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $value and not ref $value or die "${name}: expected text\n" 23 0 23
Condition33%1/3
defined $value and not ref $value
!ll&&!rl&&r
0023
MC/DC0%0/2
defined $value and not ref $value
defined $value not ref $value
Truth table33%1/3
A and not(B)
A= defined $valueB= not ref $value
ABresult
0X0
100
111
111 23 ▶ length $value >= ($field->{minLength} || 0) or die "$name: text is too short\n";
Branch: 1 branch
BranchTrueFalseTotal
length $value >= ($field->{"minLength"} || 0) or die "${name}: text is too short\n" 21 2 23
Condition100%2/2
$field->{'minLength'} || 0
l!l
617
MC/DC100%1/1
$field->{'minLength'} || 0
$field->{'minLength'}
Truth table100%2/2
A
A= $field->{'minLength'}
Aresult
11
00
112 21 ▶ !defined $field->{maxLength} || length $value <= $field->{maxLength} or die "$name: text is too long\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $field->{"maxLength"} or length $value <= $field->{"maxLength"} or die "${name}: text is too long\n" 19 2 21
Condition100%3/3
not defined $field->{"maxLength"} or length $value <= $field->{"maxLength"}
l!l&&r!l&&!r
9102
MC/DC100%2/2
not defined $field->{"maxLength"} or length $value <= $field->{"maxLength"}
not defined $field->{"maxLength"} length $value <= $field->{"maxLength"}
Truth table100%3/3
not(A) or B
A= not defined $field->{"maxLength"}B= length $value <= $field->{"maxLength"}
ABresult
1X1
011
000
113 19 ▶ !exists $field->{choices} || grep $_->{value} eq $value, @{$field->{choices}}
Branch: 1 branch
BranchTrueFalseTotal
not exists $field->{"choices"} or grep(($_->{"value"} eq $value), @{$$field{"choices"};}) or die "${name}: unknown choice\n" 19 0 19
Condition66%2/3
not exists $field->{"choices"} or grep(($_->{"value"} eq $value), @{$$field{"choices"};})
l!l&&r!l&&!r
1180
MC/DC0%0/2
not exists $field->{"choices"} or grep(($_->{"value"} eq $value), @{$$field{"choices"};})
not exists $field->{"choices"} grep(($_->{"value"} eq $value), @{$$field{"choices"};})
Truth table66%2/3
not(A) or B
A= not exists $field->{"choices"}B= grep(($_->{"value"} eq $value), @{$$field{"choices"};})
ABresult
1X1
011
000
114 or die "$name: unknown choice\n";
115 } else {
116 9 ▶ defined $value && !ref $value && looks_like_number $value
Branch: 1 branch
BranchTrueFalseTotal
defined $value and not ref $value and &looks_like_number($value) and not $value =~ /nan|inf/iu or die "${name}: expected a number\n" 9 0 9
Condition33%3/9
defined $value and not ref $value and &looks_like_number($value) and not $value =~ /nan|inf/iu
!ll&&!rl&&r
009
defined $value and not ref $value and &looks_like_number($value)
!ll&&!rl&&r
009
defined $value and not ref $value
!ll&&!rl&&r
009
MC/DC0%0/4
defined $value and not ref $value and &looks_like_number($value) and not $value =~ /nan|inf/iu
defined $value not ref $value &looks_like_number($value) not $value =~ /nan|inf/iu
Truth table20%1/5
A and not(B) and C and not(D)
A= defined $valueB= not ref $valueC= &looks_like_number($value)D= not $value =~ /nan|inf/iu
ABCDresult
0XXX0
10XX0
110X0
11100
11111
117 && $value !~ /nan|inf/i or die "$name: expected a number\n";
118 9 $value = 0 + $value;
119 9 ▶ "$value" !~ /nan|inf/i or die "$name: expected a finite number\n";
Branch: 1 branch
BranchTrueFalseTotal
"$value" =~ /nan|inf/iu and die "${name}: expected a finite number\n" 0 9 9
120 9 ▶ $field->{type} ne "integer" || $value == int $value or die "$name: expected an integer\n";
Branch: 1 branch
BranchTrueFalseTotal
$field->{"type"} ne "integer" or $value == int $value or die "${name}: expected an integer\n" 9 0 9
Condition66%2/3
$field->{"type"} ne "integer" or $value == int $value
l!l&&r!l&&!r
810
MC/DC0%0/2
$field->{"type"} ne "integer" or $value == int $value
$field->{"type"} ne "integer" $value == int $value
Truth table66%2/3
A or B
A= $field->{"type"} ne "integer"B= $value == int $value
ABresult
1X1
011
000
121 9 ▶ !defined $field->{minimum} || $value >= $field->{minimum} or die "$name: below minimum\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $field->{"minimum"} or $value >= $field->{"minimum"} or die "${name}: below minimum\n" 9 0 9
Condition66%2/3
not defined $field->{"minimum"} or $value >= $field->{"minimum"}
l!l&&r!l&&!r
180
MC/DC0%0/2
not defined $field->{"minimum"} or $value >= $field->{"minimum"}
not defined $field->{"minimum"} $value >= $field->{"minimum"}
Truth table66%2/3
not(A) or B
A= not defined $field->{"minimum"}B= $value >= $field->{"minimum"}
ABresult
1X1
011
000
122 9 ▶ !defined $field->{maximum} || $value <= $field->{maximum} or die "$name: above maximum\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $field->{"maximum"} or $value <= $field->{"maximum"} or die "${name}: above maximum\n" 9 0 9
Condition66%2/3
not defined $field->{"maximum"} or $value <= $field->{"maximum"}
l!l&&r!l&&!r
180
MC/DC0%0/2
not defined $field->{"maximum"} or $value <= $field->{"maximum"}
not defined $field->{"maximum"} $value <= $field->{"maximum"}
Truth table66%2/3
not(A) or B
A= not defined $field->{"maximum"}B= $value <= $field->{"maximum"}
ABresult
1X1
011
000
123  
124 9 return 0 + $value;
125 }
126 27 $value
127 }
128  
129 39 ▶sub fields {
Subroutine fields: called CC=64 SCAR=52.4
130 39 my ($params) = @_;
131  
132 39 ▶ ref $params eq "HASH" && (!defined $params->{mode} || $params->{mode} eq "form")
Branch: 1 branch
BranchTrueFalseTotal
ref $params eq "HASH" and !defined($params->{"mode"}) || $params->{"mode"} eq "form" or die "Only form elicitation is supported\n" 38 1 39
Condition83%5/6
ref $params eq "HASH" and !defined($params->{"mode"}) || $params->{"mode"} eq "form"
!ll&&!rl&&r
0138
not defined $params->{"mode"} or $params->{"mode"} eq "form"
l!l&&r!l&&!r
3261
MC/DC66%2/3
ref $params eq "HASH" and !defined($params->{"mode"}) || $params->{"mode"} eq "form"
ref $params eq "HASH" not defined $params->{"mode"} $params->{"mode"} eq "form"
Truth table75%3/4
A and not(B) or C
A= ref $params eq "HASH"B= not defined $params->{"mode"}C= $params->{"mode"} eq "form"
ABCresult
0XX0
1000
11X1
1011
133 or die "Only form elicitation is supported\n";
134 defined $params->{message} && !ref $params->{message}
135 38 ▶ or die "Elicitation needs a message\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{"message"} and not ref $params->{"message"} or die "Elicitation needs a message\n" 38 0 38
Condition33%1/3
defined $params->{"message"} and not ref $params->{"message"}
!ll&&!rl&&r
0038
MC/DC0%0/2
defined $params->{"message"} and not ref $params->{"message"}
defined $params->{"message"} not ref $params->{"message"}
Truth table33%1/3
A and not(B)
A= defined $params->{"message"}B= not ref $params->{"message"}
ABresult
0X0
100
111
136 38 my $schema = $params->{requestedSchema};
137 38 ▶ ref $schema eq "HASH" && $schema->{type} eq "object" && ref $schema->{properties} eq "HASH"
Branch: 1 branch
BranchTrueFalseTotal
ref $schema eq "HASH" and $schema->{"type"} eq "object" and ref $schema->{"properties"} eq "HASH" or die "Elicitation needs a flat object schema\n" 38 0 38
Condition33%2/6
ref $schema eq "HASH" and $schema->{"type"} eq "object" and ref $schema->{"properties"} eq "HASH"
!ll&&!rl&&r
0038
ref $schema eq "HASH" and $schema->{"type"} eq "object"
!ll&&!rl&&r
0038
MC/DC0%0/3
ref $schema eq "HASH" and $schema->{"type"} eq "object" and ref $schema->{"properties"} eq "HASH"
ref $schema eq "HASH" $schema->{"type"} eq "object" ref $schema->{"properties"} eq "HASH"
Truth table25%1/4
A and B and C
A= ref $schema eq "HASH"B= $schema->{"type"} eq "object"C= ref $schema->{"properties"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
138 or die "Elicitation needs a flat object schema\n";
139 38 ▶ !grep !/\A(?:type|properties|required|\$schema)\z/, keys %$schema
Branch: 1 branch
BranchTrueFalseTotal
grep((!/\A(?:type|properties|required|\$schema)\z/u), keys %$schema) and die "Unsupported form schema keyword\n" 0 38 38
140 or die "Unsupported form schema keyword\n";
141 38 ▶ keys %{$schema->{properties}} <= 32 or die "Too many form fields\n";
Branch: 1 branch
BranchTrueFalseTotal
keys %{$$schema{"properties"};} <= 32 or die "Too many form fields\n" 38 0 38
142 38 ▶ !exists $schema->{required} || ref $schema->{required} eq "ARRAY"
Branch: 1 branch
BranchTrueFalseTotal
not exists $schema->{"required"} or ref $schema->{"required"} eq "ARRAY" or die "Invalid required fields\n" 38 0 38
Condition66%2/3
not exists $schema->{"required"} or ref $schema->{"required"} eq "ARRAY"
l!l&&r!l&&!r
6320
MC/DC0%0/2
not exists $schema->{"required"} or ref $schema->{"required"} eq "ARRAY"
not exists $schema->{"required"} ref $schema->{"required"} eq "ARRAY"
Truth table66%2/3
not(A) or B
A= not exists $schema->{"required"}B= ref $schema->{"required"} eq "ARRAY"
ABresult
1X1
011
000
143 or die "Invalid required fields\n";
144 38 my %required;
145 38 ▶ for (@{$schema->{required} || []}) {
Condition100%2/2
$schema->{'required'} || []
l!l
326
MC/DC100%1/1
$schema->{'required'} || []
$schema->{'required'}
Truth table100%2/2
A
A= $schema->{'required'}
Aresult
11
00
146 50 ▶ defined && !ref && exists $schema->{properties}{$_} or die "Unknown required field\n";
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not ref $_ and exists $schema->{"properties"}{$_} or die "Unknown required field\n" 49 1 50
Condition50%3/6
defined $_ and not ref $_ and exists $schema->{"properties"}{$_}
!ll&&!rl&&r
0149
defined $_ and not ref $_
!ll&&!rl&&r
0050
MC/DC33%1/3
defined $_ and not ref $_ and exists $schema->{"properties"}{$_}
defined $_ not ref $_ exists $schema->{"properties"}{$_}
Truth table50%2/4
A and not(B) and C
A= defined $_B= not ref $_C= exists $schema->{"properties"}{$_}
ABCresult
0XX0
10X0
1100
1111
147 49 $required{$_} = 1;
148 }
149  
150 37 my @fields;
151 37 for my $name (sort keys %{$schema->{properties}}) {
152 70 my $field = $schema->{properties}{$name};
153 70 ▶ ref $field eq "HASH" && $field->{type} =~ /\A(?:string|number|integer|boolean)\z/
Branch: 1 branch
BranchTrueFalseTotal
ref $field eq "HASH" and $field->{"type"} =~ /\A(?:string|number|integer|boolean)\z/u or die "Unsupported field type for $name\n" 69 1 70
Condition66%2/3
ref $field eq "HASH" and $field->{"type"} =~ /\A(?:string|number|integer|boolean)\z/u
!ll&&!rl&&r
0169
MC/DC50%1/2
ref $field eq "HASH" and $field->{"type"} =~ /\A(?:string|number|integer|boolean)\z/u
ref $field eq "HASH" $field->{"type"} =~ /\A(?:string|number|integer|boolean)\z/u
Truth table66%2/3
A and B
A= ref $field eq "HASH"B= $field->{"type"} =~ /\A(?:string|number|integer|boolean)\z/u
ABresult
0X0
100
111
154 or die "Unsupported field type for $name\n";
155 69 my %allowed = map { $_ => 1 } qw(type title description default);
156 69 ▶ $allowed{$_} = 1 for $field->{type} eq "string" ? qw(minLength maxLength enum oneOf) :
Branch: 2 branches
BranchTrueFalseTotal
$field->{'type'} eq 'string' ? : 45 24 69
$field->{'type'} eq 'boolean' ? : 9 15 24
157 $field->{type} eq "boolean" ? () : qw(minimum maximum);
158 69 ▶ !grep !$allowed{$_}, keys %$field or die "Unsupported schema keyword for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
grep((!$allowed{$_}), keys %$field) and die "Unsupported schema keyword for $name\n" 1 68 69
159 68 for (qw(title description)) {
160 136 ▶ !exists $field->{$_} || defined $field->{$_} && !ref $field->{$_}
Branch: 1 branch
BranchTrueFalseTotal
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} or die "Invalid $_ for $name\n" 136 0 136
Condition50%3/6
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_}
l!l&&r!l&&!r
13060
defined $field->{$_} and not ref $field->{$_}
!ll&&!rl&&r
006
MC/DC0%0/3
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_}
not exists $field->{$_} defined $field->{$_} not ref $field->{$_}
Truth table50%2/4
not(A) or B and not(C)
A= not exists $field->{$_}B= defined $field->{$_}C= not ref $field->{$_}
ABCresult
1XX1
0111
00X0
0100
161 or die "Invalid $_ for $name\n";
162 }
163 68 my $copy = { %$field, name => $name, required => $required{$name} };
164 68 ▶ if (exists $field->{enum} || exists $field->{oneOf}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $field->{"enum"} or exists $field->{"oneOf"}) 10 58 68
Condition100%3/3
exists $field->{"enum"} or exists $field->{"oneOf"}
l!l&&r!l&&!r
4658
MC/DC100%2/2
exists $field->{"enum"} or exists $field->{"oneOf"}
exists $field->{"enum"} exists $field->{"oneOf"}
Truth table100%3/3
A or B
A= exists $field->{"enum"}B= exists $field->{"oneOf"}
ABresult
1X1
011
000
165 10 ▶ !(exists $field->{enum} && exists $field->{oneOf}) or die "Conflicting enums for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
(exists $field->{"enum"} and exists $field->{"oneOf"}) and die "Conflicting enums for $name\n" 0 10 10
Condition66%2/3
exists $field->{"enum"} and exists $field->{"oneOf"}
!ll&&!rl&&r
640
MC/DC0%0/2
exists $field->{"enum"} and exists $field->{"oneOf"}
exists $field->{"enum"} exists $field->{"oneOf"}
Truth table66%2/3
A and B
A= exists $field->{"enum"}B= exists $field->{"oneOf"}
ABresult
0X0
100
111
166 10 ▶ my $items = $field->{enum} || $field->{oneOf};
Condition66%2/3
$field->{'enum'} || $field->{'oneOf'}
l!l&&r!l&&!r
460
MC/DC0%0/2
$field->{'enum'} || $field->{'oneOf'}
$field->{'enum'} $field->{'oneOf'}
Truth table66%2/3
A || B
A= $field->{'enum'}B= $field->{'oneOf'}
ABresult
1X1
011
000
167 10 ▶ ref $items eq "ARRAY" && @$items && @$items <= 256 or die "Invalid enum for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $items eq "ARRAY" and @$items and @$items <= 256 or die "Invalid enum for $name\n" 10 0 10
Condition33%2/6
ref $items eq "ARRAY" and @$items and @$items <= 256
!ll&&!rl&&r
0010
ref $items eq "ARRAY" and @$items
!ll&&!rl&&r
0010
MC/DC0%0/3
ref $items eq "ARRAY" and @$items and @$items <= 256
ref $items eq "ARRAY" @$items @$items <= 256
Truth table25%1/4
A and B and C
A= ref $items eq "ARRAY"B= @$itemsC= @$items <= 256
ABCresult
0XX0
10X0
1100
1111
168 10 my %seen;
169 $copy->{choices} = [map {
170 10 my ($v, $label);
171 20 ▶ if (exists $field->{oneOf}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $field->{'oneOf'}) { } 12 8 20
172 12 ▶ ref $_ eq "HASH" && !grep !/\A(?:const|title)\z/, keys %$_
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "HASH" and not grep((!/\A(?:const|title)\z/u), keys %$_) or die "Invalid titled enum for $name\n" 12 0 12
Condition33%1/3
ref $_ eq "HASH" and not grep((!/\A(?:const|title)\z/u), keys %$_)
!ll&&!rl&&r
0012
MC/DC0%0/2
ref $_ eq "HASH" and not grep((!/\A(?:const|title)\z/u), keys %$_)
ref $_ eq "HASH" not grep((!/\A(?:const|title)\z/u), keys %$_)
Truth table33%1/3
A and not(B)
A= ref $_ eq "HASH"B= not grep((!/\A(?:const|title)\z/u), keys %$_)
ABresult
0X0
100
111
173 or die "Invalid titled enum for $name\n";
174 12 ▶ ($v, $label) = ($_->{const}, $_->{title} // $_->{const});
Condition33%1/3
$_->{"title"} // $_->{"const"}
l!l&&r!l&&!r
1200
MC/DC0%0/2
$_->{"title"} // $_->{"const"}
$_->{"title"} $_->{"const"}
Truth table33%1/3
A // B
A= $_->{"title"}B= $_->{"const"}
ABresult
1X1
011
000
175 } else {
176 8 ($v, $label) = ($_, $_);
177 }
178 20 ▶ defined $v && !ref $v && defined $label && !ref $label && !$seen{$v}++
Branch: 1 branch
BranchTrueFalseTotal
defined $v and not ref $v and defined $label and not ref $label and not $seen{$v}++ or die "Invalid enum value for $name\n" 19 1 20
Condition41%5/12
defined $v and not ref $v and defined $label and not ref $label and not $seen{$v}++
!ll&&!rl&&r
0119
defined $v and not ref $v and defined $label and not ref $label
!ll&&!rl&&r
0020
defined $v and not ref $v and defined $label
!ll&&!rl&&r
0020
defined $v and not ref $v
!ll&&!rl&&r
0020
MC/DC20%1/5
defined $v and not ref $v and defined $label and not ref $label and not $seen{$v}++
defined $v not ref $v defined $label not ref $label not $seen{$v}++
Truth table33%2/6
A and not(B) and C and not(D) and not(E)
A= defined $vB= not ref $vC= defined $labelD= not ref $labelE= not $seen{$v}++
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
179 or die "Invalid enum value for $name\n";
180 19 +{ value => $v, label => $label }
181 } @$items];
182 }
183 67 for (qw(minLength maxLength)) {
184 !exists $field->{$_} || defined $field->{$_} && !ref $field->{$_}
185 134 ▶ && $field->{$_} =~ /\A[0-9]+\z/ or die "Invalid $_ for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and $field->{$_} =~ /\A[0-9]+\z/u or die "Invalid $_ for $name\n" 134 0 134
Condition44%4/9
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and $field->{$_} =~ /\A[0-9]+\z/u
l!l&&r!l&&!r
78560
defined $field->{$_} and not ref $field->{$_} and $field->{$_} =~ /\A[0-9]+\z/u
!ll&&!rl&&r
0056
defined $field->{$_} and not ref $field->{$_}
!ll&&!rl&&r
0056
MC/DC0%0/4
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and $field->{$_} =~ /\A[0-9]+\z/u
not exists $field->{$_} defined $field->{$_} not ref $field->{$_} $field->{$_} =~ /\A[0-9]+\z/u
Truth table40%2/5
not(A) or B and not(C) and D
A= not exists $field->{$_}B= defined $field->{$_}C= not ref $field->{$_}D= $field->{$_} =~ /\A[0-9]+\z/u
ABCDresult
1XXX1
01111
00XX0
010X0
01100
186 }
187 67 for (qw(minimum maximum)) {
188 !exists $field->{$_} || defined $field->{$_} && !ref $field->{$_}
189 134 ▶ && looks_like_number $field->{$_} && $field->{$_} !~ /nan|inf/i
Branch: 1 branch
BranchTrueFalseTotal
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and &looks_like_number($field->{$_}) and not $field->{$_} =~ /nan|inf/iu or die "Invalid $_ for $name\n" 134 0 134
Condition41%5/12
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and &looks_like_number($field->{$_}) and not $field->{$_} =~ /nan|inf/iu
l!l&&r!l&&!r
122120
defined $field->{$_} and not ref $field->{$_} and &looks_like_number($field->{$_}) and not $field->{$_} =~ /nan|inf/iu
!ll&&!rl&&r
0012
defined $field->{$_} and not ref $field->{$_} and &looks_like_number($field->{$_})
!ll&&!rl&&r
0012
defined $field->{$_} and not ref $field->{$_}
!ll&&!rl&&r
0012
MC/DC0%0/5
not exists $field->{$_} or defined $field->{$_} and not ref $field->{$_} and &looks_like_number($field->{$_}) and not $field->{$_} =~ /nan|inf/iu
not exists $field->{$_} defined $field->{$_} not ref $field->{$_} &looks_like_number($field->{$_}) not $field->{$_} =~ /nan|inf/iu
Truth table33%2/6
not(A) or B and not(C) and D and not(E)
A= not exists $field->{$_}B= defined $field->{$_}C= not ref $field->{$_}D= &looks_like_number($field->{$_})E= not $field->{$_} =~ /nan|inf/iu
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
190 or die "Invalid $_ for $name\n";
191 }
192 !defined $field->{minLength} || !defined $field->{maxLength}
193 67 ▶ || $field->{minLength} <= $field->{maxLength} or die "Invalid length bounds for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $field->{"minLength"} && defined $field->{"maxLength"} or $field->{"minLength"} <= $field->{"maxLength"} or die "Invalid length bounds for $name\n" 67 0 67
Condition66%4/6
not defined $field->{"minLength"} && defined $field->{"maxLength"} or $field->{"minLength"} <= $field->{"maxLength"}
l!l&&r!l&&!r
42250
defined $field->{'minLength'} && defined $field->{'maxLength'}
!ll&&!rl&&r
42025
MC/DC0%0/3
not defined $field->{"minLength"} && defined $field->{"maxLength"} or $field->{"minLength"} <= $field->{"maxLength"}
defined $field->{'minLength'} defined $field->{'maxLength'} $field->{"minLength"} <= $field->{"maxLength"}
Truth table50%2/4
not(A && B) or C
A= defined $field->{'minLength'}B= defined $field->{'maxLength'}C= $field->{"minLength"} <= $field->{"maxLength"}
ABCresult
0XX1
10X1
1111
1100
194 !defined $field->{minimum} || !defined $field->{maximum}
195 67 ▶ || $field->{minimum} <= $field->{maximum} or die "Invalid numeric bounds for $name\n";
Branch: 1 branch
BranchTrueFalseTotal
not defined $field->{"minimum"} && defined $field->{"maximum"} or $field->{"minimum"} <= $field->{"maximum"} or die "Invalid numeric bounds for $name\n" 67 0 67
Condition66%4/6
not defined $field->{"minimum"} && defined $field->{"maximum"} or $field->{"minimum"} <= $field->{"maximum"}
l!l&&r!l&&!r
6160
defined $field->{'minimum'} && defined $field->{'maximum'}
!ll&&!rl&&r
6106
MC/DC0%0/3
not defined $field->{"minimum"} && defined $field->{"maximum"} or $field->{"minimum"} <= $field->{"maximum"}
defined $field->{'minimum'} defined $field->{'maximum'} $field->{"minimum"} <= $field->{"maximum"}
Truth table50%2/4
not(A && B) or C
A= defined $field->{'minimum'}B= defined $field->{'maximum'}C= $field->{"minimum"} <= $field->{"maximum"}
ABCresult
0XX1
10X1
1111
1100
196 67 ▶ value ($copy, $field->{default}) if exists $field->{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field->{"default"} 24 43 67
197 67 push @fields, $copy;
198 }
199 \@fields
200 34 }
201  
202 9 ▶sub response {
Subroutine response: called CC=12 SCAR=28.1
203 9 my ($params, $response) = @_;
204  
205 9 my $fields = fields $params;
206 9 ▶ ref $response eq "HASH" or die "Invalid elicitation response\n";
Branch: 1 branch
BranchTrueFalseTotal
ref $response eq "HASH" or die "Invalid elicitation response\n" 9 0 9
207 9 my $action = $response->{action};
208 9 ▶ return { action => $action } if defined $action && ($action eq "decline" || $action eq "cancel");
Branch: 1 branch
BranchTrueFalseTotal
if defined $action and $action eq "decline" || $action eq "cancel" 0 9 9
Condition33%2/6
defined $action and $action eq "decline" || $action eq "cancel"
!ll&&!rl&&r
090
$action eq "decline" or $action eq "cancel"
l!l&&r!l&&!r
009
MC/DC0%0/3
defined $action and $action eq "decline" || $action eq "cancel"
defined $action $action eq "decline" $action eq "cancel"
Truth table25%1/4
A and B or C
A= defined $actionB= $action eq "decline"C= $action eq "cancel"
ABCresult
0XX0
1000
11X1
1011
209 9 ▶ defined $action && $action eq "accept" && ref $response->{content} eq "HASH"
Branch: 1 branch
BranchTrueFalseTotal
defined $action and $action eq "accept" and ref $response->{"content"} eq "HASH" or die "Invalid elicitation response action\n" 9 0 9
Condition33%2/6
defined $action and $action eq "accept" and ref $response->{"content"} eq "HASH"
!ll&&!rl&&r
009
defined $action and $action eq "accept"
!ll&&!rl&&r
009
MC/DC0%0/3
defined $action and $action eq "accept" and ref $response->{"content"} eq "HASH"
defined $action $action eq "accept" ref $response->{"content"} eq "HASH"
Truth table25%1/4
A and B and C
A= defined $actionB= $action eq "accept"C= ref $response->{"content"} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
210 or die "Invalid elicitation response action\n";
211 9 my %known = map { $_->{name} => 1 } @$fields;
212 9 ▶ !grep !$known{$_}, keys %{$response->{content}} or die "Unknown response field\n";
Branch: 1 branch
BranchTrueFalseTotal
grep((!$known{$_}), keys %{$$response{"content"};}) and die "Unknown response field\n" 0 9 9
213 9 my %content;
214 9 for my $field (@$fields) {
215 20 my $name = $field->{name};
216 20 ▶ if (exists $response->{content}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{'content'}{$name}) { } 16 4 20
217 16 $content{$name} = value ($field, $response->{content}{$name});
218 } else {
219 4 ▶ !$field->{required} or die "$name: required field is missing\n";
Branch: 1 branch
BranchTrueFalseTotal
$field->{"required"} and die "${name}: required field is missing\n" 0 4 4
220 }
221 }
222 5 { action => "accept", content => \%content }
223 }
224  
225 # escape terminal controls without interpreting markup or form field syntax.
226 102 ▶sub visible {
Subroutine visible: called CC=1 SCAR=0.2
227 102 my $text = shift;
228  
229 0 $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
230 102 $text
231 }
232  
233 74 ▶sub label {
Subroutine label: called CC=1 SCAR=0.0
234 74 my $text = visible shift;
235  
236 74 $text =~ s/([:!\t\n])/sprintf "\\u{%X}", ord $1/ge;
237 74 $text
238 }
239  
240 128 ▶sub yad_text {
Subroutine yad_text: called CC=1 SCAR=0.0
241 128 my $text = shift;
242  
243 128 $text =~ s/\\/\\\\/g;
244 128 $text
245 }
246  
247 my $yad_pid;
248 0 ▶$SIG{TERM} = $SIG{INT} = sub {
Subroutine __ANON__: not called CC=2 SCAR=7.0
249 9 ▶ if ($yad_pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yad_pid) 9 0 9
250 9 kill TERM => $yad_pid;
251 9 waitpid $yad_pid, 0;
252 }
253 9 exit 1;
254 };
255  
256 28 ▶sub yad {
Subroutine yad: called CC=7 SCAR=19.8
257 28 my $pid = open my $fh, "-|";
258 28 ▶ return unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 28 28
259 28 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 13 15 28
260 13 ▶ open STDERR, ">", "/dev/null" or exit 127;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", "/dev/null" or exit 127 13 0 13
261 13 exec "yad", "--no-markup", map AnyEvent::MCP::utf8enc $_, @_;
262 0 exit 127;
263 }
264 15 $yad_pid = $pid;
265 15 local $/;
266 15 my $output = <$fh>;
267 15 close $fh;
268 15 my $status = $?;
269 15 undef $yad_pid;
270 15 ▶ return if $status == 1 << 8 || $status == 127 << 8 || $status & 127;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 256 or $status == 32512 or $status & 127 2 13 15
Condition66%4/6
$status == 256 or $status == 32512 or $status & 127
l!l&&r!l&&!r
2013
$status == 256 or $status == 32512
l!l&&r!l&&!r
2013
MC/DC33%1/3
$status == 256 or $status == 32512 or $status & 127
$status == 256 $status == 32512 $status & 127
Truth table50%2/4
A or B or C
A= $status == 256B= $status == 32512C= $status & 127
ABCresult
1XX1
01X1
0011
0000
271 13 ($status >> 8, AnyEvent::MCP::utf8dec $output)
272 }
273  
274 my $fields = fields $params;
275 for my $field (@$fields) {
276 $field->{choices} = [
277 { label => "No", value => JSON::XS::false },
278 { label => "Yes", value => JSON::XS::true },
279 ] if $field->{type} eq "boolean";
280 }
281  
282 46 ▶sub initial {
Subroutine initial: called CC=6 SCAR=17.9
283 46 my ($field) = @_;
284  
285 46 ▶ return $field->{choices} ? 1 : "" unless exists $field->{default};
Branch: 2 branches
BranchTrueFalseTotal
unless exists $field->{"default"} 30 16 46
$field->{'choices'} ? : 4 26 30
286 16 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"choices"}) 8 8 16
287 8 my $default = $json->encode ($field->{default});
288 8 for (0 .. $#{$field->{choices}}) {
289 12 ▶ return $_ + 2 if $json->encode ($field->{choices}[$_]{value}) eq $default;
Branch: 1 branch
BranchTrueFalseTotal
if $json->encode($field->{"choices"}[$_]{"value"}) eq $default 8 4 12
290 }
291 }
292 $field->{default}
293 8 }
294  
295 9 ▶sub contents {
Subroutine contents: called CC=10 SCAR=23.7
296 9 my ($raw) = @_;
297  
298 9 my %content;
299 9 for my $i (0 .. $#$fields) {
300 20 my $field = $fields->[$i];
301 20 my $value = $raw->[$i];
302 20 ▶ if ($field->{choices}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field->{'choices'}) { } 6 14 20
elsif ($field->{'type'} ne 'string') { } 5 9 14
303 6 ▶ defined $value && $value =~ /\A[0-9]+\z/ && $value <= @{$field->{choices}} + 1
Branch: 1 branch
BranchTrueFalseTotal
defined $value and $value =~ /\A[0-9]+\z/u and $value <= @{$field->{"choices"};} + 1 or die qq[$field->{"name"}: invalid selection\n] 6 0 6
Condition33%2/6
defined $value and $value =~ /\A[0-9]+\z/u and $value <= @{$field->{"choices"};} + 1
!ll&&!rl&&r
006
defined $value and $value =~ /\A[0-9]+\z/u
!ll&&!rl&&r
006
MC/DC0%0/3
defined $value and $value =~ /\A[0-9]+\z/u and $value <= @{$field->{"choices"};} + 1
defined $value $value =~ /\A[0-9]+\z/u $value <= @{$field->{"choices"};} + 1
Truth table25%1/4
A and B and C
A= defined $valueB= $value =~ /\A[0-9]+\z/uC= $value <= @{$field->{"choices"};} + 1
ABCresult
0XX0
10X0
1100
1111
304 or die "$field->{name}: invalid selection\n";
305 6 ▶ next if $value < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 2 2 4 6
306 4 $value = $field->{choices}[$value - 2]{value};
307 } elsif ($field->{type} ne "string") {
308 5 ▶ next if !defined $value || $value eq "";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $value or $value eq "" 2 3 5
Condition66%2/3
not defined $value or $value eq ""
l!l&&r!l&&!r
023
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value $value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
ABresult
1X1
011
000
309 }
310 16 $content{$field->{name}} = $value;
311 }
312 9 response ($params, { action => "accept", content => \%content })
313 }
314  
315 24 ▶sub graphical {
Subroutine graphical: called CC=21 SCAR=30.9
316 24 my @raw = map initial ($_), @$fields;
317 24 my $error = "";
318 24 while (1) {
319 28 my (@options, @values);
320 28 for my $i (0 .. $#$fields) {
321 50 my $field = $fields->[$i];
322 50 ▶ my $title = label ($field->{title} // $field->{name});
Condition66%2/3
$field->{"title"} // $field->{"name"}
l!l&&r!l&&!r
4460
MC/DC0%0/2
$field->{"title"} // $field->{"name"}
$field->{"title"} $field->{"name"}
Truth table66%2/3
A // B
A= $field->{"title"}B= $field->{"name"}
ABresult
1X1
011
000
323 50 ▶ $title .= " *" if $field->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"required"} 38 12 50
324 50 my $value = $raw[$i];
325 50 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'choices'}) { } 12 38 50
326 12 my @items = ("(no selection)", map label ($_->{label}), @{$field->{choices}});
327 12 ▶ my $selected = length $value ? $value - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 12 0 12
328 12 $items[$selected] = "^$items[$selected]";
329 12 $value = join "\x1f", @items;
330 12 push @options, "--field=" . yad_text ($title) . ":CB";
331 } else {
332 38 ▶ $value !~ /\0/ && $value ne "\@disabled\@"
Branch: 1 branch
BranchTrueFalseTotal
not $value =~ /\0/u and $value ne "\@disabled\@" or die qq[$field->{"name"}: default cannot be represented by YAD\n] 38 0 38
Condition33%1/3
not $value =~ /\0/u and $value ne "\@disabled\@"
!ll&&!rl&&r
0038
MC/DC0%0/2
not $value =~ /\0/u and $value ne "\@disabled\@"
not $value =~ /\0/u $value ne "\@disabled\@"
Truth table33%1/3
not(A) and B
A= not $value =~ /\0/uB= $value ne "\@disabled\@"
ABresult
0X0
100
111
333 or die "$field->{name}: default cannot be represented by YAD\n";
334 38 ▶ push @options, "--field=" . yad_text ($title) . ($field->{type} eq "string" ? ":TXT" : "");
Branch: 1 branch
BranchTrueFalseTotal
$field->{'type'} eq 'string' ? : 28 10 38
335 }
336 50 push @values, yad_text $value;
337 }
338 my $message = join "\n\n", (length $error ? $error : ()), visible ($params->{message}),
339 0 ▶ map { label ($_->{title} // $_->{name}) . ": " . visible ($_->{description}) }
Condition0%0/3
$_->{"title"} // $_->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$_->{"title"} // $_->{"name"}
$_->{"title"} $_->{"name"}
Truth table0%0/3
A // B
A= $_->{"title"}B= $_->{"name"}
ABresult
1X1
011
000
340 28 ▶ grep length $_->{description}, @$fields;
Branch: 1 branch
BranchTrueFalseTotal
length $error ? : 4 24 28
341 28 my ($status, $output) = yad (
342 "--form", "--title=MCP form", "--width=650", "--height=450", "--scroll",
343 "--text=" . yad_text ($message), "--quoted-output", "--separator= ",
344 "--item-separator=\x1f", "--num-output", "--always-print-result",
345 "--button=Submit:2", "--button=Decline:4", "--button=Cancel:6",
346 @options, "--", @values,
347 );
348 15 ▶ return unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 2 13 15
349 13 ▶ return { action => "decline" } if $status == 4;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 4 2 11 13
350 11 ▶ return { action => "cancel" } unless $status == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 2 2 9 11
351 9 @raw = Text::ParseWords::shellwords $output;
352 9 ▶ @raw == @$fields or die "Invalid YAD form output\n";
Branch: 1 branch
BranchTrueFalseTotal
@raw == @$fields or die "Invalid YAD form output\n" 9 0 9
353  
354 # YAD TXT output escapes backslashes, tabs and newlines inside the shell quoting.
355 9 for my $i (0 .. $#$fields) {
356 20 ▶ next unless $fields->[$i]{type} eq "string" && !$fields->[$i]{choices};
Branch: 1 branch
BranchTrueFalseTotal
unless $fields->[$i]{"type"} eq "string" and not $fields->[$i]{"choices"} 11 9 20
Condition100%3/3
$fields->[$i]{"type"} eq "string" and not $fields->[$i]{"choices"}
!ll&&!rl&&r
839
MC/DC100%2/2
$fields->[$i]{"type"} eq "string" and not $fields->[$i]{"choices"}
$fields->[$i]{"type"} eq "string" not $fields->[$i]{"choices"}
Truth table100%3/3
A and not(B)
A= $fields->[$i]{"type"} eq "string"B= not $fields->[$i]{"choices"}
ABresult
0X0
100
111
357 9 ▶ $raw[$i] =~ s/\\([\\nt])/$1 eq "n" ? "\n" : $1 eq "t" ? "\t" : "\\"/ge;
Branch: 2 branches
BranchTrueFalseTotal
$1 eq 'n' ? : 4 16 20
$1 eq 't' ? : 4 12 16
358 }
359  
360 9 my $response = eval { contents \@raw };
361 9 ▶ return $response unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 5 4 9
362 4 $error = $@;
363 }
364 }
365  
366 2 ▶sub terminal {
Subroutine terminal: called CC=24 SCAR=63.4
367 2 ▶ open my $tty, "+<", "/dev/tty" or die "Neither YAD nor a terminal is available\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $tty, "+<", "/dev/tty" or die "Neither YAD nor a terminal is available\n" 0 2 2
368 0 binmode $tty, ":encoding(UTF-8)";
369 0 my $old = select $tty; $| = 1; select $old;
370 0 my @raw = map initial ($_), @$fields;
371 0 print {$tty} visible ($params->{message}), "\n";
372 0 print {$tty} "Enter keeps the displayed default; :omit skips an optional field.\n",
373 ":decline refuses, :cancel cancels, << starts multiline text (end with .).\n";
374  
375 0 ▶ my $read = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
376 0 my $line = <$tty>;
377 0 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
378 0 $line =~ s/\r?\n\z//;
379 0 $line
380 0 };
381 0 while (1) {
382 0 for my $i (0 .. $#$fields) {
383 0 my $field = $fields->[$i];
384 0 ▶ print {$tty} "\n", visible ($field->{title} // $field->{name}),
Branch: 1 branch
BranchTrueFalseTotal
$field->{'required'} ? : 0 0 0
Condition0%0/3
$field->{"title"} // $field->{"name"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$field->{"title"} // $field->{"name"}
$field->{"title"} $field->{"name"}
Truth table0%0/3
A // B
A= $field->{"title"}B= $field->{"name"}
ABresult
1X1
011
000
385 0 ($field->{required} ? " (required)" : ""), "\n";
386 0 ▶ print {$tty} visible ($field->{description}), "\n" if length $field->{description};
Branch: 1 branch
BranchTrueFalseTotal
if length $field->{"description"} 0 0 0
387 0 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"choices"}) 0 0 0
388 0 print {$tty} " 1: (no selection)\n";
389 0 print {$tty} " ", $_ + 2, ": ", visible ($field->{choices}[$_]{label}), "\n"
390 0 for 0 .. $#{$field->{choices}};
391 }
392 0 print {$tty} "[", visible ($raw[$i]), "] > ";
393 0 my $line = $read->();
394 0 ▶ return { action => "cancel" } if !defined $line || $line eq ":cancel";
Branch: 1 branch
BranchTrueFalseTotal
if not defined $line or $line eq ":cancel" 0 0 0
Condition0%0/3
not defined $line or $line eq ":cancel"
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $line or $line eq ":cancel"
not defined $line $line eq ":cancel"
Truth table0%0/3
not(A) or B
A= not defined $lineB= $line eq ":cancel"
ABresult
1X1
011
000
395 0 ▶ return { action => "decline" } if $line eq ":decline";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq ":decline" 0 0 0
396 0 ▶ if ($line eq ":omit") {
Branch: 3 branches
BranchTrueFalseTotal
if ($line eq ':omit') { } 0 0 0
elsif ($line eq '<<' and $field->{'type'} eq 'string' and not $field->{'choices'}) { } 0 0 0
elsif (length $line) { } 0 0 0
397 0 ▶ $raw[$i] = $field->{choices} ? "1" : "";
Branch: 1 branch
BranchTrueFalseTotal
$field->{'choices'} ? : 0 0 0
398 ▶ } elsif ($line eq "<<" && $field->{type} eq "string" && !$field->{choices}) {
Condition0%0/6
$line eq "<<" and $field->{"type"} eq "string" and not $field->{"choices"}
!ll&&!rl&&r
000
$line eq "<<" and $field->{"type"} eq "string"
!ll&&!rl&&r
000
MC/DC0%0/3
$line eq "<<" and $field->{"type"} eq "string" and not $field->{"choices"}
$line eq "<<" $field->{"type"} eq "string" not $field->{"choices"}
Truth table0%0/4
A and B and not(C)
A= $line eq "<<"B= $field->{"type"} eq "string"C= not $field->{"choices"}
ABCresult
0XX0
10X0
1100
1111
399 0 my @lines;
400 0 while (1) {
401 0 my $line = $read->();
402 0 ▶ return { action => "cancel" } unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
403 0 ▶ last if $line eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "." 0 0 0
404 0 push @lines, $line;
405 }
406 0 $raw[$i] = join "\n", @lines;
407 } elsif (length $line) {
408 0 $line =~ s/\A::/:/;
409 0 $raw[$i] = $line;
410 }
411 }
412 0 my $response = eval { contents \@raw };
413 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
414 0 print {$tty} "\n", visible ($@);
415 0 next;
416 }
417 0 print {$tty} "\n", $json->pretty->encode ($response->{content}), "\n",
418 "Submit [Enter], edit [e], decline [d], cancel [c]: ";
419 0 my $line = $read->();
420 0 ▶ return { action => "cancel" } unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
421 0 ▶ return $response if $line eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 0 0 0
422 0 ▶ return { action => "decline" } if $line eq "d";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "d" 0 0 0
423 0 ▶ return { action => "cancel" } if $line eq "c";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "c" 0 0 0
424 }
425 }
426  
427 my $response = $tty_only ? terminal : graphical;
428 $response = terminal unless $response || $yad_only;
429 defined $response or die "YAD is unavailable\n";
430 print JSON::XS::encode_json ($response), "\n";
« blib/lib/AnyEvent/MCP/Server/Simple.pm ↑ Summary blib/lib/AnyEvent/MCP/Server/Permissions.pm »