Corvus/CodeGen.pm

filter: Statementstmt 60.2% 770 / 1278 Branchbran 45.1% 355 / 786 Conditioncond 43.1% 288 / 667 MC/DCmcdc 18.4% 63 / 341 Subroutinesub 81.9% 86 / 105 Podpod 0.0% 0 / 60 totaltotal 48.2% 1562 / 3237 CC 677 SCAR 54.8
CC
677
Cov
52%
__ANON__
1560.0
__ANON__
1122.0
tracking_body
812.0
CRAP 240.1
« Corvus/Regex/Linear.pm ↑ Summary Corvus/Regex/Parse.pm »
1 package JSON::Schema::Corvus::CodeGen;
2  
3 # Generates Perl from a compiled schema graph: a port of the Python package's codegen.py (itself a port of the
4 # TypeScript evaluator's generator). Each node becomes one sub whose body is exactly the checks that node needs: the
5 # C# evaluator's plan, unrolled into straight-line code. The analyses that pick C# plans pick the shape of the code:
6 # pure-$ref elision, type-only children tested in place, discriminator and type dispatch for oneOf and anyOf, flat
7 # object compositions merged into one section, unevaluatedProperties decided statically (with guards for conditional
8 # contributors), a dynamic scope only where a $dynamicRef stays dynamic, and evaluated-property or item tracking only
9 # where unevaluatedProperties or unevaluatedItems consume it.
10 #
11 # Where Perl differs from Python the code takes Perl's form: a type test is ref() for containers and booleans, and how
12 # a scalar was created for numbers and strings (see JSON::Schema::Corvus::Json); sets are hashes; an object's
13 # properties are visited with keys (never each, whose iterator a return would leave half way).
14  
15 2 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use JSON::Schema::Corvus::Dialect qw(DRAFT4 DRAFT6);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use JSON::Schema::Corvus::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use JSON::Schema::Corvus::Formats ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use JSON::Schema::Corvus::Json ();
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 ▶use JSON::Schema::Corvus::Node qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use JSON::Schema::Corvus::Pattern ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 2 my @KINDS = qw(string number object array boolean null);
28  
29 2 ▶use constant { REF_START => "\x01", REF_END => "\x02" };
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 20 ▶sub _env { my ($name, $fallback) = @_; my $v = $ENV{$name}; defined $v && $v =~ /\A[0-9]+\z/ ? 0 + $v : $fallback }
Subroutine _env: called CC=3 SCAR=12.5
Branch: 1 branch
BranchTrueFalseTotal
defined $v && $v =~ /\A[0-9]+\z/u ? : 0 20 20
Condition33%1/3
defined $v and $v =~ /\A[0-9]+\z/u
!ll&&!rl&&r
2000
MC/DC0%0/2
defined $v and $v =~ /\A[0-9]+\z/u
defined $v $v =~ /\A[0-9]+\z/u
Truth table33%1/3
A and B
A= defined $vB= $v =~ /\A[0-9]+\z/u
ABresult
0X0
100
111
32  
33 # Objects with at most this many declared properties (or only required ones) are checked by direct lookups.
34 2 my $MAX_PROBED_PROPERTIES = _env('CORVUS_PERL_PROBE', 8);
35 2 my $MAX_PROBED_REQUIRED = _env('CORVUS_PERL_PROBE_REQUIRED', 32);
36 # The number of declared names above which property dispatch goes through a hash of subs.
37 2 my $MAX_CHAIN_NAMES = _env('CORVUS_PERL_CHAIN', 4);
38 # Required names above which presence is tested with a loop over a list.
39 2 my $MAX_REQUIRED_TESTS = _env('CORVUS_PERL_REQUIRED_TESTS', 3);
40 # At most this many guarded coverages decide unevaluatedProperties statically; more falls back to tracking.
41 2 ▶use constant MAX_GUARDED_COVERAGES => 32;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 # A guarded coverage with more names than this tests them with a hash.
43 2 ▶use constant MAX_GUARD_NAMES => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 # A leaf schema with at most this many keywords to test is tested at its call site instead of by a call.
45 2 my $MAX_INLINE_CONDITIONS = _env('CORVUS_PERL_INLINE', 6);
46 # Children that are small (non-leaf) schemas are generated into their caller, at most this deep and this long.
47 2 my $INLINE_CHILDREN = _env('CORVUS_PERL_INLINE_CHILDREN', 1);
48 2 my $MAX_INLINE_DEPTH = _env('CORVUS_PERL_INLINE_DEPTH', 2);
49 2 my $MAX_INLINE_LINES = _env('CORVUS_PERL_INLINE_LINES', 40);
50 # Children that are simple arrays (array type, length bounds, leaf items) are checked in their parent's code.
51 2 my $INLINE_ARRAYS = _env('CORVUS_PERL_INLINE_ARRAYS', 1);
52 # Enums of more values than this are tested by hash lookup.
53 2 my $MAX_CHAINED_VALUES = _env('CORVUS_PERL_CHAINED_VALUES', 3);
54  
55 # The test of how a scalar was created: builtin::created_as_number, an op, where Perl has it (5.36 and later).
56 2 ▶my $CAN = defined &builtin::created_as_number ? 'builtin::created_as_number'
Branch: 1 branch
BranchTrueFalseTotal
defined &builtin::created_as_number ? : 2 0 2
57 : 'JSON::Schema::Corvus::Json::_created_as_number';
58  
59 4874 ▶sub kind_allowed {
Subroutine kind_allowed: called CC=6 SCAR=17.9
Pod undocumented
60 4874 my ($mask, $kind) = @_;
61 4874 ▶ return ($mask & T_NULL) != 0 if $kind eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "null" 859 4015 4874
62 4015 ▶ return ($mask & T_BOOLEAN) != 0 if $kind eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "boolean" 859 3156 4015
63 3156 ▶ return ($mask & T_OBJECT) != 0 if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 1044 2112 3156
64 2112 ▶ return ($mask & T_ARRAY) != 0 if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 859 1253 2112
65 1253 ▶ return ($mask & (T_NUMBER | T_INTEGER)) != 0 if $kind eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "number" 394 859 1253
66 859 return ($mask & T_STRING) != 0;
67 }
68  
69 48 ▶sub _type { JSON::Schema::Corvus::Json::type_of($_[0]) }
Subroutine _type: called CC=1 SCAR=0.0
70  
71 25 ▶sub _is_primitive {
Subroutine _is_primitive: called CC=8 SCAR=22.6
72 25 my ($x) = @_;
73 25 my $t = _type($x);
74 25 ▶ return 1 if $t eq 'null' || $t eq 'string' || $t eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "null" or $t eq "string" or $t eq "boolean" 22 3 25
Condition66%4/6
$t eq "null" or $t eq "string" or $t eq "boolean"
l!l&&r!l&&!r
2203
$t eq "null" or $t eq "string"
l!l&&r!l&&!r
0223
MC/DC33%1/3
$t eq "null" or $t eq "string" or $t eq "boolean"
$t eq "null" $t eq "string" $t eq "boolean"
Truth table50%2/4
A or B or C
A= $t eq "null"B= $t eq "string"C= $t eq "boolean"
ABCresult
1XX1
01X1
0011
0000
75 3 ▶ return 1 if $t eq 'number' && (ref $x || ($x == $x && $x * 0 == 0));
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "number" and ref $x || $x == $x && $x * 0 == 0 1 2 3
Condition44%4/9
$t eq "number" and ref $x || $x == $x && $x * 0 == 0
!ll&&!rl&&r
201
ref $x or $x == $x and $x * 0 == 0
l!l&&r!l&&!r
010
$x == $x and $x * 0 == 0
!ll&&!rl&&r
001
MC/DC25%1/4
$t eq "number" and ref $x || $x == $x && $x * 0 == 0
$t eq "number" ref $x $x == $x $x * 0 == 0
Truth table40%2/5
A and B or C and D
A= $t eq "number"B= ref $xC= $x == $xD= $x * 0 == 0
ABCDresult
0XXX0
100X0
10100
11XX1
10111
76 2 return 0;
77 }
78  
79 # A Perl literal for a string.
80 1565 ▶sub perl_string {
Subroutine perl_string: called CC=8 SCAR=21.3
Pod undocumented
81 1565 my ($s) = @_;
82 1565 ▶ if ($s !~ /[^\x20-\x7e]/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s =~ /[^\x20-\x7e]/u) 1564 1 1565
83 1564 (my $q = $s) =~ s/([\\'])/\\$1/g;
84 1564 return "'$q'";
85 }
86 2 ▶ no warnings qw(surrogate nonchar non_unicode);
Subroutine BEGIN: called CC=1 SCAR=0.0
87 my $q = join '', map {
88 1 my $c = ord $_;
89 4 ▶ $c < 0x20 || $c > 0x7e ? sprintf('\x{%x}', $c) : $_ eq '\\' ? '\\\\' : $_ eq '"' ? '\\"' : $_ eq '$' ? '\\$'
Branch: 5 branches
BranchTrueFalseTotal
$c < 32 || $c > 126 ? : 1 3 4
$_ eq '\\' ? : 0 3 3
$_ eq '"' ? : 0 3 3
$_ eq '$' ? : 0 3 3
$_ eq '@' ? : 0 3 3
Condition66%2/3
$c < 32 or $c > 126
l!l&&r!l&&!r
013
MC/DC50%1/2
$c < 32 or $c > 126
$c < 32 $c > 126
Truth table66%2/3
A or B
A= $c < 32B= $c > 126
ABresult
1X1
011
000
90 : $_ eq '@' ? '\\@' : $_
91 } split //, $s;
92 1 return qq{"$q"};
93 }
94  
95 # A Perl literal for a number: an integer exactly, a floating point number as its shortest text that reads back.
96 226 ▶sub perl_number {
Subroutine perl_number: called CC=5 SCAR=18.4
Pod undocumented
97 226 my ($self, $v) = @_;
98 226 ▶ return $self->constant('Math::BigInt->new(' . perl_string("$v") . ')') if ref $v;
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 226 226
99 226 ▶ if (JSON::Schema::Corvus::Json::is_integer($v) && B::svref_2object(\$v)->FLAGS & B::SVf_IOK) {
Branch: 1 branch
BranchTrueFalseTotal
if (JSON::Schema::Corvus::Json::is_integer($v) and B::svref_2object(\$v)->FLAGS & 256) 226 0 226
Condition33%1/3
JSON::Schema::Corvus::Json::is_integer($v) and B::svref_2object(\$v)->FLAGS & 256
!ll&&!rl&&r
00226
MC/DC0%0/2
JSON::Schema::Corvus::Json::is_integer($v) and B::svref_2object(\$v)->FLAGS & 256
JSON::Schema::Corvus::Json::is_integer($v) B::svref_2object(\$v)->FLAGS & 256
Truth table33%1/3
A and B
A= JSON::Schema::Corvus::Json::is_integer($v)B= B::svref_2object(\$v)->FLAGS & 256
ABresult
0X0
100
111
100 226 my $copy = $v;
101 226 my $text = "$copy";
102 226 ▶ return $text if $text =~ /\A-?[0-9]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $text =~ /\A-?[0-9]+\z/u 226 0 226
103 }
104 # A floating point number as a constant with its exact bits: Perl's reading of a decimal literal is not correctly
105 # rounded on every version, so a literal could come back as a neighbouring double.
106 0 return $self->constant("unpack('d', pack('H*', '" . unpack('H*', pack('d', $v)) . "'))");
107 }
108  
109 111 ▶sub _wrap {
Subroutine _wrap: called CC=5 SCAR=16.2
110 111 my ($expr) = @_;
111 111 ▶ return $expr if $expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/ || $expr =~ /\A-?[0-9.]+\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/u or $expr =~ /\A-?[0-9.]+\z/u 18 93 111
Condition66%2/3
$expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/u or $expr =~ /\A-?[0-9.]+\z/u
l!l&&r!l&&!r
18093
MC/DC50%1/2
$expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/u or $expr =~ /\A-?[0-9.]+\z/u
$expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/u $expr =~ /\A-?[0-9.]+\z/u
Truth table66%2/3
A or B
A= $expr =~ /\A[\$\w:\x01\x02]+(?:\([^()]*\))?\z/uB= $expr =~ /\A-?[0-9.]+\z/u
ABresult
1X1
011
000
112 93 ▶ return $expr if substr($expr, 0, 1) eq '(' && _balanced($expr);
Branch: 1 branch
BranchTrueFalseTotal
if substr($expr, 0, 1) eq "(" and _balanced($expr) 45 48 93
Condition66%2/3
substr($expr, 0, 1) eq "(" and _balanced($expr)
!ll&&!rl&&r
48045
MC/DC50%1/2
substr($expr, 0, 1) eq "(" and _balanced($expr)
substr($expr, 0, 1) eq "(" _balanced($expr)
Truth table66%2/3
A and B
A= substr($expr, 0, 1) eq "("B= _balanced($expr)
ABresult
0X0
100
111
113 48 return "($expr)";
114 }
115  
116 45 ▶sub _balanced {
Subroutine _balanced: called CC=11 SCAR=24.0
117 45 my ($expr) = @_;
118 45 my $depth = 0;
119 45 my $in_string = '';
120 45 my @chars = split //, $expr;
121 45 for my $i (0 .. $#chars) {
122 3524 my $ch = $chars[$i];
123 3524 ▶ if ($in_string) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_string) 328 3196 3524
124 328 ▶ if ($ch eq '\\') { $i++; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "\\") 1 327 328
125 327 ▶ $in_string = '' if $ch eq $in_string;
Branch: 1 branch
BranchTrueFalseTotal
if $ch eq $in_string 67 260 327
126 327 next;
127 }
128 3196 ▶ if ($ch eq "'" || $ch eq '"') { $in_string = $ch; next }
Branch: 1 branch
BranchTrueFalseTotal
if ($ch eq "'" or $ch eq "\"") 67 3129 3196
Condition100%3/3
$ch eq "'" or $ch eq "\""
l!l&&r!l&&!r
6613129
MC/DC100%2/2
$ch eq "'" or $ch eq "\""
$ch eq "'" $ch eq "\""
Truth table100%3/3
A or B
A= $ch eq "'"B= $ch eq "\""
ABresult
1X1
011
000
129 3129 ▶ if ($ch eq '(') { $depth++ }
Branch: 2 branches
BranchTrueFalseTotal
if ($ch eq '(') { } 176 2953 3129
elsif ($ch eq ')') { } 176 2777 2953
130 elsif ($ch eq ')') {
131 176 $depth--;
132 176 ▶ return 0 if $depth == 0 && $i < $#chars;
Branch: 1 branch
BranchTrueFalseTotal
if $depth == 0 and $i < $#chars 0 176 176
Condition66%2/3
$depth == 0 and $i < $#chars
!ll&&!rl&&r
131450
MC/DC0%0/2
$depth == 0 and $i < $#chars
$depth == 0 $i < $#chars
Truth table66%2/3
A and B
A= $depth == 0B= $i < $#chars
ABresult
0X0
100
111
133 }
134 }
135 45 return $depth == 0;
136 }
137  
138 232 ▶sub _indent {
Subroutine _indent: called CC=2 SCAR=7.0
139 232 my ($lines, $depth) = @_;
140 232 ▶ my $pad = ' ' x ($depth // 1);
Condition50%1/2
$depth // 1
l!l
0232
MC/DC0%0/1
$depth // 1
$depth
Truth table50%1/2
A
A= $depth
Aresult
11
00
141 232 return map { "$pad$_" } @$lines;
142 }
143  
144 # "return 0 unless CHECK" (nothing for a check that always holds).
145 32 ▶sub _push {
Subroutine _push: called CC=3 SCAR=12.0
146 32 my ($out, $check) = @_;
147 32 ▶ return if $check eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check eq 1 0 32 32
148 0 ▶ if ($check eq '0') { push @$out, 'return 0;' }
Branch: 1 branch
BranchTrueFalseTotal
if ($check eq '0') { } 0 32 32
149 32 else { push @$out, "return 0 unless $check;" }
150 }
151  
152 40 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
153 40 my ($class, $program) = @_;
154 return bless {
155 program => $program,
156 nodes => $program->{nodes},
157 40 templates => {},
158 template_order => [],
159 queue => [],
160 constants => {},
161 constant_order => [],
162 custom_formats => [],
163 custom_format_index => {},
164 uses_depth => 0,
165 tmp => 0,
166 uses_tx => 0,
167 elided => {},
168 generating => [],
169 inline_depth => 0,
170 trivial => {},
171 generated => {},
172 }, $class;
173 }
174  
175 # The generated code: { functions => [[name, text]], constants => [[name, init]], root => name, custom_formats,
176 # uses_dynamic_scope, uses_depth, root_resource, max_depth }.
177 40 ▶sub generate {
Subroutine generate: called CC=2 SCAR=6.9
Pod undocumented
178 40 my ($self) = @_;
179 40 my $root_name = $self->request($self->entry_name($self->{program}{root}));
180 40 ▶ for (my $q = 0; $q < @{ $self->{queue} }; $q++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($q < @{$self->{"queue"};}) 104 40 144
181 104 my $name = $self->{queue}[$q];
182 104 $self->{templates}{$name} = $self->generate_function($name);
183 }
184 40 my ($functions, $constants, $root) = $self->link($root_name);
185 return {
186 functions => $functions,
187 constants => $constants,
188 root => $root,
189 custom_formats => $self->{custom_formats},
190 uses_dynamic_scope => $self->{program}{uses_dynamic_scope},
191 uses_depth => $self->{uses_depth},
192 root_resource => $self->{program}{root_resource},
193 max_depth => $self->{program}{options}{max_depth},
194 40 };
195 }
196  
197 # --- Names and references ---
198  
199 40 ▶sub entry_name { 'v' . $_[0]->elide($_[1]) }
Subroutine entry_name: called CC=1 SCAR=0.0
Pod undocumented
200  
201 2158 ▶sub request {
Subroutine request: called CC=2 SCAR=6.9
Pod undocumented
202 2158 my ($self, $name) = @_;
203 2158 ▶ if (!exists $self->{templates}{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"templates"}{$name}) 104 2054 2158
204 104 $self->{templates}{$name} = '';
205 104 push @{ $self->{template_order} }, $name;
206 104 push @{ $self->{queue} }, $name;
207 }
208 2158 return $name;
209 }
210  
211 2118 ▶sub ref_to { REF_START . $_[0]->request($_[1]) . REF_END }
Subroutine ref_to: called CC=1 SCAR=0.0
Pod undocumented
212  
213 # A constant of the generated package, by its initialiser: its variable, such as $C3.
214 109 ▶sub constant {
Subroutine constant: called CC=2 SCAR=6.9
Pod undocumented
215 109 my ($self, $init) = @_;
216 109 my $name = $self->{constants}{$init};
217 109 ▶ if (!defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $name) 14 95 109
218 14 $name = '$C' . scalar @{ $self->{constant_order} };
219 14 $self->{constants}{$init} = $name;
220 14 push @{ $self->{constant_order} }, $init;
221 }
222 109 return $name;
223 }
224  
225 # Follows pure-$ref chains (jump-target inlining); not across resources when a dynamic scope is kept.
226 3252 ▶sub elide {
Subroutine elide: called CC=7 SCAR=19.7
Pod undocumented
227 3252 my ($self, $node_id) = @_;
228 3252 ▶ return $self->{elided}{$node_id} if exists $self->{elided}{$node_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"elided"}{$node_id} 3113 139 3252
229 139 my $n = $self->{nodes}[$node_id];
230 139 for (1 .. 64) {
231 178 ▶ last if !$n->is_pure_ref || $n->{in_place_cycle};
Branch: 1 branch
BranchTrueFalseTotal
if not $n->is_pure_ref or $n->{"in_place_cycle"} 139 39 178
Condition100%3/3
not $n->is_pure_ref or $n->{"in_place_cycle"}
l!l&&r!l&&!r
136339
MC/DC100%2/2
not $n->is_pure_ref or $n->{"in_place_cycle"}
not $n->is_pure_ref $n->{"in_place_cycle"}
Truth table100%3/3
not(A) or B
A= not $n->is_pure_refB= $n->{"in_place_cycle"}
ABresult
1X1
011
000
232 39 my $next = $self->{nodes}[ $n->{ref} ];
233 39 ▶ last if $self->{program}{uses_dynamic_scope} && $next->{resource_id} != $n->{resource_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"program"}{"uses_dynamic_scope"} and $next->{"resource_id"} != $n->{"resource_id"} 0 39 39
Condition33%1/3
$self->{"program"}{"uses_dynamic_scope"} and $next->{"resource_id"} != $n->{"resource_id"}
!ll&&!rl&&r
3900
MC/DC0%0/2
$self->{"program"}{"uses_dynamic_scope"} and $next->{"resource_id"} != $n->{"resource_id"}
$self->{"program"}{"uses_dynamic_scope"} $next->{"resource_id"} != $n->{"resource_id"}
Truth table33%1/3
A and B
A= $self->{"program"}{"uses_dynamic_scope"}B= $next->{"resource_id"} != $n->{"resource_id"}
ABresult
0X0
100
111
234 39 $n = $next;
235 }
236 139 return $self->{elided}{$node_id} = $n->{id};
237 }
238  
239 861 ▶sub _tx {
Subroutine _tx: called CC=2 SCAR=6.9
240 861 my ($self, $v) = @_;
241 861 ▶ if ($v eq '$x') {
Branch: 1 branch
BranchTrueFalseTotal
if ($v eq "\$x") 108 753 861
242 108 $self->{uses_tx} = 1;
243 108 return '$tx';
244 }
245 753 return "ref($v)";
246 }
247  
248 861 ▶sub kind_test {
Subroutine kind_test: called CC=6 SCAR=17.9
Pod undocumented
249 861 my ($self, $kind, $v) = @_;
250 861 ▶ return "!defined($v)" if $kind eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "null" 0 861 861
251 861 my $t = $self->_tx($v);
252 861 ▶ return "$t eq 'JSON::PP::Boolean'" if $kind eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "boolean" 109 752 861
253 752 ▶ return "$t eq 'HASH'" if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 44 708 752
254 708 ▶ return "$t eq 'ARRAY'" if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 6 702 708
255 702 ▶ if ($kind eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "number") 336 366 702
256 336 return "($t eq '' ? defined($v) && $CAN($v) : $t eq 'Math::BigInt')";
257 }
258 366 return "($t eq '' && defined($v) && !$CAN($v))";
259 }
260  
261 # A test that a number (known to be one) is an integer: a whole number, in every draft (see Json::is_integer).
262 206 ▶sub _integer_test {
Subroutine _integer_test: called CC=1 SCAR=0.0
263 206 my ($self, $v, $dialect) = @_;
264 206 return "(ref($v) || $v == int($v))";
265 }
266  
267 # An expression that is true when v has one of the types in the mask.
268 465 ▶sub type_expr {
Subroutine type_expr: called CC=7 SCAR=19.5
Pod undocumented
269 465 my ($self, $mask, $v, $dialect) = @_;
270 465 my @parts;
271 465 for my $kind (qw(string object array boolean null)) {
272 2325 ▶ next unless kind_allowed($mask, $kind);
Branch: 1 branch
BranchTrueFalseTotal
unless kind_allowed($mask, $kind) 1960 365 2325
273 365 push @parts, $self->kind_test($kind, $v);
274 }
275 465 ▶ if ($mask & T_NUMBER) {
Branch: 2 branches
BranchTrueFalseTotal
if ($mask & 16) { } 96 369 465
elsif ($mask & 64) { } 4 365 369
276 96 push @parts, $self->kind_test('number', $v);
277 }
278 elsif ($mask & T_INTEGER) {
279 4 push @parts, '(' . $self->kind_test('number', $v) . ' && ' . $self->_integer_test($v, $dialect) . ')';
280 }
281 465 ▶ return '0' unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 0 465 465
282 465 ▶ return @parts == 1 ? $parts[0] : '(' . join(' || ', @parts) . ')';
Branch: 1 branch
BranchTrueFalseTotal
@parts == 1 ? : 465 0 465
283 }
284  
285 # An expression that evaluates child node_id against v from a node in resource source. e is the evaluated set to mark
286 # (tracking variant), or undef (flag variant).
287 1477 ▶sub call {
Subroutine call: called CC=12 SCAR=27.0
Pod undocumented
288 1477 my ($self, $node_id, $v, $source, $e) = @_;
289 1477 my $target = $self->elide($node_id);
290 1477 my $n = $self->{nodes}[$target];
291 1477 ▶ return '1' if $n->{always_true};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_true"} 4 1473 1477
292 1473 ▶ return '0' if $n->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_false"} 0 1473 1473
293 1473 ▶ my $crosses = $self->{program}{uses_dynamic_scope} && $n->{resource_id} != $source;
Condition33%1/3
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
!ll&&!rl&&r
147300
MC/DC0%0/2
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
$self->{'program'}{'uses_dynamic_scope'} $n->{'resource_id'} != $source
Truth table33%1/3
A && B
A= $self->{'program'}{'uses_dynamic_scope'}B= $n->{'resource_id'} != $source
ABresult
0X0
100
111
294 1473 ▶ if (!defined $e && !$crosses) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $e or $crosses) 1473 0 1473
Condition33%1/3
defined $e or $crosses
l!l&&r!l&&!r
001473
MC/DC0%0/2
defined $e or $crosses
defined $e $crosses
Truth table33%1/3
A or B
A= defined $eB= $crosses
ABresult
1X1
011
000
295 1473 ▶ return $self->type_expr($n->{type}, $v, $n->{dialect}) if $n->is_type_only;
Branch: 1 branch
BranchTrueFalseTotal
if $n->is_type_only 465 1008 1473
296 1008 ▶ return $self->inline_leaf($n, $v) if $self->is_inline_leaf($n);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_inline_leaf($n) 292 716 1008
297 716 ▶ return '1' if $self->is_trivial($target);
Branch: 1 branch
BranchTrueFalseTotal
if $self->is_trivial($target) 0 716 716
298 }
299 716 ▶ my $variant = defined $e ? 't' : 'v';
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 716 716
300 716 ▶ my $name = ($crosses ? 's' : '') . $variant . $target;
Branch: 1 branch
BranchTrueFalseTotal
$crosses ? : 0 716 716
301 716 ▶ return $self->ref_to($name) . "($v" . (defined $e ? ", $e" : '') . ')';
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 716 716
302 }
303  
304 # A reference to the flag sub of child node_id (for dispatch tables), or '1' for a schema that accepts everything.
305 1447 ▶sub function_ref {
Subroutine function_ref: called CC=6 SCAR=19.0
Pod undocumented
306 1447 my ($self, $node_id, $source) = @_;
307 1447 my $target = $self->elide($node_id);
308 1447 my $n = $self->{nodes}[$target];
309 1447 ▶ return '1' if $n->{always_true} || $self->call($node_id, '$v', $source) eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_true"} or $self->call($node_id, "\$v", $source) eq 1 47 1400 1447
Condition66%2/3
$n->{"always_true"} or $self->call($node_id, "\$v", $source) eq 1
l!l&&r!l&&!r
4701400
MC/DC50%1/2
$n->{"always_true"} or $self->call($node_id, "\$v", $source) eq 1
$n->{"always_true"} $self->call($node_id, "\$v", $source) eq 1
Truth table66%2/3
A or B
A= $n->{"always_true"}B= $self->call($node_id, "\$v", $source) eq 1
ABresult
1X1
011
000
310 1400 ▶ return '\&JSON::Schema::Corvus::Runtime::never' if $n->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_false"} 0 1400 1400
311 1400 ▶ my $crosses = $self->{program}{uses_dynamic_scope} && $n->{resource_id} != $source;
Condition33%1/3
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
!ll&&!rl&&r
140000
MC/DC0%0/2
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
$self->{'program'}{'uses_dynamic_scope'} $n->{'resource_id'} != $source
Truth table33%1/3
A && B
A= $self->{'program'}{'uses_dynamic_scope'}B= $n->{'resource_id'} != $source
ABresult
0X0
100
111
312 1400 ▶ return '\&' . $self->ref_to(($crosses ? 'sv' : 'v') . $target);
Branch: 1 branch
BranchTrueFalseTotal
$crosses ? : 0 1400 1400
313 }
314  
315 # A leaf (type, const or enum of primitives, string and number keywords, nothing that applies a subschema) small
316 # enough to test at the call site, without a call.
317 1016 ▶sub is_inline_leaf {
Subroutine is_inline_leaf: called CC=11 SCAR=24.8
Pod undocumented
318 1016 my ($self, $n) = @_;
319 1016 ▶ return 0 if $n->has_object_keywords || $n->has_array_keywords || $n->has_in_place_applicators || $n->{in_place_cycle};
Branch: 1 branch
BranchTrueFalseTotal
if $n->has_object_keywords or $n->has_array_keywords or $n->has_in_place_applicators or $n->{"in_place_cycle"} 722 294 1016
Condition88%8/9
$n->has_object_keywords or $n->has_array_keywords or $n->has_in_place_applicators or $n->{"in_place_cycle"}
l!l&&r!l&&!r
7220294
$n->has_object_keywords or $n->has_array_keywords or $n->has_in_place_applicators
l!l&&r!l&&!r
394328294
$n->has_object_keywords or $n->has_array_keywords
l!l&&r!l&&!r
223171622
MC/DC75%3/4
$n->has_object_keywords or $n->has_array_keywords or $n->has_in_place_applicators or $n->{"in_place_cycle"}
$n->has_object_keywords $n->has_array_keywords $n->has_in_place_applicators $n->{"in_place_cycle"}
Truth table80%4/5
A or B or C or D
A= $n->has_object_keywordsB= $n->has_array_keywordsC= $n->has_in_place_applicatorsD= $n->{"in_place_cycle"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
320 294 ▶ return 0 if $n->{has_const} && !_is_primitive($n->{const_value});
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"has_const"} and not _is_primitive($n->{"const_value"}) 0 294 294
Condition33%1/3
$n->{"has_const"} and not _is_primitive($n->{"const_value"})
!ll&&!rl&&r
29400
MC/DC0%0/2
$n->{"has_const"} and not _is_primitive($n->{"const_value"})
$n->{"has_const"} not _is_primitive($n->{"const_value"})
Truth table33%1/3
A and not(B)
A= $n->{"has_const"}B= not _is_primitive($n->{"const_value"})
ABresult
0X0
100
111
321 294 ▶ return 0 if $n->{enum_values} && grep { !_is_primitive($_) } @{ $n->{enum_values} };
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"enum_values"} and grep {not _is_primitive($_);} @{$$n{"enum_values"};} 0 294 294
Condition66%2/3
$n->{"enum_values"} and grep {not _is_primitive($_);} @{$$n{"enum_values"};}
!ll&&!rl&&r
29130
MC/DC0%0/2
$n->{"enum_values"} and grep {not _is_primitive($_);} @{$$n{"enum_values"};}
$n->{"enum_values"} grep {not _is_primitive($_);} @{$$n{"enum_values"};}
Truth table66%2/3
A and B
A= $n->{"enum_values"}B= grep {not _is_primitive($_);} @{$$n{"enum_values"};}
ABresult
0X0
100
111
322 294 ▶ my $conditions = $self->_string_condition_count($n) + ($n->{has_const} ? 1 : 0) + (defined $n->{enum_values} ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$n->{'has_const'} ? : 0 294 294
defined $n->{'enum_values'} ? : 3 291 294
323 294 my $numbers = grep { defined } @$n{qw(minimum maximum exclusive_minimum exclusive_maximum multiple_of)};
324 294 return $conditions + $numbers <= $MAX_INLINE_CONDITIONS;
325 }
326  
327 294 ▶sub _string_condition_count {
Subroutine _string_condition_count: called CC=3 SCAR=13.3
328 294 my ($self, $n) = @_;
329 1470 ▶ return scalar grep { $_ } ($n->{min_length} > 0, $n->{max_length} >= 0, defined $n->{pattern},
Condition33%2/6
$n->{'assert_format'} && defined $n->{'format'} && !JSON::Schema::Corvus::Formats::is_numeric_format($n->{'format_kind'})
!ll&&!rl&&r
29400
$n->{"assert_format"} and defined $n->{"format"}
!ll&&!rl&&r
29400
MC/DC0%0/3
$n->{'assert_format'} && defined $n->{'format'} && !JSON::Schema::Corvus::Formats::is_numeric_format($n->{'format_kind'})
$n->{"assert_format"} defined $n->{"format"} !JSON::Schema::Corvus::Formats::is_numeric_format($n->{'format_kind'})
Truth table25%1/4
A and B && not(C)
A= $n->{"assert_format"}B= defined $n->{"format"}C= !JSON::Schema::Corvus::Formats::is_numeric_format($n->{'format_kind'})
ABCresult
0XX0
10X0
1100
1111
330 $n->{assert_format} && defined $n->{format} && !JSON::Schema::Corvus::Formats::is_numeric_format($n->{format_kind}),
331 294 $n->{assert_content});
332 }
333  
334 # A leaf's keywords as one expression over v: per kind, its type test and the conditions for that kind, then const
335 # and enum.
336 292 ▶sub inline_leaf {
Subroutine inline_leaf: called CC=14 SCAR=27.5
Pod undocumented
337 292 my ($self, $n, $v) = @_;
338 my %sections = (
339 string => [ $self->string_conditions($n, $v) ],
340 292 number => [ (grep { defined } $self->integer_condition($n, $v)), $self->number_conditions($n, $v) ],
341 );
342 292 my @parts;
343 292 ▶ if ($n->{has_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{'has_type'}) { } 288 4 292
344 288 my @clauses;
345 288 for my $kind (@KINDS) {
346 1728 ▶ next unless kind_allowed($n->{type}, $kind);
Branch: 1 branch
BranchTrueFalseTotal
unless kind_allowed($n->{"type"}, $kind) 1440 288 1728
347 288 my $test = $self->kind_test($kind, $v);
348 288 ▶ my $conditions = $sections{$kind} // [];
Condition50%1/2
$sections{$kind} // []
l!l
2880
MC/DC0%0/1
$sections{$kind} // []
$sections{$kind}
Truth table50%1/2
A
A= $sections{$kind}
Aresult
11
00
349 288 ▶ push @clauses, @$conditions ? '(' . join(' && ', $test, @$conditions) . ')' : $test;
Branch: 1 branch
BranchTrueFalseTotal
@$conditions ? : 288 0 288
350 }
351 288 ▶ return '0' unless @clauses;
Branch: 1 branch
BranchTrueFalseTotal
unless @clauses 0 288 288
352 288 ▶ push @parts, @clauses == 1 ? $clauses[0] : '(' . join(' || ', @clauses) . ')';
Branch: 1 branch
BranchTrueFalseTotal
@clauses == 1 ? : 288 0 288
353 }
354 else {
355 4 for my $kind (qw(string number)) {
356 8 my $conditions = $sections{$kind};
357 8 ▶ next unless @$conditions;
Branch: 1 branch
BranchTrueFalseTotal
unless @$conditions 8 0 8
358 0 push @parts, '(!' . _wrap($self->kind_test($kind, $v)) . ' || ' . join(' && ', map { _wrap($_) } @$conditions)
359 . ')';
360 }
361 }
362 292 ▶ push @parts, $self->eq_test($v, $n->{const_value}) if $n->{has_const};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"has_const"} 0 292 292
363 292 ▶ push @parts, $self->enum_test($n->{enum_values}, $v) if defined $n->{enum_values};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"enum_values"} 2 290 292
364 292 ▶ return '1' unless @parts;
Branch: 1 branch
BranchTrueFalseTotal
unless @parts 2 290 292
365 290 ▶ return @parts == 1 ? $parts[0] : '(' . join(' && ', @parts) . ')';
Branch: 1 branch
BranchTrueFalseTotal
@parts == 1 ? : 290 0 290
366 }
367  
368 # A test that v is JSON-equal to the primitive value.
369 2 ▶sub eq_test {
Subroutine eq_test: called CC=5 SCAR=17.0
Pod undocumented
370 2 my ($self, $v, $value) = @_;
371 2 my $t = _type($value);
372 2 ▶ return "!defined($v)" if $t eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "null" 0 2 2
373 2 ▶ return "(ref($v) eq 'JSON::PP::Boolean' && " . ($value ? $v : "!$v") . ')' if $t eq 'boolean';
Branch: 2 branches
BranchTrueFalseTotal
if $t eq "boolean" 0 2 2
$value ? : 0 0 0
374 2 ▶ if ($t eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "string") 1 1 2
375 1 return '(' . $self->kind_test('string', $v) . " && $v eq " . perl_string($value) . ')';
376 }
377 1 return '(' . $self->kind_test('number', $v) . " && $v == " . $self->perl_number($value) . ')';
378 }
379  
380 # A test that v is one of a list of primitives: a hash lookup for more than a few strings, a chain of tests otherwise.
381 2 ▶sub enum_test {
Subroutine enum_test: called CC=5 SCAR=21.5
Pod undocumented
382 2 my ($self, $values, $v) = @_;
383 2 ▶ return '0' unless @$values;
Branch: 1 branch
BranchTrueFalseTotal
unless @$values 0 2 2
384 2 ▶ if (@$values > $MAX_CHAINED_VALUES && !grep { _type($_) ne 'string' } @$values) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$values > $MAX_CHAINED_VALUES and not grep({_type($_) ne "string";} @$values)) 2 0 2
Condition33%1/3
@$values > $MAX_CHAINED_VALUES and not grep({_type($_) ne "string";} @$values)
!ll&&!rl&&r
002
MC/DC0%0/2
@$values > $MAX_CHAINED_VALUES and not grep({_type($_) ne "string";} @$values)
@$values > $MAX_CHAINED_VALUES not grep({_type($_) ne "string";} @$values)
Truth table33%1/3
A and not(B)
A= @$values > $MAX_CHAINED_VALUESB= not grep({_type($_) ne "string";} @$values)
ABresult
0X0
100
111
385 2 my $set = $self->constant('{' . join(', ', map { perl_string($_) . ' => 1' } @$values) . '}');
386 2 return '(' . $self->kind_test('string', $v) . " && exists $set\->{$v})";
387 }
388 0 ▶ if (@$values > $MAX_CHAINED_VALUES) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$values > $MAX_CHAINED_VALUES) 0 0 0
389 0 my $keys = $self->constant('{ map { JSON::Schema::Corvus::Runtime::key($_) => 1 } @{ '
390 . $self->json_value($values) . ' } }');
391 0 return "exists $keys\->{JSON::Schema::Corvus::Runtime::key($v)}";
392 }
393 0 return '(' . join(' || ', map { $self->eq_test($v, $_) } @$values) . ')';
394 }
395  
396 # The initialiser of a JSON value constant.
397 2 ▶sub json_value {
Subroutine json_value: called CC=1 SCAR=0.0
Pod undocumented
398 2 my ($self, $value) = @_;
399 2 return 'JSON::Schema::Corvus::Json::decode(' . perl_string(JSON::Schema::Corvus::Json::encode($value)) . ')';
400 }
401  
402 2 ▶sub json_constant { $_[0]->constant($_[0]->json_value($_[1])) }
Subroutine json_constant: called CC=1 SCAR=0.0
Pod undocumented
403  
404 8 ▶sub scratch {
Subroutine scratch: called CC=1 SCAR=0.0
Pod undocumented
405 8 my ($self, $prefix) = @_;
406 8 return '$' . $prefix . $self->{tmp}++;
407 }
408  
409 # --- Functions ---
410  
411 110 ▶sub _params { $_[0] eq 'v' ? 'my $x = $_[0];' : 'my ($x, $ev) = @_;' }
Subroutine _params: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq 'v' ? : 110 0 110
412  
413 104 ▶sub generate_function {
Subroutine generate_function: called CC=7 SCAR=21.8
Pod undocumented
414 104 my ($self, $name) = @_;
415 104 my $kind = substr($name, 0, 1);
416 104 ▶ if ($kind eq 's') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "s") 0 104 104
417 0 my $variant = substr($name, 1, 1);
418 0 my $node_id = substr($name, 2);
419 0 my $n = $self->{nodes}[$node_id];
420 0 ▶ my $args = $variant eq 'v' ? '$x' : '$x, $ev';
Branch: 1 branch
BranchTrueFalseTotal
$variant eq 'v' ? : 0 0 0
421 0 return join "\n", 'sub @ {', ' ' . _params($variant), " push \@DS, $n->{resource_id};",
422 ' my $r = ' . $self->ref_to($variant . $node_id) . "($args);", ' pop @DS;', ' return $r;', '}';
423 }
424 104 ▶ return $self->generate_dynamic_resolver(substr($name, 2), substr($name, 1, 1)) if $kind eq 'd';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "d" 0 104 104
425 104 ▶ return $self->generate_node_function(substr($name, 2), substr($name, 1, 1)) if $kind eq 'b';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "b" 2 102 104
426 102 my $variant = $kind;
427 102 my $node_id = substr($name, 1);
428 102 my $n = $self->{nodes}[$node_id];
429 102 ▶ if ($n->{in_place_cycle}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"in_place_cycle"}) 2 100 102
430 2 $self->{uses_depth} = 1;
431 2 ▶ my $args = $variant eq 'v' ? '$x' : '$x, $ev';
Branch: 1 branch
BranchTrueFalseTotal
$variant eq 'v' ? : 2 0 2
432 2 return join "\n", 'sub @ {', ' ' . _params($variant),
433 ' JSON::Schema::Corvus::Runtime::depth_exceeded() if ++$depth > $MAXDEPTH;',
434 ' my $r = ' . $self->ref_to("b$variant$node_id") . "($args);", ' $depth--;', ' return $r;', '}';
435 }
436 100 return $self->generate_node_function($node_id, $variant);
437 }
438  
439 0 ▶sub generate_dynamic_resolver {
Subroutine generate_dynamic_resolver: not called CC=4 SCAR=30.0
Pod undocumented
440 0 my ($self, $node_id, $variant) = @_;
441 0 my $n = $self->{nodes}[$node_id];
442 0 my $d = $n->{dynamic_ref};
443 0 ▶ my $e = $variant eq 't' ? '$ev' : undef;
Branch: 1 branch
BranchTrueFalseTotal
$variant eq 't' ? : 0 0 0
444 0 $self->{uses_tx} = 0;
445 0 my @lines = ('for my $r (@DS) {');
446 0 for my $resource (sort { $a <=> $b } keys %{ $d->{by_resource} }) {
447 0 push @lines, " return " . $self->call($d->{by_resource}{$resource}, '$x', $n->{resource_id}, $e)
448 . " if \$r == $resource;";
449 }
450 0 push @lines, '}', 'return ' . $self->call($d->{fallback}, '$x', $n->{resource_id}, $e) . ';';
451 0 ▶ unshift @lines, 'my $tx = ref($x);' if $self->{uses_tx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"uses_tx"} 0 0 0
452 0 return join "\n", 'sub @ {', ' ' . _params($variant), _indent(\@lines), '}';
453 }
454  
455 108 ▶sub generate_node_function {
Subroutine generate_node_function: called CC=2 SCAR=7.6
Pod undocumented
456 108 my ($self, $node_id, $variant) = @_;
457 # A node's text depends only on the node and the inlining depth (which names nested inlines).
458 108 my $key = "$node_id $variant $self->{inline_depth}";
459 108 ▶ return $self->{generated}{$key} //= $self->_generate_node_function($node_id, $variant);
Condition33%1/3
$self->{"generated"}{$key} //= $self->_generate_node_function($node_id, $variant)
l!l&&r!l&&!r
01080
MC/DC0%0/2
$self->{"generated"}{$key} //= $self->_generate_node_function($node_id, $variant)
$self->{"generated"}{$key} $self->_generate_node_function($node_id, $variant)
Truth table33%1/3
A //= B
A= $self->{"generated"}{$key}B= $self->_generate_node_function($node_id, $variant)
ABresult
1X1
011
000
460 }
461  
462 108 ▶sub _generate_node_function {
Subroutine _generate_node_function: called CC=5 SCAR=16.7
463 108 my ($self, $node_id, $variant) = @_;
464 108 my $n = $self->{nodes}[$node_id];
465 # Scratch names restart per function so that structurally identical functions produce identical text.
466 108 $self->{tmp} = 0;
467 108 $self->{uses_tx} = 0;
468 108 push @{ $self->{generating} }, $node_id;
469 108 ▶ my $tracking = $variant eq 't' || $n->{unevaluated_properties} >= 0 || $n->{unevaluated_items} >= 0;
Condition33%2/6
$variant eq 't' || $n->{'unevaluated_properties'} >= 0 || $n->{'unevaluated_items'} >= 0
l!l&&r!l&&!r
00108
$variant eq "t" or $n->{"unevaluated_properties"} >= 0
l!l&&r!l&&!r
00108
MC/DC0%0/3
$variant eq 't' || $n->{'unevaluated_properties'} >= 0 || $n->{'unevaluated_items'} >= 0
$variant eq "t" $n->{"unevaluated_properties"} >= 0 $n->{'unevaluated_items'} >= 0
Truth table25%1/4
A or B || C
A= $variant eq "t"B= $n->{"unevaluated_properties"} >= 0C= $n->{'unevaluated_items'} >= 0
ABCresult
1XX1
01X1
0011
0000
470 108 ▶ my $body = $tracking ? $self->tracking_body($n, $variant) : $self->flag_body($n);
Branch: 1 branch
BranchTrueFalseTotal
$tracking ? : 0 108 108
471 108 pop @{ $self->{generating} };
472 108 ▶ unshift @$body, 'my $tx = ref($x);' if $self->{uses_tx};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"uses_tx"} 97 11 108
473 108 return join "\n", 'sub @ {', ' ' . _params($variant), _indent($body), '}';
474 }
475  
476 # Whether a node accepts everything without testing anything (no assertion of its own, and only $ref and allOf to
477 # nodes that are themselves trivial), so a call to it can be dropped.
478 734 ▶sub is_trivial {
Subroutine is_trivial: called CC=22 SCAR=34.6
Pod undocumented
479 734 my ($self, $node_id) = @_;
480 734 ▶ return $self->{trivial}{$node_id} if exists $self->{trivial}{$node_id};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"trivial"}{$node_id} 690 44 734
481 44 $self->{trivial}{$node_id} = 0;
482 44 my $n = $self->{nodes}[$node_id];
483 44 ▶ my @children = map { $self->elide($_) } grep { $_ >= 0 } $n->{ref}, $n->{static_dynamic_ref}, @{ $n->{all_of} // [] };
Condition100%2/2
$n->{"all_of"} // []
l!l
143
MC/DC100%1/1
$n->{"all_of"} // []
$n->{"all_of"}
Truth table100%2/2
A
A= $n->{"all_of"}
Aresult
11
00
484 my $crosses = $self->{program}{uses_dynamic_scope}
485 0 ▶ && grep { $self->{nodes}[$_]{resource_id} != $n->{resource_id} } @children;
Condition33%1/3
$self->{'program'}{'uses_dynamic_scope'} && grep({$self->{'nodes'}[$_]{'resource_id'} != $n->{'resource_id'};} @children)
!ll&&!rl&&r
4400
MC/DC0%0/2
$self->{'program'}{'uses_dynamic_scope'} && grep({$self->{'nodes'}[$_]{'resource_id'} != $n->{'resource_id'};} @children)
$self->{'program'}{'uses_dynamic_scope'} grep({$self->{'nodes'}[$_]{'resource_id'} != $n->{'resource_id'};} @children)
Truth table33%1/3
A && B
A= $self->{'program'}{'uses_dynamic_scope'}B= grep({$self->{'nodes'}[$_]{'resource_id'} != $n->{'resource_id'};} @children)
ABresult
0X0
100
111
486 my $trivial = $n->{always_true} || (!$crosses && !$n->{always_false} && !$n->{in_place_cycle} && !$n->{has_type}
487 && !$n->{has_const} && !defined $n->{enum_values} && !$n->has_object_keywords && !$n->has_array_keywords
488 && !$n->has_string_keywords && !$n->has_number_keywords && !defined $n->{dynamic_ref} && !defined $n->{any_of}
489 && !defined $n->{one_of} && $n->{not_} < 0 && $n->{if_} < 0 && !defined $n->{dependencies}
490 44 ▶ && !grep { !$self->is_trivial($_) } @children);
Condition68%35/51
$n->{'always_true'} || !($crosses || $n->{'always_false'} || $n->{'in_place_cycle'} || $n->{'has_type'} || $n->{'has_const'} || defined $n->{'enum_values'} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{'dynamic_ref'} || defined $n->{'any_of'} || defined $n->{'one_of'}) && $n->{'not_'} < 0 && $n->{'if_'} < 0 && !defined($n->{'dependencies'}) && !grep({not $self->is_trivial($_);} @children)
l!l&&r!l&&!r
0044
not $crosses || $n->{"always_false"} || $n->{"in_place_cycle"} || $n->{"has_type"} || $n->{"has_const"} || defined $n->{"enum_values"} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{"dynamic_ref"} || defined $n->{"any_of"} || defined $n->{"one_of"} and $n->{"not_"} < 0 and $n->{"if_"} < 0 and not defined $n->{"dependencies"} and not grep({not $self->is_trivial($_);} @children)
!ll&&!rl&&r
26180
not $crosses || $n->{"always_false"} || $n->{"in_place_cycle"} || $n->{"has_type"} || $n->{"has_const"} || defined $n->{"enum_values"} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{"dynamic_ref"} || defined $n->{"any_of"} || defined $n->{"one_of"} and $n->{"not_"} < 0 and $n->{"if_"} < 0 and not defined $n->{"dependencies"}
!ll&&!rl&&r
26018
not $crosses || $n->{"always_false"} || $n->{"in_place_cycle"} || $n->{"has_type"} || $n->{"has_const"} || defined $n->{"enum_values"} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{"dynamic_ref"} || defined $n->{"any_of"} || defined $n->{"one_of"} and $n->{"not_"} < 0 and $n->{"if_"} < 0
!ll&&!rl&&r
26018
not $crosses || $n->{"always_false"} || $n->{"in_place_cycle"} || $n->{"has_type"} || $n->{"has_const"} || defined $n->{"enum_values"} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{"dynamic_ref"} || defined $n->{"any_of"} || defined $n->{"one_of"} and $n->{"not_"} < 0
!ll&&!rl&&r
26018
$crosses || $n->{'always_false'} || $n->{'in_place_cycle'} || $n->{'has_type'} || $n->{'has_const'} || defined $n->{'enum_values'} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{'dynamic_ref'} || defined $n->{'any_of'} || defined $n->{'one_of'}
l!l&&r!l&&!r
26018
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords or $n->has_array_keywords or $n->has_string_keywords or $n->has_number_keywords or defined $n->{"dynamic_ref"} or defined $n->{"any_of"}
l!l&&r!l&&!r
24218
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords or $n->has_array_keywords or $n->has_string_keywords or $n->has_number_keywords or defined $n->{"dynamic_ref"}
l!l&&r!l&&!r
24020
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords or $n->has_array_keywords or $n->has_string_keywords or $n->has_number_keywords
l!l&&r!l&&!r
24020
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords or $n->has_array_keywords or $n->has_string_keywords
l!l&&r!l&&!r
23120
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords or $n->has_array_keywords
l!l&&r!l&&!r
23021
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_object_keywords
l!l&&r!l&&!r
23021
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"} or defined $n->{"enum_values"}
l!l&&r!l&&!r
23021
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"} or $n->{"has_const"}
l!l&&r!l&&!r
23021
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"has_type"}
l!l&&r!l&&!r
22121
$crosses or $n->{"always_false"} or $n->{"in_place_cycle"}
l!l&&r!l&&!r
0242
$crosses or $n->{"always_false"}
l!l&&r!l&&!r
0044
MC/DC0%0/18
$n->{'always_true'} || !($crosses || $n->{'always_false'} || $n->{'in_place_cycle'} || $n->{'has_type'} || $n->{'has_const'} || defined $n->{'enum_values'} || $n->has_object_keywords || $n->has_array_keywords || $n->has_string_keywords || $n->has_number_keywords || defined $n->{'dynamic_ref'} || defined $n->{'any_of'} || defined $n->{'one_of'}) && $n->{'not_'} < 0 && $n->{'if_'} < 0 && !defined($n->{'dependencies'}) && !grep({not $self->is_trivial($_);} @children)
too many conditions
491 44 ▶ return $self->{trivial}{$node_id} = $trivial ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$trivial ? : 0 44 44
492 }
493  
494 # The statements of a child's sub, to run in place of "return 0 unless child(subject)", or undef when the child is not
495 # worth or not safe to inline. The child's body is generated as usual, its locals are renamed (its subject becomes the
496 # subject, every other name gets a suffix for the inlining depth, string literals and sub references untouched) and its
497 # final "return 1" dropped: its "return 0" fails the caller, as the call it replaces would.
498 2 my $LOCAL_RE = qr/('(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|\x01[^\x02]*\x02)|\$(x|tx|p|v|k|f|w|i|r|(?:[nmesgdcl]|any|one)\d+(?:_\d+)?)\b/;
499  
500 23 ▶sub inline_child {
Subroutine inline_child: called CC=20 SCAR=34.7
Pod undocumented
501 23 my ($self, $node_id, $subject, $source) = @_;
502 23 ▶ return undef if !$INLINE_CHILDREN || $self->{inline_depth} >= $MAX_INLINE_DEPTH;
Branch: 1 branch
BranchTrueFalseTotal
if not $INLINE_CHILDREN or $self->{"inline_depth"} >= $MAX_INLINE_DEPTH 0 23 23
Condition33%1/3
not $INLINE_CHILDREN or $self->{"inline_depth"} >= $MAX_INLINE_DEPTH
l!l&&r!l&&!r
0023
MC/DC0%0/2
not $INLINE_CHILDREN or $self->{"inline_depth"} >= $MAX_INLINE_DEPTH
not $INLINE_CHILDREN $self->{"inline_depth"} >= $MAX_INLINE_DEPTH
Truth table33%1/3
not(A) or B
A= not $INLINE_CHILDRENB= $self->{"inline_depth"} >= $MAX_INLINE_DEPTH
ABresult
1X1
011
000
503 23 my $target = $self->elide($node_id);
504 23 my $n = $self->{nodes}[$target];
505 23 ▶ my $crosses = $self->{program}{uses_dynamic_scope} && $n->{resource_id} != $source;
Condition33%1/3
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
!ll&&!rl&&r
2300
MC/DC0%0/2
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
$self->{'program'}{'uses_dynamic_scope'} $n->{'resource_id'} != $source
Truth table33%1/3
A && B
A= $self->{'program'}{'uses_dynamic_scope'}B= $n->{'resource_id'} != $source
ABresult
0X0
100
111
506 return undef if $crosses || $n->{always_true} || $n->{always_false} || $n->{in_place_cycle}
507 23 ▶ || $n->{unevaluated_properties} >= 0 || $n->{unevaluated_items} >= 0 || (grep { $_ == $target } @{ $self->{generating} })
Branch: 1 branch
BranchTrueFalseTotal
if $crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0 or grep {$_ == $target;} @{$$self{"generating"};} or $n->is_type_only or $self->is_inline_leaf($n) 17 6 23
Condition45%11/24
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0 or grep {$_ == $target;} @{$$self{"generating"};} or $n->is_type_only or $self->is_inline_leaf($n)
l!l&&r!l&&!r
1526
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0 or grep {$_ == $target;} @{$$self{"generating"};} or $n->is_type_only
l!l&&r!l&&!r
0158
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0 or grep {$_ == $target;} @{$$self{"generating"};}
l!l&&r!l&&!r
0023
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0
l!l&&r!l&&!r
0023
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0
l!l&&r!l&&!r
0023
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"}
l!l&&r!l&&!r
0023
$crosses or $n->{"always_true"} or $n->{"always_false"}
l!l&&r!l&&!r
0023
$crosses or $n->{"always_true"}
l!l&&r!l&&!r
0023
MC/DC22%2/9
$crosses or $n->{"always_true"} or $n->{"always_false"} or $n->{"in_place_cycle"} or $n->{"unevaluated_properties"} >= 0 or $n->{"unevaluated_items"} >= 0 or grep {$_ == $target;} @{$$self{"generating"};} or $n->is_type_only or $self->is_inline_leaf($n)
$crosses $n->{"always_true"} $n->{"always_false"} $n->{"in_place_cycle"} $n->{"unevaluated_properties"} >= 0 $n->{"unevaluated_items"} >= 0 grep {$_ == $target;} @{$$self{"generating"};} $n->is_type_only $self->is_inline_leaf($n)
Truth table30%3/10
A or B or C or D or E or F or G or H or I
A= $crossesB= $n->{"always_true"}C= $n->{"always_false"}D= $n->{"in_place_cycle"}E= $n->{"unevaluated_properties"} >= 0F= $n->{"unevaluated_items"} >= 0G= grep {$_ == $target;} @{$$self{"generating"};}H= $n->is_type_onlyI= $self->is_inline_leaf($n)
ABCDEFGHIresult
1XXXXXXXX1
01XXXXXXX1
001XXXXXX1
0001XXXXX1
00001XXXX1
000001XXX1
0000001XX1
00000001X1
0000000011
0000000000
508 || $n->is_type_only || $self->is_inline_leaf($n);
509 6 my @saved = @$self{qw(tmp uses_tx)};
510 6 $self->{inline_depth}++;
511 6 my $text = $self->generate_node_function($target, 'v');
512 6 $self->{inline_depth}--;
513 6 @$self{qw(tmp uses_tx)} = @saved;
514 6 my @lines = split /\n/, $text;
515 # sub @ {, my $x = $_[0];, the body, }
516 6 my @body = map { substr($_, 2) } @lines[ 2 .. $#lines - 1 ];
517 6 ▶ return undef if @body > $MAX_INLINE_LINES || @body < 2 || $body[-1] ne 'return 1;';
Branch: 1 branch
BranchTrueFalseTotal
if @body > $MAX_INLINE_LINES or @body < 2 or $body[-1] ne "return 1;" 0 6 6
Condition33%2/6
@body > $MAX_INLINE_LINES or @body < 2 or $body[-1] ne "return 1;"
l!l&&r!l&&!r
006
@body > $MAX_INLINE_LINES or @body < 2
l!l&&r!l&&!r
006
MC/DC0%0/3
@body > $MAX_INLINE_LINES or @body < 2 or $body[-1] ne "return 1;"
@body > $MAX_INLINE_LINES @body < 2 $body[-1] ne "return 1;"
Truth table25%1/4
A or B or C
A= @body > $MAX_INLINE_LINESB= @body < 2C= $body[-1] ne "return 1;"
ABCresult
1XX1
01X1
0011
0000
518 6 ▶ return undef if grep { /return 1|\bnext\b|\blast\b/ } @body[ 0 .. $#body - 1 ];
Branch: 1 branch
BranchTrueFalseTotal
if grep {/return 1|\bnext\b|\blast\b/u;} @body[0 .. $#body - 1] 4 2 6
519 2 my $suffix = '_' . ($self->{inline_depth} + 1);
520 2 (my $bare = $subject) =~ s/\A\$//;
521 2 for (@body[ 0 .. $#body - 1 ]) {
522 10 ▶ s/$LOCAL_RE/defined $1 ? $1 : $2 eq 'x' ? "\$$bare" : "\$$2$suffix"/ge;
Branch: 2 branches
BranchTrueFalseTotal
defined $1 ? : 4 12 16
$2 eq 'x' ? : 4 8 12
523 }
524 2 pop @body;
525 2 return \@body;
526 }
527  
528 # Flag mode: type-directed blocks, then const and enum, then the in-place applicators.
529 108 ▶sub flag_body {
Subroutine flag_body: called CC=4 SCAR=13.9
Pod undocumented
530 108 my ($self, $n) = @_;
531 108 ▶ return ['return 0;'] if $n->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_false"} 1 107 108
532 107 ▶ return ['return 1;'] if $n->{always_true};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_true"} 1 106 107
533 106 my @out;
534 106 my $flat = $self->flat_object($n);
535 106 ▶ if ($flat) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flat) 23 83 106
536 # Objects take the merged section and return; the code below still serves every other kind.
537 23 push @out, 'if (' . $self->kind_test('object', '$x') . ') {';
538 23 push @out, _indent([ @{ $self->object_section($flat, undef, 1) }, 'return 1;' ]);
539 23 push @out, '}';
540 }
541 106 ▶ push @out, @{ $self->kind_blocks($n, sub { $self->kind_section($n, $_[0], undef, 1) }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
542 106 push @out, @{ $self->const_enum($n) };
543 106 push @out, @{ $self->in_place($n, undef, undef) };
544 106 push @out, 'return 1;';
545 106 return \@out;
546 }
547  
548 # A flat composition, for object values: a node whose in-place applicators are $ref and allOf chains, where the node
549 # and every branch are plain object schemas (declared properties, required and count bounds, no type that excludes
550 # objects) and each property name resolves to one schema. Returns a node holding the merged object keywords (the C#
551 # and Rust flat fused plan), or undef.
552 106 ▶sub flat_object {
Subroutine flat_object: called CC=27 SCAR=43.6
Pod undocumented
553 106 my ($self, $n) = @_;
554 106 ▶ return undef if $n->{ref} < 0 && $n->{static_dynamic_ref} < 0 && !defined $n->{all_of};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"ref"} < 0 and $n->{"static_dynamic_ref"} < 0 and not defined $n->{"all_of"} 80 26 106
Condition100%6/6
$n->{"ref"} < 0 and $n->{"static_dynamic_ref"} < 0 and not defined $n->{"all_of"}
!ll&&!rl&&r
25180
$n->{"ref"} < 0 and $n->{"static_dynamic_ref"} < 0
!ll&&!rl&&r
32281
MC/DC100%3/3
$n->{"ref"} < 0 and $n->{"static_dynamic_ref"} < 0 and not defined $n->{"all_of"}
$n->{"ref"} < 0 $n->{"static_dynamic_ref"} < 0 not defined $n->{"all_of"}
Truth table100%4/4
A and B and not(C)
A= $n->{"ref"} < 0B= $n->{"static_dynamic_ref"} < 0C= not defined $n->{"all_of"}
ABCresult
0XX0
10X0
1100
1111
555 26 my @branches;
556 my %visited;
557 26 my $collect;
558 210 ▶ $collect = sub {
Subroutine __ANON__: called CC=26 SCAR=40.9
559 210 my ($m) = @_;
560 210 ▶ return 1 if $visited{ $m->{id} }++;
Branch: 1 branch
BranchTrueFalseTotal
if $visited{$m->{"id"}}++ 0 210 210
561 210 ▶ return 1 if $m->{always_true};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"always_true"} 0 210 210
562 210 ▶ return 0 if $m->{always_false} || $m->{in_place_cycle};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"always_false"} or $m->{"in_place_cycle"} 2 208 210
Condition66%2/3
$m->{"always_false"} or $m->{"in_place_cycle"}
l!l&&r!l&&!r
02208
MC/DC50%1/2
$m->{"always_false"} or $m->{"in_place_cycle"}
$m->{"always_false"} $m->{"in_place_cycle"}
Truth table66%2/3
A or B
A= $m->{"always_false"}B= $m->{"in_place_cycle"}
ABresult
1X1
011
000
563 208 ▶ return 0 if $self->{program}{uses_dynamic_scope} && $m->{resource_id} != $n->{resource_id};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"} 0 208 208
Condition33%1/3
$self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"}
!ll&&!rl&&r
20800
MC/DC0%0/2
$self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"}
$self->{"program"}{"uses_dynamic_scope"} $m->{"resource_id"} != $n->{"resource_id"}
Truth table33%1/3
A and B
A= $self->{"program"}{"uses_dynamic_scope"}B= $m->{"resource_id"} != $n->{"resource_id"}
ABresult
0X0
100
111
564 208 ▶ return 0 if $m->{has_const} || defined $m->{enum_values} || ($m->{has_type} && !kind_allowed($m->{type}, 'object'));
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"has_const"} or defined $m->{"enum_values"} or $m->{"has_type"} and not kind_allowed($m->{"type"}, "object") 1 207 208
Condition66%6/9
$m->{"has_const"} or defined $m->{"enum_values"} or $m->{"has_type"} and not kind_allowed($m->{"type"}, "object")
l!l&&r!l&&!r
01207
$m->{"has_const"} or defined $m->{"enum_values"}
l!l&&r!l&&!r
00208
$m->{"has_type"} and not kind_allowed($m->{"type"}, "object")
!ll&&!rl&&r
231841
MC/DC50%2/4
$m->{"has_const"} or defined $m->{"enum_values"} or $m->{"has_type"} and not kind_allowed($m->{"type"}, "object")
$m->{"has_const"} defined $m->{"enum_values"} $m->{"has_type"} not kind_allowed($m->{"type"}, "object")
Truth table60%3/5
A or B or C and not(D)
A= $m->{"has_const"}B= defined $m->{"enum_values"}C= $m->{"has_type"}D= not kind_allowed($m->{"type"}, "object")
ABCDresult
1XXX1
01XX1
00111
000X0
00100
565 return 0 if defined $m->{pattern_properties} || $m->{additional_properties} >= 0 || $m->{property_names} >= 0
566 207 ▶ || defined $m->{dependencies};
Branch: 1 branch
BranchTrueFalseTotal
if defined $m->{"pattern_properties"} or $m->{"additional_properties"} >= 0 or $m->{"property_names"} >= 0 or defined $m->{"dependencies"} 0 207 207
Condition33%3/9
defined $m->{"pattern_properties"} or $m->{"additional_properties"} >= 0 or $m->{"property_names"} >= 0 or defined $m->{"dependencies"}
l!l&&r!l&&!r
00207
defined $m->{"pattern_properties"} or $m->{"additional_properties"} >= 0 or $m->{"property_names"} >= 0
l!l&&r!l&&!r
00207
defined $m->{"pattern_properties"} or $m->{"additional_properties"} >= 0
l!l&&r!l&&!r
00207
MC/DC0%0/4
defined $m->{"pattern_properties"} or $m->{"additional_properties"} >= 0 or $m->{"property_names"} >= 0 or defined $m->{"dependencies"}
defined $m->{"pattern_properties"} $m->{"additional_properties"} >= 0 $m->{"property_names"} >= 0 defined $m->{"dependencies"}
Truth table20%1/5
A or B or C or D
A= defined $m->{"pattern_properties"}B= $m->{"additional_properties"} >= 0C= $m->{"property_names"} >= 0D= defined $m->{"dependencies"}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
567 207 ▶ return 0 if $m->{unevaluated_properties} >= 0 || $m->{unevaluated_items} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"unevaluated_properties"} >= 0 or $m->{"unevaluated_items"} >= 0 0 207 207
Condition33%1/3
$m->{"unevaluated_properties"} >= 0 or $m->{"unevaluated_items"} >= 0
l!l&&r!l&&!r
00207
MC/DC0%0/2
$m->{"unevaluated_properties"} >= 0 or $m->{"unevaluated_items"} >= 0
$m->{"unevaluated_properties"} >= 0 $m->{"unevaluated_items"} >= 0
Truth table33%1/3
A or B
A= $m->{"unevaluated_properties"} >= 0B= $m->{"unevaluated_items"} >= 0
ABresult
1X1
011
000
568 return 0 if defined $m->{dynamic_ref} || defined $m->{any_of} || defined $m->{one_of} || $m->{not_} >= 0
569 207 ▶ || $m->{if_} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if defined $m->{"dynamic_ref"} or defined $m->{"any_of"} or defined $m->{"one_of"} or $m->{"not_"} >= 0 or $m->{"if_"} >= 0 0 207 207
Condition33%4/12
defined $m->{"dynamic_ref"} or defined $m->{"any_of"} or defined $m->{"one_of"} or $m->{"not_"} >= 0 or $m->{"if_"} >= 0
l!l&&r!l&&!r
00207
defined $m->{"dynamic_ref"} or defined $m->{"any_of"} or defined $m->{"one_of"} or $m->{"not_"} >= 0
l!l&&r!l&&!r
00207
defined $m->{"dynamic_ref"} or defined $m->{"any_of"} or defined $m->{"one_of"}
l!l&&r!l&&!r
00207
defined $m->{"dynamic_ref"} or defined $m->{"any_of"}
l!l&&r!l&&!r
00207
MC/DC0%0/5
defined $m->{"dynamic_ref"} or defined $m->{"any_of"} or defined $m->{"one_of"} or $m->{"not_"} >= 0 or $m->{"if_"} >= 0
defined $m->{"dynamic_ref"} defined $m->{"any_of"} defined $m->{"one_of"} $m->{"not_"} >= 0 $m->{"if_"} >= 0
Truth table16%1/6
A or B or C or D or E
A= defined $m->{"dynamic_ref"}B= defined $m->{"any_of"}C= defined $m->{"one_of"}D= $m->{"not_"} >= 0E= $m->{"if_"} >= 0
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
570 207 push @branches, $m;
571 207 ▶ for my $c ($m->{ref}, $m->{static_dynamic_ref}, @{ $m->{all_of} // [] }) {
Condition100%2/2
$m->{"all_of"} // []
l!l
23184
MC/DC100%1/1
$m->{"all_of"} // []
$m->{"all_of"}
Truth table100%2/2
A
A= $m->{"all_of"}
Aresult
11
00
572 574 ▶ return 0 if $c >= 0 && !$collect->($self->{nodes}[ $self->elide($c) ]);
Branch: 1 branch
BranchTrueFalseTotal
if $c >= 0 and not &$collect($self->{"nodes"}[$self->elide($c)]) 1 573 574
Condition100%3/3
$c >= 0 and not &$collect($self->{"nodes"}[$self->elide($c)])
!ll&&!rl&&r
3901831
MC/DC100%2/2
$c >= 0 and not &$collect($self->{"nodes"}[$self->elide($c)])
$c >= 0 not &$collect($self->{"nodes"}[$self->elide($c)])
Truth table100%3/3
A and not(B)
A= $c >= 0B= not &$collect($self->{"nodes"}[$self->elide($c)])
ABresult
0X0
100
111
573 }
574 206 return 1;
575 26 };
576 26 my $ok = $collect->($n);
577 26 undef $collect;
578 26 ▶ return undef unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 3 23 26
579 0 my @effective = grep { defined $_->{properties} || ($_->{required} && @{ $_->{required} })
580 206 ▶ || $_->{min_properties} >= 0 || $_->{max_properties} >= 0 } @branches;
Condition58%7/12
defined $_->{'properties'} || $_->{'required'} && @{$_->{'required'};} || $_->{'min_properties'} >= 0 || $_->{'max_properties'} >= 0
l!l&&r!l&&!r
184022
defined $_->{"properties"} or $_->{"required"} and @{$_->{"required"};} or $_->{"min_properties"} >= 0
l!l&&r!l&&!r
184022
defined $_->{"properties"} or $_->{"required"} and @{$_->{"required"};}
l!l&&r!l&&!r
184022
$_->{"required"} and @{$_->{"required"};}
!ll&&!rl&&r
2200
MC/DC20%1/5
defined $_->{'properties'} || $_->{'required'} && @{$_->{'required'};} || $_->{'min_properties'} >= 0 || $_->{'max_properties'} >= 0
defined $_->{"properties"} $_->{"required"} @{$_->{"required"};} $_->{"min_properties"} >= 0 $_->{'max_properties'} >= 0
Truth table25%2/8
A or B and C or D || E
A= defined $_->{"properties"}B= $_->{"required"}C= @{$_->{"required"};}D= $_->{"min_properties"} >= 0E= $_->{'max_properties'} >= 0
ABCDEresult
1XXXX1
011XX1
00X1X1
0101X1
00X011
010011
00X000
010000
581 23 ▶ return undef if @effective < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @effective < 2 0 23 23
582 0 ▶ my $same = sub {
Subroutine __ANON__: not called CC=5 SCAR=34.0
583 0 my ($a, $b) = @_;
584 0 my $x = $self->{nodes}[ $self->elide($a) ];
585 0 my $y = $self->{nodes}[ $self->elide($b) ];
586 return $x->{id} == $y->{id} || ($x->is_type_only && $y->is_type_only && $x->{type} == $y->{type}
587 0 ▶ && $x->{dialect} == $y->{dialect});
Condition0%0/12
$x->{'id'} == $y->{'id'} || $x->is_type_only && $y->is_type_only && $x->{'type'} == $y->{'type'} && $x->{'dialect'} == $y->{'dialect'}
l!l&&r!l&&!r
000
$x->is_type_only and $y->is_type_only and $x->{"type"} == $y->{"type"} and $x->{"dialect"} == $y->{"dialect"}
!ll&&!rl&&r
000
$x->is_type_only and $y->is_type_only and $x->{"type"} == $y->{"type"}
!ll&&!rl&&r
000
$x->is_type_only and $y->is_type_only
!ll&&!rl&&r
000
MC/DC0%0/5
$x->{'id'} == $y->{'id'} || $x->is_type_only && $y->is_type_only && $x->{'type'} == $y->{'type'} && $x->{'dialect'} == $y->{'dialect'}
$x->{'id'} == $y->{'id'} $x->is_type_only $y->is_type_only $x->{"type"} == $y->{"type"} $x->{"dialect"} == $y->{"dialect"}
Truth table0%0/6
A || B and C and D and E
A= $x->{'id'} == $y->{'id'}B= $x->is_type_onlyC= $y->is_type_onlyD= $x->{"type"} == $y->{"type"}E= $x->{"dialect"} == $y->{"dialect"}
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
588 23 };
589 my $merged = JSON::Schema::Corvus::Node->new(id => $n->{id}, resource_id => $n->{resource_id},
590 23 dialect => $n->{dialect}, location => $n->{location}, pointer => $n->{pointer});
591 23 my (%properties, @order, @required, %required);
592 23 for my $b (@branches) {
593 206 ▶ for my $name (@{ $b->{property_order} // [] }) {
Condition100%2/2
$b->{"property_order"} // []
l!l
18422
MC/DC100%1/1
$b->{"property_order"} // []
$b->{"property_order"}
Truth table100%2/2
A
A= $b->{"property_order"}
Aresult
11
00
594 1403 my $child = $b->{properties}{$name};
595 1403 my $existing = $properties{$name};
596 1403 ▶ if (!defined $existing || $self->{nodes}[ $self->elide($existing) ]{always_true}) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $existing or $self->{'nodes'}[$self->elide($existing)]{'always_true'}) { } 1403 0 1403
elsif (not &$same($existing, $child) || $self->{'nodes'}[$self->elide($child)]{'always_true'}) { } 0 0 0
Condition33%1/3
not defined $existing or $self->{"nodes"}[$self->elide($existing)]{"always_true"}
l!l&&r!l&&!r
140300
MC/DC0%0/2
not defined $existing or $self->{"nodes"}[$self->elide($existing)]{"always_true"}
not defined $existing $self->{"nodes"}[$self->elide($existing)]{"always_true"}
Truth table33%1/3
not(A) or B
A= not defined $existingB= $self->{"nodes"}[$self->elide($existing)]{"always_true"}
ABresult
1X1
011
000
597 1403 ▶ push @order, $name unless defined $existing;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $existing 1403 0 1403
598 1403 $properties{$name} = $child;
599 }
600 ▶ elsif (!$same->($existing, $child) && !$self->{nodes}[ $self->elide($child) ]{always_true}) {
Condition0%0/3
&$same($existing, $child) || $self->{'nodes'}[$self->elide($child)]{'always_true'}
l!l&&r!l&&!r
000
MC/DC0%0/2
&$same($existing, $child) || $self->{'nodes'}[$self->elide($child)]{'always_true'}
&$same($existing, $child) $self->{'nodes'}[$self->elide($child)]{'always_true'}
Truth table0%0/3
A || B
A= &$same($existing, $child)B= $self->{'nodes'}[$self->elide($child)]{'always_true'}
ABresult
1X1
011
000
601 0 return undef;
602 }
603 }
604 206 ▶ for my $name (@{ $b->{required} // [] }) {
Condition50%1/2
$b->{"required"} // []
l!l
0206
MC/DC0%0/1
$b->{"required"} // []
$b->{"required"}
Truth table50%1/2
A
A= $b->{"required"}
Aresult
11
00
605 0 ▶ push @required, $name unless $required{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $required{$name}++ 0 0 0
606 }
607 206 ▶ $merged->{min_properties} = $b->{min_properties} if $b->{min_properties} > $merged->{min_properties};
Branch: 1 branch
BranchTrueFalseTotal
if $b->{"min_properties"} > $merged->{"min_properties"} 0 206 206
608 206 ▶ if ($b->{max_properties} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b->{"max_properties"} >= 0) 0 206 206
609 $merged->{max_properties} = $merged->{max_properties} < 0 || $b->{max_properties} < $merged->{max_properties}
610 0 ▶ ? $b->{max_properties} : $merged->{max_properties};
Branch: 1 branch
BranchTrueFalseTotal
$merged->{'max_properties'} < 0 || $b->{'max_properties'} < $merged->{'max_properties'} ? : 0 0 0
Condition0%0/3
$merged->{"max_properties"} < 0 or $b->{"max_properties"} < $merged->{"max_properties"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$merged->{"max_properties"} < 0 or $b->{"max_properties"} < $merged->{"max_properties"}
$merged->{"max_properties"} < 0 $b->{"max_properties"} < $merged->{"max_properties"}
Truth table0%0/3
A or B
A= $merged->{"max_properties"} < 0B= $b->{"max_properties"} < $merged->{"max_properties"}
ABresult
1X1
011
000
611 }
612 }
613 23 ▶ if (%properties) {
Branch: 1 branch
BranchTrueFalseTotal
if (%properties) 23 0 23
614 23 $merged->{properties} = \%properties;
615 23 $merged->{property_order} = \@order;
616 }
617 23 ▶ $merged->{required} = \@required if @required;
Branch: 1 branch
BranchTrueFalseTotal
if @required 0 23 23
618 23 return $merged;
619 }
620  
621 # The per-kind sections: kinds with work get a branch, allowed kinds without work fall through, and a type restriction
622 # fails every other kind.
623 106 ▶sub kind_blocks {
Subroutine kind_blocks: called CC=13 SCAR=26.0
Pod undocumented
624 106 my ($self, $n, $section) = @_;
625 106 ▶ my $mask = $n->{has_type} ? $n->{type} : T_ALL;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'has_type'} ? : 58 48 106
626 106 my @allowed = grep { kind_allowed($mask, $_) } @KINDS;
627 106 ▶ return ['return 0;'] unless @allowed;
Branch: 1 branch
BranchTrueFalseTotal
unless @allowed 0 106 106
628 106 my @with_work = grep { @{ $_->[1] } } map { [ $_, $section->($_) ] } @allowed;
629 106 my @out;
630 106 ▶ if ($n->{has_type} && @allowed == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"has_type"} and @allowed == 1) 50 56 106
Condition100%3/3
$n->{"has_type"} and @allowed == 1
!ll&&!rl&&r
48850
MC/DC100%2/2
$n->{"has_type"} and @allowed == 1
$n->{"has_type"} @allowed == 1
Truth table100%3/3
A and B
A= $n->{"has_type"}B= @allowed == 1
ABresult
0X0
100
111
631 50 push @out, 'return 0 unless ' . _wrap($self->kind_test($allowed[0], '$x')) . ';';
632 50 ▶ push @out, @{ $with_work[0][1] } if @with_work;
Branch: 1 branch
BranchTrueFalseTotal
if @with_work 29 21 50
633 50 return \@out;
634 }
635 56 my %worked = map { $_->[0] => 1 } @with_work;
636 56 my @rest_ok = grep { !$worked{$_} } @allowed;
637 56 for my $i (0 .. $#with_work) {
638 23 my ($k, $lines) = @{ $with_work[$i] };
639 23 ▶ push @out, ($i == 0 ? 'if (' : '} elsif (') . $self->kind_test($k, '$x') . ') {';
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 23 0 23
640 23 push @out, _indent($lines);
641 }
642 56 ▶ my $restricted = $n->{has_type} && @allowed < @KINDS;
Condition66%2/3
$n->{'has_type'} && @allowed < @KINDS
!ll&&!rl&&r
4808
MC/DC50%1/2
$n->{'has_type'} && @allowed < @KINDS
$n->{'has_type'} @allowed < @KINDS
Truth table66%2/3
A && B
A= $n->{'has_type'}B= @allowed < @KINDS
ABresult
0X0
100
111
643 56 ▶ if (@with_work) {
Branch: 2 branches
BranchTrueFalseTotal
if (@with_work) { } 23 33 56
elsif ($restricted) { } 0 33 33
644 23 ▶ if ($restricted) {
Branch: 1 branch
BranchTrueFalseTotal
if ($restricted) 8 15 23
645 8 ▶ if (!@rest_ok) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @rest_ok) { } 0 8 8
646 0 push @out, '} else {';
647 }
648 else {
649 8 push @out, '} elsif (!(' . join(' || ', map { $self->kind_test($_, '$x') } @rest_ok) . ')) {';
650 }
651 8 push @out, ' return 0;';
652 }
653 23 push @out, '}';
654 }
655 elsif ($restricted) {
656 0 push @out, 'return 0 unless ' . join(' || ', map { $self->kind_test($_, '$x') } @rest_ok) . ';';
657 }
658 56 return \@out;
659 }
660  
661 354 ▶sub kind_section {
Subroutine kind_section: called CC=8 SCAR=20.8
Pod undocumented
662 354 my ($self, $n, $kind, $e, $flag_layout) = @_;
663 354 ▶ my $integer_only = $n->{has_type} && ($n->{type} & T_INTEGER) && !($n->{type} & T_NUMBER);
Condition83%5/6
$n->{'has_type'} && $n->{'type'} & 64 && !($n->{'type'} & 16)
!ll&&!rl&&r
344010
$n->{"has_type"} and $n->{"type"} & 64
!ll&&!rl&&r
2885610
MC/DC66%2/3
$n->{'has_type'} && $n->{'type'} & 64 && !($n->{'type'} & 16)
$n->{"has_type"} $n->{"type"} & 64 !($n->{'type'} & 16)
Truth table75%3/4
A and B && not(C)
A= $n->{"has_type"}B= $n->{"type"} & 64C= !($n->{'type'} & 16)
ABCresult
0XX0
10X0
1100
1111
664 354 ▶ return $self->object_section($n, $e, $flag_layout) if $kind eq 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "object" 69 285 354
665 285 ▶ return $self->array_section($n, $e) if $kind eq 'array';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "array" 54 231 285
666 231 ▶ return $self->string_section($n) if $kind eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "string" 59 172 231
667 172 ▶ if ($kind eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq "number") 64 108 172
668 64 my @lines;
669 64 ▶ push @lines, 'return 0 unless ' . $self->_integer_test('$x', $n->{dialect}) . ';' if $integer_only;
Branch: 1 branch
BranchTrueFalseTotal
if $integer_only 10 54 64
670 64 return [ @lines, @{ $self->number_section($n) } ];
671 }
672 108 return [];
673 }
674  
675 106 ▶sub const_enum {
Subroutine const_enum: called CC=6 SCAR=22.5
Pod undocumented
676 106 my ($self, $n) = @_;
677 106 my @out;
678 106 ▶ if ($n->{has_const}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"has_const"}) 4 102 106
679 4 ▶ if (_is_primitive($n->{const_value})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_primitive($n->{'const_value'})) { } 2 2 4
680 2 push @out, 'return 0 unless ' . _wrap($self->eq_test('$x', $n->{const_value})) . ';';
681 }
682 else {
683 push @out, 'return 0 unless JSON::Schema::Corvus::Runtime::equal($x, ' . $self->json_constant($n->{const_value})
684 2 . ');';
685 }
686 }
687 106 ▶ if (defined $n->{enum_values}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->{"enum_values"}) 0 106 106
688 0 my $values = $n->{enum_values};
689 0 ▶ if (!@$values) {
Branch: 2 branches
BranchTrueFalseTotal
if (not @$values) { } 0 0 0
elsif (not grep({not _is_primitive($_);} @$values)) { } 0 0 0
690 0 push @out, 'return 0;';
691 }
692 0 elsif (!grep { !_is_primitive($_) } @$values) {
693 0 push @out, 'return 0 unless ' . _wrap($self->enum_test($values, '$x')) . ';';
694 }
695 else {
696 0 push @out, 'return 0 unless JSON::Schema::Corvus::Runtime::includes(' . $self->json_constant($values) . ', $x);';
697 }
698 }
699 106 return \@out;
700 }
701  
702 # --- Objects ---
703  
704 92 ▶sub object_section {
Subroutine object_section: called CC=31 SCAR=38.8
Pod undocumented
705 92 my ($self, $n, $e, $flag_layout) = @_;
706 92 my @out;
707 92 my $props = $n->{properties};
708 92 ▶ my @names = @{ $n->{property_order} // [] };
Condition100%2/2
$n->{"property_order"} // []
l!l
3557
MC/DC100%1/1
$n->{"property_order"} // []
$n->{"property_order"}
Truth table100%2/2
A
A= $n->{"property_order"}
Aresult
11
00
709 92 ▶ my $required = $n->{required} // [];
Condition100%2/2
$n->{"required"} // []
l!l
290
MC/DC100%1/1
$n->{"required"} // []
$n->{"required"}
Truth table100%2/2
A
A= $n->{"required"}
Aresult
11
00
710 92 ▶ my $all_patterns = $n->{pattern_properties} // [];
Condition50%1/2
$n->{"pattern_properties"} // []
l!l
092
MC/DC0%0/1
$n->{"pattern_properties"} // []
$n->{"pattern_properties"}
Truth table50%1/2
A
A= $n->{"pattern_properties"}
Aresult
11
00
711 my $additional_needs_match = $n->{additional_properties} >= 0
712 92 ▶ && !$self->{nodes}[ $self->elide($n->{additional_properties}) ]{always_true};
Condition66%2/3
$n->{'additional_properties'} >= 0 && !$self->{'nodes'}[$self->elide($n->{'additional_properties'})]{'always_true'}
!ll&&!rl&&r
82010
MC/DC50%1/2
$n->{'additional_properties'} >= 0 && !$self->{'nodes'}[$self->elide($n->{'additional_properties'})]{'always_true'}
$n->{'additional_properties'} >= 0 !$self->{'nodes'}[$self->elide($n->{'additional_properties'})]{'always_true'}
Truth table66%2/3
A && not(B)
A= $n->{'additional_properties'} >= 0B= !$self->{'nodes'}[$self->elide($n->{'additional_properties'})]{'always_true'}
ABresult
0X0
100
111
713 # A pattern property whose schema is true does nothing unless marking or additionalProperties needs it.
714 my @patterns = defined $e || $additional_needs_match ? @$all_patterns
715 0 ▶ : grep { !$self->{nodes}[ $self->elide($_->{node}) ]{always_true} } @$all_patterns;
Branch: 1 branch
BranchTrueFalseTotal
defined $e || $additional_needs_match ? : 10 82 92
Condition66%2/3
defined $e or $additional_needs_match
l!l&&r!l&&!r
01082
MC/DC50%1/2
defined $e or $additional_needs_match
defined $e $additional_needs_match
Truth table66%2/3
A or B
A= defined $eB= $additional_needs_match
ABresult
1X1
011
000
716 92 ▶ my $ap = $n->{additional_properties} >= 0 ? $self->{nodes}[ $self->elide($n->{additional_properties}) ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'additional_properties'} >= 0 ? : 10 82 92
717 92 ▶ my $pn = $n->{property_names} >= 0 ? $self->{nodes}[ $self->elide($n->{property_names}) ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'property_names'} >= 0 ? : 2 90 92
718 92 ▶ my $ap_needs_loop = $ap && !$ap->{always_true};
Condition66%2/3
$ap && !$ap->{'always_true'}
!ll&&!rl&&r
82010
MC/DC50%1/2
$ap && !$ap->{'always_true'}
$ap !$ap->{'always_true'}
Truth table66%2/3
A && not(B)
A= $apB= !$ap->{'always_true'}
ABresult
0X0
100
111
719 92 ▶ my $pn_needs_loop = $pn && !$pn->{always_true};
Condition66%2/3
$pn && !$pn->{'always_true'}
!ll&&!rl&&r
9002
MC/DC50%1/2
$pn && !$pn->{'always_true'}
$pn !$pn->{'always_true'}
Truth table66%2/3
A && not(B)
A= $pnB= !$pn->{'always_true'}
ABresult
0X0
100
111
720 92 my %required = map { $_ => 1 } @$required;
721 92 ▶ my $all_required = !$props || !grep { !$required{$_} } @names;
Condition100%3/3
$props && grep({not $required{$_};} @names)
!ll&&!rl&&r
57134
MC/DC100%2/2
$props && grep({not $required{$_};} @names)
$props grep({not $required{$_};} @names)
Truth table100%3/3
A && B
A= $propsB= grep({not $required{$_};} @names)
ABresult
0X0
100
111
722 92 ▶ my $probeable = @names <= $MAX_PROBED_PROPERTIES || ($all_required && @names <= $MAX_PROBED_REQUIRED);
Condition50%3/6
@names <= $MAX_PROBED_PROPERTIES || $all_required && @names <= $MAX_PROBED_REQUIRED
l!l&&r!l&&!r
66026
$all_required and @names <= $MAX_PROBED_REQUIRED
!ll&&!rl&&r
2600
MC/DC33%1/3
@names <= $MAX_PROBED_PROPERTIES || $all_required && @names <= $MAX_PROBED_REQUIRED
@names <= $MAX_PROBED_PROPERTIES $all_required @names <= $MAX_PROBED_REQUIRED
Truth table50%2/4
A || B and C
A= @names <= $MAX_PROBED_PROPERTIESB= $all_requiredC= @names <= $MAX_PROBED_REQUIRED
ABCresult
1XX1
0111
00X0
0100
723  
724 # Counts and required names first: they fail fast without looking at any value.
725 92 ▶ push @out, "return 0 if keys(%\$x) < $n->{min_properties};" if $n->{min_properties} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"min_properties"} > 0 0 92 92
726 92 ▶ push @out, "return 0 if keys(%\$x) > $n->{max_properties};" if $n->{max_properties} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"max_properties"} >= 0 0 92 92
727 92 push @out, @{ $self->required_test('$x', $required) };
728  
729 92 ▶ my $simple = !defined $e && !@patterns && !$pn_needs_loop;
Condition50%3/6
defined $e || @patterns || $pn_needs_loop
l!l&&r!l&&!r
0290
defined $e or @patterns
l!l&&r!l&&!r
0092
MC/DC33%1/3
defined $e || @patterns || $pn_needs_loop
defined $e @patterns $pn_needs_loop
Truth table50%2/4
A or B || C
A= defined $eB= @patternsC= $pn_needs_loop
ABCresult
1XX1
01X1
0011
0000
730 92 ▶ if ($simple && !$ap_needs_loop && $probeable) {
Branch: 3 branches
BranchTrueFalseTotal
if ($simple and not $ap_needs_loop and $probeable) { } 56 36 92
elsif ($simple and $ap and $ap->{'always_false'} and $probeable) { } 0 36 36
elsif ($simple and not @names and $ap and $ap_needs_loop) { } 8 28 36
Condition100%6/6
$simple and not $ap_needs_loop and $probeable
!ll&&!rl&&r
102656
$simple and not $ap_needs_loop
!ll&&!rl&&r
2882
MC/DC100%3/3
$simple and not $ap_needs_loop and $probeable
$simple not $ap_needs_loop $probeable
Truth table100%4/4
A and not(B) and C
A= $simpleB= not $ap_needs_loopC= $probeable
ABCresult
0XX0
10X0
1100
1111
731 56 push @out, @{ $self->object_probe($n, \@names, $required) };
732 }
733 ▶ elsif ($simple && $ap && $ap->{always_false} && $probeable) {
Condition66%6/9
$simple and $ap and $ap->{"always_false"} and $probeable
!ll&&!rl&&r
3600
$simple and $ap and $ap->{"always_false"}
!ll&&!rl&&r
2880
$simple and $ap
!ll&&!rl&&r
2268
MC/DC0%0/4
$simple and $ap and $ap->{"always_false"} and $probeable
$simple $ap $ap->{"always_false"} $probeable
Truth table60%3/5
A and B and C and D
A= $simpleB= $apC= $ap->{"always_false"}D= $probeable
ABCDresult
0XXX0
10XX0
110X0
11100
11111
734 # additionalProperties: false: the names must all be declared, then each declared name is probed.
735 0 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) { } 0 0 0
736 0 my $set = $self->constant('{' . join(', ', map { perl_string($_) . ' => 1' } @names) . '}');
737 0 push @out, "for (keys %\$x) { return 0 unless exists $set\->{\$_} }";
738 }
739 else {
740 0 push @out, 'return 0 if %$x;';
741 }
742 0 push @out, @{ $self->object_probe($n, \@names, $required) };
743 }
744 ▶ elsif ($simple && !@names && $ap && $ap_needs_loop) {
Condition77%7/9
$simple and not @names and $ap and $ap_needs_loop
!ll&&!rl&&r
2808
$simple and not @names and $ap
!ll&&!rl&&r
2808
$simple and not @names
!ll&&!rl&&r
2268
MC/DC50%2/4
$simple and not @names and $ap and $ap_needs_loop
$simple not @names $ap $ap_needs_loop
Truth table60%3/5
A and not(B) and C and D
A= $simpleB= not @namesC= $apD= $ap_needs_loop
ABCDresult
0XXX0
10XX0
110X0
11100
11111
745 8 push @out, @{ $self->object_values($n, $ap) };
746 }
747 else {
748 28 push @out, @{ $self->object_loop($n, $e, \@patterns, $ap, $pn, $ap_needs_loop, $pn_needs_loop) };
749 }
750 0 ▶ push @out, @{ $self->object_dependencies($n, $e, $flag_layout) } if $n->{dependencies};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"dependencies"} 0 92 92
751 92 return \@out;
752 }
753  
754 92 ▶sub required_test {
Subroutine required_test: called CC=3 SCAR=12.0
Pod undocumented
755 92 my ($self, $v, $required) = @_;
756 92 ▶ return [] unless @$required;
Branch: 1 branch
BranchTrueFalseTotal
unless @$required 90 2 92
757 2 ▶ if (@$required <= $MAX_REQUIRED_TESTS) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$required <= $MAX_REQUIRED_TESTS) 2 0 2
758 2 return [ 'return 0 if ' . join(' || ', map { '!exists ' . $v . '->{' . perl_string($_) . '}' } @$required) . ';' ];
759 }
760 0 my $names = $self->constant('[' . join(', ', map { perl_string($_) } @$required) . ']');
761 0 return [ "for ($names\->\@*) { return 0 unless exists $v\->{\$_} }" ];
762 }
763  
764 # Each declared name looked up directly (required names are already known to be present).
765 56 ▶sub object_probe {
Subroutine object_probe: called CC=8 SCAR=20.9
Pod undocumented
766 56 my ($self, $n, $names, $required) = @_;
767 56 my @out;
768 56 my %required = map { $_ => 1 } @$required;
769 56 for my $name (@$names) {
770 22 my $child = $n->{properties}{$name};
771 22 my $check = $self->call($child, '$p', $n->{resource_id});
772 22 ▶ next if $check eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check eq 1 2 20 22
773 20 my $key = perl_string($name);
774 my $nested = $INLINE_ARRAYS ? $self->simple_array_lines($self->{nodes}[ $self->elide($child) ], '$p', '$w',
775 20 ▶ $n->{resource_id}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$INLINE_ARRAYS ? : 20 0 20
776 20 my $lines;
777 20 ▶ if ($nested) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nested) { } 1 19 20
elsif ($check eq '0') { } 0 19 19
778 1 $lines = $nested;
779 }
780 elsif ($check eq '0') {
781 0 push @out, "return 0 if exists \$x->{$key};";
782 0 next;
783 }
784 else {
785 19 my $inlined = $self->inline_child($child, '$p', $n->{resource_id});
786 19 ▶ $lines = $inlined // [ 'return 0 unless ' . _wrap($check) . ';' ];
Condition100%2/2
$inlined // ['return 0 unless ' . _wrap($check) . ';']
l!l
217
MC/DC100%1/1
$inlined // ['return 0 unless ' . _wrap($check) . ';']
$inlined
Truth table100%2/2
A
A= $inlined
Aresult
11
00
787 }
788 20 ▶ if ($required{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($required{$name}) { } 1 19 20
789 1 push @out, '{', " my \$p = \$x->{$key};", _indent($lines), '}';
790 }
791 else {
792 19 push @out, "if (exists \$x->{$key}) {", " my \$p = \$x->{$key};", _indent($lines), '}';
793 }
794 }
795 56 return \@out;
796 }
797  
798 # A map: only the values matter.
799 8 ▶sub object_values {
Subroutine object_values: called CC=2 SCAR=7.0
Pod undocumented
800 8 my ($self, $n, $ap) = @_;
801 8 my $check = $self->call($ap->{id}, '$v', $n->{resource_id});
802 8 ▶ return ['return 0 if %$x;'] if $check eq '0';
Branch: 1 branch
BranchTrueFalseTotal
if $check eq 0 0 8 8
803 8 return [ 'for my $v (values %$x) {', ' return 0 unless ' . _wrap($check) . ';', '}' ];
804 }
805  
806 # One pass over the instance's properties: names dispatched to their subschemas, then patterns and additional.
807 28 ▶sub object_loop {
Subroutine object_loop: called CC=36 SCAR=52.4
Pod undocumented
808 28 my ($self, $n, $e, $patterns, $ap, $pn, $ap_needs_loop, $pn_needs_loop) = @_;
809 28 my @out;
810 28 ▶ my @names = @{ $n->{property_order} // [] };
Condition100%2/2
$n->{"property_order"} // []
l!l
262
MC/DC100%1/1
$n->{"property_order"} // []
$n->{"property_order"}
Truth table100%2/2
A
A= $n->{"property_order"}
Aresult
11
00
811 28 ▶ my $props = $n->{properties} // {};
Condition100%2/2
$n->{"properties"} // {}
l!l
262
MC/DC100%1/1
$n->{"properties"} // {}
$n->{"properties"}
Truth table100%2/2
A
A= $n->{"properties"}
Aresult
11
00
812 28 ▶ my $needs_value = @names || @$patterns || $ap_needs_loop;
Condition66%4/6
@names || @$patterns || $ap_needs_loop
l!l&&r!l&&!r
2620
@names or @$patterns
l!l&&r!l&&!r
2602
MC/DC0%0/3
@names || @$patterns || $ap_needs_loop
@names @$patterns $ap_needs_loop
Truth table50%2/4
A or B || C
A= @namesB= @$patternsC= $ap_needs_loop
ABCresult
1XX1
01X1
0011
0000
813 28 my @body;
814 28 ▶ push @body, 'my $v = $x->{$k};' if $needs_value;
Branch: 1 branch
BranchTrueFalseTotal
if $needs_value 28 0 28
815 28 ▶ push @body, 'return 0 unless ' . _wrap($self->call($pn->{id}, '$k', $n->{resource_id})) . ';' if $pn_needs_loop;
Branch: 1 branch
BranchTrueFalseTotal
if $pn_needs_loop 2 26 28
816 28 ▶ my $mark = defined $e ? "$e\->{\$k} = 1;" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 28 28
817 28 ▶ my $has_ap_tail = $ap && ($ap_needs_loop || defined $mark);
Condition50%3/6
$ap && ($ap_needs_loop || defined $mark)
!ll&&!rl&&r
2602
$ap_needs_loop or defined $mark
l!l&&r!l&&!r
200
MC/DC33%1/3
$ap && ($ap_needs_loop || defined $mark)
$ap $ap_needs_loop defined $mark
Truth table50%2/4
A && B or C
A= $apB= $ap_needs_loopC= defined $mark
ABCresult
0XX0
1000
11X1
1011
818 # When nothing follows the declared names (no patterns), a declared name goes on to the next property.
819 28 ▶ my $matched = @$patterns && $has_ap_tail ? $self->scratch('m') : undef;
Branch: 1 branch
BranchTrueFalseTotal
@$patterns && $has_ap_tail ? : 0 28 28
Condition33%1/3
@$patterns and $has_ap_tail
!ll&&!rl&&r
2800
MC/DC0%0/2
@$patterns and $has_ap_tail
@$patterns $has_ap_tail
Truth table33%1/3
A and B
A= @$patternsB= $has_ap_tail
ABresult
0X0
100
111
820 28 ▶ push @body, "my $matched = 0;" if $matched;
Branch: 1 branch
BranchTrueFalseTotal
if $matched 0 28 28
821 28 ▶ if (@names) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names) 26 2 28
822 26 my $continue_after = !@$patterns;
823 0 ▶ my $case_body = sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
824 0 my ($name) = @_;
825 0 my @lines;
826 0 my $check = $self->call($props->{$name}, '$v', $n->{resource_id});
827 0 ▶ if ($check ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($check ne 1) 0 0 0
828 0 my $inlined = $self->inline_child($props->{$name}, '$v', $n->{resource_id});
829 0 ▶ push @lines, @{ $inlined // [ 'return 0 unless ' . _wrap($check) . ';' ] };
Condition0%0/2
$inlined // ['return 0 unless ' . _wrap($check) . ';']
l!l
00
MC/DC0%0/1
$inlined // ['return 0 unless ' . _wrap($check) . ';']
$inlined
Truth table0%0/2
A
A= $inlined
Aresult
11
00
830 }
831 0 ▶ push @lines, $mark if $mark;
Branch: 1 branch
BranchTrueFalseTotal
if $mark 0 0 0
832 0 ▶ push @lines, "$matched = 1;" if $matched;
Branch: 1 branch
BranchTrueFalseTotal
if $matched 0 0 0
833 0 ▶ push @lines, 'next;' if $continue_after && $has_ap_tail;
Branch: 1 branch
BranchTrueFalseTotal
if $continue_after and $has_ap_tail 0 0 0
Condition0%0/3
$continue_after and $has_ap_tail
!ll&&!rl&&r
000
MC/DC0%0/2
$continue_after and $has_ap_tail
$continue_after $has_ap_tail
Truth table0%0/3
A and B
A= $continue_afterB= $has_ap_tail
ABresult
0X0
100
111
834 0 return \@lines;
835 26 };
836 26 ▶ if (@names <= $MAX_CHAIN_NAMES) {
Branch: 1 branch
BranchTrueFalseTotal
if (@names <= $MAX_CHAIN_NAMES) { } 0 26 26
837 0 for my $i (0 .. $#names) {
838 0 ▶ push @body, ($i == 0 ? 'if' : '} elsif') . ' ($k eq ' . perl_string($names[$i]) . ') {';
Branch: 1 branch
BranchTrueFalseTotal
$i == 0 ? : 0 0 0
839 0 push @body, _indent($case_body->($names[$i]));
840 }
841 0 push @body, '}';
842 }
843 else {
844 # A hash from names to subs: one lookup instead of a chain of comparisons.
845 26 my ($table, $trivial) = $self->dispatch_table($n, \@names);
846 26 push @body, "if (my \$f = $table\->{\$k}) {";
847 26 my @lines;
848 26 ▶ push @lines, 'return 0 unless ' . ($trivial ? '!ref($f) || ' : '') . '$f->($v);';
Branch: 1 branch
BranchTrueFalseTotal
$trivial ? : 24 2 26
849 26 ▶ push @lines, $mark if $mark;
Branch: 1 branch
BranchTrueFalseTotal
if $mark 0 26 26
850 26 ▶ push @lines, "$matched = 1;" if $matched;
Branch: 1 branch
BranchTrueFalseTotal
if $matched 0 26 26
851 26 ▶ push @lines, 'next;' if $continue_after && $has_ap_tail;
Branch: 1 branch
BranchTrueFalseTotal
if $continue_after and $has_ap_tail 0 26 26
Condition33%1/3
$continue_after and $has_ap_tail
!ll&&!rl&&r
0260
MC/DC0%0/2
$continue_after and $has_ap_tail
$continue_after $has_ap_tail
Truth table33%1/3
A and B
A= $continue_afterB= $has_ap_tail
ABresult
0X0
100
111
852 26 push @body, _indent(\@lines), '}';
853 }
854 }
855 28 for my $p (@$patterns) {
856 0 my $check = $self->call($p->{node}, '$v', $n->{resource_id});
857 0 my @lines;
858 0 ▶ push @lines, 'return 0 unless ' . _wrap($check) . ';' if $check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check ne 1 0 0 0
859 0 ▶ push @lines, $mark if $mark;
Branch: 1 branch
BranchTrueFalseTotal
if $mark 0 0 0
860 0 ▶ push @lines, "$matched = 1;" if $matched;
Branch: 1 branch
BranchTrueFalseTotal
if $matched 0 0 0
861 0 ▶ if (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 0 0 0
862 0 push @body, 'if (' . $self->pattern_test($p->{pattern}, '$k') . ') {', _indent(\@lines), '}';
863 }
864 }
865 28 ▶ if ($ap && ($ap_needs_loop || $mark)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ap and $ap_needs_loop || $mark) 2 26 28
Condition50%3/6
$ap and $ap_needs_loop || $mark
!ll&&!rl&&r
2602
$ap_needs_loop or $mark
l!l&&r!l&&!r
200
MC/DC33%1/3
$ap and $ap_needs_loop || $mark
$ap $ap_needs_loop $mark
Truth table50%2/4
A and B or C
A= $apB= $ap_needs_loopC= $mark
ABCresult
0XX0
1000
11X1
1011
866 2 my @lines;
867 2 my $check = $self->call($ap->{id}, '$v', $n->{resource_id});
868 0 ▶ if ($check eq '0') { push @lines, 'return 0;' }
Branch: 2 branches
BranchTrueFalseTotal
if ($check eq '0') { } 0 2 2
elsif ($check ne '1') { } 2 0 2
869 2 elsif ($check ne '1') { push @lines, 'return 0 unless ' . _wrap($check) . ';' }
870 2 ▶ push @lines, $mark if $mark;
Branch: 1 branch
BranchTrueFalseTotal
if $mark 0 2 2
871 2 ▶ if (@lines) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines) 2 0 2
872 2 ▶ if ($matched) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matched) { } 0 2 2
873 0 push @body, "unless ($matched) {", _indent(\@lines), '}';
874 }
875 else {
876 2 push @body, @lines;
877 }
878 }
879 }
880 28 ▶ return [] unless grep { $_ ne 'my $v = $x->{$k};' } @body;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ ne "my \$v = \$x->{\$k};";} @body 0 28 28
881 28 return [ 'for my $k (keys %$x) {', _indent(\@body), '}' ];
882 }
883  
884 # A hash constant from declared names to their check subs (1 for a schema that accepts everything); and whether any
885 # entry is 1.
886 26 ▶sub dispatch_table {
Subroutine dispatch_table: called CC=2 SCAR=6.9
Pod undocumented
887 26 my ($self, $n, $names) = @_;
888 26 my @refs = map { $self->function_ref($n->{properties}{$_}, $n->{resource_id}) } @$names;
889 26 my $entries = join ', ', map { perl_string($names->[$_]) . " => $refs[$_]" } 0 .. $#$names;
890 26 ▶ return ($self->constant("{$entries}"), (grep { $_ eq '1' } @refs) ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
grep({$_ eq '1';} @refs) ? : 24 2 26
891 }
892  
893 # Dependencies: required lists always; schemas here only in the flag layout (tracking evaluates them in place).
894 0 ▶sub object_dependencies {
Subroutine object_dependencies: not called CC=9 SCAR=45.0
Pod undocumented
895 0 my ($self, $n, $e, $flag_layout) = @_;
896 0 my @out;
897 0 ▶ for my $d (@{ $n->{dependencies} // [] }) {
Condition0%0/2
$n->{"dependencies"} // []
l!l
00
MC/DC0%0/1
$n->{"dependencies"} // []
$n->{"dependencies"}
Truth table0%0/2
A
A= $n->{"dependencies"}
Aresult
11
00
898 0 ▶ my @lines = @{ $self->required_test('$x', $d->{required} // []) };
Condition0%0/2
$d->{"required"} // []
l!l
00
MC/DC0%0/1
$d->{"required"} // []
$d->{"required"}
Truth table0%0/2
A
A= $d->{"required"}
Aresult
11
00
899 0 ▶ if (defined $d->{schema} && $flag_layout && !defined $e) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d->{"schema"} and $flag_layout and not defined $e) 0 0 0
Condition0%0/6
defined $d->{"schema"} and $flag_layout and not defined $e
!ll&&!rl&&r
000
defined $d->{"schema"} and $flag_layout
!ll&&!rl&&r
000
MC/DC0%0/3
defined $d->{"schema"} and $flag_layout and not defined $e
defined $d->{"schema"} $flag_layout not defined $e
Truth table0%0/4
A and B and not(C)
A= defined $d->{"schema"}B= $flag_layoutC= not defined $e
ABCresult
0XX0
10X0
1100
1111
900 0 my $check = $self->call($d->{schema}, '$x', $n->{resource_id});
901 0 ▶ push @lines, 'return 0 unless ' . _wrap($check) . ';' if $check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check ne 1 0 0 0
902 }
903 0 ▶ push @out, 'if (exists $x->{' . perl_string($d->{name}) . '}) {', _indent(\@lines), '}' if @lines;
Branch: 1 branch
BranchTrueFalseTotal
if @lines 0 0 0
904 }
905 0 return \@out;
906 }
907  
908 # --- Arrays ---
909  
910 54 ▶sub array_section {
Subroutine array_section: called CC=35 SCAR=51.4
Pod undocumented
911 54 my ($self, $n, $e) = @_;
912 54 my @out;
913 54 ▶ my $prefix = $n->{prefix_items} // [];
Condition50%1/2
$n->{"prefix_items"} // []
l!l
054
MC/DC0%0/1
$n->{"prefix_items"} // []
$n->{"prefix_items"}
Truth table50%1/2
A
A= $n->{"prefix_items"}
Aresult
11
00
914 54 ▶ my $has_length = $n->{min_items} > 0 || $n->{max_items} >= 0 || @$prefix || $n->{items} >= 0 || $n->{contains} >= 0
Condition73%11/15
$n->{'min_items'} > 0 || $n->{'max_items'} >= 0 || @$prefix || $n->{'items'} >= 0 || $n->{'contains'} >= 0 || defined $e
l!l&&r!l&&!r
6048
$n->{"min_items"} > 0 or $n->{"max_items"} >= 0 or @$prefix or $n->{"items"} >= 0 or $n->{"contains"} >= 0
l!l&&r!l&&!r
6048
$n->{"min_items"} > 0 or $n->{"max_items"} >= 0 or @$prefix or $n->{"items"} >= 0
l!l&&r!l&&!r
2448
$n->{"min_items"} > 0 or $n->{"max_items"} >= 0 or @$prefix
l!l&&r!l&&!r
2052
$n->{"min_items"} > 0 or $n->{"max_items"} >= 0
l!l&&r!l&&!r
2052
MC/DC33%2/6
$n->{'min_items'} > 0 || $n->{'max_items'} >= 0 || @$prefix || $n->{'items'} >= 0 || $n->{'contains'} >= 0 || defined $e
$n->{"min_items"} > 0 $n->{"max_items"} >= 0 @$prefix $n->{"items"} >= 0 $n->{"contains"} >= 0 defined $e
Truth table42%3/7
A or B or C or D or E || F
A= $n->{"min_items"} > 0B= $n->{"max_items"} >= 0C= @$prefixD= $n->{"items"} >= 0E= $n->{"contains"} >= 0F= defined $e
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
915 || defined $e;
916 54 ▶ return \@out if !$has_length && !$n->{unique_items};
Branch: 1 branch
BranchTrueFalseTotal
unless $has_length or $n->{"unique_items"} 48 6 54
Condition66%2/3
$has_length or $n->{"unique_items"}
l!l&&r!l&&!r
6048
MC/DC50%1/2
$has_length or $n->{"unique_items"}
$has_length $n->{"unique_items"}
Truth table66%2/3
A or B
A= $has_lengthB= $n->{"unique_items"}
ABresult
1X1
011
000
917 6 my $length = $self->scratch('n');
918 6 push @out, "my $length = \@\$x;";
919 6 ▶ push @out, "return 0 if $length < $n->{min_items};" if $n->{min_items} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"min_items"} > 0 2 4 6
920 6 ▶ push @out, "return 0 if $length > $n->{max_items};" if $n->{max_items} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"max_items"} >= 0 0 6 6
921 6 for my $i (0 .. $#$prefix) {
922 0 my $check = $self->call($prefix->[$i], "\$x->[$i]", $n->{resource_id});
923 0 ▶ next if $check eq '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check eq 1 0 0 0
924 0 push @out, "return 0 if $length > $i && !" . _wrap($check) . ';';
925 }
926 6 ▶ if (defined $e && @$prefix) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and @$prefix) 0 6 6
Condition33%1/3
defined $e and @$prefix
!ll&&!rl&&r
600
MC/DC0%0/2
defined $e and @$prefix
defined $e @$prefix
Truth table33%1/3
A and B
A= defined $eB= @$prefix
ABresult
0X0
100
111
927 0 my $count = scalar @$prefix;
928 0 push @out, "$e\->{\$_} = 1 for 0 .. ($length < $count ? $length : $count) - 1;";
929 }
930 6 ▶ if ($n->{items} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"items"} >= 0) 6 0 6
931 6 my $item = $self->{nodes}[ $self->elide($n->{items}) ];
932 6 my $count = scalar @$prefix;
933 6 ▶ if ($item->{always_false}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($item->{'always_false'}) { } 0 6 6
934 0 push @out, "return 0 if $length > $count;";
935 }
936 else {
937 6 my $check = $self->call($item->{id}, '$v', $n->{resource_id});
938 6 ▶ my $source = $count ? "\@\$x[$count .. \$#\$x]" : '@$x';
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 0 6 6
939 6 ▶ my $nested = $INLINE_ARRAYS ? $self->simple_array_lines($item, '$v', '$w', $n->{resource_id}) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$INLINE_ARRAYS ? : 6 0 6
940 6 ▶ if ($nested) {
Branch: 2 branches
BranchTrueFalseTotal
if ($nested) { } 0 6 6
elsif ($check ne '1') { } 4 2 6
941 # Items that are simple arrays (GeoJSON's positions): checked here, with no call per item.
942 0 push @out, "for my \$v ($source) {", _indent($nested), '}';
943 }
944 elsif ($check ne '1') {
945 4 my $inlined = $self->inline_child($item->{id}, '$v', $n->{resource_id});
946 4 ▶ push @out, "for my \$v ($source) {", _indent($inlined // [ 'return 0 unless ' . _wrap($check) . ';' ]), '}';
Condition50%1/2
$inlined // ['return 0 unless ' . _wrap($check) . ';']
l!l
04
MC/DC0%0/1
$inlined // ['return 0 unless ' . _wrap($check) . ';']
$inlined
Truth table50%1/2
A
A= $inlined
Aresult
11
00
947 }
948 6 ▶ push @out, "$e\->{\$_} = 1 for $count .. $length - 1;" if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 0 6 6
949 }
950 }
951 6 ▶ if ($n->{contains} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"contains"} >= 0) 0 6 6
952 0 my $check = $self->call($n->{contains}, '$v', $n->{resource_id});
953 0 my ($lo, $hi) = ($n->{min_contains}, $n->{max_contains});
954 0 ▶ my $mark_contains = defined $e && $n->{contains_marks_evaluated};
Condition0%0/3
defined $e && $n->{'contains_marks_evaluated'}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e && $n->{'contains_marks_evaluated'}
defined $e $n->{'contains_marks_evaluated'}
Truth table0%0/3
A && B
A= defined $eB= $n->{'contains_marks_evaluated'}
ABresult
0X0
100
111
955 0 ▶ if (!($lo <= 0 && $hi < 0 && !$mark_contains)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lo <= 0 and $hi < 0 and not $mark_contains) 0 0 0
Condition0%0/6
$lo <= 0 and $hi < 0 and not $mark_contains
!ll&&!rl&&r
000
$lo <= 0 and $hi < 0
!ll&&!rl&&r
000
MC/DC0%0/3
$lo <= 0 and $hi < 0 and not $mark_contains
$lo <= 0 $hi < 0 not $mark_contains
Truth table0%0/4
A and B and not(C)
A= $lo <= 0B= $hi < 0C= not $mark_contains
ABCresult
0XX0
10X0
1100
1111
956 0 my $c = $self->scratch('c');
957 0 push @out, "my $c = 0;";
958 0 ▶ if ($mark_contains) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mark_contains) { } 0 0 0
959 0 push @out, 'for my $i (0 .. $#$x) {', ' my $v = $x->[$i];', " if ($check) {", " $c++;", " $e\->{\$i} = 1;",
960 ' }', '}';
961 }
962 else {
963 0 push @out, 'for my $v (@$x) {', " if ($check) {", " $c++;";
964 0 ▶ push @out, " last if $c >= $lo;" if $hi < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hi < 0 0 0 0
965 0 push @out, ' }', '}';
966 }
967 0 ▶ push @out, "return 0 if $c < $lo;" if $lo > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $lo > 0 0 0 0
968 0 ▶ push @out, "return 0 if $c > $hi;" if $hi >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $hi >= 0 0 0 0
969 }
970 }
971 6 ▶ if ($n->{unique_items}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"unique_items"}) 2 4 6
972 2 ▶ if ($self->items_are_strings($n)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->items_are_strings($n)) { } 2 0 2
973 # Every item passed its schema above, so all are strings, which a hash compares as JSON does.
974 2 (my $seen = $self->scratch('s')) =~ s/\A\$//;
975 2 push @out, "if ($length > 1) {", " my %$seen;", ' @' . $seen . '{@$x} = ();',
976 " return 0 if keys(%$seen) != $length;", '}';
977 }
978 else {
979 0 push @out, "return 0 if $length > 1 && !JSON::Schema::Corvus::Runtime::unique(\$x);";
980 }
981 }
982 6 ▶ shift @out unless grep { index($_, $length) >= 0 } @out[ 1 .. $#out ];
Branch: 1 branch
BranchTrueFalseTotal
unless grep {index($_, $length) != -1;} @out[1 .. $#out] 3 3 6
983 6 return \@out;
984 }
985  
986 # The statements that check v against a simple array schema (the type array, optional length bounds and a leaf items
987 # schema, nothing else), or undef for any other schema. Its items are visited as w.
988 26 ▶sub simple_array_lines {
Subroutine simple_array_lines: called CC=24 SCAR=39.8
Pod undocumented
989 26 my ($self, $n, $v, $w, $source) = @_;
990 26 ▶ my $crosses = $self->{program}{uses_dynamic_scope} && $n->{resource_id} != $source;
Condition33%1/3
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
!ll&&!rl&&r
2600
MC/DC0%0/2
$self->{'program'}{'uses_dynamic_scope'} && $n->{'resource_id'} != $source
$self->{'program'}{'uses_dynamic_scope'} $n->{'resource_id'} != $source
Truth table33%1/3
A && B
A= $self->{'program'}{'uses_dynamic_scope'}B= $n->{'resource_id'} != $source
ABresult
0X0
100
111
991 return undef if $crosses || $n->{in_place_cycle} || !($n->{has_type} && $n->{type} == T_ARRAY) || $n->{items} < 0
992 0 || ($n->{prefix_items} && @{ $n->{prefix_items} }) || $n->{contains} >= 0 || $n->{unique_items}
993 26 ▶ || $n->{unevaluated_items} >= 0 || $n->{has_const} || defined $n->{enum_values} || $n->has_in_place_applicators
Branch: 1 branch
BranchTrueFalseTotal
if $crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_in_place_applicators or $n->has_object_keywords 25 1 26
Condition64%25/39
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_in_place_applicators or $n->has_object_keywords
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_in_place_applicators
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"} or defined $n->{"enum_values"}
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"}
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"}
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};}
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0
l!l&&r!l&&!r
2501
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8
l!l&&r!l&&!r
0251
$crosses or $n->{"in_place_cycle"}
l!l&&r!l&&!r
0026
$n->{'has_type'} && $n->{'type'} == 8
!ll&&!rl&&r
7181
$n->{"prefix_items"} and @{$n->{"prefix_items"};}
!ll&&!rl&&r
100
MC/DC14%2/14
$crosses or $n->{"in_place_cycle"} or not $n->{"has_type"} && $n->{"type"} == 8 or $n->{"items"} < 0 or $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"contains"} >= 0 or $n->{"unique_items"} or $n->{"unevaluated_items"} >= 0 or $n->{"has_const"} or defined $n->{"enum_values"} or $n->has_in_place_applicators or $n->has_object_keywords
$crosses $n->{"in_place_cycle"} $n->{'has_type'} $n->{'type'} == 8 $n->{"items"} < 0 $n->{"prefix_items"} @{$n->{"prefix_items"};} $n->{"contains"} >= 0 $n->{"unique_items"} $n->{"unevaluated_items"} >= 0 $n->{"has_const"} defined $n->{"enum_values"} $n->has_in_place_applicators $n->has_object_keywords
Truth table13%3/22
A or B or not(C && D) or E or F and G or H or I or J or K or L or M or N
A= $crossesB= $n->{"in_place_cycle"}C= $n->{'has_type'}D= $n->{'type'} == 8E= $n->{"items"} < 0F= $n->{"prefix_items"}G= @{$n->{"prefix_items"};}H= $n->{"contains"} >= 0I= $n->{"unique_items"}J= $n->{"unevaluated_items"} >= 0K= $n->{"has_const"}L= defined $n->{"enum_values"}M= $n->has_in_place_applicatorsN= $n->has_object_keywords
ABCDEFGHIJKLMNresult
1XXXXXXXXXXXXX1
01XXXXXXXXXXXX1
000XXXXXXXXXXX1
0010XXXXXXXXXX1
00111XXXXXXXXX1
0011011XXXXXXX1
001100X1XXXXXX1
00110101XXXXXX1
001100X01XXXXX1
001101001XXXXX1
001100X001XXXX1
0011010001XXXX1
001100X0001XXX1
00110100001XXX1
001100X00001XX1
001101000001XX1
001100X000001X1
0011010000001X1
001100X00000011
001101000000011
001100X00000000
001101000000000
994 || $n->has_object_keywords;
995 1 my $item = $self->{nodes}[ $self->elide($n->{items}) ];
996 1 ▶ return undef unless $item->{always_true} || $item->is_type_only || $self->is_inline_leaf($item);
Branch: 1 branch
BranchTrueFalseTotal
unless $item->{"always_true"} or $item->is_type_only or $self->is_inline_leaf($item) 0 1 1
Condition33%2/6
$item->{"always_true"} or $item->is_type_only or $self->is_inline_leaf($item)
l!l&&r!l&&!r
100
$item->{"always_true"} or $item->is_type_only
l!l&&r!l&&!r
100
MC/DC0%0/3
$item->{"always_true"} or $item->is_type_only or $self->is_inline_leaf($item)
$item->{"always_true"} $item->is_type_only $self->is_inline_leaf($item)
Truth table25%1/4
A or B or C
A= $item->{"always_true"}B= $item->is_type_onlyC= $self->is_inline_leaf($item)
ABCresult
1XX1
01X1
0011
0000
997 1 my $check = $self->call($item->{id}, $w, $source);
998 1 my @lines = ("return 0 unless ref($v) eq 'ARRAY';");
999 1 my @bounds;
1000 1 ▶ push @bounds, "\@$v < $n->{min_items}" if $n->{min_items} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"min_items"} > 0 0 1 1
1001 1 ▶ push @bounds, "\@$v > $n->{max_items}" if $n->{max_items} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"max_items"} >= 0 0 1 1
1002 1 ▶ push @lines, 'return 0 if ' . join(' || ', @bounds) . ';' if @bounds;
Branch: 1 branch
BranchTrueFalseTotal
if @bounds 0 1 1
1003 1 ▶ if ($check eq '0') {
Branch: 2 branches
BranchTrueFalseTotal
if ($check eq '0') { } 0 1 1
elsif ($check ne '1') { } 0 1 1
1004 0 push @lines, "return 0 if \@{$v};";
1005 }
1006 elsif ($check ne '1') {
1007 0 push @lines, "for my $w (\@{$v}) {", ' return 0 unless ' . _wrap($check) . ';', '}';
1008 }
1009 1 return \@lines;
1010 }
1011  
1012 # Whether every item of an array this node accepts is a string (by its items schema).
1013 2 ▶sub items_are_strings {
Subroutine items_are_strings: called CC=8 SCAR=24.7
Pod undocumented
1014 2 my ($self, $n) = @_;
1015 0 ▶ return 0 if ($n->{prefix_items} && @{ $n->{prefix_items} }) || $n->{items} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"items"} < 0 0 2 2
Condition33%2/6
$n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"items"} < 0
l!l&&r!l&&!r
002
$n->{"prefix_items"} and @{$n->{"prefix_items"};}
!ll&&!rl&&r
200
MC/DC0%0/3
$n->{"prefix_items"} and @{$n->{"prefix_items"};} or $n->{"items"} < 0
$n->{"prefix_items"} @{$n->{"prefix_items"};} $n->{"items"} < 0
Truth table20%1/5
A and B or C
A= $n->{"prefix_items"}B= @{$n->{"prefix_items"};}C= $n->{"items"} < 0
ABCresult
11X1
0X11
1011
0X00
1000
1016 2 my $item = $self->{nodes}[ $self->elide($n->{items}) ];
1017 2 ▶ return 1 if $item->{has_type} && $item->{type} == T_STRING;
Branch: 1 branch
BranchTrueFalseTotal
if $item->{"has_type"} and $item->{"type"} == 32 1 1 2
Condition66%2/3
$item->{"has_type"} and $item->{"type"} == 32
!ll&&!rl&&r
101
MC/DC50%1/2
$item->{"has_type"} and $item->{"type"} == 32
$item->{"has_type"} $item->{"type"} == 32
Truth table66%2/3
A and B
A= $item->{"has_type"}B= $item->{"type"} == 32
ABresult
0X0
100
111
1018 1 ▶ return $item->{enum_values} && @{ $item->{enum_values} } && !grep { _type($_) ne 'string' } @{ $item->{enum_values} };
Condition33%2/6
$item->{'enum_values'} && @{$item->{'enum_values'};} && !grep({_type($_) ne 'string';} @{$$item{'enum_values'};})
!ll&&!rl&&r
001
$item->{"enum_values"} and @{$item->{"enum_values"};}
!ll&&!rl&&r
001
MC/DC0%0/3
$item->{'enum_values'} && @{$item->{'enum_values'};} && !grep({_type($_) ne 'string';} @{$$item{'enum_values'};})
$item->{"enum_values"} @{$item->{"enum_values"};} !grep({_type($_) ne 'string';} @{$$item{'enum_values'};})
Truth table25%1/4
A and B && not(C)
A= $item->{"enum_values"}B= @{$item->{"enum_values"};}C= !grep({_type($_) ne 'string';} @{$$item{'enum_values'};})
ABCresult
0XX0
10X0
1100
1111
1019 }
1020  
1021 # --- Strings and numbers ---
1022  
1023 351 ▶sub string_conditions {
Subroutine string_conditions: called CC=11 SCAR=24.9
Pod undocumented
1024 351 my ($self, $n, $v) = @_;
1025 351 my @out;
1026 351 ▶ push @out, "length($v) >= $n->{min_length}" if $n->{min_length} > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"min_length"} > 0 0 351 351
1027 351 ▶ push @out, "length($v) <= $n->{max_length}" if $n->{max_length} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"max_length"} >= 0 0 351 351
1028 351 ▶ push @out, $self->pattern_test($n->{pattern}, $v) if defined $n->{pattern};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"pattern"} 77 274 351
1029 351 ▶ if ($n->{assert_format} && defined $n->{format} && !JSON::Schema::Corvus::Formats::is_numeric_format($n->{format_kind})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})) 7 344 351
Condition66%4/6
$n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
!ll&&!rl&&r
34407
$n->{"assert_format"} and defined $n->{"format"}
!ll&&!rl&&r
34407
MC/DC33%1/3
$n->{"assert_format"} and defined $n->{"format"} and not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
$n->{"assert_format"} defined $n->{"format"} not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
Truth table50%2/4
A and B and not(C)
A= $n->{"assert_format"}B= defined $n->{"format"}C= not JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
ABCresult
0XX0
10X0
1100
1111
1030 7 my $f = $self->format_function($n->{format}, $n->{format_kind}, $n->{dialect});
1031 7 ▶ push @out, "$f\->($v)" if defined $f;
Branch: 1 branch
BranchTrueFalseTotal
if defined $f 7 0 7
1032 }
1033 351 ▶ if ($n->{assert_content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_content"}) 1 350 351
1034 1 ▶ my $kind = $n->{content} == CONTENT_BASE64 ? 1 : $n->{content} == CONTENT_JSON ? 2 : 3;
Branch: 2 branches
BranchTrueFalseTotal
$n->{'content'} == 1 ? : 0 1 1
$n->{'content'} == 2 ? : 1 0 1
1035 1 push @out, "JSON::Schema::Corvus::Runtime::content($v, $kind)";
1036 }
1037 351 return @out;
1038 }
1039  
1040 356 ▶sub number_conditions {
Subroutine number_conditions: called CC=9 SCAR=25.9
Pod undocumented
1041 356 my ($self, $n, $v) = @_;
1042 356 my @out;
1043 356 ▶ if ($n->{assert_format} && JSON::Schema::Corvus::Formats::is_numeric_format($n->{format_kind})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"assert_format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})) 0 356 356
Condition66%2/3
$n->{"assert_format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
!ll&&!rl&&r
34970
MC/DC0%0/2
$n->{"assert_format"} and JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
$n->{"assert_format"} JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
Truth table66%2/3
A and B
A= $n->{"assert_format"}B= JSON::Schema::Corvus::Formats::is_numeric_format($n->{"format_kind"})
ABresult
0X0
100
111
1044 0 ▶ if (my $custom = $self->{program}{options}{formats}{ $n->{format} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $custom = $self->{'program'}{'options'}{'formats'}{$n->{'format'}}) { } 0 0 0
1045 0 my $f = $self->_custom_format($custom);
1046 0 push @out, "$f\->(JSON::Schema::Corvus::Collecting::number_text($v))";
1047 }
1048 else {
1049 my $f = $self->constant('$JSON::Schema::Corvus::Formats::NUMERIC_FORMAT_VALIDATORS{'
1050 0 . perl_string($n->{format_kind}) . '}');
1051 0 push @out, "$f\->($v)";
1052 }
1053 }
1054 356 ▶ push @out, "$v >= " . $self->perl_number($n->{minimum}) if defined $n->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"minimum"} 196 160 356
1055 356 ▶ push @out, "$v <= " . $self->perl_number($n->{maximum}) if defined $n->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"maximum"} 2 354 356
1056 356 ▶ push @out, "$v > " . $self->perl_number($n->{exclusive_minimum}) if defined $n->{exclusive_minimum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"exclusive_minimum"} 27 329 356
1057 356 ▶ push @out, "$v < " . $self->perl_number($n->{exclusive_maximum}) if defined $n->{exclusive_maximum};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"exclusive_maximum"} 0 356 356
1058 356 ▶ if (defined $n->{multiple_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $n->{"multiple_of"}) 0 356 356
1059 0 push @out, "JSON::Schema::Corvus::Runtime::multiple_of($v, " . $self->perl_number($n->{multiple_of}) . ')';
1060 }
1061 356 return @out;
1062 }
1063  
1064 # For a number restricted to integers, the condition that it is one.
1065 292 ▶sub integer_condition {
Subroutine integer_condition: called CC=4 SCAR=13.9
Pod undocumented
1066 292 my ($self, $n, $v) = @_;
1067 292 ▶ return undef unless $n->{has_type} && ($n->{type} & T_INTEGER) && !($n->{type} & T_NUMBER);
Branch: 1 branch
BranchTrueFalseTotal
unless $n->{"has_type"} and $n->{"type"} & 64 and not $n->{"type"} & 16 100 192 292
Condition83%5/6
$n->{"has_type"} and $n->{"type"} & 64 and not $n->{"type"} & 16
!ll&&!rl&&r
1000192
$n->{"has_type"} and $n->{"type"} & 64
!ll&&!rl&&r
496192
MC/DC66%2/3
$n->{"has_type"} and $n->{"type"} & 64 and not $n->{"type"} & 16
$n->{"has_type"} $n->{"type"} & 64 not $n->{"type"} & 16
Truth table75%3/4
A and B and not(C)
A= $n->{"has_type"}B= $n->{"type"} & 64C= not $n->{"type"} & 16
ABCresult
0XX0
10X0
1100
1111
1068 192 return $self->_integer_test($v, $n->{dialect});
1069 }
1070  
1071 59 ▶sub string_section {
Subroutine string_section: called CC=1 SCAR=0.0
Pod undocumented
1072 59 my ($self, $n) = @_;
1073 59 return [ map { 'return 0 unless ' . _wrap($_) . ';' } $self->string_conditions($n, '$x') ];
1074 }
1075  
1076 64 ▶sub number_section {
Subroutine number_section: called CC=1 SCAR=0.0
Pod undocumented
1077 64 my ($self, $n) = @_;
1078 64 return [ map { 'return 0 unless ' . _wrap($_) . ';' } $self->number_conditions($n, '$x') ];
1079 }
1080  
1081 2 my $PLAIN_RE = qr/\A[A-Za-z0-9 _\-\/:@,;=!%&'"<>~`#]*\z/;
1082  
1083 # A test of v (a string) against an ECMAScript pattern. Common shapes match without a regular expression, as
1084 # PatternMatcher does in C#: a literal prefix, an exact literal or literal alternation, and a contained literal.
1085 77 ▶sub pattern_test {
Subroutine pattern_test: called CC=16 SCAR=41.5
Pod undocumented
1086 77 my ($self, $pattern, $v) = @_;
1087 77 ▶ my $plain = sub { $_[0] =~ $PLAIN_RE };
Subroutine __ANON__: called CC=1 SCAR=0.0
1088 77 ▶ if (substr($pattern, 0, 1) eq '^' && $plain->(substr($pattern, 1)) && substr($pattern, -1) ne '$') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($pattern, 0, 1) eq "^" and &$plain(substr($pattern, 1)) and substr($pattern, -1) ne "\$") 0 77 77
Condition33%2/6
substr($pattern, 0, 1) eq "^" and &$plain(substr($pattern, 1)) and substr($pattern, -1) ne "\$"
!ll&&!rl&&r
7700
substr($pattern, 0, 1) eq "^" and &$plain(substr($pattern, 1))
!ll&&!rl&&r
0770
MC/DC0%0/3
substr($pattern, 0, 1) eq "^" and &$plain(substr($pattern, 1)) and substr($pattern, -1) ne "\$"
substr($pattern, 0, 1) eq "^" &$plain(substr($pattern, 1)) substr($pattern, -1) ne "\$"
Truth table25%1/4
A and B and C
A= substr($pattern, 0, 1) eq "^"B= &$plain(substr($pattern, 1))C= substr($pattern, -1) ne "\$"
ABCresult
0XX0
10X0
1100
1111
1089 0 return "index($v, " . perl_string(substr($pattern, 1)) . ') == 0';
1090 }
1091 77 ▶ if (length $pattern >= 2 && substr($pattern, 0, 1) eq '^' && substr($pattern, -1) eq '$'
Branch: 1 branch
BranchTrueFalseTotal
if (length $pattern >= 2 and substr($pattern, 0, 1) eq "^" and substr($pattern, -1) eq "\$" and &$plain(substr($pattern, 1, -1))) 0 77 77
Condition33%3/9
length $pattern >= 2 and substr($pattern, 0, 1) eq "^" and substr($pattern, -1) eq "\$" and &$plain(substr($pattern, 1, -1))
!ll&&!rl&&r
0770
length $pattern >= 2 and substr($pattern, 0, 1) eq "^" and substr($pattern, -1) eq "\$"
!ll&&!rl&&r
0077
length $pattern >= 2 and substr($pattern, 0, 1) eq "^"
!ll&&!rl&&r
0077
MC/DC0%0/4
length $pattern >= 2 and substr($pattern, 0, 1) eq "^" and substr($pattern, -1) eq "\$" and &$plain(substr($pattern, 1, -1))
length $pattern >= 2 substr($pattern, 0, 1) eq "^" substr($pattern, -1) eq "\$" &$plain(substr($pattern, 1, -1))
Truth table20%1/5
A and B and C and D
A= length $pattern >= 2B= substr($pattern, 0, 1) eq "^"C= substr($pattern, -1) eq "\$"D= &$plain(substr($pattern, 1, -1))
ABCDresult
0XXX0
10XX0
110X0
11100
11111
1092 && $plain->(substr($pattern, 1, -1))) {
1093 0 return "$v eq " . perl_string(substr($pattern, 1, -1));
1094 }
1095 77 ▶ if ($pattern =~ /\A\^\(\?:([^()]*)\)\$\z/ || $pattern =~ /\A\^\(([^()]*)\)\$\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pattern =~ /\A\^\(\?:([^()]*)\)\$\z/u or $pattern =~ /\A\^\(([^()]*)\)\$\z/u) 0 77 77
Condition33%1/3
$pattern =~ /\A\^\(\?:([^()]*)\)\$\z/u or $pattern =~ /\A\^\(([^()]*)\)\$\z/u
l!l&&r!l&&!r
0077
MC/DC0%0/2
$pattern =~ /\A\^\(\?:([^()]*)\)\$\z/u or $pattern =~ /\A\^\(([^()]*)\)\$\z/u
$pattern =~ /\A\^\(\?:([^()]*)\)\$\z/u $pattern =~ /\A\^\(([^()]*)\)\$\z/u
Truth table33%1/3
A or B
A= $pattern =~ /\A\^\(\?:([^()]*)\)\$\z/uB= $pattern =~ /\A\^\(([^()]*)\)\$\z/u
ABresult
1X1
011
000
1096 0 my @alternatives = split /\|/, $1, -1;
1097 0 ▶ if (!grep { !$plain->($_) } @alternatives) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {not &$plain($_);} @alternatives) 0 0 0
1098 0 ▶ return '(' . join(' || ', map { "$v eq " . perl_string($_) } @alternatives) . ')' if @alternatives <= 6;
Branch: 1 branch
BranchTrueFalseTotal
if @alternatives <= 6 0 0 0
1099 0 my $set = $self->constant('{' . join(', ', map { perl_string($_) . ' => 1' } @alternatives) . '}');
1100 0 return "exists $set\->{$v}";
1101 }
1102 }
1103 77 ▶ return 'index(' . $v . ', ' . perl_string($pattern) . ') >= 0' if length $pattern && $plain->($pattern);
Branch: 1 branch
BranchTrueFalseTotal
if length $pattern and &$plain($pattern) 0 77 77
Condition33%1/3
length $pattern and &$plain($pattern)
!ll&&!rl&&r
0770
MC/DC0%0/2
length $pattern and &$plain($pattern)
length $pattern &$plain($pattern)
Truth table33%1/3
A and B
A= length $patternB= &$plain($pattern)
ABresult
0X0
100
111
1104 77 my $limit = $self->{program}{options}{pattern_match_limit};
1105 77 ▶ JSON::Schema::Corvus::Pattern::compile_pattern($pattern, $limit)
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Pattern::compile_pattern($pattern, $limit) or die "JSON::Schema::Corvus::Error::Compilation"->_new("Invalid regular expression '${pattern}'.") 77 0 77
1106 or die JSON::Schema::Corvus::Error::Compilation->_new("Invalid regular expression '$pattern'.");
1107 77 ▶ my $matcher = $self->constant('JSON::Schema::Corvus::Pattern::compile_pattern(' . perl_string($pattern) . ', '
Branch: 1 branch
BranchTrueFalseTotal
defined $limit ? : 75 2 77
1108 . (defined $limit ? JSON::Schema::Corvus::Json::number_text(0.0 + $limit) : 'undef') . ')');
1109 77 return "$matcher\->($v)";
1110 }
1111  
1112 5 ▶sub _custom_format {
Subroutine _custom_format: called CC=2 SCAR=6.9
1113 5 my ($self, $custom) = @_;
1114 5 my $i = $self->{custom_format_index}{$custom};
1115 5 ▶ if (!defined $i) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $i) 5 0 5
1116 5 $i = @{ $self->{custom_formats} };
1117 5 push @{ $self->{custom_formats} }, $custom;
1118 5 $self->{custom_format_index}{$custom} = $i;
1119 }
1120 5 return "\$F->[$i]";
1121 }
1122  
1123 7 ▶sub format_function {
Subroutine format_function: called CC=5 SCAR=17.0
Pod undocumented
1124 7 my ($self, $format, $kind, $dialect) = @_;
1125 7 ▶ if (my $custom = $self->{program}{options}{formats}{$format}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $custom = $self->{"program"}{"options"}{"formats"}{$format}) 5 2 7
1126 5 return $self->_custom_format($custom);
1127 }
1128 # Draft 4 and 6 host names are RFC 1123 names; later drafts apply the IDNA rules.
1129 2 ▶ return $self->constant('\&JSON::Schema::Corvus::Formats::legacy_hostname') if $kind eq 'hostname' && $dialect <= DRAFT6;
Branch: 1 branch
BranchTrueFalseTotal
if $kind eq "hostname" and $dialect <= 1 0 2 2
Condition33%1/3
$kind eq "hostname" and $dialect <= 1
!ll&&!rl&&r
200
MC/DC0%0/2
$kind eq "hostname" and $dialect <= 1
$kind eq "hostname" $dialect <= 1
Truth table33%1/3
A and B
A= $kind eq "hostname"B= $dialect <= 1
ABresult
0X0
100
111
1130 # Names the dialect does not define are unknown formats, which always match.
1131 2 ▶ return undef unless exists $JSON::Schema::Corvus::Formats::FORMAT_VALIDATORS{$kind};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $JSON::Schema::Corvus::Formats::FORMAT_VALIDATORS{$kind} 0 2 2
1132 2 return $self->constant('$JSON::Schema::Corvus::Formats::FORMAT_VALIDATORS{' . perl_string($kind) . '}');
1133 }
1134  
1135 # --- In-place applicators ---
1136  
1137 # The in-place applicators. e is the evaluated set being marked (property names for objects, indexes for arrays), with
1138 # kind saying which; undef for flag evaluation.
1139 106 ▶sub in_place {
Subroutine in_place: called CC=40 SCAR=65.5
Pod undocumented
1140 106 my ($self, $n, $e, $kind) = @_;
1141 106 my @out;
1142 32 ▶ my $marks = sub {
Subroutine __ANON__: called CC=3 SCAR=16.5
1143 32 my ($node_id) = @_;
1144 32 ▶ return 0 unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 32 0 32
1145 0 my $c = $self->{nodes}[ $self->elide($node_id) ];
1146 0 ▶ return $kind eq 'object' ? $c->{marks_properties} : $c->{marks_items};
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'object' ? : 0 0 0
1147 106 };
1148 106 ▶ my $direct = sub { $self->call($_[0], '$x', $n->{resource_id}, $marks->($_[0]) ? $e : undef) };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
&$marks($_[0]) ? : 0 32 32
1149  
1150 106 ▶ _push(\@out, $direct->($n->{ref})) if $n->{ref} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"ref"} >= 0 3 103 106
1151 106 ▶ _push(\@out, $direct->($n->{static_dynamic_ref})) if $n->{static_dynamic_ref} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"static_dynamic_ref"} >= 0 22 84 106
1152 106 ▶ if ($n->{dynamic_ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"dynamic_ref"}) 0 106 106
1153 0 ▶ my $variant = defined $e && defined $kind && $self->dynamic_marks($n, $kind) ? 't' : 'v';
Branch: 1 branch
BranchTrueFalseTotal
defined $e && defined $kind && $self->dynamic_marks($n, $kind) ? : 0 0 0
Condition0%0/6
defined $e and defined $kind and $self->dynamic_marks($n, $kind)
!ll&&!rl&&r
000
defined $e and defined $kind
!ll&&!rl&&r
000
MC/DC0%0/3
defined $e and defined $kind and $self->dynamic_marks($n, $kind)
defined $e defined $kind $self->dynamic_marks($n, $kind)
Truth table0%0/4
A and B and C
A= defined $eB= defined $kindC= $self->dynamic_marks($n, $kind)
ABCresult
0XX0
10X0
1100
1111
1154 0 ▶ push @out, 'return 0 unless ' . $self->ref_to("d$variant$n->{id}") . '($x' . ($variant eq 't' && $e ? ", $e" : '')
Branch: 1 branch
BranchTrueFalseTotal
$variant eq 't' && $e ? : 0 0 0
Condition0%0/3
$variant eq "t" and $e
!ll&&!rl&&r
000
MC/DC0%0/2
$variant eq "t" and $e
$variant eq "t" $e
Truth table0%0/3
A and B
A= $variant eq "t"B= $e
ABresult
0X0
100
111
1155 . ');';
1156 }
1157 106 ▶ _push(\@out, $direct->($_)) for @{ $n->{all_of} // [] };
Condition100%2/2
$n->{"all_of"} // []
l!l
1105
MC/DC100%1/1
$n->{"all_of"} // []
$n->{"all_of"}
Truth table100%2/2
A
A= $n->{"all_of"}
Aresult
11
00
1158  
1159 106 ▶ if ($n->{any_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"any_of"}) 2 104 106
1160 0 ▶ if (defined $e && grep { $marks->($_) } @{ $n->{any_of} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and grep {&$marks($_);} @{$$n{'any_of'};}) { } 0 2 2
Condition33%1/3
defined $e and grep {&$marks($_);} @{$$n{"any_of"};}
!ll&&!rl&&r
200
MC/DC0%0/2
defined $e and grep {&$marks($_);} @{$$n{"any_of"};}
defined $e grep {&$marks($_);} @{$$n{"any_of"};}
Truth table33%1/3
A and B
A= defined $eB= grep {&$marks($_);} @{$$n{"any_of"};}
ABresult
0X0
100
111
1161 # Every passing branch contributes its annotations, so every branch is evaluated.
1162 0 my $any = $self->scratch('any');
1163 0 push @out, "my $any = 0;";
1164 0 for my $c (@{ $n->{any_of} }) {
1165 0 ▶ if ($marks->($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$marks($c)) { } 0 0 0
1166 0 my $s = $self->scratch('s');
1167 0 push @out, "my $s = {};";
1168 0 push @out, 'if (' . $self->call($c, '$x', $n->{resource_id}, $s) . ') {', " $any = 1;",
1169 ' @{' . $e . '}{keys %{' . $s . '}} = values %{' . $s . '};', '}';
1170 }
1171 else {
1172 0 push @out, "$any = 1 if !$any && " . _wrap($self->call($c, '$x', $n->{resource_id})) . ';';
1173 }
1174 }
1175 0 push @out, "return 0 unless $any;";
1176 }
1177 else {
1178 2 push @out, @{ $self->select_branches($n, $n->{any_of}, $n->{any_of_discriminator},
1179 2 ▶ sub { $self->any_of_check($n, $_[0]) }) };
Subroutine __ANON__: called CC=1 SCAR=0.0
1180 }
1181 }
1182  
1183 106 ▶ if ($n->{one_of}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"one_of"}) 0 106 106
1184 0 ▶ if (defined $e && grep { $marks->($_) } @{ $n->{one_of} }) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and grep {&$marks($_);} @{$$n{'one_of'};}) { } 0 0 0
Condition0%0/3
defined $e and grep {&$marks($_);} @{$$n{"one_of"};}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $e and grep {&$marks($_);} @{$$n{"one_of"};}
defined $e grep {&$marks($_);} @{$$n{"one_of"};}
Truth table0%0/3
A and B
A= defined $eB= grep {&$marks($_);} @{$$n{"one_of"};}
ABresult
0X0
100
111
1185 0 my $count = $self->scratch('one');
1186 0 push @out, "my $count = 0;";
1187 0 for my $c (@{ $n->{one_of} }) {
1188 0 ▶ if ($marks->($c)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$marks($c)) { } 0 0 0
1189 0 my $s = $self->scratch('s');
1190 0 push @out, "my $s = {};";
1191 0 push @out, 'if (' . $self->call($c, '$x', $n->{resource_id}, $s) . ') {', " $count++;",
1192 ' @{' . $e . '}{keys %{' . $s . '}} = values %{' . $s . '};', '}';
1193 }
1194 else {
1195 0 push @out, "$count++ if " . _wrap($self->call($c, '$x', $n->{resource_id})) . ';';
1196 }
1197 }
1198 0 push @out, "return 0 if $count != 1;";
1199 }
1200 else {
1201 0 push @out, @{ $self->select_branches($n, $n->{one_of}, $n->{one_of_discriminator},
1202 0 ▶ sub { $self->one_of_check($n, $_[0]) }) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1203 }
1204 }
1205  
1206 106 ▶ if ($n->{not_} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"not_"} >= 0) 0 106 106
1207 0 my $check = $self->call($n->{not_}, '$x', $n->{resource_id});
1208 0 ▶ if ($check eq '1') { push @out, 'return 0;' }
Branch: 2 branches
BranchTrueFalseTotal
if ($check eq '1') { } 0 0 0
elsif ($check ne '0') { } 0 0 0
1209 0 elsif ($check ne '0') { push @out, "return 0 if $check;" }
1210 }
1211  
1212 106 ▶ if ($n->{if_} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"if_"} >= 0) 0 106 106
1213 0 ▶ my $then_check = $n->{then} >= 0 ? $direct->($n->{then}) : '1';
Branch: 1 branch
BranchTrueFalseTotal
$n->{'then'} >= 0 ? : 0 0 0
1214 0 ▶ my $else_check = $n->{else_} >= 0 ? $direct->($n->{else_}) : '1';
Branch: 1 branch
BranchTrueFalseTotal
$n->{'else_'} >= 0 ? : 0 0 0
1215 0 ▶ if ($then_check ne '1' || $else_check ne '1' || $marks->($n->{if_})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($then_check ne 1 or $else_check ne 1 or &$marks($n->{"if_"})) 0 0 0
Condition0%0/6
$then_check ne 1 or $else_check ne 1 or &$marks($n->{"if_"})
l!l&&r!l&&!r
000
$then_check ne 1 or $else_check ne 1
l!l&&r!l&&!r
000
MC/DC0%0/3
$then_check ne 1 or $else_check ne 1 or &$marks($n->{"if_"})
$then_check ne 1 $else_check ne 1 &$marks($n->{"if_"})
Truth table0%0/4
A or B or C
A= $then_check ne 1B= $else_check ne 1C= &$marks($n->{"if_"})
ABCresult
1XX1
01X1
0011
0000
1216 0 ▶ if ($marks->($n->{if_})) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$marks($n->{'if_'})) { } 0 0 0
1217 0 my $s = $self->scratch('s');
1218 0 push @out, "my $s = {};";
1219 0 my $cond = $self->call($n->{if_}, '$x', $n->{resource_id}, $s);
1220 0 push @out, "if ($cond) {", ' @{' . $e . '}{keys %{' . $s . '}} = values %{' . $s . '};';
1221 }
1222 else {
1223 0 push @out, 'if (' . $self->call($n->{if_}, '$x', $n->{resource_id}) . ') {';
1224 }
1225 0 ▶ push @out, ' return 0 unless ' . _wrap($then_check) . ';' if $then_check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $then_check ne 1 0 0 0
1226 0 ▶ if ($else_check ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($else_check ne 1) 0 0 0
1227 0 push @out, '} else {', ' return 0 unless ' . _wrap($else_check) . ';';
1228 }
1229 0 push @out, '}';
1230 }
1231 }
1232  
1233 # Dependent schemas are in-place applicators; the flag layout emits them in the object section.
1234 106 ▶ if (defined $e && defined $kind && $kind eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $e and defined $kind and $kind eq "object") 0 106 106
Condition33%2/6
defined $e and defined $kind and $kind eq "object"
!ll&&!rl&&r
10600
defined $e and defined $kind
!ll&&!rl&&r
10600
MC/DC0%0/3
defined $e and defined $kind and $kind eq "object"
defined $e defined $kind $kind eq "object"
Truth table25%1/4
A and B and C
A= defined $eB= defined $kindC= $kind eq "object"
ABCresult
0XX0
10X0
1100
1111
1235 0 ▶ for my $d (@{ $n->{dependencies} // [] }) {
Condition0%0/2
$n->{"dependencies"} // []
l!l
00
MC/DC0%0/1
$n->{"dependencies"} // []
$n->{"dependencies"}
Truth table0%0/2
A
A= $n->{"dependencies"}
Aresult
11
00
1236 0 ▶ next unless defined $d->{schema};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $d->{"schema"} 0 0 0
1237 0 my $check = $direct->($d->{schema});
1238 0 ▶ push @out, 'return 0 if exists $x->{' . perl_string($d->{name}) . '} && !' . _wrap($check) . ';' if $check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check ne 1 0 0 0
1239 }
1240 }
1241 106 return \@out;
1242 }
1243  
1244 0 ▶sub dynamic_marks {
Subroutine dynamic_marks: not called CC=4 SCAR=30.0
Pod undocumented
1245 0 my ($self, $n, $kind) = @_;
1246 0 my $d = $n->{dynamic_ref};
1247 0 for my $node_id ($d->{fallback}, values %{ $d->{by_resource} }) {
1248 0 my $c = $self->{nodes}[ $self->elide($node_id) ];
1249 0 ▶ return 1 if $kind eq 'object' ? $c->{marks_properties} : $c->{marks_items};
Branch: 2 branches
BranchTrueFalseTotal
if $kind eq "object" ? $c->{"marks_properties"} : $c->{"marks_items"} 0 0 0
$kind eq 'object' ? : 0 0 0
1250 }
1251 0 return 0;
1252 }
1253  
1254 2 ▶sub any_of_check {
Subroutine any_of_check: called CC=4 SCAR=14.1
Pod undocumented
1255 2 my ($self, $n, $branches) = @_;
1256 2 ▶ return ['return 0;'] unless @$branches;
Branch: 1 branch
BranchTrueFalseTotal
unless @$branches 0 2 2
1257 2 my $dispatch = $self->type_dispatch($n, $branches);
1258 2 ▶ return $dispatch if $dispatch;
Branch: 1 branch
BranchTrueFalseTotal
if $dispatch 0 2 2
1259 2 my @checks = map { $self->call($_, '$x', $n->{resource_id}) } @$branches;
1260 2 ▶ return [] if grep { $_ eq '1' } @checks;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq 1;} @checks 0 2 2
1261 2 return [ 'return 0 unless ' . join(' || ', map { _wrap($_) } @checks) . ';' ];
1262 }
1263  
1264 0 ▶sub one_of_check {
Subroutine one_of_check: not called CC=7 SCAR=40.3
Pod undocumented
1265 0 my ($self, $n, $branches) = @_;
1266 0 ▶ return ['return 0;'] unless @$branches;
Branch: 1 branch
BranchTrueFalseTotal
unless @$branches 0 0 0
1267 0 ▶ if (@$branches == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$branches == 1) 0 0 0
1268 0 my $check = $self->call($branches->[0], '$x', $n->{resource_id});
1269 0 ▶ return $check eq '1' ? [] : [ 'return 0 unless ' . _wrap($check) . ';' ];
Branch: 1 branch
BranchTrueFalseTotal
$check eq '1' ? : 0 0 0
1270 }
1271 0 my $dispatch = $self->type_dispatch($n, $branches);
1272 0 ▶ return $dispatch if $dispatch;
Branch: 1 branch
BranchTrueFalseTotal
if $dispatch 0 0 0
1273 0 my $count = $self->scratch('one');
1274 0 my @out = ("my $count = 0;");
1275 0 for my $i (0 .. $#$branches) {
1276 0 my $check = $self->call($branches->[$i], '$x', $n->{resource_id});
1277 0 ▶ if ($i == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i == 0) { } 0 0 0
1278 0 push @out, "$count = 1 if " . _wrap($check) . ';';
1279 }
1280 else {
1281 0 push @out, 'if (' . $check . ') {', " return 0 if $count;", " $count = 1;", '}';
1282 }
1283 }
1284 0 push @out, "return 0 unless $count;";
1285 0 return \@out;
1286 }
1287  
1288 # When every branch asserts a type and no two accept the same kind, the instance's kind selects the only branch that
1289 # can pass (SchemaCompiler.ComputeTypeDispatch). Correct for anyOf and oneOf alike.
1290 2 ▶sub type_dispatch {
Subroutine type_dispatch: called CC=15 SCAR=49.3
Pod undocumented
1291 2 my ($self, $n, $branches) = @_;
1292 2 my %owner;
1293 2 for my $b (@$branches) {
1294 2 my $c = $self->{nodes}[ $self->elide($b) ];
1295 2 ▶ next if $c->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"always_false"} 0 2 2
1296 2 ▶ return undef if $c->{always_true} || !$c->{has_type};
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"always_true"} or not $c->{"has_type"} 2 0 2
Condition33%1/3
$c->{"always_true"} or not $c->{"has_type"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$c->{"always_true"} or not $c->{"has_type"}
$c->{"always_true"} not $c->{"has_type"}
Truth table33%1/3
A or not(B)
A= $c->{"always_true"}B= not $c->{"has_type"}
ABresult
1X1
011
000
1297 0 for my $k (@KINDS) {
1298 0 ▶ next unless kind_allowed($c->{type}, $k);
Branch: 1 branch
BranchTrueFalseTotal
unless kind_allowed($c->{"type"}, $k) 0 0 0
1299 0 ▶ return undef if exists $owner{$k};
Branch: 1 branch
BranchTrueFalseTotal
if exists $owner{$k} 0 0 0
1300 0 $owner{$k} = $b;
1301 }
1302 }
1303 0 ▶ return undef if @$branches < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @$branches < 2 0 0 0
1304 0 my @out;
1305 0 my $first = 1;
1306 0 for my $b (@$branches) {
1307 0 ▶ my @kinds = grep { exists $owner{$_} && $owner{$_} == $b } @KINDS;
Condition0%0/3
exists $owner{$_} && $owner{$_} == $b
!ll&&!rl&&r
000
MC/DC0%0/2
exists $owner{$_} && $owner{$_} == $b
exists $owner{$_} $owner{$_} == $b
Truth table0%0/3
A && B
A= exists $owner{$_}B= $owner{$_} == $b
ABresult
0X0
100
111
1308 0 ▶ next unless @kinds;
Branch: 1 branch
BranchTrueFalseTotal
unless @kinds 0 0 0
1309 0 my $check = $self->call($b, '$x', $n->{resource_id});
1310 0 my $test = join ' || ', map { $self->kind_test($_, '$x') } @kinds;
1311 0 ▶ push @out, ($first ? 'if (' : '} elsif (') . "$test) {";
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
1312 0 ▶ push @out, ' return 0 unless ' . _wrap($check) . ';' if $check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check ne 1 0 0 0
1313 0 $first = 0;
1314 }
1315 0 ▶ return ['return 0;'] if $first;
Branch: 1 branch
BranchTrueFalseTotal
if $first 0 0 0
1316 0 push @out, '} else {', ' return 0;', '}';
1317 0 return \@out;
1318 }
1319  
1320 # Narrows oneOf or anyOf branches by a discriminator property when the instance is an object that has it.
1321 2 ▶sub select_branches {
Subroutine select_branches: called CC=10 SCAR=44.9
Pod undocumented
1322 2 my ($self, $n, $branches, $disc, $check) = @_;
1323 0 ▶ return $check->($branches) unless $disc && !grep { !_is_primitive($_->[0]) } @{ $disc->{known} };
Branch: 1 branch
BranchTrueFalseTotal
unless $disc and not grep({not _is_primitive($_->[0]);} @{$$disc{"known"};}) 2 0 2
Condition33%1/3
$disc and not grep({not _is_primitive($_->[0]);} @{$$disc{"known"};})
!ll&&!rl&&r
200
MC/DC0%0/2
$disc and not grep({not _is_primitive($_->[0]);} @{$$disc{"known"};})
$disc not grep({not _is_primitive($_->[0]);} @{$$disc{"known"};})
Truth table33%1/3
A and not(B)
A= $discB= not grep({not _is_primitive($_->[0]);} @{$$disc{"known"};})
ABresult
0X0
100
111
1324 0 my $d = $self->scratch('d');
1325 0 my $key = perl_string($disc->{property});
1326 0 my @out;
1327 0 push @out, 'if (' . $self->kind_test('object', '$x') . ') {';
1328 0 push @out, " if (!exists \$x->{$key}) {";
1329 0 ▶ push @out, _indent($disc->{all_require} ? ['return 0;'] : $check->($branches), 2);
Branch: 1 branch
BranchTrueFalseTotal
$disc->{'all_require'} ? : 0 0 0
1330 0 push @out, ' } else {';
1331 0 push @out, " my $d = \$x->{$key};";
1332 # The values that select the same subset of branches, together.
1333 0 my (%groups, @group_order);
1334 0 for my $entry (@{ $disc->{known} }) {
1335 0 my ($value, $subset) = @$entry;
1336 0 my $k = join ',', @$subset;
1337 0 ▶ push @group_order, $k unless exists $groups{$k};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $groups{$k} 0 0 0
1338 0 push @{ $groups{$k} }, $value;
1339 }
1340 0 my $first = 1;
1341 0 for my $k (@group_order) {
1342 0 ▶ my @subset = map { $branches->[$_] } length $k ? split /,/, $k : ();
Branch: 1 branch
BranchTrueFalseTotal
length $k ? : 0 0 0
1343 0 my $test = join ' || ', map { $self->eq_test($d, $_) } @{ $groups{$k} };
1344 0 ▶ push @out, ' ' . ($first ? 'if (' : '} elsif (') . "$test) {";
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
1345 0 push @out, _indent($check->(\@subset), 3);
1346 0 $first = 0;
1347 }
1348 0 ▶ push @out, $first ? ' {' : ' } else {';
Branch: 1 branch
BranchTrueFalseTotal
$first ? : 0 0 0
1349 0 push @out, _indent($check->([ map { $branches->[$_] } @{ $disc->{unknown} } ]), 3);
1350 0 push @out, ' }', ' }', '} else {';
1351 0 push @out, _indent($check->($branches));
1352 0 push @out, '}';
1353 0 return \@out;
1354 }
1355  
1356 # --- The tracking layout (unevaluatedProperties and unevaluatedItems) ---
1357  
1358 0 ▶sub _coverage { { names => {}, patterns => [], prefix => 0, all => 0 } }
Subroutine _coverage: not called CC=1 SCAR=6.9
1359  
1360 0 ▶sub _within {
Subroutine _within: not called CC=7 SCAR=40.3
1361 0 my ($main, $c, $check_prefix) = @_;
1362 0 ▶ return 1 if $main->{all};
Branch: 1 branch
BranchTrueFalseTotal
if $main->{"all"} 0 0 0
1363 0 ▶ return 0 if $c->{all};
Branch: 1 branch
BranchTrueFalseTotal
if $c->{"all"} 0 0 0
1364 0 ▶ return 0 if $check_prefix && $c->{prefix} > $main->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $check_prefix and $c->{"prefix"} > $main->{"prefix"} 0 0 0
Condition0%0/3
$check_prefix and $c->{"prefix"} > $main->{"prefix"}
!ll&&!rl&&r
000
MC/DC0%0/2
$check_prefix and $c->{"prefix"} > $main->{"prefix"}
$check_prefix $c->{"prefix"} > $main->{"prefix"}
Truth table0%0/3
A and B
A= $check_prefixB= $c->{"prefix"} > $main->{"prefix"}
ABresult
0X0
100
111
1365 0 ▶ return 0 if grep { !$main->{names}{$_} } keys %{ $c->{names} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $main->{"names"}{$_};} keys %{$$c{"names"};} 0 0 0
1366 0 my %main_patterns = map { $_ => 1 } @{ $main->{patterns} };
1367 0 ▶ return 0 if grep { !$main_patterns{$_} } @{ $c->{patterns} };
Branch: 1 branch
BranchTrueFalseTotal
if grep {not $main_patterns{$_};} @{$$c{"patterns"};} 0 0 0
1368 0 return 1;
1369 }
1370  
1371 # When every in-place contributor of evaluated properties or items is unconditional ($ref and allOf chains, with no
1372 # marking anyOf, oneOf, if, dependentSchemas or $dynamicRef), the evaluated set is static: declared names, patterns,
1373 # a prefix length, or everything, and unevaluatedProperties or unevaluatedItems needs no tracking at run time. undef
1374 # when some contribution is conditional.
1375 0 ▶sub static_coverage {
Subroutine static_coverage: not called CC=3 SCAR=24.8
Pod undocumented
1376 0 my ($self, $n, $kind) = @_;
1377 0 my $main = _coverage();
1378 0 my @conditional;
1379 0 ▶ my $marks = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1380 0 my $c = $self->{nodes}[ $self->elide($_[0]) ];
1381 0 ▶ return $kind eq 'object' ? $c->{marks_properties} : $c->{marks_items};
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'object' ? : 0 0 0
1382 0 };
1383 0 my $visit;
1384 0 ▶ $visit = sub {
Subroutine __ANON__: not called CC=33 SCAR=70.2
1385 0 my ($node_id, $root, $coverage, $visited) = @_;
1386 0 my $m = $self->{nodes}[$node_id];
1387 0 ▶ return 1 if $visited->{$node_id}++;
Branch: 1 branch
BranchTrueFalseTotal
if $visited->{$node_id}++ 0 0 0
1388 0 ▶ return 1 if $m->{always_true} || $m->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"always_true"} or $m->{"always_false"} 0 0 0
Condition0%0/3
$m->{"always_true"} or $m->{"always_false"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$m->{"always_true"} or $m->{"always_false"}
$m->{"always_true"} $m->{"always_false"}
Truth table0%0/3
A or B
A= $m->{"always_true"}B= $m->{"always_false"}
ABresult
1X1
011
000
1389 0 ▶ my @conditional_children = (@{ $m->{any_of} // [] }, @{ $m->{one_of} // [] },
Condition0%0/4
$m->{"any_of"} // []
l!l
00
$m->{"one_of"} // []
l!l
00
MC/DC0%0/1
$m->{"any_of"} // []
$m->{"any_of"}
MC/DC0%0/1
$m->{"one_of"} // []
$m->{"one_of"}
Truth table0%0/2
A
A= $m->{"any_of"}
Aresult
11
00
Truth table0%0/2
A
A= $m->{"one_of"}
Aresult
11
00
1390 0 (grep { $_ >= 0 } $m->{if_}, $m->{then}, $m->{else_}),
1391 0 ▶ (map { defined $_->{schema} ? $_->{schema} : () } @{ $m->{dependencies} // [] }),
Branch: 2 branches
BranchTrueFalseTotal
defined $_->{'schema'} ? : 0 0 0
$m->{'dynamic_ref'} ? : 0 0 0
Condition0%0/2
$m->{"dependencies"} // []
l!l
00
MC/DC0%0/1
$m->{"dependencies"} // []
$m->{"dependencies"}
Truth table0%0/2
A
A= $m->{"dependencies"}
Aresult
11
00
1392 0 ($m->{dynamic_ref} ? ($m->{dynamic_ref}{fallback}, values %{ $m->{dynamic_ref}{by_resource} }) : ()));
1393 0 for my $c (@conditional_children) {
1394 0 ▶ next unless $marks->($c);
Branch: 1 branch
BranchTrueFalseTotal
unless &$marks($c) 0 0 0
1395 0 my $sub = _coverage();
1396 0 ▶ return 0 unless $visit->($self->elide($c), 0, $sub, {});
Branch: 1 branch
BranchTrueFalseTotal
unless &$visit($self->elide($c), 0, $sub, scalar {}) 0 0 0
1397 0 push @conditional, $sub;
1398 }
1399 0 ▶ if ($kind eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'object') { } 0 0 0
1400 0 ▶ $coverage->{names}{$_} = 1 for @{ $m->{property_order} // [] };
Condition0%0/2
$m->{"property_order"} // []
l!l
00
MC/DC0%0/1
$m->{"property_order"} // []
$m->{"property_order"}
Truth table0%0/2
A
A= $m->{"property_order"}
Aresult
11
00
1401 0 ▶ for my $p (@{ $m->{pattern_properties} // [] }) {
Condition0%0/2
$m->{"pattern_properties"} // []
l!l
00
MC/DC0%0/1
$m->{"pattern_properties"} // []
$m->{"pattern_properties"}
Truth table0%0/2
A
A= $m->{"pattern_properties"}
Aresult
11
00
1402 0 ▶ push @{ $coverage->{patterns} }, $p->{pattern} unless grep { $_ eq $p->{pattern} } @{ $coverage->{patterns} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $p->{"pattern"};} @{$$coverage{"patterns"};} 0 0 0
1403 }
1404 0 ▶ $coverage->{all} = 1 if $m->{additional_properties} >= 0 || (!$root && $m->{unevaluated_properties} >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0 0 0 0
Condition0%0/6
$m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0
l!l&&r!l&&!r
000
not $root and $m->{"unevaluated_properties"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0
$m->{"additional_properties"} >= 0 not $root $m->{"unevaluated_properties"} >= 0
Truth table0%0/4
A or not(B) and C
A= $m->{"additional_properties"} >= 0B= not $rootC= $m->{"unevaluated_properties"} >= 0
ABCresult
1XX1
0111
00X0
0100
1405 }
1406 else {
1407 0 ▶ my $count = @{ $m->{prefix_items} // [] };
Condition0%0/2
$m->{"prefix_items"} // []
l!l
00
MC/DC0%0/1
$m->{"prefix_items"} // []
$m->{"prefix_items"}
Truth table0%0/2
A
A= $m->{"prefix_items"}
Aresult
11
00
1408 0 ▶ $coverage->{prefix} = $count if $count > $coverage->{prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $count > $coverage->{"prefix"} 0 0 0
1409 0 ▶ $coverage->{all} = 1 if $m->{items} >= 0 || (!$root && $m->{unevaluated_items} >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"items"} >= 0 or not $root and $m->{"unevaluated_items"} >= 0 0 0 0
Condition0%0/6
$m->{"items"} >= 0 or not $root and $m->{"unevaluated_items"} >= 0
l!l&&r!l&&!r
000
not $root and $m->{"unevaluated_items"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$m->{"items"} >= 0 or not $root and $m->{"unevaluated_items"} >= 0
$m->{"items"} >= 0 not $root $m->{"unevaluated_items"} >= 0
Truth table0%0/4
A or not(B) and C
A= $m->{"items"} >= 0B= not $rootC= $m->{"unevaluated_items"} >= 0
ABCresult
1XX1
0111
00X0
0100
1410 0 ▶ return 0 if $m->{contains} >= 0 && $m->{contains_marks_evaluated};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"contains"} >= 0 and $m->{"contains_marks_evaluated"} 0 0 0
Condition0%0/3
$m->{"contains"} >= 0 and $m->{"contains_marks_evaluated"}
!ll&&!rl&&r
000
MC/DC0%0/2
$m->{"contains"} >= 0 and $m->{"contains_marks_evaluated"}
$m->{"contains"} >= 0 $m->{"contains_marks_evaluated"}
Truth table0%0/3
A and B
A= $m->{"contains"} >= 0B= $m->{"contains_marks_evaluated"}
ABresult
0X0
100
111
1411 }
1412 0 ▶ for my $c ($m->{ref}, $m->{static_dynamic_ref}, @{ $m->{all_of} // [] }) {
Condition0%0/2
$m->{"all_of"} // []
l!l
00
MC/DC0%0/1
$m->{"all_of"} // []
$m->{"all_of"}
Truth table0%0/2
A
A= $m->{"all_of"}
Aresult
11
00
1413 0 ▶ return 0 if $c >= 0 && $marks->($c) && !$visit->($self->elide($c), 0, $coverage, $visited);
Branch: 1 branch
BranchTrueFalseTotal
if $c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $visited) 0 0 0
Condition0%0/6
$c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $visited)
!ll&&!rl&&r
000
$c >= 0 and &$marks($c)
!ll&&!rl&&r
000
MC/DC0%0/3
$c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $visited)
$c >= 0 &$marks($c) not &$visit($self->elide($c), 0, $coverage, $visited)
Truth table0%0/4
A and B and not(C)
A= $c >= 0B= &$marks($c)C= not &$visit($self->elide($c), 0, $coverage, $visited)
ABCresult
0XX0
10X0
1100
1111
1414 }
1415 0 return 1;
1416 0 };
1417 0 my $ok = $visit->($n->{id}, 1, $main, {});
1418 0 undef $visit;
1419 0 ▶ return undef unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
1420 0 ▶ return (grep { !_within($main, $_, 1) } @conditional) ? undef : $main;
Branch: 1 branch
BranchTrueFalseTotal
grep({not _within($main, $_, 1);} @conditional) ? : 0 0 0
1421 }
1422  
1423 # Static coverage for objects with guards: a contribution under if, then or else or a dependency's schema is kept with
1424 # the conditions it applies under, so an object's evaluated names are the unconditional coverage plus every guarded
1425 # coverage whose guards hold, all tested statically. Returns (coverage, guarded) or ().
1426 0 ▶sub guarded_coverage {
Subroutine guarded_coverage: not called CC=4 SCAR=30.0
Pod undocumented
1427 0 my ($self, $n) = @_;
1428 0 my $main = _coverage();
1429 0 my (@guarded, @unguarded);
1430 0 ▶ my $marks = sub { $self->{nodes}[ $self->elide($_[0]) ]{marks_properties} };
Subroutine __ANON__: not called CC=1 SCAR=6.9
1431 0 my $visit;
1432 0 ▶ $visit = sub {
Subroutine __ANON__: not called CC=39 SCAR=73.5
1433 0 my ($node_id, $root, $coverage, $guards, $visited) = @_;
1434 0 my $m = $self->{nodes}[$node_id];
1435 0 ▶ return 1 if $visited->{$node_id}++;
Branch: 1 branch
BranchTrueFalseTotal
if $visited->{$node_id}++ 0 0 0
1436 0 ▶ return 1 if $m->{always_true} || $m->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"always_true"} or $m->{"always_false"} 0 0 0
Condition0%0/3
$m->{"always_true"} or $m->{"always_false"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$m->{"always_true"} or $m->{"always_false"}
$m->{"always_true"} $m->{"always_false"}
Truth table0%0/3
A or B
A= $m->{"always_true"}B= $m->{"always_false"}
ABresult
1X1
011
000
1437 0 ▶ return 0 if $m->{in_place_cycle} || ($self->{program}{uses_dynamic_scope} && $m->{resource_id} != $n->{resource_id});
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"in_place_cycle"} or $self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"} 0 0 0
Condition0%0/6
$m->{"in_place_cycle"} or $self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"}
l!l&&r!l&&!r
000
$self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"}
!ll&&!rl&&r
000
MC/DC0%0/3
$m->{"in_place_cycle"} or $self->{"program"}{"uses_dynamic_scope"} and $m->{"resource_id"} != $n->{"resource_id"}
$m->{"in_place_cycle"} $self->{"program"}{"uses_dynamic_scope"} $m->{"resource_id"} != $n->{"resource_id"}
Truth table0%0/4
A or B and C
A= $m->{"in_place_cycle"}B= $self->{"program"}{"uses_dynamic_scope"}C= $m->{"resource_id"} != $n->{"resource_id"}
ABCresult
1XX1
0111
00X0
0100
1438 0 ▶ my $branch = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
1439 0 my ($c, $g) = @_;
1440 0 my $sub = _coverage();
1441 0 ▶ if (defined $g) { push @guarded, [ $g, $sub ] } else { push @unguarded, $sub }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $g) { } 0 0 0
1442 0 return $visit->($self->elide($c), 0, $sub, $g, {});
1443 0 };
1444 0 ▶ my @alternatives = (@{ $m->{any_of} // [] }, @{ $m->{one_of} // [] },
Branch: 1 branch
BranchTrueFalseTotal
$m->{'dynamic_ref'} ? : 0 0 0
Condition0%0/4
$m->{"any_of"} // []
l!l
00
$m->{"one_of"} // []
l!l
00
MC/DC0%0/1
$m->{"any_of"} // []
$m->{"any_of"}
MC/DC0%0/1
$m->{"one_of"} // []
$m->{"one_of"}
Truth table0%0/2
A
A= $m->{"any_of"}
Aresult
11
00
Truth table0%0/2
A
A= $m->{"one_of"}
Aresult
11
00
1445 0 ($m->{dynamic_ref} ? ($m->{dynamic_ref}{fallback}, values %{ $m->{dynamic_ref}{by_resource} }) : ()));
1446 0 for my $c (@alternatives) {
1447 0 ▶ return 0 if $marks->($c) && !$branch->($c, undef);
Branch: 1 branch
BranchTrueFalseTotal
if &$marks($c) and not &$branch($c, undef) 0 0 0
Condition0%0/3
&$marks($c) and not &$branch($c, undef)
!ll&&!rl&&r
000
MC/DC0%0/2
&$marks($c) and not &$branch($c, undef)
&$marks($c) not &$branch($c, undef)
Truth table0%0/3
A and not(B)
A= &$marks($c)B= not &$branch($c, undef)
ABresult
0X0
100
111
1448 }
1449 0 ▶ if ($m->{if_} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m->{"if_"} >= 0) 0 0 0
1450 0 my $test = $self->call($m->{if_}, '$x', $n->{resource_id});
1451 0 for my $pair ([ $m->{if_}, 1 ], [ $m->{then}, 1 ], [ $m->{else_}, 0 ]) {
1452 0 my ($c, $holds) = @$pair;
1453 0 ▶ next unless $c >= 0 && $marks->($c);
Branch: 1 branch
BranchTrueFalseTotal
unless $c >= 0 and &$marks($c) 0 0 0
Condition0%0/3
$c >= 0 and &$marks($c)
!ll&&!rl&&r
000
MC/DC0%0/2
$c >= 0 and &$marks($c)
$c >= 0 &$marks($c)
Truth table0%0/3
A and B
A= $c >= 0B= &$marks($c)
ABresult
0X0
100
111
1454 0 ▶ my $g = defined $guards ? [ @$guards, $holds ? $test : '!' . _wrap($test) ] : undef;
Branch: 2 branches
BranchTrueFalseTotal
defined $guards ? : 0 0 0
$holds ? : 0 0 0
1455 0 ▶ return 0 unless $branch->($c, $g);
Branch: 1 branch
BranchTrueFalseTotal
unless &$branch($c, $g) 0 0 0
1456 }
1457 }
1458 0 ▶ for my $dep (@{ $m->{dependencies} // [] }) {
Condition0%0/2
$m->{"dependencies"} // []
l!l
00
MC/DC0%0/1
$m->{"dependencies"} // []
$m->{"dependencies"}
Truth table0%0/2
A
A= $m->{"dependencies"}
Aresult
11
00
1459 0 ▶ next if !defined $dep->{schema} || !$marks->($dep->{schema});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dep->{"schema"} and &$marks($dep->{"schema"}) 0 0 0
Condition0%0/3
defined $dep->{"schema"} and &$marks($dep->{"schema"})
!ll&&!rl&&r
000
MC/DC0%0/2
defined $dep->{"schema"} and &$marks($dep->{"schema"})
defined $dep->{"schema"} &$marks($dep->{"schema"})
Truth table0%0/3
A and B
A= defined $dep->{"schema"}B= &$marks($dep->{"schema"})
ABresult
0X0
100
111
1460 0 ▶ my $g = defined $guards ? [ @$guards, 'exists $x->{' . perl_string($dep->{name}) . '}' ] : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $guards ? : 0 0 0
1461 0 ▶ return 0 unless $branch->($dep->{schema}, $g);
Branch: 1 branch
BranchTrueFalseTotal
unless &$branch($dep->{"schema"}, $g) 0 0 0
1462 }
1463 0 ▶ $coverage->{names}{$_} = 1 for @{ $m->{property_order} // [] };
Condition0%0/2
$m->{"property_order"} // []
l!l
00
MC/DC0%0/1
$m->{"property_order"} // []
$m->{"property_order"}
Truth table0%0/2
A
A= $m->{"property_order"}
Aresult
11
00
1464 0 ▶ for my $p (@{ $m->{pattern_properties} // [] }) {
Condition0%0/2
$m->{"pattern_properties"} // []
l!l
00
MC/DC0%0/1
$m->{"pattern_properties"} // []
$m->{"pattern_properties"}
Truth table0%0/2
A
A= $m->{"pattern_properties"}
Aresult
11
00
1465 0 ▶ push @{ $coverage->{patterns} }, $p->{pattern} unless grep { $_ eq $p->{pattern} } @{ $coverage->{patterns} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $p->{"pattern"};} @{$$coverage{"patterns"};} 0 0 0
1466 }
1467 0 ▶ $coverage->{all} = 1 if $m->{additional_properties} >= 0 || (!$root && $m->{unevaluated_properties} >= 0);
Branch: 1 branch
BranchTrueFalseTotal
if $m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0 0 0 0
Condition0%0/6
$m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0
l!l&&r!l&&!r
000
not $root and $m->{"unevaluated_properties"} >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
$m->{"additional_properties"} >= 0 or not $root and $m->{"unevaluated_properties"} >= 0
$m->{"additional_properties"} >= 0 not $root $m->{"unevaluated_properties"} >= 0
Truth table0%0/4
A or not(B) and C
A= $m->{"additional_properties"} >= 0B= not $rootC= $m->{"unevaluated_properties"} >= 0
ABCresult
1XX1
0111
00X0
0100
1468 0 ▶ for my $c ($m->{ref}, $m->{static_dynamic_ref}, @{ $m->{all_of} // [] }) {
Condition0%0/2
$m->{"all_of"} // []
l!l
00
MC/DC0%0/1
$m->{"all_of"} // []
$m->{"all_of"}
Truth table0%0/2
A
A= $m->{"all_of"}
Aresult
11
00
1469 0 ▶ return 0 if $c >= 0 && $marks->($c) && !$visit->($self->elide($c), 0, $coverage, $guards, $visited);
Branch: 1 branch
BranchTrueFalseTotal
if $c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $guards, $visited) 0 0 0
Condition0%0/6
$c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $guards, $visited)
!ll&&!rl&&r
000
$c >= 0 and &$marks($c)
!ll&&!rl&&r
000
MC/DC0%0/3
$c >= 0 and &$marks($c) and not &$visit($self->elide($c), 0, $coverage, $guards, $visited)
$c >= 0 &$marks($c) not &$visit($self->elide($c), 0, $coverage, $guards, $visited)
Truth table0%0/4
A and B and not(C)
A= $c >= 0B= &$marks($c)C= not &$visit($self->elide($c), 0, $coverage, $guards, $visited)
ABCresult
0XX0
10X0
1100
1111
1470 }
1471 0 return 1;
1472 0 };
1473 0 my $ok = $visit->($n->{id}, 1, $main, [], {});
1474 0 undef $visit;
1475 0 ▶ return () unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 0 0
1476 0 ▶ return () if grep { !_within($main, $_, 0) } @unguarded;
Branch: 1 branch
BranchTrueFalseTotal
if grep {not _within($main, $_, 0);} @unguarded 0 0 0
1477 0 my @adding = grep { !_within($main, $_->[1], 0) } @guarded;
1478 0 ▶ return @adding <= MAX_GUARDED_COVERAGES ? ($main, \@adding) : ();
Branch: 1 branch
BranchTrueFalseTotal
@adding <= 32 ? : 0 0 0
1479 }
1480  
1481 # The object or array branch of a node whose unevaluated keyword is decided by static coverage.
1482 0 ▶sub fused_unevaluated {
Subroutine fused_unevaluated: not called CC=10 SCAR=47.0
Pod undocumented
1483 0 my ($self, $n, $kind, $coverage, $variant, $guarded) = @_;
1484 0 my @lines;
1485 0 push @lines, @{ $self->kind_section($n, $kind, undef, 1) };
1486 0 push @lines, @{ $self->in_place($n, undef, undef) };
1487 0 ▶ if (!$coverage->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($coverage->{"all"}) 0 0 0
1488 0 ▶ if ($kind eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'object') { } 0 0 0
1489 0 my $check = $self->call($n->{unevaluated_properties}, '$v', $n->{resource_id});
1490 0 ▶ push @lines, @{ $self->uncovered_properties($coverage, $guarded // [], $check) } if $check ne '1';
Branch: 1 branch
BranchTrueFalseTotal
if $check ne 1 0 0 0
Condition0%0/2
$guarded // []
l!l
00
MC/DC0%0/1
$guarded // []
$guarded
Truth table0%0/2
A
A= $guarded
Aresult
11
00
1491 }
1492 else {
1493 0 my $check = $self->call($n->{unevaluated_items}, '$v', $n->{resource_id});
1494 0 ▶ if ($check eq '0') {
Branch: 2 branches
BranchTrueFalseTotal
if ($check eq '0') { } 0 0 0
elsif ($check ne '1') { } 0 0 0
1495 0 push @lines, "return 0 if \@\$x > $coverage->{prefix};";
1496 }
1497 elsif ($check ne '1') {
1498 0 ▶ my $source = $coverage->{prefix} ? "\@\$x[$coverage->{prefix} .. \$#\$x]" : '@$x';
Branch: 1 branch
BranchTrueFalseTotal
$coverage->{'prefix'} ? : 0 0 0
1499 0 push @lines, "for my \$v ($source) {", ' return 0 unless ' . _wrap($check) . ';', '}';
1500 }
1501 }
1502 }
1503 0 ▶ if ($variant eq 't') {
Branch: 1 branch
BranchTrueFalseTotal
if ($variant eq "t") 0 0 0
1504 0 ▶ push @lines, $kind eq 'object' ? '$ev->{$_} = 1 for keys %$x;' : '$ev->{$_} = 1 for 0 .. $#$x;';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'object' ? : 0 0 0
1505 }
1506 0 push @lines, 'return 1;';
1507 0 return \@lines;
1508 }
1509  
1510 # The test of every property no coverage evaluated, against unevaluatedProperties.
1511 0 ▶sub uncovered_properties {
Subroutine uncovered_properties: not called CC=20 SCAR=60.4
Pod undocumented
1512 0 my ($self, $coverage, $guarded, $check) = @_;
1513 0 my @lines;
1514 0 my @sorted = sort keys %{ $coverage->{names} };
1515 0 ▶ my $names = @sorted ? $self->constant('{' . join(', ', map { perl_string($_) . ' => 1' } @sorted) . '}') : undef;
Branch: 1 branch
BranchTrueFalseTotal
@sorted ? : 0 0 0
1516 0 ▶ if (!@{ $coverage->{patterns} } && !@$guarded && $check eq '0') {
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$coverage->{"patterns"};} || @$guarded and $check eq 0) 0 0 0
Condition0%0/6
not @{$coverage->{"patterns"};} || @$guarded and $check eq 0
!ll&&!rl&&r
000
@{$coverage->{'patterns'};} || @$guarded
l!l&&r!l&&!r
000
MC/DC0%0/3
not @{$coverage->{"patterns"};} || @$guarded and $check eq 0
@{$coverage->{'patterns'};} @$guarded $check eq 0
Truth table0%0/4
not(A || B) and C
A= @{$coverage->{'patterns'};}B= @$guardedC= $check eq 0
ABCresult
1XX0
01X0
0000
0011
1517 # Nothing beyond the declared names may appear.
1518 0 ▶ push @lines, $names ? "for (keys %\$x) { return 0 unless exists $names\->{\$_} }" : 'return 0 if %$x;';
Branch: 1 branch
BranchTrueFalseTotal
$names ? : 0 0 0
1519 0 return \@lines;
1520 }
1521 # Each distinct guard is decided once for an object, before the pass.
1522 0 my (%guard_names, @guard_order);
1523 0 for my $g (@$guarded) {
1524 0 for my $expr (@{ $g->[0] }) {
1525 0 ▶ next if exists $guard_names{$expr};
Branch: 1 branch
BranchTrueFalseTotal
if exists $guard_names{$expr} 0 0 0
1526 0 my $name = $self->scratch('g');
1527 0 $guard_names{$expr} = $name;
1528 0 push @lines, "my $name = $expr;";
1529 }
1530 }
1531 0 my @body = ('my $v = $x->{$k};');
1532 0 ▶ push @body, "next if exists $names\->{\$k};" if $names;
Branch: 1 branch
BranchTrueFalseTotal
if $names 0 0 0
1533 0 push @body, 'next if ' . $self->pattern_test($_, '$k') . ';' for @{ $coverage->{patterns} };
1534 0 for my $g (@$guarded) {
1535 0 my ($guards, $c) = @$g;
1536 0 my $when = join ' && ', map { $guard_names{$_} } @$guards;
1537 0 my @covered;
1538 0 my @extra = sort keys %{ $c->{names} };
1539 0 ▶ if (@extra && @extra <= MAX_GUARD_NAMES) {
Branch: 2 branches
BranchTrueFalseTotal
if (@extra and @extra <= 6) { } 0 0 0
elsif (@extra) { } 0 0 0
Condition0%0/3
@extra and @extra <= 6
!ll&&!rl&&r
000
MC/DC0%0/2
@extra and @extra <= 6
@extra @extra <= 6
Truth table0%0/3
A and B
A= @extraB= @extra <= 6
ABresult
0X0
100
111
1540 0 push @covered, map { '$k eq ' . perl_string($_) } @extra;
1541 }
1542 elsif (@extra) {
1543 0 push @covered, 'exists ' . $self->constant('{' . join(', ', map { perl_string($_) . ' => 1' } @extra) . '}')
1544 . '->{$k}';
1545 }
1546 0 push @covered, map { $self->pattern_test($_, '$k') } @{ $c->{patterns} };
1547 0 ▶ if ($c->{all}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($c->{'all'}) { } 0 0 0
elsif (@covered) { } 0 0 0
1548 0 ▶ push @body, 'next if ' . ($when || '1') . ';';
Condition0%0/2
$when || '1'
l!l
00
MC/DC0%0/1
$when || '1'
$when
Truth table0%0/2
A
A= $when
Aresult
11
00
1549 }
1550 elsif (@covered) {
1551 0 ▶ push @body, 'next if ' . ($when ? "$when && " : '') . '(' . join(' || ', @covered) . ');';
Branch: 1 branch
BranchTrueFalseTotal
$when ? : 0 0 0
1552 }
1553 }
1554 0 ▶ push @body, $check eq '0' ? 'return 0;' : 'return 0 unless ' . _wrap($check) . ';';
Branch: 1 branch
BranchTrueFalseTotal
$check eq '0' ? : 0 0 0
1555 0 push @lines, 'for my $k (keys %$x) {', _indent(\@body), '}';
1556 0 return \@lines;
1557 }
1558  
1559 0 ▶sub tracking_body {
Subroutine tracking_body: not called CC=28 SCAR=67.0
Pod undocumented
1560 0 my ($self, $n, $variant) = @_;
1561 0 ▶ return ['return 0;'] if $n->{always_false};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_false"} 0 0 0
1562 0 ▶ return ['return 1;'] if $n->{always_true};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"always_true"} 0 0 0
1563 0 my @out = @{ $self->const_enum($n) };
1564 0 ▶ my $mask = $n->{has_type} ? $n->{type} : T_ALL;
Branch: 1 branch
BranchTrueFalseTotal
$n->{'has_type'} ? : 0 0 0
1565 0 for my $kind (qw(array object)) {
1566 0 my $test = $self->kind_test($kind, '$x');
1567 0 ▶ if (!kind_allowed($mask, $kind)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (kind_allowed($mask, $kind)) 0 0 0
1568 0 push @out, "return 0 if $test;";
1569 0 next;
1570 }
1571 0 ▶ my $own = $kind eq 'object' ? $n->{unevaluated_properties} >= 0 : $n->{unevaluated_items} >= 0;
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'object' ? : 0 0 0
1572 0 ▶ my $coverage = $own ? $self->static_coverage($n, $kind) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$own ? : 0 0 0
1573 0 ▶ if ($coverage) {
Branch: 1 branch
BranchTrueFalseTotal
if ($coverage) 0 0 0
1574 0 push @out, "if ($test) {", _indent($self->fused_unevaluated($n, $kind, $coverage, $variant)), '}';
1575 0 next;
1576 }
1577 0 ▶ my @guarded = $own && $kind eq 'object' ? $self->guarded_coverage($n) : ();
Branch: 1 branch
BranchTrueFalseTotal
$own && $kind eq 'object' ? : 0 0 0
Condition0%0/3
$own and $kind eq "object"
!ll&&!rl&&r
000
MC/DC0%0/2
$own and $kind eq "object"
$own $kind eq "object"
Truth table0%0/3
A and B
A= $ownB= $kind eq "object"
ABresult
0X0
100
111
1578 0 ▶ if (@guarded) {
Branch: 1 branch
BranchTrueFalseTotal
if (@guarded) 0 0 0
1579 0 push @out, "if ($test) {", _indent($self->fused_unevaluated($n, $kind, $guarded[0], $variant, $guarded[1])), '}';
1580 0 next;
1581 }
1582 0 ▶ my $e = $own ? $self->scratch('e') : $variant eq 't' ? '$ev' : undef;
Branch: 2 branches
BranchTrueFalseTotal
$own ? : 0 0 0
$variant eq 't' ? : 0 0 0
1583 0 my @lines;
1584 0 ▶ push @lines, "my $e = {};" if $own;
Branch: 1 branch
BranchTrueFalseTotal
if $own 0 0 0
1585 0 push @lines, @{ $self->kind_section($n, $kind, $e, !defined $e) };
1586 0 ▶ push @lines, @{ $self->in_place($n, $e, defined $e ? $kind : undef) };
Branch: 1 branch
BranchTrueFalseTotal
defined $e ? : 0 0 0
1587 0 ▶ if ($own) {
Branch: 1 branch
BranchTrueFalseTotal
if ($own) 0 0 0
1588 0 ▶ if ($kind eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($kind eq 'object') { } 0 0 0
1589 0 my $check = $self->call($n->{unevaluated_properties}, '$v', $n->{resource_id});
1590 0 ▶ if ($check ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($check ne 1) 0 0 0
1591 0 push @lines, 'for my $k (keys %$x) {', ' my $v = $x->{$k};',
1592 " return 0 if !exists $e\->{\$k} && !" . _wrap($check) . ';', '}';
1593 }
1594 0 ▶ push @lines, '$ev->{$_} = 1 for keys %$x;' if $variant eq 't';
Branch: 1 branch
BranchTrueFalseTotal
if $variant eq "t" 0 0 0
1595 }
1596 else {
1597 0 my $check = $self->call($n->{unevaluated_items}, '$v', $n->{resource_id});
1598 0 ▶ if ($check ne '1') {
Branch: 1 branch
BranchTrueFalseTotal
if ($check ne 1) 0 0 0
1599 0 push @lines, 'for my $i (0 .. $#$x) {', ' my $v = $x->[$i];',
1600 " return 0 if !exists $e\->{\$i} && !" . _wrap($check) . ';', '}';
1601 }
1602 0 ▶ push @lines, '$ev->{$_} = 1 for 0 .. $#$x;' if $variant eq 't';
Branch: 1 branch
BranchTrueFalseTotal
if $variant eq "t" 0 0 0
1603 }
1604 }
1605 0 push @lines, 'return 1;';
1606 0 push @out, "if ($test) {", _indent(\@lines), '}';
1607 }
1608 # Scalars: flag evaluation.
1609 0 ▶ my @scalar_kinds = grep { $_ ne 'object' && $_ ne 'array' } @KINDS;
Condition0%0/3
$_ ne 'object' && $_ ne 'array'
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne 'object' && $_ ne 'array'
$_ ne 'object' $_ ne 'array'
Truth table0%0/3
A && B
A= $_ ne 'object'B= $_ ne 'array'
ABresult
0X0
100
111
1610 0 my @allowed = grep { kind_allowed($mask, $_) } @scalar_kinds;
1611 0 ▶ if (!@allowed) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@allowed) 0 0 0
1612 0 push @out, 'return 0;';
1613 0 return \@out;
1614 }
1615 0 for my $k (@allowed) {
1616 0 my $lines = $self->kind_section($n, $k, undef, 1);
1617 0 ▶ push @out, 'if (' . $self->kind_test($k, '$x') . ') {', _indent($lines), '}' if @$lines;
Branch: 1 branch
BranchTrueFalseTotal
if @$lines 0 0 0
1618 }
1619 0 ▶ if ($n->{has_type} && @allowed < @scalar_kinds) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n->{"has_type"} and @allowed < @scalar_kinds) 0 0 0
Condition0%0/3
$n->{"has_type"} and @allowed < @scalar_kinds
!ll&&!rl&&r
000
MC/DC0%0/2
$n->{"has_type"} and @allowed < @scalar_kinds
$n->{"has_type"} @allowed < @scalar_kinds
Truth table0%0/3
A and B
A= $n->{"has_type"}B= @allowed < @scalar_kinds
ABresult
0X0
100
111
1620 0 push @out, 'return 0 unless ' . join(' || ', map { $self->kind_test($_, '$x') } @allowed) . ';';
1621 }
1622 0 push @out, @{ $self->in_place($n, undef, undef) };
1623 0 push @out, 'return 1;';
1624 0 return \@out;
1625 }
1626  
1627 # --- Linking: merge structurally identical subs, then emit the reachable ones ---
1628  
1629 2 my $REF_RE = qr/\x01([^\x02]+)\x02/;
1630  
1631 40 ▶sub link {
Subroutine link: called CC=11 SCAR=24.0
Pod undocumented
1632 40 my ($self, $root_name) = @_;
1633 40 my @names = @{ $self->{template_order} };
1634 40 my %index_of = map { $names[$_] => $_ } 0 .. $#names;
1635 # Each template split once: literal parts (even indexes) around references (odd indexes).
1636 40 my @parts = map { [ split /\x01([^\x02]+)\x02/, $self->{templates}{$_}, -1 ] } @names;
1637 40 my @refs = map { my $p = $_; [ map { $index_of{ $p->[$_] } } grep { $_ % 2 } 0 .. $#$p ] } @parts;
1638  
1639 # Partition refinement: classes from the literal parts alone, refined by the classes of the references until the
1640 # number of classes stops growing. Bisimilar subs (identical text up to equivalent callees) merge.
1641 40 my %intern;
1642 my @class_of;
1643 40 for my $p (@parts) {
1644 104 my $sig = join "\x01", map { $p->[$_] } grep { !($_ % 2) } 0 .. $#$p;
1645 104 ▶ $intern{$sig} = scalar keys %intern unless exists $intern{$sig};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $intern{$sig} 65 39 104
1646 104 push @class_of, $intern{$sig};
1647 }
1648 40 my $count = keys %intern;
1649 40 ▶ @class_of = $count < @names ? @{ _refine_classes(\@class_of, $count, \@refs) } : 0 .. $#names;
Branch: 1 branch
BranchTrueFalseTotal
$count < @names ? : 2 38 40
1650  
1651 40 my $root = $index_of{$root_name};
1652 40 my @representative = (-1) x @names;
1653 40 $representative[ $class_of[$root] ] = $root;
1654 40 for my $i (0 .. $#names) {
1655 104 ▶ $representative[ $class_of[$i] ] = $i if $representative[ $class_of[$i] ] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $representative[$class_of[$i]] < 0 27 77 104
1656 }
1657 # The reachable representatives: from the root, and from the subs that dispatch tables name.
1658 40 my @emitted = (0) x @names;
1659 40 my @out;
1660 40 my @stack = ($representative[ $class_of[$root] ]);
1661 40 for my $init (@{ $self->{constant_order} }) {
1662 14 push @stack, map { $representative[ $class_of[ $index_of{$_} ] ] } $init =~ /\x01([^\x02]+)\x02/g;
1663 }
1664 40 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 154 40 194
1665 154 my $i = pop @stack;
1666 154 ▶ next if $emitted[$i]++;
Branch: 1 branch
BranchTrueFalseTotal
if $emitted[$i]++ 87 67 154
1667 67 my $p = $parts[$i];
1668 67 (my $text = $p->[0]) =~ s/\Asub \@ \{/sub _$names[$i] {/;
1669 67 ▶ for (my $k = 1; $k < @$p; $k += 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($k < @$p) 23 67 90
1670 23 my $target = $representative[ $class_of[ $refs[$i][ ($k - 1) / 2 ] ] ];
1671 23 $text .= "_$names[$target]" . $p->[ $k + 1 ];
1672 23 ▶ push @stack, $target unless $emitted[$target];
Branch: 1 branch
BranchTrueFalseTotal
unless $emitted[$target] 12 11 23
1673 }
1674 67 push @out, [ $names[$i], $text ];
1675 }
1676 my @constants = map {
1677 14 my $init = $_;
1678 14 $init =~ s/\x01([^\x02]+)\x02/_$names[ $representative[ $class_of[ $index_of{$1} ] ] ]/g;
1679 14 [ $self->{constants}{$_}, $init ];
1680 40 } @{ $self->{constant_order} };
1681 # Every sub's name starts with _: v1 alone would be a version string.
1682 40 return (\@out, \@constants, '_' . $names[ $representative[ $class_of[$root] ] ]);
1683 }
1684  
1685 2 ▶sub _refine_classes {
Subroutine _refine_classes: called CC=8 SCAR=20.8
1686 2 my ($initial, $initial_count, $refs) = @_;
1687 2 my @class_of = @$initial;
1688 2 my $count = $initial_count;
1689 2 my $n = @class_of;
1690 2 my @size = (0) x $count;
1691 2 $size[$_]++ for @class_of;
1692 2 while (1) {
1693 3 my %intern;
1694 3 my @next = (0) x $n;
1695 3 my $next_count = 0;
1696 3 my @singleton = (-1) x $count;
1697 3 for my $i (0 .. $n - 1) {
1698 128 my $cls = $class_of[$i];
1699 128 ▶ if ($size[$cls] == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($size[$cls] == 1) 40 88 128
1700 40 ▶ $singleton[$cls] = $next_count++ if $singleton[$cls] < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $singleton[$cls] < 0 40 0 40
1701 40 $next[$i] = $singleton[$cls];
1702 40 next;
1703 }
1704 88 my $sig = join ',', $cls, map { $class_of[$_] } @{ $refs->[$i] };
1705 88 ▶ $intern{$sig} //= $next_count++;
Condition100%2/2
$intern{$sig} //= $next_count++
l!l
7216
MC/DC100%1/1
$intern{$sig} //= $next_count++
$intern{$sig}
Truth table100%2/2
A
A= $intern{$sig}
Aresult
11
00
1706 88 $next[$i] = $intern{$sig};
1707 }
1708 3 @class_of = @next;
1709 3 ▶ return \@class_of if $next_count == $count;
Branch: 1 branch
BranchTrueFalseTotal
if $next_count == $count 2 1 3
1710 1 $count = $next_count;
1711 1 @size = (0) x $count;
1712 1 $size[$_]++ for @class_of;
1713 }
1714 }
1715  
1716 2 1;
« Corvus/Regex/Linear.pm ↑ Summary Corvus/Regex/Parse.pm »