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
« bin/anyevent-mcp-askpermission ↑ Summary blib/lib/AnyEvent/MCP/Server/Simple.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 ("tty" => \my $tty_only, "yad" => \my $yad_only, "help" => \my $help) or exit 2;
79 die "Unexpected arguments\n" if @ARGV;
80 die "--tty and --yad are mutually exclusive\n" if $tty_only && $yad_only;
81 if ($help) {
82 print "usage: $0 [--tty | --yad] <request.json >response.json\n";
83 exit;
84 }
85  
86 binmode STDIN;
87 binmode STDOUT;
88 my $json = JSON::XS->new->canonical;
89 my $input = "";
90 while (read STDIN, my $chunk, 8192) {
91 $input .= $chunk;
92 length $input <= 1 << 20 or die "Form request exceeds 1 MiB\n";
93 }
94 my $params = JSON::XS::decode_json $input;
95  
96 40 ▶sub value {
Subroutine value: called CC=23 SCAR=35.6
97 40 my ($field, $value) = @_;
98  
99 40 my $name = $field->{name};
100 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
101 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
102 } elsif ($field->{type} eq "string") {
103 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
104 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
105 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
106 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
107 or die "$name: unknown choice\n";
108 } else {
109 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
110 && $value !~ /nan|inf/i or die "$name: expected a number\n";
111 9 $value = 0 + $value;
112 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
113 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
114 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
115 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
116  
117 9 return 0 + $value;
118 }
119 27 $value
120 }
121  
122 39 ▶sub fields {
Subroutine fields: called CC=64 SCAR=52.4
123 39 my ($params) = @_;
124  
125 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
126 or die "Only form elicitation is supported\n";
127 defined $params->{message} && !ref $params->{message}
128 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
129 38 my $schema = $params->{requestedSchema};
130 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
131 or die "Elicitation needs a flat object schema\n";
132 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
133 or die "Unsupported form schema keyword\n";
134 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
135 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
136 or die "Invalid required fields\n";
137 38 my %required;
138 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
139 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
140 49 $required{$_} = 1;
141 }
142  
143 37 my @fields;
144 37 for my $name (sort keys %{$schema->{properties}}) {
145 70 my $field = $schema->{properties}{$name};
146 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
147 or die "Unsupported field type for $name\n";
148 69 my %allowed = map { $_ => 1 } qw(type title description default);
149 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
150 $field->{type} eq "boolean" ? () : qw(minimum maximum);
151 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
152 68 for (qw(title description)) {
153 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
154 or die "Invalid $_ for $name\n";
155 }
156 68 my $copy = { %$field, name => $name, required => $required{$name} };
157 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
158 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
159 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
160 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
161 10 my %seen;
162 $copy->{choices} = [map {
163 10 my ($v, $label);
164 20 ▶ if (exists $field->{oneOf}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $field->{'oneOf'}) { } 12 8 20
165 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
166 or die "Invalid titled enum for $name\n";
167 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
168 } else {
169 8 ($v, $label) = ($_, $_);
170 }
171 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
172 or die "Invalid enum value for $name\n";
173 19 +{ value => $v, label => $label }
174 } @$items];
175 }
176 67 for (qw(minLength maxLength)) {
177 !exists $field->{$_} || defined $field->{$_} && !ref $field->{$_}
178 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
179 }
180 67 for (qw(minimum maximum)) {
181 !exists $field->{$_} || defined $field->{$_} && !ref $field->{$_}
182 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
183 or die "Invalid $_ for $name\n";
184 }
185 !defined $field->{minLength} || !defined $field->{maxLength}
186 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
187 !defined $field->{minimum} || !defined $field->{maximum}
188 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
189 67 ▶ value ($copy, $field->{default}) if exists $field->{default};
Branch: 1 branch
BranchTrueFalseTotal
if exists $field->{"default"} 24 43 67
190 67 push @fields, $copy;
191 }
192 \@fields
193 34 }
194  
195 9 ▶sub response {
Subroutine response: called CC=12 SCAR=28.1
196 9 my ($params, $response) = @_;
197  
198 9 my $fields = fields $params;
199 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
200 9 my $action = $response->{action};
201 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
202 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
203 or die "Invalid elicitation response action\n";
204 9 my %known = map { $_->{name} => 1 } @$fields;
205 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
206 9 my %content;
207 9 for my $field (@$fields) {
208 20 my $name = $field->{name};
209 20 ▶ if (exists $response->{content}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $response->{'content'}{$name}) { } 16 4 20
210 16 $content{$name} = value ($field, $response->{content}{$name});
211 } else {
212 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
213 }
214 }
215 5 { action => "accept", content => \%content }
216 }
217  
218 # escape terminal controls without interpreting markup or form field syntax.
219 102 ▶sub visible {
Subroutine visible: called CC=1 SCAR=0.2
220 102 my $text = shift;
221  
222 0 $text =~ s/([\x00-\x08\x0b-\x1f\x7f-\x9f\x{202a}-\x{202e}\x{2066}-\x{2069}])/sprintf "\\u{%X}", ord $1/ge;
223 102 $text
224 }
225  
226 74 ▶sub label {
Subroutine label: called CC=1 SCAR=0.0
227 74 my $text = visible shift;
228  
229 74 $text =~ s/([:!\t\n])/sprintf "\\u{%X}", ord $1/ge;
230 74 $text
231 }
232  
233 128 ▶sub yad_text {
Subroutine yad_text: called CC=1 SCAR=0.0
234 128 my $text = shift;
235  
236 128 $text =~ s/\\/\\\\/g;
237 128 $text
238 }
239  
240 my $yad_pid;
241 0 ▶$SIG{TERM} = $SIG{INT} = sub {
Subroutine __ANON__: not called CC=2 SCAR=7.0
242 9 ▶ if ($yad_pid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($yad_pid) 9 0 9
243 9 kill TERM => $yad_pid;
244 9 waitpid $yad_pid, 0;
245 }
246 9 exit 1;
247 };
248  
249 28 ▶sub yad {
Subroutine yad: called CC=7 SCAR=19.8
250 28 my $pid = open my $fh, "-|";
251 28 ▶ return unless defined $pid;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pid 0 28 28
252 28 ▶ if (!$pid) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pid) 13 15 28
253 13 ▶ open STDERR, ">", "/dev/null" or exit 127;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">", "/dev/null" or exit 127 13 0 13
254 13 exec "yad", "--no-markup", map AnyEvent::MCP::utf8enc $_, @_;
255 0 exit 127;
256 }
257 15 $yad_pid = $pid;
258 15 local $/;
259 15 my $output = <$fh>;
260 15 close $fh;
261 15 my $status = $?;
262 15 undef $yad_pid;
263 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
264 13 ($status >> 8, AnyEvent::MCP::utf8dec $output)
265 }
266  
267 my $fields = fields $params;
268 for my $field (@$fields) {
269 $field->{choices} = [
270 { label => "No", value => JSON::XS::false },
271 { label => "Yes", value => JSON::XS::true },
272 ] if $field->{type} eq "boolean";
273 }
274  
275 46 ▶sub initial {
Subroutine initial: called CC=6 SCAR=17.9
276 46 my ($field) = @_;
277  
278 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
279 16 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"choices"}) 8 8 16
280 8 my $default = $json->encode ($field->{default});
281 8 for (0 .. $#{$field->{choices}}) {
282 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
283 }
284 }
285 $field->{default}
286 8 }
287  
288 9 ▶sub contents {
Subroutine contents: called CC=10 SCAR=23.7
289 9 my ($raw) = @_;
290  
291 9 my %content;
292 9 for my $i (0 .. $#$fields) {
293 20 my $field = $fields->[$i];
294 20 my $value = $raw->[$i];
295 20 ▶ if ($field->{choices}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($field->{'choices'}) { } 6 14 20
elsif ($field->{'type'} ne 'string') { } 5 9 14
296 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
297 or die "$field->{name}: invalid selection\n";
298 6 ▶ next if $value < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $value < 2 2 4 6
299 4 $value = $field->{choices}[$value - 2]{value};
300 } elsif ($field->{type} ne "string") {
301 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
302 }
303 16 $content{$field->{name}} = $value;
304 }
305 9 response ($params, { action => "accept", content => \%content })
306 }
307  
308 24 ▶sub graphical {
Subroutine graphical: called CC=21 SCAR=30.9
309 24 my @raw = map initial ($_), @$fields;
310 24 my $error = "";
311 24 while (1) {
312 28 my (@options, @values);
313 28 for my $i (0 .. $#$fields) {
314 50 my $field = $fields->[$i];
315 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
316 50 ▶ $title .= " *" if $field->{required};
Branch: 1 branch
BranchTrueFalseTotal
if $field->{"required"} 38 12 50
317 50 my $value = $raw[$i];
318 50 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{'choices'}) { } 12 38 50
319 12 my @items = ("(no selection)", map label ($_->{label}), @{$field->{choices}});
320 12 ▶ my $selected = length $value ? $value - 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
length $value ? : 12 0 12
321 12 $items[$selected] = "^$items[$selected]";
322 12 $value = join "\x1f", @items;
323 12 push @options, "--field=" . yad_text ($title) . ":CB";
324 } else {
325 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
326 or die "$field->{name}: default cannot be represented by YAD\n";
327 38 ▶ push @options, "--field=" . yad_text ($title) . ($field->{type} eq "string" ? ":TXT" : "");
Branch: 1 branch
BranchTrueFalseTotal
$field->{'type'} eq 'string' ? : 28 10 38
328 }
329 50 push @values, yad_text $value;
330 }
331 my $message = join "\n\n", (length $error ? $error : ()), visible ($params->{message}),
332 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
333 28 ▶ grep length $_->{description}, @$fields;
Branch: 1 branch
BranchTrueFalseTotal
length $error ? : 4 24 28
334 28 my ($status, $output) = yad (
335 "--form", "--title=MCP form", "--width=650", "--height=450", "--scroll",
336 "--text=" . yad_text ($message), "--quoted-output", "--separator= ",
337 "--item-separator=\x1f", "--num-output", "--always-print-result",
338 "--button=Submit:2", "--button=Decline:4", "--button=Cancel:6",
339 @options, "--", @values,
340 );
341 15 ▶ return unless defined $status;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $status 2 13 15
342 13 ▶ return { action => "decline" } if $status == 4;
Branch: 1 branch
BranchTrueFalseTotal
if $status == 4 2 11 13
343 11 ▶ return { action => "cancel" } unless $status == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless $status == 2 2 9 11
344 9 @raw = Text::ParseWords::shellwords $output;
345 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
346  
347 # YAD TXT output escapes backslashes, tabs and newlines inside the shell quoting.
348 9 for my $i (0 .. $#$fields) {
349 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
350 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
351 }
352  
353 9 my $response = eval { contents \@raw };
354 9 ▶ return $response unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 5 4 9
355 4 $error = $@;
356 }
357 }
358  
359 2 ▶sub terminal {
Subroutine terminal: called CC=24 SCAR=63.4
360 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
361 0 binmode $tty, ":encoding(UTF-8)";
362 0 my $old = select $tty; $| = 1; select $old;
363 0 my @raw = map initial ($_), @$fields;
364 0 print {$tty} visible ($params->{message}), "\n";
365 0 print {$tty} "Enter keeps the displayed default; :omit skips an optional field.\n",
366 ":decline refuses, :cancel cancels, << starts multiline text (end with .).\n";
367  
368 0 ▶ my $read = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
369 0 my $line = <$tty>;
370 0 ▶ return unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
371 0 $line =~ s/\r?\n\z//;
372 0 $line
373 0 };
374 0 while (1) {
375 0 for my $i (0 .. $#$fields) {
376 0 my $field = $fields->[$i];
377 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
378 0 ($field->{required} ? " (required)" : ""), "\n";
379 0 ▶ print {$tty} visible ($field->{description}), "\n" if length $field->{description};
Branch: 1 branch
BranchTrueFalseTotal
if length $field->{"description"} 0 0 0
380 0 ▶ if ($field->{choices}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"choices"}) 0 0 0
381 0 print {$tty} " 1: (no selection)\n";
382 0 print {$tty} " ", $_ + 2, ": ", visible ($field->{choices}[$_]{label}), "\n"
383 0 for 0 .. $#{$field->{choices}};
384 }
385 0 print {$tty} "[", visible ($raw[$i]), "] > ";
386 0 my $line = $read->();
387 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
388 0 ▶ return { action => "decline" } if $line eq ":decline";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq ":decline" 0 0 0
389 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
390 0 ▶ $raw[$i] = $field->{choices} ? "1" : "";
Branch: 1 branch
BranchTrueFalseTotal
$field->{'choices'} ? : 0 0 0
391 ▶ } 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
392 0 my @lines;
393 0 while (1) {
394 0 my $line = $read->();
395 0 ▶ return { action => "cancel" } unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
396 0 ▶ last if $line eq ".";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "." 0 0 0
397 0 push @lines, $line;
398 }
399 0 $raw[$i] = join "\n", @lines;
400 } elsif (length $line) {
401 0 $line =~ s/\A::/:/;
402 0 $raw[$i] = $line;
403 }
404 }
405 0 my $response = eval { contents \@raw };
406 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
407 0 print {$tty} "\n", visible ($@);
408 0 next;
409 }
410 0 print {$tty} "\n", $json->pretty->encode ($response->{content}), "\n",
411 "Submit [Enter], edit [e], decline [d], cancel [c]: ";
412 0 my $line = $read->();
413 0 ▶ return { action => "cancel" } unless defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
414 0 ▶ return $response if $line eq "";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "" 0 0 0
415 0 ▶ return { action => "decline" } if $line eq "d";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "d" 0 0 0
416 0 ▶ return { action => "cancel" } if $line eq "c";
Branch: 1 branch
BranchTrueFalseTotal
if $line eq "c" 0 0 0
417 }
418 }
419  
420 my $response = $tty_only ? terminal : graphical;
421 $response = terminal unless $response || $yad_only;
422 defined $response or die "YAD is unavailable\n";
423 print JSON::XS::encode_json ($response), "\n";
« bin/anyevent-mcp-askpermission ↑ Summary blib/lib/AnyEvent/MCP/Server/Simple.pm »