Corvus/Compiler.pm

filter: Statementstmt 75.2% 404 / 537 Branchbran 55.9% 180 / 322 Conditioncond 42.8% 101 / 236 MC/DCmcdc 16.0% 21 / 131 Subroutinesub 86.2% 50 / 58 Podpod 0.0% 0 / 4 totaltotal 58.7% 756 / 1288 CC 271 SCAR 47.5
CC
271
Cov
63%
_collect_annotations
338.1
_classify
306.0
_compile_node
205.5
CRAP 115.2
« Corvus/Regex/Parse.pm ↑ Summary Corvus/Formats.pm »
1 package JSON::Schema::Corvus::Compiler;
2  
3 # Compiles loaded schema documents into a node graph and runs the compile-time analyses. A port of the Python
4 # package's compiler.py (Corvus.Text.Json.RuntimeEvaluator.Compilation.SchemaCompiler, flag-mode subset).
5  
6 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use List::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use JSON::Schema::Corvus::Dialect qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use JSON::Schema::Corvus::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use JSON::Schema::Corvus::Formats ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use JSON::Schema::Corvus::Json;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use JSON::Schema::Corvus::Loader;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use JSON::Schema::Corvus::Node qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use JSON::Schema::Corvus::Pattern ();
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use JSON::Schema::Corvus::Uri;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Keywords CompileNode handles itself; anything else is an unknown keyword (an annotation from 2019-09).
20 4 my %KNOWN_KEYWORDS = map { $_ => 1 } qw(
21 if not type enum $ref then else const items allOf anyOf oneOf title $defs format pattern maximum minimum default
22 $schema $anchor required contains maxItems minItems examples readOnly $comment maxLength minLength writeOnly
23 properties multipleOf deprecated uniqueItems prefixItems minContains maxContains description $vocabulary definitions
24 $dynamicRef dependencies propertyNames maxProperties minProperties contentSchema $recursiveRef $dynamicAnchor
25 contentEncoding additionalItems exclusiveMaximum exclusiveMinimum unevaluatedItems contentMediaType $recursiveAnchor
26 dependentSchemas patternProperties dependentRequired additionalProperties unevaluatedProperties id $id
27 );
28  
29 4 my %TYPE_MASKS = (null => T_NULL, boolean => T_BOOLEAN, object => T_OBJECT, array => T_ARRAY, number => T_NUMBER,
30 string => T_STRING, integer => T_INTEGER);
31  
32 1627 ▶sub _is_number { JSON::Schema::Corvus::Json::is_number($_[0]) }
Subroutine _is_number: called CC=1 SCAR=0.0
33 675 ▶sub _is_string { JSON::Schema::Corvus::Json::is_string($_[0]) }
Subroutine _is_string: called CC=1 SCAR=0.0
34 150 ▶sub _is_true { JSON::Schema::Corvus::Json::is_bool($_[0]) && $_[0] }
Subroutine _is_true: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Json::is_bool($_[0]) and $_[0] 3 147 150
35 586 ▶sub _num { _is_number($_[0]) ? $_[0] : undef }
Subroutine _num: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
_is_number($_[0]) ? : 9 577 586
36  
37 894 ▶sub _get_int {
Subroutine _get_int: called CC=4 SCAR=14.9
38 894 my ($v, $fallback) = @_;
39 894 ▶ return $fallback unless _is_number($v);
Branch: 1 branch
BranchTrueFalseTotal
unless _is_number($v) 892 2 894
40 2 ▶ return ref $v ? (0 + "$v") : int($v) if JSON::Schema::Corvus::Json::is_integer($v, 0);
Branch: 2 branches
BranchTrueFalseTotal
if JSON::Schema::Corvus::Json::is_integer($v, 0) 2 0 2
ref $v ? : 0 2 2
41 0 return $fallback;
42 }
43  
44 2 ▶sub _strings { [ grep { _is_string($_) } @{ $_[0] } ] }
Subroutine _strings: called CC=1 SCAR=0.0
45  
46 16 ▶sub _kw { '/' . JSON::Schema::Corvus::Uri::escape_pointer_token($_[0]) }
Subroutine _kw: called CC=1 SCAR=0.0
47  
48 139 ▶sub _target {
Subroutine _target: called CC=1 SCAR=0.0
49 139 my ($document, $pointer, $value, $resource) = @_;
50 139 return { document => $document, pointer => $pointer, value => $value, resource => $resource };
51 }
52  
53 # Compiles a schema (a JSON value) with the options: the program { nodes, root, root_resource, uses_dynamic_scope,
54 # options, annotation_sources }.
55 44 ▶sub compile {
Subroutine compile: called CC=1 SCAR=0.0
Pod undocumented
56 44 my ($class, $schema, $options) = @_;
57 44 my $loader = JSON::Schema::Corvus::Loader->new($options);
58 44 my $root_resource = $loader->load_root($schema, $options->{base_uri});
59 44 return $class->_compile_from($loader, $options, $root_resource, $schema);
60 }
61  
62 2 ▶sub compile_from_uri {
Subroutine compile_from_uri: called CC=1 SCAR=0.0
Pod undocumented
63 2 my ($class, $uri, $options) = @_;
64 2 my $loader = JSON::Schema::Corvus::Loader->new($options);
65 2 my $root_resource = $loader->load_root_from_uri($uri);
66 2 return $class->_compile_from($loader, $options, $root_resource,
67 JSON::Schema::Corvus::Loader::resource_root($root_resource));
68 }
69  
70 46 ▶sub _compile_from {
Subroutine _compile_from: called CC=4 SCAR=13.9
71 46 my ($class, $loader, $options, $root_resource, $schema) = @_;
72 46 my $self = bless {
73 loader => $loader,
74 options => $options,
75 nodes => [],
76 targets => [],
77 worklist => [],
78 worklist_head => 0,
79 pending_dynamic_refs => [],
80 annotation_sources => [],
81 entry_node => -1,
82 }, $class;
83 46 my $target = _target($root_resource->{document}, '', $schema, $root_resource);
84 46 ▶ if (defined $options->{entry_point}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"entry_point"}) 1 45 46
85 $target = $loader->try_resolve_reference($root_resource, $options->{entry_point})
86 1 ▶ or die JSON::Schema::Corvus::Error::Compilation->_new(
Branch: 1 branch
BranchTrueFalseTotal
$target = $loader->try_resolve_reference($root_resource, $options->{"entry_point"}) or die "JSON::Schema::Corvus::Error::Compilation"->_new(qq[Unable to resolve the entry point '$options->{"entry_point"}'.]) 1 0 1
87 "Unable to resolve the entry point '$options->{entry_point}'.");
88 }
89 46 $self->{entry_node} = $self->_get_node($target);
90 46 $self->_compile_all;
91 40 ▶ my $uses_dynamic_scope = (List::Util::any { defined $_->{dynamic_ref} } @{ $self->{nodes} }) ? 1 : 0;
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
&List::Util::any(sub { defined $_->{'dynamic_ref'}; } , @{$$self{'nodes'};}) ? : 0 40 40
92 40 $self->_analyse;
93 return {
94 nodes => $self->{nodes},
95 root => $self->{entry_node},
96 root_resource => $self->{nodes}[ $self->{entry_node} ]{resource_id},
97 uses_dynamic_scope => $uses_dynamic_scope,
98 options => $options,
99 annotation_sources => $self->{annotation_sources},
100 40 };
101 }
102  
103 359 ▶sub _get_node {
Subroutine _get_node: called CC=2 SCAR=6.9
104 359 my ($self, $target) = @_;
105 359 my $loader = $self->{loader};
106 359 my $node_id = $loader->node_of($target->{document}, $target->{value}, $target->{pointer});
107 359 ▶ if (!defined $node_id) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $node_id) 159 200 359
108 159 $node_id = scalar @{ $self->{nodes} };
109 159 push @{ $self->{nodes} }, JSON::Schema::Corvus::Node->new(
110 id => $node_id,
111 resource_id => $target->{resource}{id},
112 dialect => $target->{resource}{dialect},
113 location => "$target->{document}{retrieval_uri}#$target->{pointer}",
114 pointer => $target->{pointer},
115 159 );
116 159 push @{ $self->{targets} }, $target;
117 159 push @{ $self->{annotation_sources} }, undef;
118 159 $loader->set_node_of($target->{document}, $target->{value}, $target->{pointer}, $node_id);
119 159 push @{ $self->{worklist} }, $node_id;
120 }
121 359 return $node_id;
122 }
123  
124 47 ▶sub _drain {
Subroutine _drain: called CC=2 SCAR=6.9
125 47 my ($self) = @_;
126 47 ▶ while ($self->{worklist_head} < @{ $self->{worklist} }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"worklist_head"} < @{$self->{"worklist"};}) 159 41 200
127 159 my $node_id = $self->{worklist}[ $self->{worklist_head}++ ];
128 159 $self->_compile_node($self->{nodes}[$node_id], $self->{targets}[$node_id]);
129 }
130 }
131  
132 46 ▶sub _compile_all {
Subroutine _compile_all: called CC=5 SCAR=16.6
133 46 my ($self) = @_;
134 46 while (1) {
135 46 $self->_drain;
136 40 ▶ last if !@{ $self->{pending_dynamic_refs} }
Condition33%1/3
not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
!ll&&!rl&&r
001
MC/DC0%0/2
not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
not $self->_expand_dynamic_refs $self->{"worklist_head"} == @{$self->{"worklist"};}
Truth table33%1/3
not(A) and B
A= not $self->_expand_dynamic_refsB= $self->{"worklist_head"} == @{$self->{"worklist"};}
ABresult
0X0
100
111
137 40 ▶ || (!$self->_expand_dynamic_refs && $self->{worklist_head} == @{ $self->{worklist} });
Branch: 1 branch
BranchTrueFalseTotal
if not @{$self->{"pending_dynamic_refs"};} or not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};} 40 0 40
Condition66%2/3
not @{$self->{"pending_dynamic_refs"};} or not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
l!l&&r!l&&!r
3910
MC/DC0%0/2
not @{$self->{"pending_dynamic_refs"};} or not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
not @{$self->{"pending_dynamic_refs"};} not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
Truth table66%2/3
not(A) or B
A= not @{$self->{"pending_dynamic_refs"};}B= not $self->_expand_dynamic_refs and $self->{"worklist_head"} == @{$self->{"worklist"};}
ABresult
1X1
011
000
138 }
139 # Most schemas have no dynamic reference: skip the finalisation.
140 40 ▶ $self->_finalize_dynamic_refs if @{ $self->{pending_dynamic_refs} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$self->{"pending_dynamic_refs"};} 1 39 40
141 }
142  
143 93 ▶sub _child {
Subroutine _child: called CC=2 SCAR=7.4
144 93 my ($self, $parent, $value, $relative) = @_;
145 93 my $pointer = $parent->{pointer} . $relative;
146 93 ▶ my $resource = $self->{loader}->resource_of($parent->{document}, $value, $pointer) || $parent->{resource};
Condition33%1/3
$self->{'loader'}->resource_of($parent->{'document'}, $value, $pointer) || $parent->{'resource'}
l!l&&r!l&&!r
9300
MC/DC0%0/2
$self->{'loader'}->resource_of($parent->{'document'}, $value, $pointer) || $parent->{'resource'}
$self->{'loader'}->resource_of($parent->{'document'}, $value, $pointer) $parent->{'resource'}
Truth table33%1/3
A || B
A= $self->{'loader'}->resource_of($parent->{'document'}, $value, $pointer)B= $parent->{'resource'}
ABresult
1X1
011
000
147 93 return $self->_get_node(_target($parent->{document}, $pointer, $value, $resource));
148 }
149  
150 3 ▶sub _child_array {
Subroutine _child_array: called CC=2 SCAR=7.0
151 3 my ($self, $parent, $value, $keyword) = @_;
152 3 ▶ return undef unless ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $value eq "ARRAY" 0 3 3
153 3 return [ map { $self->_child($parent, $value->[$_], "/$keyword/$_") } 0 .. $#$value ];
154 }
155  
156 159 ▶sub _compile_node {
Subroutine _compile_node: called CC=75 SCAR=53.3
157 159 my ($self, $node, $target) = @_;
158 159 my $e = $target->{value};
159 159 ▶ if (JSON::Schema::Corvus::Json::is_bool($e)) {
Branch: 1 branch
BranchTrueFalseTotal
if (JSON::Schema::Corvus::Json::is_bool($e)) 6 153 159
160 6 ▶ $node->{$e ? 'always_true' : 'always_false'} = 1;
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 5 1 6
161 6 return;
162 }
163 153 ▶ if (ref $e ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e ne "HASH") 0 153 153
164 0 $node->{always_true} = 1;
165 0 return;
166 }
167  
168 153 my $dialect = $target->{resource}{dialect};
169 153 my $vocab = $target->{resource}{vocabularies};
170 153 my $legacy = $dialect <= DRAFT7;
171  
172 153 ▶ if ($legacy && _is_string($e->{'$ref'})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($legacy and _is_string($e->{"\$ref"})) 0 153 153
Condition66%2/3
$legacy and _is_string($e->{"\$ref"})
!ll&&!rl&&r
14940
MC/DC0%0/2
$legacy and _is_string($e->{"\$ref"})
$legacy _is_string($e->{"\$ref"})
Truth table66%2/3
A and B
A= $legacyB= _is_string($e->{"\$ref"})
ABresult
0X0
100
111
173 # In draft 7 and earlier, $ref replaces every sibling keyword.
174 0 $self->_compile_ref($node, $target, $e->{'$ref'});
175 0 return;
176 }
177  
178 153 ▶ my $applicator = $legacy || ($vocab & V_APPLICATOR);
Condition66%2/3
$legacy || $vocab & 2
l!l&&r!l&&!r
41490
MC/DC0%0/2
$legacy || $vocab & 2
$legacy $vocab & 2
Truth table66%2/3
A || B
A= $legacyB= $vocab & 2
ABresult
1X1
011
000
179 153 ▶ my $validation = $legacy || ($vocab & V_VALIDATION);
Condition66%2/3
$legacy || $vocab & 4
l!l&&r!l&&!r
41490
MC/DC0%0/2
$legacy || $vocab & 4
$legacy $vocab & 4
Truth table66%2/3
A || B
A= $legacyB= $vocab & 4
ABresult
1X1
011
000
180 153 ▶ my $unevaluated = $dialect == DRAFT201909 ? $applicator : ($vocab & V_UNEVALUATED);
Branch: 1 branch
BranchTrueFalseTotal
$dialect == 3 ? : 0 153 153
181 153 ▶ my $content = $legacy || ($vocab & V_CONTENT);
Condition66%2/3
$legacy || $vocab & 64
l!l&&r!l&&!r
41490
MC/DC0%0/2
$legacy || $vocab & 64
$legacy $vocab & 64
Truth table66%2/3
A || B
A= $legacyB= $vocab & 64
ABresult
1X1
011
000
182 153 my $assert_format = $self->{options}{assert_format};
183 my $format_assert = defined $assert_format ? $assert_format
184 153 ▶ : ($legacy && $self->{options}{assert_format_in_legacy_drafts}) || ($vocab & V_FORMAT_ASSERTION);
Branch: 1 branch
BranchTrueFalseTotal
defined $assert_format ? : 6 147 153
Condition83%5/6
$legacy and $self->{"options"}{"assert_format_in_legacy_drafts"} or $vocab & 32
l!l&&r!l&&!r
10146
$legacy and $self->{"options"}{"assert_format_in_legacy_drafts"}
!ll&&!rl&&r
14331
MC/DC66%2/3
$legacy and $self->{"options"}{"assert_format_in_legacy_drafts"} or $vocab & 32
$legacy $self->{"options"}{"assert_format_in_legacy_drafts"} $vocab & 32
Truth table60%3/5
A and B or C
A= $legacyB= $self->{"options"}{"assert_format_in_legacy_drafts"}C= $vocab & 32
ABCresult
11X1
0X11
1011
0X00
1000
185  
186 153 my $dependencies;
187  
188 # References.
189 153 ▶ $self->_compile_ref($node, $target, $e->{'$ref'}) if _is_string($e->{'$ref'});
Branch: 1 branch
BranchTrueFalseTotal
if _is_string($e->{"\$ref"}) 44 109 153
190 $self->_compile_dynamic_ref($node, $target, $e->{'$dynamicRef'}, 0)
191 149 ▶ if $dialect >= DRAFT202012 && _is_string($e->{'$dynamicRef'});
Branch: 1 branch
BranchTrueFalseTotal
if $dialect >= 4 and _is_string($e->{"\$dynamicRef"}) 18 131 149
Condition100%3/3
$dialect >= 4 and _is_string($e->{"\$dynamicRef"})
!ll&&!rl&&r
412718
MC/DC100%2/2
$dialect >= 4 and _is_string($e->{"\$dynamicRef"})
$dialect >= 4 _is_string($e->{"\$dynamicRef"})
Truth table100%3/3
A and B
A= $dialect >= 4B= _is_string($e->{"\$dynamicRef"})
ABresult
0X0
100
111
192 $self->_compile_dynamic_ref($node, $target, $e->{'$recursiveRef'}, 1)
193 149 ▶ if $dialect == DRAFT201909 && _is_string($e->{'$recursiveRef'});
Branch: 1 branch
BranchTrueFalseTotal
if $dialect == 3 and _is_string($e->{"\$recursiveRef"}) 0 149 149
Condition33%1/3
$dialect == 3 and _is_string($e->{"\$recursiveRef"})
!ll&&!rl&&r
14900
MC/DC0%0/2
$dialect == 3 and _is_string($e->{"\$recursiveRef"})
$dialect == 3 _is_string($e->{"\$recursiveRef"})
Truth table33%1/3
A and B
A= $dialect == 3B= _is_string($e->{"\$recursiveRef"})
ABresult
0X0
100
111
194  
195 # Applicators.
196 149 ▶ if ($applicator) {
Branch: 1 branch
BranchTrueFalseTotal
if ($applicator) 149 0 149
197 149 ▶ $node->{all_of} = $self->_child_array($target, $e->{allOf}, 'allOf') if exists $e->{allOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"allOf"} 1 148 149
198 149 ▶ $node->{any_of} = $self->_child_array($target, $e->{anyOf}, 'anyOf') if exists $e->{anyOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"anyOf"} 2 147 149
199 149 ▶ $node->{one_of} = $self->_child_array($target, $e->{oneOf}, 'oneOf') if exists $e->{oneOf};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"oneOf"} 0 149 149
200 149 ▶ $node->{not_} = $self->_child($target, $e->{not}, _kw('not')) if exists $e->{not};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"not"} 0 149 149
201 149 ▶ if ($dialect >= DRAFT7 && exists $e->{if}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 2 and exists $e->{"if"}) 0 149 149
Condition66%2/3
$dialect >= 2 and exists $e->{"if"}
!ll&&!rl&&r
11480
MC/DC0%0/2
$dialect >= 2 and exists $e->{"if"}
$dialect >= 2 exists $e->{"if"}
Truth table66%2/3
A and B
A= $dialect >= 2B= exists $e->{"if"}
ABresult
0X0
100
111
202 0 $node->{if_} = $self->_child($target, $e->{if}, _kw('if'));
203 0 ▶ $node->{then} = $self->_child($target, $e->{then}, _kw('then')) if exists $e->{then};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"then"} 0 0 0
204 0 ▶ $node->{else_} = $self->_child($target, $e->{else}, _kw('else')) if exists $e->{else};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"else"} 0 0 0
205 }
206 149 my $props = $e->{properties};
207 149 ▶ if (ref $props eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $props eq "HASH") 12 137 149
208 12 my @order = JSON::Schema::Corvus::Json::names($props);
209 12 $node->{property_order} = \@order;
210 $node->{properties} = { map {
211 12 $_ => $self->_child($target, $props->{$_}, '/properties/' . JSON::Schema::Corvus::Uri::escape_pointer_token($_))
212 } @order };
213 }
214 149 my $pattern_props = $e->{patternProperties};
215 149 ▶ if (ref $pattern_props eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $pattern_props eq "HASH") 0 149 149
216 0 $self->_check_pattern($_) for JSON::Schema::Corvus::Json::names($pattern_props);
217 $node->{pattern_properties} = [ map {
218 0 { pattern => $_, node => $self->_child($target, $pattern_props->{$_},
219 '/patternProperties/' . JSON::Schema::Corvus::Uri::escape_pointer_token($_)) }
220 } JSON::Schema::Corvus::Json::names($pattern_props) ];
221 }
222 $node->{additional_properties} = $self->_child($target, $e->{additionalProperties}, _kw('additionalProperties'))
223 149 ▶ if exists $e->{additionalProperties};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"additionalProperties"} 8 141 149
224 $node->{property_names} = $self->_child($target, $e->{propertyNames}, _kw('propertyNames'))
225 149 ▶ if $dialect >= DRAFT6 && exists $e->{propertyNames};
Branch: 1 branch
BranchTrueFalseTotal
if $dialect >= 1 and exists $e->{"propertyNames"} 2 147 149
Condition100%3/3
$dialect >= 1 and exists $e->{"propertyNames"}
!ll&&!rl&&r
11462
MC/DC100%2/2
$dialect >= 1 and exists $e->{"propertyNames"}
$dialect >= 1 exists $e->{"propertyNames"}
Truth table100%3/3
A and B
A= $dialect >= 1B= exists $e->{"propertyNames"}
ABresult
0X0
100
111
226 $node->{contains} = $self->_child($target, $e->{contains}, _kw('contains'))
227 149 ▶ if $dialect >= DRAFT6 && exists $e->{contains};
Branch: 1 branch
BranchTrueFalseTotal
if $dialect >= 1 and exists $e->{"contains"} 0 149 149
Condition66%2/3
$dialect >= 1 and exists $e->{"contains"}
!ll&&!rl&&r
11480
MC/DC0%0/2
$dialect >= 1 and exists $e->{"contains"}
$dialect >= 1 exists $e->{"contains"}
Truth table66%2/3
A and B
A= $dialect >= 1B= exists $e->{"contains"}
ABresult
0X0
100
111
228  
229 # "dependencies" is honoured in every dialect: in 2019-09 and later it is an optional compatibility keyword.
230 149 ▶ if (ref $e->{dependencies} eq 'HASH' || ($dialect >= DRAFT201909 && ref $e->{dependentSchemas} eq 'HASH')) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{"dependencies"} eq "HASH" or $dialect >= 3 and ref $e->{"dependentSchemas"} eq "HASH") 0 149 149
Condition50%3/6
ref $e->{"dependencies"} eq "HASH" or $dialect >= 3 and ref $e->{"dependentSchemas"} eq "HASH"
l!l&&r!l&&!r
00149
$dialect >= 3 and ref $e->{"dependentSchemas"} eq "HASH"
!ll&&!rl&&r
41450
MC/DC0%0/3
ref $e->{"dependencies"} eq "HASH" or $dialect >= 3 and ref $e->{"dependentSchemas"} eq "HASH"
ref $e->{"dependencies"} eq "HASH" $dialect >= 3 ref $e->{"dependentSchemas"} eq "HASH"
Truth table50%2/4
A or B and C
A= ref $e->{"dependencies"} eq "HASH"B= $dialect >= 3C= ref $e->{"dependentSchemas"} eq "HASH"
ABCresult
1XX1
0111
00X0
0100
231 0 $dependencies = $self->_compile_dependency_schemas($target, $e, $dialect);
232 }
233  
234 # Array applicators.
235 149 ▶ if ($dialect >= DRAFT202012) {
Branch: 2 branches
BranchTrueFalseTotal
if ($dialect >= 4) { } 145 4 149
elsif (exists $e->{'items'}) { } 0 4 4
236 $node->{prefix_items} = $self->_child_array($target, $e->{prefixItems}, 'prefixItems')
237 145 ▶ if ref $e->{prefixItems} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $e->{"prefixItems"} eq "ARRAY" 0 145 145
238 $node->{items} = $self->_child($target, $e->{items}, _kw('items'))
239 145 ▶ if exists $e->{items} && ref $e->{items} ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"items"} and ref $e->{"items"} ne "ARRAY" 6 139 145
Condition66%2/3
exists $e->{"items"} and ref $e->{"items"} ne "ARRAY"
!ll&&!rl&&r
13906
MC/DC50%1/2
exists $e->{"items"} and ref $e->{"items"} ne "ARRAY"
exists $e->{"items"} ref $e->{"items"} ne "ARRAY"
Truth table66%2/3
A and B
A= exists $e->{"items"}B= ref $e->{"items"} ne "ARRAY"
ABresult
0X0
100
111
240 }
241 elsif (exists $e->{items}) {
242 0 ▶ if (ref $e->{items} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{'items'} eq 'ARRAY') { } 0 0 0
243 0 $self->_compile_items_array($node, $target, $e);
244 }
245 else {
246 0 $node->{items} = $self->_child($target, $e->{items}, _kw('items'));
247 }
248 }
249 149 ▶ $node->{contains_marks_evaluated} = $dialect >= DRAFT202012 ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$dialect >= 4 ? : 145 4 149
250 }
251  
252 149 ▶ if ($unevaluated && $dialect >= DRAFT201909) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unevaluated and $dialect >= 3) 145 4 149
Condition66%2/3
$unevaluated and $dialect >= 3
!ll&&!rl&&r
04145
MC/DC50%1/2
$unevaluated and $dialect >= 3
$unevaluated $dialect >= 3
Truth table66%2/3
A and B
A= $unevaluatedB= $dialect >= 3
ABresult
0X0
100
111
253 $node->{unevaluated_properties} = $self->_child($target, $e->{unevaluatedProperties}, _kw('unevaluatedProperties'))
254 145 ▶ if exists $e->{unevaluatedProperties};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"unevaluatedProperties"} 0 145 145
255 $node->{unevaluated_items} = $self->_child($target, $e->{unevaluatedItems}, _kw('unevaluatedItems'))
256 145 ▶ if exists $e->{unevaluatedItems};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"unevaluatedItems"} 0 145 145
257 }
258  
259 149 ▶ if ($validation) {
Branch: 1 branch
BranchTrueFalseTotal
if ($validation) 149 0 149
260 149 ▶ $self->_compile_type($node, $e->{type}) if exists $e->{type};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"type"} 63 86 149
261 149 ▶ if ($dialect >= DRAFT6 && exists $e->{const}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 1 and exists $e->{"const"}) 4 145 149
Condition100%3/3
$dialect >= 1 and exists $e->{"const"}
!ll&&!rl&&r
11444
MC/DC100%2/2
$dialect >= 1 and exists $e->{"const"}
$dialect >= 1 exists $e->{"const"}
Truth table100%3/3
A and B
A= $dialect >= 1B= exists $e->{"const"}
ABresult
0X0
100
111
262 4 $node->{has_const} = 1;
263 4 $node->{const_value} = $e->{const};
264 }
265 149 ▶ $node->{enum_values} = $e->{enum} if ref $e->{enum} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $e->{"enum"} eq "ARRAY" 1 148 149
266 149 ▶ if (ref $e->{required} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e->{"required"} eq "ARRAY") 2 147 149
267 2 $node->{required_list} = _strings($e->{required});
268 2 my %seen;
269 2 $node->{required} = [ grep { !$seen{$_}++ } @{ $node->{required_list} } ];
270 }
271 149 ▶ if ($dialect >= DRAFT201909 && ref $e->{dependentRequired} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 3 and ref $e->{"dependentRequired"} eq "HASH") 0 149 149
Condition66%2/3
$dialect >= 3 and ref $e->{"dependentRequired"} eq "HASH"
!ll&&!rl&&r
41450
MC/DC0%0/2
$dialect >= 3 and ref $e->{"dependentRequired"} eq "HASH"
$dialect >= 3 ref $e->{"dependentRequired"} eq "HASH"
Truth table66%2/3
A and B
A= $dialect >= 3B= ref $e->{"dependentRequired"} eq "HASH"
ABresult
0X0
100
111
272 0 ▶ $dependencies //= [];
Condition0%0/2
$dependencies //= []
l!l
00
MC/DC0%0/1
$dependencies //= []
$dependencies
Truth table0%0/2
A
A= $dependencies
Aresult
11
00
273 0 for my $name (JSON::Schema::Corvus::Json::names($e->{dependentRequired})) {
274 0 my $v = $e->{dependentRequired}{$name};
275 0 ▶ push @$dependencies, { keyword => 'dependentRequired', name => $name, required => _strings($v) }
Branch: 1 branch
BranchTrueFalseTotal
if ref $v eq "ARRAY" 0 0 0
276 if ref $v eq 'ARRAY';
277 }
278 }
279 149 $node->{min_properties} = _get_int($e->{minProperties}, -1);
280 149 $node->{max_properties} = _get_int($e->{maxProperties}, -1);
281 149 $node->{min_items} = _get_int($e->{minItems}, -1);
282 149 $node->{max_items} = _get_int($e->{maxItems}, -1);
283 149 ▶ $node->{unique_items} = _is_true($e->{uniqueItems}) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
_is_true($e->{'uniqueItems'}) ? : 2 147 149
284 149 $node->{min_length} = _get_int($e->{minLength}, -1);
285 149 $node->{max_length} = _get_int($e->{maxLength}, -1);
286 149 ▶ if (_is_string($e->{pattern})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string($e->{"pattern"})) 7 142 149
287 7 $node->{pattern} = $e->{pattern};
288 7 $self->_check_pattern($e->{pattern});
289 }
290 147 ▶ $node->{multiple_of} = $e->{multipleOf} if _is_number($e->{multipleOf});
Branch: 1 branch
BranchTrueFalseTotal
if _is_number($e->{"multipleOf"}) 0 147 147
291  
292 147 ▶ if ($dialect == DRAFT4) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect == 0) { } 1 146 147
293 1 _compile_draft4_bounds($node, $e);
294 }
295 else {
296 146 $node->{maximum} = _num($e->{maximum});
297 146 $node->{minimum} = _num($e->{minimum});
298 146 $node->{exclusive_maximum} = _num($e->{exclusiveMaximum});
299 146 $node->{exclusive_minimum} = _num($e->{exclusiveMinimum});
300 }
301  
302 147 ▶ if ($dialect >= DRAFT201909 && $node->{contains} >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 3 and $node->{"contains"} >= 0) 0 147 147
Condition66%2/3
$dialect >= 3 and $node->{"contains"} >= 0
!ll&&!rl&&r
41430
MC/DC0%0/2
$dialect >= 3 and $node->{"contains"} >= 0
$dialect >= 3 $node->{"contains"} >= 0
Truth table66%2/3
A and B
A= $dialect >= 3B= $node->{"contains"} >= 0
ABresult
0X0
100
111
303 0 ▶ $node->{min_contains} = _get_int($e->{minContains}, 1) if exists $e->{minContains};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"minContains"} 0 0 0
304 0 ▶ $node->{max_contains} = _get_int($e->{maxContains}, -1) if exists $e->{maxContains};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"maxContains"} 0 0 0
305 }
306 }
307  
308 147 ▶ if (_is_string($e->{format})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string($e->{"format"})) 13 134 147
309 13 $node->{format} = $e->{format};
310 13 $node->{format_kind} = JSON::Schema::Corvus::Formats::format_kind($e->{format}, $dialect);
311 13 ▶ $node->{assert_format} = $format_assert ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$format_assert ? : 7 6 13
312 }
313  
314 # Content keywords are asserted only in draft 7 (and annotations elsewhere).
315 147 ▶ if ($content && $dialect >= DRAFT7 && (exists $e->{contentEncoding} || exists $e->{contentMediaType})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"}) 2 145 147
Condition77%7/9
$content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"}
!ll&&!rl&&r
11442
$content and $dialect >= 2
!ll&&!rl&&r
01146
exists $e->{"contentEncoding"} or exists $e->{"contentMediaType"}
l!l&&r!l&&!r
02144
MC/DC50%2/4
$content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"}
$content $dialect >= 2 exists $e->{"contentEncoding"} exists $e->{"contentMediaType"}
Truth table60%3/5
A and B and C or D
A= $contentB= $dialect >= 2C= exists $e->{"contentEncoding"}D= exists $e->{"contentMediaType"}
ABCDresult
0XXX0
10XX0
11000
111X1
11011
316 2 $self->_compile_content($node, $e, $dialect);
317 }
318  
319 147 ▶ if ($dependencies) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies) 0 147 147
320 # In the order the three keywords appear in the schema, as CompileNode meets them.
321 0 my @order = JSON::Schema::Corvus::Json::names($e);
322 0 my %position = map { $order[$_] => $_ } 0 .. $#order;
323 0 @$dependencies = map { $_->[1] } sort { $a->[0] <=> $b->[0] } map { [ $position{ $_->{keyword} }, $_ ] }
324 @$dependencies;
325 }
326 147 $node->{dependencies} = $dependencies;
327 147 $self->{annotation_sources}[ $node->{id} ] = { e => $e, dialect => $dialect, vocab => $vocab, legacy => $legacy,
328 content => $content };
329 }
330  
331 # A regular expression that is not valid does not compile, and one over a limit of size dies with a PatternTooLarge
332 # error.
333 7 ▶sub _check_pattern {
Subroutine _check_pattern: called CC=2 SCAR=6.9
334 7 my ($self, $pattern) = @_;
335 JSON::Schema::Corvus::Pattern::compile_pattern($pattern, $self->{options}{pattern_match_limit})
336 7 ▶ or die JSON::Schema::Corvus::Error::Compilation->_new("Invalid regular expression '$pattern'.");
Branch: 1 branch
BranchTrueFalseTotal
JSON::Schema::Corvus::Pattern::compile_pattern($pattern, $self->{"options"}{"pattern_match_limit"}) or die "JSON::Schema::Corvus::Error::Compilation"->_new("Invalid regular expression '${pattern}'.") 5 1 6
337 }
338  
339 1 ▶sub _compile_draft4_bounds {
Subroutine _compile_draft4_bounds: called CC=5 SCAR=18.9
340 1 my ($node, $e) = @_;
341 1 my $maximum = _num($e->{maximum});
342 1 my $minimum = _num($e->{minimum});
343 1 ▶ if (defined $maximum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $maximum) 0 1 1
344 0 ▶ $node->{ _is_true($e->{exclusiveMaximum}) ? 'exclusive_maximum' : 'maximum' } = $maximum;
Branch: 1 branch
BranchTrueFalseTotal
_is_true($e->{'exclusiveMaximum'}) ? : 0 0 0
345 }
346 1 ▶ if (defined $minimum) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $minimum) 1 0 1
347 1 ▶ $node->{ _is_true($e->{exclusiveMinimum}) ? 'exclusive_minimum' : 'minimum' } = $minimum;
Branch: 1 branch
BranchTrueFalseTotal
_is_true($e->{'exclusiveMinimum'}) ? : 1 0 1
348 }
349 }
350  
351 0 ▶sub _compile_dependency_schemas {
Subroutine _compile_dependency_schemas: not called CC=7 SCAR=40.3
352 0 my ($self, $target, $e, $dialect) = @_;
353 0 my @dependencies;
354 0 my $deps = $e->{dependencies};
355 0 ▶ if (ref $deps eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $deps eq "HASH") 0 0 0
356 0 for my $name (JSON::Schema::Corvus::Json::names($deps)) {
357 0 my $v = $deps->{$name};
358 0 ▶ if (ref $v eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $v eq 'ARRAY') { } 0 0 0
359 0 push @dependencies, { keyword => 'dependencies', name => $name, required => _strings($v) };
360 }
361 else {
362 0 my $child = $self->_child($target, $v, '/dependencies/' . JSON::Schema::Corvus::Uri::escape_pointer_token($name));
363 0 push @dependencies, { keyword => 'dependencies', name => $name, schema => $child };
364 }
365 }
366 }
367 0 my $schemas = $e->{dependentSchemas};
368 0 ▶ if ($dialect >= DRAFT201909 && ref $schemas eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 3 and ref $schemas eq "HASH") 0 0 0
Condition0%0/3
$dialect >= 3 and ref $schemas eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$dialect >= 3 and ref $schemas eq "HASH"
$dialect >= 3 ref $schemas eq "HASH"
Truth table0%0/3
A and B
A= $dialect >= 3B= ref $schemas eq "HASH"
ABresult
0X0
100
111
369 0 for my $name (JSON::Schema::Corvus::Json::names($schemas)) {
370 0 my $child = $self->_child($target, $schemas->{$name},
371 '/dependentSchemas/' . JSON::Schema::Corvus::Uri::escape_pointer_token($name));
372 0 push @dependencies, { keyword => 'dependentSchemas', name => $name, schema => $child };
373 }
374 }
375 0 return \@dependencies;
376 }
377  
378 # Array-form items (before 2020-12): positional schemas, then additionalItems for the rest.
379 0 ▶sub _compile_items_array {
Subroutine _compile_items_array: not called CC=2 SCAR=17.9
380 0 my ($self, $node, $target, $e) = @_;
381 0 $node->{prefix_items} = $self->_child_array($target, $e->{items}, 'items');
382 0 $node->{prefix_keyword} = 'items';
383 0 ▶ if (exists $e->{additionalItems}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"additionalItems"}) 0 0 0
384 0 $node->{items} = $self->_child($target, $e->{additionalItems}, '/additionalItems');
385 0 $node->{items_keyword} = 'additionalItems';
386 }
387 }
388  
389 2 ▶sub _compile_content {
Subroutine _compile_content: called CC=9 SCAR=26.5
390 2 my ($self, $node, $e, $dialect) = @_;
391 2 ▶ my $base64 = _is_string($e->{contentEncoding}) && $e->{contentEncoding} eq 'base64';
Condition33%1/3
_is_string($e->{'contentEncoding'}) && $e->{'contentEncoding'} eq 'base64'
!ll&&!rl&&r
200
MC/DC0%0/2
_is_string($e->{'contentEncoding'}) && $e->{'contentEncoding'} eq 'base64'
_is_string($e->{'contentEncoding'}) $e->{'contentEncoding'} eq 'base64'
Truth table33%1/3
A && B
A= _is_string($e->{'contentEncoding'})B= $e->{'contentEncoding'} eq 'base64'
ABresult
0X0
100
111
392 2 ▶ my $is_json = _is_string($e->{contentMediaType}) && $e->{contentMediaType} eq 'application/json';
Condition33%1/3
_is_string($e->{'contentMediaType'}) && $e->{'contentMediaType'} eq 'application/json'
!ll&&!rl&&r
002
MC/DC0%0/2
_is_string($e->{'contentMediaType'}) && $e->{'contentMediaType'} eq 'application/json'
_is_string($e->{'contentMediaType'}) $e->{'contentMediaType'} eq 'application/json'
Truth table33%1/3
A && B
A= _is_string($e->{'contentMediaType'})B= $e->{'contentMediaType'} eq 'application/json'
ABresult
0X0
100
111
393 2 ▶ $node->{content} = $base64 ? ($is_json ? CONTENT_BASE64_JSON : CONTENT_BASE64) : $is_json ? CONTENT_JSON
Branch: 3 branches
BranchTrueFalseTotal
$base64 ? : 0 2 2
$is_json ? : 0 0 0
$is_json ? : 2 0 2
394 : CONTENT_NONE;
395 2 ▶ $node->{assert_content} = ($dialect == DRAFT7 && $self->{options}{assert_content} && $node->{content} != CONTENT_NONE)
Branch: 1 branch
BranchTrueFalseTotal
$dialect == 2 && $self->{'options'}{'assert_content'} && $node->{'content'} != 0 ? : 1 1 2
Condition66%4/6
$dialect == 2 and $self->{"options"}{"assert_content"} and $node->{"content"} != 0
!ll&&!rl&&r
101
$dialect == 2 and $self->{"options"}{"assert_content"}
!ll&&!rl&&r
011
MC/DC33%1/3
$dialect == 2 and $self->{"options"}{"assert_content"} and $node->{"content"} != 0
$dialect == 2 $self->{"options"}{"assert_content"} $node->{"content"} != 0
Truth table50%2/4
A and B and C
A= $dialect == 2B= $self->{"options"}{"assert_content"}C= $node->{"content"} != 0
ABCresult
0XX0
10X0
1100
1111
396 ? 1 : 0;
397 }
398  
399 63 ▶sub _compile_type {
Subroutine _compile_type: called CC=7 SCAR=20.3
400 63 my ($self, $node, $value) = @_;
401 63 my $mask = T_NONE;
402 63 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 8 55 63
elsif (_is_string($value)) { } 55 0 55
403 8 ▶ $mask |= (_is_string($_) ? $TYPE_MASKS{$_} // T_NONE : T_NONE) for @$value;
Branch: 1 branch
BranchTrueFalseTotal
_is_string($_) ? : 16 0 16
Condition50%1/2
$TYPE_MASKS{$_} // 0
l!l
160
MC/DC0%0/1
$TYPE_MASKS{$_} // 0
$TYPE_MASKS{$_}
Truth table50%1/2
A
A= $TYPE_MASKS{$_}
Aresult
11
00
404 }
405 elsif (_is_string($value)) {
406 55 ▶ $mask = $TYPE_MASKS{$value} // T_NONE;
Condition50%1/2
$TYPE_MASKS{$value} // 0
l!l
550
MC/DC0%0/1
$TYPE_MASKS{$value} // 0
$TYPE_MASKS{$value}
Truth table50%1/2
A
A= $TYPE_MASKS{$value}
Aresult
11
00
407 }
408 63 $node->{type} = $mask;
409 63 $node->{has_type} = 1;
410 }
411  
412 44 ▶sub _compile_ref {
Subroutine _compile_ref: called CC=2 SCAR=6.9
413 44 my ($self, $node, $target, $reference) = @_;
414 44 ▶ my $resolved = $self->{loader}->try_resolve_reference($target->{resource}, $reference)
Branch: 1 branch
BranchTrueFalseTotal
my $resolved = $self->{"loader"}->try_resolve_reference($target->{"resource"}, $reference) or die "JSON::Schema::Corvus::Error::Compilation"->_new(qq[Unable to resolve reference '${reference}' from '$target->{"resource"}{"uri"}'.]) 40 2 42
415 or die JSON::Schema::Corvus::Error::Compilation->_new(
416 "Unable to resolve reference '$reference' from '$target->{resource}{uri}'.");
417 40 $node->{ref} = $self->_get_node($resolved);
418 }
419  
420 18 ▶sub _compile_dynamic_ref {
Subroutine _compile_dynamic_ref: called CC=10 SCAR=32.5
421 18 my ($self, $node, $target, $reference, $is_recursive) = @_;
422 18 ▶ my $resolved = $self->{loader}->try_resolve_reference($target->{resource}, $reference)
Branch: 1 branch
BranchTrueFalseTotal
my $resolved = $self->{"loader"}->try_resolve_reference($target->{"resource"}, $reference) or die "JSON::Schema::Corvus::Error::Compilation"->_new(qq[Unable to resolve reference '${reference}' from '$target->{"resource"}{"uri"}'.]) 18 0 18
423 or die JSON::Schema::Corvus::Error::Compilation->_new(
424 "Unable to resolve reference '$reference' from '$target->{resource}{uri}'.");
425 18 my $fragment = JSON::Schema::Corvus::Uri::decode_fragment((JSON::Schema::Corvus::Uri::split_fragment($reference))[1]);
426 18 my $dynamic;
427 18 ▶ if ($is_recursive) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_recursive) { } 0 18 18
428 0 ▶ $dynamic = $resolved->{resource}{recursive_anchor} && $resolved->{pointer} eq $resolved->{resource}{root_pointer};
Condition0%0/3
$resolved->{'resource'}{'recursive_anchor'} && $resolved->{'pointer'} eq $resolved->{'resource'}{'root_pointer'}
!ll&&!rl&&r
000
MC/DC0%0/2
$resolved->{'resource'}{'recursive_anchor'} && $resolved->{'pointer'} eq $resolved->{'resource'}{'root_pointer'}
$resolved->{'resource'}{'recursive_anchor'} $resolved->{'pointer'} eq $resolved->{'resource'}{'root_pointer'}
Truth table0%0/3
A && B
A= $resolved->{'resource'}{'recursive_anchor'}B= $resolved->{'pointer'} eq $resolved->{'resource'}{'root_pointer'}
ABresult
0X0
100
111
429 }
430 else {
431 18 my $anchors = $resolved->{resource}{dynamic_anchors};
432 $dynamic = length $fragment && substr($fragment, 0, 1) ne '/' && $anchors && defined $anchors->{$fragment}
433 18 ▶ && $anchors->{$fragment} eq $resolved->{pointer};
Condition33%4/12
length $fragment && substr($fragment, 0, 1) ne '/' && $anchors && defined $anchors->{$fragment} && $anchors->{$fragment} eq $resolved->{'pointer'}
!ll&&!rl&&r
0018
length $fragment and substr($fragment, 0, 1) ne "/" and $anchors and defined $anchors->{$fragment}
!ll&&!rl&&r
0018
length $fragment and substr($fragment, 0, 1) ne "/" and $anchors
!ll&&!rl&&r
0018
length $fragment and substr($fragment, 0, 1) ne "/"
!ll&&!rl&&r
0018
MC/DC0%0/5
length $fragment && substr($fragment, 0, 1) ne '/' && $anchors && defined $anchors->{$fragment} && $anchors->{$fragment} eq $resolved->{'pointer'}
length $fragment substr($fragment, 0, 1) ne "/" $anchors defined $anchors->{$fragment} $anchors->{$fragment} eq $resolved->{'pointer'}
Truth table16%1/6
A and B and C and D && E
A= length $fragmentB= substr($fragment, 0, 1) ne "/"C= $anchorsD= defined $anchors->{$fragment}E= $anchors->{$fragment} eq $resolved->{'pointer'}
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
434 }
435 18 ▶ if (!$dynamic) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dynamic) 0 18 18
436 # A static reference, kept apart from any sibling $ref (C# overwrites the $ref; both apply here).
437 0 $node->{static_dynamic_ref} = $self->_get_node($resolved);
438 0 ▶ $node->{static_dynamic_keyword} = $is_recursive ? '$recursiveRef' : '$dynamicRef';
Branch: 1 branch
BranchTrueFalseTotal
$is_recursive ? : 0 0 0
439 0 return;
440 }
441 18 push @{ $self->{pending_dynamic_refs} }, { node_id => $node->{id}, anchor => $fragment, is_recursive => $is_recursive,
442 initial_target => $resolved, seen_resources => {}, candidates => [] };
443 }
444  
445 1 ▶sub _expand_dynamic_refs {
Subroutine _expand_dynamic_refs: called CC=9 SCAR=24.0
446 1 my ($self) = @_;
447 1 my $added = 0;
448 1 for my $pending (@{ $self->{pending_dynamic_refs} }) {
449 18 for my $resource (@{ $self->{loader}{resources} }) {
450 144 ▶ next if $pending->{seen_resources}{ $resource->{id} }++;
Branch: 1 branch
BranchTrueFalseTotal
if $pending->{"seen_resources"}{$resource->{"id"}}++ 0 144 144
451 144 my $pointer;
452 144 ▶ if ($pending->{is_recursive}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pending->{'is_recursive'}) { } 0 144 144
453 0 ▶ next unless $resource->{recursive_anchor};
Branch: 1 branch
BranchTrueFalseTotal
unless $resource->{"recursive_anchor"} 0 0 0
454 0 $pointer = $resource->{root_pointer};
455 }
456 else {
457 144 ▶ $pointer = $resource->{dynamic_anchors} ? $resource->{dynamic_anchors}{ $pending->{anchor} } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$resource->{'dynamic_anchors'} ? : 144 0 144
458 144 ▶ next unless defined $pointer;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pointer 0 144 144
459 }
460 144 my $before = @{ $self->{nodes} };
461 144 my $node_id = $self->_get_node($self->_target_in($resource, $pointer));
462 144 ▶ $added ||= @{ $self->{nodes} } != $before;
Condition33%1/3
$added ||= @{$self->{"nodes"};} != $before
l!l&&r!l&&!r
00144
MC/DC0%0/2
$added ||= @{$self->{"nodes"};} != $before
$added @{$self->{"nodes"};} != $before
Truth table33%1/3
A ||= B
A= $addedB= @{$self->{"nodes"};} != $before
ABresult
1X1
011
000
463 144 push @{ $pending->{candidates} }, [ $resource->{id}, $node_id ];
464 }
465 }
466 1 return $added;
467 }
468  
469 144 ▶sub _target_in {
Subroutine _target_in: called CC=3 SCAR=12.5
470 144 my ($self, $resource, $pointer) = @_;
471 my $t = $self->{loader}->try_resolve_fragment($resource,
472 144 ▶ $pointer eq $resource->{root_pointer} ? '' : substr($pointer, length $resource->{root_pointer}));
Branch: 1 branch
BranchTrueFalseTotal
$pointer eq $resource->{'root_pointer'} ? : 144 0 144
473 144 ▶ return $t || _target($resource->{document}, $pointer, JSON::Schema::Corvus::Loader::resource_root($resource),
Condition33%1/3
$t || _target($resource->{'document'}, $pointer, JSON::Schema::Corvus::Loader::resource_root($resource), $resource)
l!l&&r!l&&!r
14400
MC/DC0%0/2
$t || _target($resource->{'document'}, $pointer, JSON::Schema::Corvus::Loader::resource_root($resource), $resource)
$t _target($resource->{'document'}, $pointer, JSON::Schema::Corvus::Loader::resource_root($resource), $resource)
Truth table33%1/3
A || B
A= $tB= _target($resource->{'document'}, $pointer, JSON::Schema::Corvus::Loader::resource_root($resource), $resource)
ABresult
1X1
011
000
474 $resource);
475 }
476  
477 1 ▶sub _finalize_dynamic_refs {
Subroutine _finalize_dynamic_refs: called CC=6 SCAR=19.5
478 1 my ($self) = @_;
479 1 my $reachable;
480 1 for my $pending (@{ $self->{pending_dynamic_refs} }) {
481 18 my $node = $self->{nodes}[ $pending->{node_id} ];
482 18 my $fallback = $self->_get_node($pending->{initial_target});
483 18 ▶ my $set_static = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
484 18 $node->{static_dynamic_ref} = $_[0];
485 18 ▶ $node->{static_dynamic_keyword} = $pending->{is_recursive} ? '$recursiveRef' : '$dynamicRef';
Branch: 1 branch
BranchTrueFalseTotal
$pending->{'is_recursive'} ? : 0 18 18
486 18 };
487 18 ▶ if (@{ $pending->{candidates} } <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$pending->{"candidates"};} <= 1) 0 18 18
488 # Only the initial target's resource defines the anchor: resolution is static.
489 0 $set_static->($fallback);
490 0 next;
491 }
492 # The dynamic scope is searched outermost first, and its outermost entry is always the resource evaluation started
493 # in: when the entry resource defines the anchor, that target is the answer on every path.
494 18 ▶ $reachable //= $self->_compute_reachability;
Condition66%2/3
$reachable //= $self->_compute_reachability
l!l&&r!l&&!r
1710
MC/DC0%0/2
$reachable //= $self->_compute_reachability
$reachable $self->_compute_reachability
Truth table66%2/3
A //= B
A= $reachableB= $self->_compute_reachability
ABresult
1X1
011
000
495 18 ▶ if (!$reachable->[ $pending->{node_id} ]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($$reachable[$pending->{"node_id"}]) 0 18 18
496 0 $set_static->($fallback);
497 0 next;
498 }
499 18 my $entry_resource = $self->{nodes}[ $self->{entry_node} ]{resource_id};
500 18 my ($uniform) = grep { $_->[0] == $entry_resource } @{ $pending->{candidates} };
501 18 ▶ if ($uniform) {
Branch: 1 branch
BranchTrueFalseTotal
if ($uniform) 18 0 18
502 18 $set_static->($uniform->[1]);
503 18 next;
504 }
505 $node->{dynamic_ref} = { anchor => $pending->{anchor}, is_recursive => $pending->{is_recursive},
506 0 fallback => $fallback, by_resource => { map { $_->[0] => $_->[1] } @{ $pending->{candidates} } } };
507 }
508 1 $self->_drain;
509 }
510  
511 # The nodes reachable from the entry, counting every candidate of a pending dynamic reference as a child.
512 1 ▶sub _compute_reachability {
Subroutine _compute_reachability: called CC=6 SCAR=17.9
513 1 my ($self) = @_;
514 1 my %extra;
515 1 for my $p (@{ $self->{pending_dynamic_refs} }) {
516 18 push @{ $extra{ $p->{node_id} } }, $self->_get_node($p->{initial_target}), map { $_->[1] } @{ $p->{candidates} };
517 }
518 1 my @reached;
519 1 my @stack = ($self->{entry_node});
520 1 $reached[ $self->{entry_node} ] = 1;
521 1 ▶ while (@stack) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack) 103 1 104
522 103 my $node_id = pop @stack;
523 103 ▶ for my $c (@{ $self->{nodes}[$node_id]->children }, @{ $extra{$node_id} // [] }) {
Condition100%2/2
$extra{$node_id} // []
l!l
1885
MC/DC100%1/1
$extra{$node_id} // []
$extra{$node_id}
Truth table100%2/2
A
A= $extra{$node_id}
Aresult
11
00
524 283 ▶ next if $reached[$c];
Branch: 1 branch
BranchTrueFalseTotal
if $reached[$c] 181 102 283
525 102 $reached[$c] = 1;
526 102 push @stack, $c;
527 }
528 }
529 1 return \@reached;
530 }
531  
532 # --- Analyses ---
533  
534 40 ▶sub _analyse {
Subroutine _analyse: called CC=8 SCAR=20.8
535 40 my ($self) = @_;
536 # The in-place edges, built once for both analyses; discriminators only where a node has a oneOf or anyOf.
537 40 my @edges;
538 40 my ($in_place, $branches) = (0, 0);
539 40 for my $n (@{ $self->{nodes} }) {
540 153 my $children = $n->in_place_children(1);
541 153 push @edges, $children;
542 153 ▶ $in_place = 1 if @$children;
Branch: 1 branch
BranchTrueFalseTotal
if @$children 61 92 153
543 153 ▶ $branches = 1 if defined $n->{one_of} || defined $n->{any_of};
Branch: 1 branch
BranchTrueFalseTotal
if defined $n->{"one_of"} or defined $n->{"any_of"} 2 151 153
Condition66%2/3
defined $n->{"one_of"} or defined $n->{"any_of"}
l!l&&r!l&&!r
02151
MC/DC50%1/2
defined $n->{"one_of"} or defined $n->{"any_of"}
defined $n->{"one_of"} defined $n->{"any_of"}
Truth table66%2/3
A or B
A= defined $n->{"one_of"}B= defined $n->{"any_of"}
ABresult
1X1
011
000
544 }
545 40 ▶ $self->_compute_marking($in_place ? \@edges : undef);
Branch: 1 branch
BranchTrueFalseTotal
$in_place ? : 5 35 40
546 40 ▶ $self->_compute_in_place_cycles(\@edges) if $in_place;
Branch: 1 branch
BranchTrueFalseTotal
if $in_place 5 35 40
547 40 ▶ $self->_compute_discriminators if $branches;
Branch: 1 branch
BranchTrueFalseTotal
if $branches 1 39 40
548 }
549  
550 # Which nodes can contribute evaluated-property or item annotations (ComputeMarking): a node marks if it has the
551 # keywords itself or an in-place child (not counting not) marks.
552 40 ▶sub _compute_marking {
Subroutine _compute_marking: called CC=19 SCAR=30.0
553 40 my ($self, $edges) = @_;
554 40 my $nodes = $self->{nodes};
555 40 for my $n (@$nodes) {
556 $n->{marks_properties} = (defined $n->{properties} || defined $n->{pattern_properties}
557 153 ▶ || $n->{additional_properties} >= 0 || $n->{unevaluated_properties} >= 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $n->{'properties'} || defined $n->{'pattern_properties'} || $n->{'additional_properties'} >= 0 || $n->{'unevaluated_properties'} >= 0 ? : 20 133 153
Condition77%7/9
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0 or $n->{"unevaluated_properties"} >= 0
l!l&&r!l&&!r
200133
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0
l!l&&r!l&&!r
128133
defined $n->{"properties"} or defined $n->{"pattern_properties"}
l!l&&r!l&&!r
120141
MC/DC50%2/4
defined $n->{"properties"} or defined $n->{"pattern_properties"} or $n->{"additional_properties"} >= 0 or $n->{"unevaluated_properties"} >= 0
defined $n->{"properties"} defined $n->{"pattern_properties"} $n->{"additional_properties"} >= 0 $n->{"unevaluated_properties"} >= 0
Truth table60%3/5
A or B or C or D
A= defined $n->{"properties"}B= defined $n->{"pattern_properties"}C= $n->{"additional_properties"} >= 0D= $n->{"unevaluated_properties"} >= 0
ABCDresult
1XXX1
01XX1
001X1
00011
00000
558 $n->{marks_items} = (defined $n->{prefix_items} || $n->{items} >= 0
559 153 ▶ || ($n->{contains} >= 0 && $n->{contains_marks_evaluated}) || $n->{unevaluated_items} >= 0) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $n->{'prefix_items'} || $n->{'items'} >= 0 || $n->{'contains'} >= 0 && $n->{'contains_marks_evaluated'} || $n->{'unevaluated_items'} >= 0 ? : 6 147 153
Condition58%7/12
defined $n->{"prefix_items"} or $n->{"items"} >= 0 or $n->{"contains"} >= 0 and $n->{"contains_marks_evaluated"} or $n->{"unevaluated_items"} >= 0
l!l&&r!l&&!r
60147
defined $n->{"prefix_items"} or $n->{"items"} >= 0 or $n->{"contains"} >= 0 and $n->{"contains_marks_evaluated"}
l!l&&r!l&&!r
60147
defined $n->{"prefix_items"} or $n->{"items"} >= 0
l!l&&r!l&&!r
06147
$n->{"contains"} >= 0 and $n->{"contains_marks_evaluated"}
!ll&&!rl&&r
14700
MC/DC20%1/5
defined $n->{"prefix_items"} or $n->{"items"} >= 0 or $n->{"contains"} >= 0 and $n->{"contains_marks_evaluated"} or $n->{"unevaluated_items"} >= 0
defined $n->{"prefix_items"} $n->{"items"} >= 0 $n->{"contains"} >= 0 $n->{"contains_marks_evaluated"} $n->{"unevaluated_items"} >= 0
Truth table28%2/7
A or B or C and D or E
A= defined $n->{"prefix_items"}B= $n->{"items"} >= 0C= $n->{"contains"} >= 0D= $n->{"contains_marks_evaluated"}E= $n->{"unevaluated_items"} >= 0
ABCDEresult
1XXXX1
01XXX1
0011X1
000X11
001011
000X00
001000
560 }
561 40 ▶ return unless $edges;
Branch: 1 branch
BranchTrueFalseTotal
unless $edges 35 5 40
562 5 my @parents = map { [] } @$nodes;
563 5 for my $i (0 .. $#$nodes) {
564 112 my $n = $nodes->[$i];
565 # not contributes no annotations: a node with one uses the edges without it.
566 112 ▶ my $children = $n->{not_} >= 0 ? $n->in_place_children(0) : $edges->[$i];
Branch: 1 branch
BranchTrueFalseTotal
$n->{'not_'} >= 0 ? : 0 112 112
567 112 push @{ $parents[$_] }, $i for @$children;
568 }
569 5 for my $flag (qw(marks_properties marks_items)) {
570 10 my @work = grep { $nodes->[$_]{$flag} } 0 .. $#$nodes;
571 10 ▶ while (@work) {
Branch: 1 branch
BranchTrueFalseTotal
if (@work) 56 10 66
572 56 for my $p (@{ $parents[ pop @work ] }) {
573 42 ▶ next if $nodes->[$p]{$flag};
Branch: 1 branch
BranchTrueFalseTotal
if $nodes->[$p]{$flag} 7 35 42
574 35 $nodes->[$p]{$flag} = 1;
575 35 push @work, $p;
576 }
577 }
578 }
579 }
580  
581 # Marks the nodes on a cycle of in-place applicators (an iterative Tarjan), the only ones that need a depth guard.
582 5 ▶sub _compute_in_place_cycles {
Subroutine _compute_in_place_cycles: called CC=15 SCAR=27.1
583 5 my ($self, $edges) = @_;
584 5 my $count = @{ $self->{nodes} };
585 5 my @index = (-1) x $count;
586 5 my @low = (0) x $count;
587 5 my @on_stack = (0) x $count;
588 5 my @stack;
589 5 my $next_index = 0;
590 5 for my $start (0 .. $count - 1) {
591 112 ▶ next if $index[$start] >= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $index[$start] >= 0 31 81 112
592 81 my @work = ([ $start, 0 ]);
593 81 $index[$start] = $low[$start] = $next_index++;
594 81 push @stack, $start;
595 81 $on_stack[$start] = 1;
596 81 ▶ while (@work) {
Branch: 1 branch
BranchTrueFalseTotal
if (@work) 181 81 262
597 181 my $frame = $work[-1];
598 181 my ($v, $ei) = @$frame;
599 181 ▶ if ($ei < @{ $edges->[$v] }) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ei < @{$edges->[$v];}) { } 69 112 181
600 69 $frame->[1]++;
601 69 my $w = $edges->[$v][$ei];
602 69 ▶ if ($index[$w] < 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($index[$w] < 0) { } 31 38 69
elsif ($on_stack[$w]) { } 1 37 38
603 31 $index[$w] = $low[$w] = $next_index++;
604 31 push @stack, $w;
605 31 $on_stack[$w] = 1;
606 31 push @work, [ $w, 0 ];
607 }
608 elsif ($on_stack[$w]) {
609 1 ▶ $low[$v] = $index[$w] if $index[$w] < $low[$v];
Branch: 1 branch
BranchTrueFalseTotal
if $index[$w] < $low[$v] 1 0 1
610 }
611 }
612 else {
613 112 pop @work;
614 112 ▶ if (@work) {
Branch: 1 branch
BranchTrueFalseTotal
if (@work) 31 81 112
615 31 my $parent = $work[-1][0];
616 31 ▶ $low[$parent] = $low[$v] if $low[$v] < $low[$parent];
Branch: 1 branch
BranchTrueFalseTotal
if $low[$v] < $low[$parent] 0 31 31
617 }
618 112 ▶ if ($low[$v] == $index[$v]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($low[$v] == $index[$v]) 111 1 112
619 111 my @component;
620 111 while (1) {
621 112 my $w = pop @stack;
622 112 $on_stack[$w] = 0;
623 112 push @component, $w;
624 112 ▶ last if $w == $v;
Branch: 1 branch
BranchTrueFalseTotal
if $w == $v 111 1 112
625 }
626 111 ▶ if (@component > 1 || grep { $_ == $v } @{ $edges->[$v] }) {
Branch: 1 branch
BranchTrueFalseTotal
if (@component > 1 or grep {$_ == $v;} @{$$edges[$v];}) 1 110 111
Condition66%2/3
@component > 1 or grep {$_ == $v;} @{$$edges[$v];}
l!l&&r!l&&!r
10110
MC/DC50%1/2
@component > 1 or grep {$_ == $v;} @{$$edges[$v];}
@component > 1 grep {$_ == $v;} @{$$edges[$v];}
Truth table66%2/3
A or B
A= @component > 1B= grep {$_ == $v;} @{$$edges[$v];}
ABresult
1X1
011
000
627 1 $self->{nodes}[$_]{in_place_cycle} = 1 for @component;
628 }
629 }
630 }
631 }
632 }
633 }
634  
635 # Follows pure $ref nodes to the node that carries constraints.
636 4 ▶sub effective_node {
Subroutine effective_node: called CC=3 SCAR=11.0
Pod undocumented
637 4 my ($self, $node_id) = @_;
638 4 my $node = $self->{nodes}[$node_id];
639 4 for (1 .. 16) {
640 6 ▶ last unless $node->is_pure_ref;
Branch: 1 branch
BranchTrueFalseTotal
unless $node->is_pure_ref 4 2 6
641 2 $node = $self->{nodes}[ $node->{ref} ];
642 }
643 4 return $node;
644 }
645  
646 1 ▶sub _compute_discriminators {
Subroutine _compute_discriminators: called CC=6 SCAR=19.3
647 1 my ($self) = @_;
648 1 for my $n (@{ $self->{nodes} }) {
649 0 ▶ $n->{one_of_discriminator} = $self->_build_discriminator($n->{one_of}) if $n->{one_of} && @{ $n->{one_of} } > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"one_of"} and @{$n->{"one_of"};} > 1 0 103 103
Condition33%1/3
$n->{"one_of"} and @{$n->{"one_of"};} > 1
!ll&&!rl&&r
10300
MC/DC0%0/2
$n->{"one_of"} and @{$n->{"one_of"};} > 1
$n->{"one_of"} @{$n->{"one_of"};} > 1
Truth table33%1/3
A and B
A= $n->{"one_of"}B= @{$n->{"one_of"};} > 1
ABresult
0X0
100
111
650 103 ▶ $n->{any_of_discriminator} = $self->_build_discriminator($n->{any_of}) if $n->{any_of} && @{ $n->{any_of} } > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"any_of"} and @{$n->{"any_of"};} > 1 2 101 103
Condition66%2/3
$n->{"any_of"} and @{$n->{"any_of"};} > 1
!ll&&!rl&&r
10102
MC/DC50%1/2
$n->{"any_of"} and @{$n->{"any_of"};} > 1
$n->{"any_of"} @{$n->{"any_of"};} > 1
Truth table66%2/3
A and B
A= $n->{"any_of"}B= @{$n->{"any_of"};} > 1
ABresult
0X0
100
111
651 }
652 }
653  
654 # Classifies the branches by the constraint their properties[X] places on the value (positive: a const or enum of
655 # primitives; negative: a string not in an enum; wildcard: anything else), and builds the table of values to branches.
656 2 ▶sub _build_discriminator {
Subroutine _build_discriminator: called CC=17 SCAR=53.1
657 2 my ($self, $branches) = @_;
658 2 my @candidates;
659 2 for my $b (@$branches) {
660 4 my $eff = $self->effective_node($b);
661 4 ▶ next unless $eff->{properties};
Branch: 1 branch
BranchTrueFalseTotal
unless $eff->{"properties"} 4 0 4
662 0 for my $name (@{ $eff->{property_order} }) {
663 0 ▶ push @candidates, $name if $self->_classify($eff, $name)->[0] ne 'wildcard';
Branch: 1 branch
BranchTrueFalseTotal
if $self->_classify($eff, $name)->[0] ne "wildcard" 0 0 0
664 }
665 0 last;
666 }
667 2 for my $name (@candidates) {
668 0 my @classes = map { $self->_classify($self->effective_node($_), $name) } @$branches;
669 0 ▶ next if (grep { $_->[0] ne 'wildcard' } @classes) < 2;
Branch: 1 branch
BranchTrueFalseTotal
if grep({$_->[0] ne "wildcard";} @classes) < 2 0 0 0
670 0 my @values;
671 0 for my $c (@classes) {
672 0 for my $v (@{ $c->[1] }) {
673 0 ▶ push @values, $v unless grep { _same_primitive($v, $_) } @values;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {_same_primitive($v, $_);} @values 0 0 0
674 }
675 }
676 0 my @known;
677 0 for my $value (@values) {
678 0 my @selected;
679 0 for my $i (0 .. $#classes) {
680 0 my ($kind, $s) = @{ $classes[$i] };
681 0 ▶ my $contains = (grep { _same_primitive($value, $_) } @$s) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
grep({_same_primitive($value, $_);} @$s) ? : 0 0 0
682 0 ▶ push @selected, $i if $kind eq 'positive' ? $contains : $kind eq 'negative' ? !$contains : 1;
Branch: 3 branches
BranchTrueFalseTotal
if $kind eq "positive" ? $contains : ($kind eq "negative" ? !$contains : 1) 0 0 0
$kind eq 'positive' ? : 0 0 0
$kind eq 'negative' ? : 0 0 0
683 }
684 0 push @known, [ $value, \@selected ];
685 }
686 0 my @unknown = grep { $classes[$_][0] ne 'positive' } 0 .. $#classes;
687 0 ▶ my $all_require = (List::Util::all {
Subroutine __ANON__: not called CC=2 SCAR=17.9
688 0 my $required = $self->effective_node($_)->{required};
689 0 ▶ $required && grep { $_ eq $name } @$required
Branch: 1 branch
BranchTrueFalseTotal
$required and grep {$_ eq $name;} @$required 0 0 0
690 0 ▶ } @$branches) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
&List::Util::all(sub { my $required = $self->effective_node($_)->{'required'}; $required and grep {$_ eq $name;} @$required; } , @$branches) ? : 0 0 0
691 0 return { property => $name, known => \@known, unknown => \@unknown, all_require => $all_require };
692 }
693 2 return undef;
694 }
695  
696 0 ▶sub _classify {
Subroutine _classify: not called CC=17 SCAR=57.2
697 0 my ($self, $branch, $name) = @_;
698 0 ▶ my $child = $branch->{properties} ? $branch->{properties}{$name} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$branch->{'properties'} ? : 0 0 0
699 0 ▶ return [ 'wildcard', [] ] unless defined $child;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $child 0 0 0
700 0 my $p = $self->effective_node($child);
701 0 ▶ return [ 'positive', [ $p->{const_value} ] ] if $p->{has_const} && _is_discriminator_primitive($p->{const_value});
Branch: 1 branch
BranchTrueFalseTotal
if $p->{"has_const"} and _is_discriminator_primitive($p->{"const_value"}) 0 0 0
Condition0%0/3
$p->{"has_const"} and _is_discriminator_primitive($p->{"const_value"})
!ll&&!rl&&r
000
MC/DC0%0/2
$p->{"has_const"} and _is_discriminator_primitive($p->{"const_value"})
$p->{"has_const"} _is_discriminator_primitive($p->{"const_value"})
Truth table0%0/3
A and B
A= $p->{"has_const"}B= _is_discriminator_primitive($p->{"const_value"})
ABresult
0X0
100
111
702 0 ▶ if ($p->{enum_values} && @{ $p->{enum_values} } && List::Util::all { _is_discriminator_primitive($_) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"enum_values"} and @{$p->{"enum_values"};} and &List::Util::all(sub { _is_discriminator_primitive($_); } , @{$$p{"enum_values"};})) 0 0 0
Condition0%0/6
$p->{"enum_values"} and @{$p->{"enum_values"};} and &List::Util::all(sub { _is_discriminator_primitive($_); } , @{$$p{"enum_values"};})
!ll&&!rl&&r
000
$p->{"enum_values"} and @{$p->{"enum_values"};}
!ll&&!rl&&r
000
MC/DC0%0/3
$p->{"enum_values"} and @{$p->{"enum_values"};} and &List::Util::all(sub { _is_discriminator_primitive($_); } , @{$$p{"enum_values"};})
$p->{"enum_values"} @{$p->{"enum_values"};} &List::Util::all(sub { _is_discriminator_primitive($_); } , @{$$p{"enum_values"};})
Truth table0%0/4
A and B and C
A= $p->{"enum_values"}B= @{$p->{"enum_values"};}C= &List::Util::all(sub { _is_discriminator_primitive($_); } , @{$$p{"enum_values"};})
ABCresult
0XX0
10X0
1100
1111
703 0 @{ $p->{enum_values} }) {
704 0 return [ 'positive', [ @{ $p->{enum_values} } ] ];
705 }
706 0 ▶ if ($p->{not_} >= 0 && $p->{has_type} && $p->{type} == T_STRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"not_"} >= 0 and $p->{"has_type"} and $p->{"type"} == 32) 0 0 0
Condition0%0/6
$p->{"not_"} >= 0 and $p->{"has_type"} and $p->{"type"} == 32
!ll&&!rl&&r
000
$p->{"not_"} >= 0 and $p->{"has_type"}
!ll&&!rl&&r
000
MC/DC0%0/3
$p->{"not_"} >= 0 and $p->{"has_type"} and $p->{"type"} == 32
$p->{"not_"} >= 0 $p->{"has_type"} $p->{"type"} == 32
Truth table0%0/4
A and B and C
A= $p->{"not_"} >= 0B= $p->{"has_type"}C= $p->{"type"} == 32
ABCresult
0XX0
10X0
1100
1111
707 0 my $not_node = $self->effective_node($p->{not_});
708 0 ▶ if ($not_node->{enum_values} && (List::Util::all { _is_string($_) } @{ $not_node->{enum_values} })
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"} and not $not_node->{"has_const"} and not $not_node->has_string_keywords and not $not_node->has_in_place_applicators) 0 0 0
Condition0%0/15
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"} and not $not_node->{"has_const"} and not $not_node->has_string_keywords and not $not_node->has_in_place_applicators
!ll&&!rl&&r
000
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"} and not $not_node->{"has_const"} and not $not_node->has_string_keywords
!ll&&!rl&&r
000
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"} and not $not_node->{"has_const"}
!ll&&!rl&&r
000
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"}
!ll&&!rl&&r
000
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};})
!ll&&!rl&&r
000
MC/DC0%0/6
$not_node->{"enum_values"} and &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) and not $not_node->{"has_type"} and not $not_node->{"has_const"} and not $not_node->has_string_keywords and not $not_node->has_in_place_applicators
$not_node->{"enum_values"} &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};}) not $not_node->{"has_type"} not $not_node->{"has_const"} not $not_node->has_string_keywords not $not_node->has_in_place_applicators
Truth table0%0/7
A and B and not(C) and not(D) and not(E) and not(F)
A= $not_node->{"enum_values"}B= &List::Util::all(sub { _is_string($_); } , @{$$not_node{"enum_values"};})C= not $not_node->{"has_type"}D= not $not_node->{"has_const"}E= not $not_node->has_string_keywordsF= not $not_node->has_in_place_applicators
ABCDEFresult
0XXXXX0
10XXXX0
110XXX0
1110XX0
11110X0
1111100
1111111
709 && !$not_node->{has_type} && !$not_node->{has_const} && !$not_node->has_string_keywords
710 && !$not_node->has_in_place_applicators) {
711 0 return [ 'negative', [ @{ $not_node->{enum_values} } ] ];
712 }
713 }
714 0 return [ 'wildcard', [] ];
715 }
716  
717 0 ▶sub _is_discriminator_primitive {
Subroutine _is_discriminator_primitive: not called CC=3 SCAR=24.8
718 0 my ($v) = @_;
719 0 ▶ return _is_string($v) || _is_number($v) || JSON::Schema::Corvus::Json::is_bool($v);
Condition0%0/6
_is_string($v) || _is_number($v) || JSON::Schema::Corvus::Json::is_bool($v)
l!l&&r!l&&!r
000
_is_string($v) or _is_number($v)
l!l&&r!l&&!r
000
MC/DC0%0/3
_is_string($v) || _is_number($v) || JSON::Schema::Corvus::Json::is_bool($v)
_is_string($v) _is_number($v) JSON::Schema::Corvus::Json::is_bool($v)
Truth table0%0/4
A or B || C
A= _is_string($v)B= _is_number($v)C= JSON::Schema::Corvus::Json::is_bool($v)
ABCresult
1XX1
01X1
0011
0000
720 }
721  
722 # JSON equality of two discriminator primitives (a boolean never equals a number).
723 0 ▶sub _same_primitive {
Subroutine _same_primitive: not called CC=6 SCAR=37.4
724 0 my ($a, $b) = @_;
725 0 my $ta = JSON::Schema::Corvus::Json::type_of($a);
726 0 my $tb = JSON::Schema::Corvus::Json::type_of($b);
727 0 ▶ return 0 if $ta ne $tb;
Branch: 1 branch
BranchTrueFalseTotal
if $ta ne $tb 0 0 0
728 0 ▶ return ($a ? 1 : 0) == ($b ? 1 : 0) if $ta eq 'boolean';
Branch: 3 branches
BranchTrueFalseTotal
if $ta eq "boolean" 0 0 0
$a ? : 0 0 0
$b ? : 0 0 0
729 0 ▶ return $a == $b if $ta eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $ta eq "number" 0 0 0
730 0 return $a eq $b;
731 }
732  
733 # --- Annotations ---
734  
735 # Fills every node's annotations (once), for results collection.
736 3 ▶sub resolve_annotations {
Subroutine resolve_annotations: called CC=4 SCAR=14.1
Pod undocumented
737 3 my ($program) = @_;
738 3 ▶ my $sources = $program->{annotation_sources} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $sources = $program->{"annotation_sources"} or return 3 0 3
739 3 $program->{annotation_sources} = undef;
740 3 my $assert_format_set = defined $program->{options}{assert_format};
741 3 for my $node_id (0 .. $#$sources) {
742 6 ▶ my $src = $sources->[$node_id] or next;
Branch: 1 branch
BranchTrueFalseTotal
my $src = $sources->[$node_id] or next 6 0 6
743 6 $program->{nodes}[$node_id]{annotations} = _collect_annotations($src, $assert_format_set);
744 }
745 }
746  
747 # The annotation keywords of a schema object, in the order CompileNode records them.
748 6 ▶sub _collect_annotations {
Subroutine _collect_annotations: called CC=34 SCAR=58.2
749 6 my ($src, $assert_format_set) = @_;
750 6 my ($e, $dialect, $vocab, $legacy, $content) = @$src{qw(e dialect vocab legacy content)};
751 6 ▶ my $meta_data = $legacy || ($vocab & V_META_DATA);
Condition33%1/3
$legacy || $vocab & 8
l!l&&r!l&&!r
060
MC/DC0%0/2
$legacy || $vocab & 8
$legacy $vocab & 8
Truth table33%1/3
A || B
A= $legacyB= $vocab & 8
ABresult
1X1
011
000
752 6 ▶ my $format_annotate = $legacy || ($vocab & (V_FORMAT_ANNOTATION | V_FORMAT_ASSERTION)) || $assert_format_set;
Condition33%2/6
$legacy || $vocab & 48 || $assert_format_set
l!l&&r!l&&!r
600
$legacy or $vocab & 48
l!l&&r!l&&!r
060
MC/DC0%0/3
$legacy || $vocab & 48 || $assert_format_set
$legacy $vocab & 48 $assert_format_set
Truth table25%1/4
A or B || C
A= $legacyB= $vocab & 48C= $assert_format_set
ABCresult
1XX1
01X1
0011
0000
753 6 my @out;
754 6 ▶ my $add = sub { push @out, { keyword => $_[0], value => $e->{ $_[0] }, strings_only => $_[1] ? 1 : 0 } };
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
$_[1] ? : 0 1 1
755 6 for my $name (JSON::Schema::Corvus::Json::names($e)) {
756 9 ▶ if ($name eq 'title' || $name eq 'description' || $name eq 'default') {
Branch: 6 branches
BranchTrueFalseTotal
if ($name eq 'title' or $name eq 'description' or $name eq 'default') { } 1 8 9
elsif ($name eq 'examples') { } 0 8 8
elsif ($name eq 'readOnly' or $name eq 'writeOnly') { } 0 8 8
elsif ($name eq 'deprecated') { } 0 8 8
elsif ($name eq 'format') { } 0 8 8
elsif ($dialect >= 3 and not $KNOWN_KEYWORDS{$name}) { } 0 8 8
Condition66%4/6
$name eq "title" or $name eq "description" or $name eq "default"
l!l&&r!l&&!r
108
$name eq "title" or $name eq "description"
l!l&&r!l&&!r
108
MC/DC33%1/3
$name eq "title" or $name eq "description" or $name eq "default"
$name eq "title" $name eq "description" $name eq "default"
Truth table50%2/4
A or B or C
A= $name eq "title"B= $name eq "description"C= $name eq "default"
ABCresult
1XX1
01X1
0011
0000
757 1 ▶ $add->($name) if $meta_data;
Branch: 1 branch
BranchTrueFalseTotal
if $meta_data 1 0 1
758 }
759 elsif ($name eq 'examples') {
760 0 ▶ $add->($name) if $meta_data && $dialect >= DRAFT6;
Branch: 1 branch
BranchTrueFalseTotal
if $meta_data and $dialect >= 1 0 0 0
Condition0%0/3
$meta_data and $dialect >= 1
!ll&&!rl&&r
000
MC/DC0%0/2
$meta_data and $dialect >= 1
$meta_data $dialect >= 1
Truth table0%0/3
A and B
A= $meta_dataB= $dialect >= 1
ABresult
0X0
100
111
761 }
762 ▶ elsif ($name eq 'readOnly' || $name eq 'writeOnly') {
Condition33%1/3
$name eq "readOnly" or $name eq "writeOnly"
l!l&&r!l&&!r
008
MC/DC0%0/2
$name eq "readOnly" or $name eq "writeOnly"
$name eq "readOnly" $name eq "writeOnly"
Truth table33%1/3
A or B
A= $name eq "readOnly"B= $name eq "writeOnly"
ABresult
1X1
011
000
763 0 ▶ $add->($name) if $meta_data && $dialect >= DRAFT7;
Branch: 1 branch
BranchTrueFalseTotal
if $meta_data and $dialect >= 2 0 0 0
Condition0%0/3
$meta_data and $dialect >= 2
!ll&&!rl&&r
000
MC/DC0%0/2
$meta_data and $dialect >= 2
$meta_data $dialect >= 2
Truth table0%0/3
A and B
A= $meta_dataB= $dialect >= 2
ABresult
0X0
100
111
764 }
765 elsif ($name eq 'deprecated') {
766 0 ▶ $add->($name) if $meta_data && $dialect >= DRAFT201909;
Branch: 1 branch
BranchTrueFalseTotal
if $meta_data and $dialect >= 3 0 0 0
Condition0%0/3
$meta_data and $dialect >= 3
!ll&&!rl&&r
000
MC/DC0%0/2
$meta_data and $dialect >= 3
$meta_data $dialect >= 3
Truth table0%0/3
A and B
A= $meta_dataB= $dialect >= 3
ABresult
0X0
100
111
767 }
768 elsif ($name eq 'format') {
769 0 ▶ $add->($name) if _is_string($e->{format}) && $format_annotate;
Branch: 1 branch
BranchTrueFalseTotal
if _is_string($e->{"format"}) and $format_annotate 0 0 0
Condition0%0/3
_is_string($e->{"format"}) and $format_annotate
!ll&&!rl&&r
000
MC/DC0%0/2
_is_string($e->{"format"}) and $format_annotate
_is_string($e->{"format"}) $format_annotate
Truth table0%0/3
A and B
A= _is_string($e->{"format"})B= $format_annotate
ABresult
0X0
100
111
770 }
771 ▶ elsif ($dialect >= DRAFT201909 && !$KNOWN_KEYWORDS{$name}) {
Condition33%1/3
$dialect >= 3 and not $KNOWN_KEYWORDS{$name}
!ll&&!rl&&r
080
MC/DC0%0/2
$dialect >= 3 and not $KNOWN_KEYWORDS{$name}
$dialect >= 3 not $KNOWN_KEYWORDS{$name}
Truth table33%1/3
A and not(B)
A= $dialect >= 3B= not $KNOWN_KEYWORDS{$name}
ABresult
0X0
100
111
772 # Unknown keywords are collected as annotations from 2019-09 onwards.
773 0 $add->($name);
774 }
775 }
776 6 ▶ if ($content && $dialect >= DRAFT7
Branch: 1 branch
BranchTrueFalseTotal
if ($content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"} || exists $e->{"contentSchema"}) 0 6 6
Condition33%4/12
$content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"} || exists $e->{"contentSchema"}
!ll&&!rl&&r
060
$content and $dialect >= 2
!ll&&!rl&&r
006
exists $e->{"contentEncoding"} or exists $e->{"contentMediaType"} or exists $e->{"contentSchema"}
l!l&&r!l&&!r
006
exists $e->{"contentEncoding"} or exists $e->{"contentMediaType"}
l!l&&r!l&&!r
006
MC/DC0%0/5
$content and $dialect >= 2 and exists $e->{"contentEncoding"} || exists $e->{"contentMediaType"} || exists $e->{"contentSchema"}
$content $dialect >= 2 exists $e->{"contentEncoding"} exists $e->{"contentMediaType"} exists $e->{"contentSchema"}
Truth table16%1/6
A and B and C or D or E
A= $contentB= $dialect >= 2C= exists $e->{"contentEncoding"}D= exists $e->{"contentMediaType"}E= exists $e->{"contentSchema"}
ABCDEresult
0XXXX0
10XXX0
110000
111XX1
1101X1
110011
777 && (exists $e->{contentEncoding} || exists $e->{contentMediaType} || exists $e->{contentSchema})) {
778 0 ▶ $add->('contentEncoding', 1) if exists $e->{contentEncoding};
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"contentEncoding"} 0 0 0
779 0 ▶ if (exists $e->{contentMediaType}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $e->{"contentMediaType"}) 0 0 0
780 0 $add->('contentMediaType', 1);
781 # contentSchema is meaningful only alongside contentMediaType.
782 0 ▶ $add->('contentSchema', 1) if exists $e->{contentSchema} && $dialect >= DRAFT201909;
Branch: 1 branch
BranchTrueFalseTotal
if exists $e->{"contentSchema"} and $dialect >= 3 0 0 0
Condition0%0/3
exists $e->{"contentSchema"} and $dialect >= 3
!ll&&!rl&&r
000
MC/DC0%0/2
exists $e->{"contentSchema"} and $dialect >= 3
exists $e->{"contentSchema"} $dialect >= 3
Truth table0%0/3
A and B
A= exists $e->{"contentSchema"}B= $dialect >= 3
ABresult
0X0
100
111
783 }
784 }
785 6 ▶ return @out ? \@out : undef;
Branch: 1 branch
BranchTrueFalseTotal
@out ? : 1 5 6
786 }
787  
788 4 1;
« Corvus/Regex/Parse.pm ↑ Summary Corvus/Formats.pm »