Modern/Vocabulary/Applicator.pm

filter: Statementstmt 100% 280 / 280 Branchbran 96.8% 215 / 222 Conditioncond 87.3% 83 / 95 MC/DCmcdc 72.5% 37 / 51 Subroutinesub 100% 59 / 59 Podpod 0.0% 0 / 3 totaltotal 94.9% 674 / 710 CC 161 SCAR 24.0
CC
161
Cov
97%
_eval_keyword_contains
27.3
_eval_keyword__items_array_schemas
19.1
_eval_keyword_properties
15.0
CRAP 11.0
« Modern/Utilities.pm ↑ Summary Modern.pm »
1 38 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 38 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package JSON::Schema::Modern::Vocabulary::Applicator;
4 # vim: set ts=8 sts=2 sw=2 tw=100 et :
5 # ABSTRACT: Implementation of the JSON Schema Applicator vocabulary
6  
7 38 our $VERSION = '0.654';
8  
9 38 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 38 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 38 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 38 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 38 ▶use experimental 0.026 qw(signatures args_array_with_signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 38 ▶no autovivification warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 38 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 38 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 38 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 38 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 38 ▶no if "$]" >= 5.041009, feature => 'smartmatch';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 38 ▶no feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
21 38 ▶use List::Util 1.45 'uniqstr';
Subroutine BEGIN: called CC=1 SCAR=0.0
22 38 ▶use if "$]" < 5.041010, 'List::Util' => 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 38 ▶use if "$]" >= 5.041010, experimental => 'keyword_any';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 38 ▶use JSON::Schema::Modern::Utilities qw(is_type jsonp E A assert_keyword_type assert_pattern true is_elements_unique);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 38 ▶use JSON::Schema::Modern::Vocabulary::Unevaluated;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 38 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 38 with 'JSON::Schema::Modern::Vocabulary';
29  
30 22 ▶sub vocabulary ($class) {
Subroutine vocabulary: called CC=1 SCAR=0.0
Pod undocumented
31 22 'https://json-schema.org/draft/2019-09/vocab/applicator' => 'draft2019-09',
32 'https://json-schema.org/draft/2020-12/vocab/applicator' => 'draft2020-12';
33 }
34  
35 18 ▶sub evaluation_order ($class) { 3 }
Subroutine evaluation_order: called CC=1 SCAR=0.0
Pod undocumented
36  
37 # the keyword order is arbitrary, except:
38 # - if must be evaluated before then, else
39 # - items must be evaluated before additionalItems
40 # - in-place applicators (allOf, anyOf, oneOf, not, if/then/else, dependentSchemas) and items,
41 # additionalItems must be evaluated before unevaluatedItems (in the Unevaluated vocabulary)
42 # - properties and patternProperties must be evaluated before additionalProperties
43 # - in-place applicators and properties, patternProperties, additionalProperties must be evaluated
44 # before unevaluatedProperties (in the Unevaluated vocabulary)
45 # - contains must be evaluated before maxContains, minContains (implemented here, rather than in the Validation vocabulary)
46 173 ▶sub keywords ($class, $spec_version) {
Subroutine keywords: called CC=9 SCAR=22.0
Pod undocumented
47 return (
48 173 ▶ qw(allOf anyOf oneOf not),
Branch: 8 branches
BranchTrueFalseTotal
!($spec_version =~ /^draft[46]\z/u) ? : 140 33 173
$spec_version =~ /^draft[467]\z/u ? : 64 109 173
!($spec_version =~ /^draft[467]\z/u) ? : 109 64 173
!($spec_version =~ /^draft(?:[467]|2019-09)\z/u) ? : 69 104 173
$spec_version =~ /^draft(?:[467]|2019-09)\z/u ? : 104 69 173
$spec_version ne 'draft4' ? : 153 20 173
$spec_version ne 'draft4' ? : 153 20 173
$spec_version eq 'draft2019-09' ? : 40 133 173
49 $spec_version !~ /^draft[46]\z/ ? qw(if then else) : (),
50 $spec_version =~ /^draft[467]\z/ ? 'dependencies' : (),
51 $spec_version !~ /^draft[467]\z/ ? 'dependentSchemas' : (),
52 $spec_version !~ /^draft(?:[467]|2019-09)\z/ ? 'prefixItems' : (),
53 'items',
54 $spec_version =~ /^draft(?:[467]|2019-09)\z/ ? 'additionalItems' : (),
55 $spec_version ne 'draft4' ? 'contains' : (),
56 qw(properties patternProperties additionalProperties),
57 $spec_version ne 'draft4' ? 'propertyNames' : (),
58 $spec_version eq 'draft2019-09' ? qw(unevaluatedItems unevaluatedProperties) : (),
59 );
60 }
61  
62 # in draft2019-09, the unevaluated keywords were part of the Applicator vocabulary
63 38 foreach my $phase (qw(traverse eval)) {
64 76 foreach my $type (qw(Items Properties)) {
65 152 my $method = '_'.$phase.'_keyword_unevaluated'.$type;
66 38 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
67 152 ▶ *{__PACKAGE__.'::'.$method} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 1469 shift;
69 1469 JSON::Schema::Modern::Vocabulary::Unevaluated->$method(@_);
70 152 };
71 }
72 }
73  
74 1022 ▶sub _traverse_keyword_allOf { shift->traverse_array_schemas(@_) }
Subroutine _traverse_keyword_allOf: called CC=1 SCAR=0.0
75  
76 1084 ▶sub _eval_keyword_allOf ($class, $data, $schema, $state) {
Subroutine _eval_keyword_allOf: called CC=7 SCAR=19.5
77 1084 my @invalid;
78 1084 foreach my $idx (0 .. $schema->{allOf}->$#*) {
79 2556 ▶ if ($class->eval($data, $schema->{allOf}[$idx], +{ %$state,
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($data, $$schema{'allOf'}[$idx], {%$state, 'keyword_path', $$state{'keyword_path'} . '/allOf/' . $idx})) { } 2037 515 2552
80 keyword_path => $state->{keyword_path}.'/allOf/'.$idx })) {
81 }
82 else {
83 515 push @invalid, $idx;
84 515 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 203 312 515
85 }
86 }
87  
88 1080 ▶ return 1 if @invalid == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @invalid == 0 623 457 1080
89  
90 457 my $pl = @invalid > 1;
91 457 ▶ return E($state, 'subschema%s %s %s not valid', $pl?'s':'', join(', ', @invalid), $pl?'are':'is');
Branch: 2 branches
BranchTrueFalseTotal
$pl ? : 47 410 457
$pl ? : 47 410 457
92 }
93  
94 719 ▶sub _traverse_keyword_anyOf { shift->traverse_array_schemas(@_) }
Subroutine _traverse_keyword_anyOf: called CC=1 SCAR=0.0
95  
96 766 ▶sub _eval_keyword_anyOf ($class, $data, $schema, $state) {
Subroutine _eval_keyword_anyOf: called CC=6 SCAR=17.9
97 766 my $valid = 0;
98 766 my @errors;
99 766 foreach my $idx (0 .. $schema->{anyOf}->$#*) {
100 next if not $class->eval($data, $schema->{anyOf}[$idx],
101 1369 ▶ +{ %$state, errors => \@errors, keyword_path => $state->{keyword_path}.'/anyOf/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
unless $class->eval($data, $$schema{"anyOf"}[$idx], {%$state, "errors", \@errors, "keyword_path", $$state{"keyword_path"} . '/anyOf/' . $idx}) 798 570 1368
102 570 ++$valid;
103 570 ▶ last if $state->{short_circuit} and not $state->{collect_annotations};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} and not $$state{"collect_annotations"} 177 393 570
Condition100%3/3
$$state{"short_circuit"} and not $$state{"collect_annotations"}
!ll&&!rl&&r
31776177
MC/DC100%2/2
$$state{"short_circuit"} and not $$state{"collect_annotations"}
$$state{"short_circuit"} not $$state{"collect_annotations"}
Truth table100%3/3
A and not(B)
A= $$state{"short_circuit"}B= not $$state{"collect_annotations"}
ABresult
0X0
100
111
104 }
105  
106 765 ▶ return 1 if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 493 272 765
107 272 push $state->{errors}->@*, @errors;
108 272 return E($state, 'no subschemas are valid');
109 }
110  
111 701 ▶sub _traverse_keyword_oneOf { shift->traverse_array_schemas(@_) }
Subroutine _traverse_keyword_oneOf: called CC=1 SCAR=0.0
112  
113 661 ▶sub _eval_keyword_oneOf ($class, $data, $schema, $state) {
Subroutine _eval_keyword_oneOf: called CC=7 SCAR=19.5
114 661 my (@valid, @errors);
115 661 foreach my $idx (0 .. $schema->{oneOf}->$#*) {
116 next if not $class->eval($data, $schema->{oneOf}[$idx],
117 1412 ▶ +{ %$state, errors => \@errors, keyword_path => $state->{keyword_path}.'/oneOf/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
unless $class->eval($data, $$schema{"oneOf"}[$idx], {%$state, "errors", \@errors, "keyword_path", $$state{"keyword_path"} . '/oneOf/' . $idx}) 801 611 1412
118 611 push @valid, $idx;
119 611 ▶ last if @valid > 1 and $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if @valid > 1 and $$state{"short_circuit"} 66 545 611
Condition100%3/3
@valid > 1 and $$state{"short_circuit"}
!ll&&!rl&&r
4658066
MC/DC100%2/2
@valid > 1 and $$state{"short_circuit"}
@valid > 1 $$state{"short_circuit"}
Truth table100%3/3
A and B
A= @valid > 1B= $$state{"short_circuit"}
ABresult
0X0
100
111
120 }
121  
122 661 ▶ return 1 if @valid == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @valid == 1 325 336 661
123  
124 336 ▶ if (not @valid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @valid) { } 196 140 336
125 196 push $state->{errors}->@*, @errors;
126 196 return E($state, 'no subschemas are valid');
127 }
128 else {
129 140 return E($state, 'multiple subschemas are valid: '.join(', ', @valid));
130 }
131 }
132  
133 490 ▶sub _traverse_keyword_not { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_not: called CC=1 SCAR=0.0
134  
135 468 ▶sub _eval_keyword_not ($class, $data, $schema, $state) {
Subroutine _eval_keyword_not: called CC=4 SCAR=13.9
136 468 ▶ return !$schema->{not} || E($state, 'subschema is true') if is_type('boolean', $schema->{not});
Branch: 1 branch
BranchTrueFalseTotal
if is_type("boolean", $$schema{"not"}) 162 306 468
Condition66%2/3
!$$schema{'not'} || E($state, 'subschema is true')
l!l&&r!l&&!r
74088
MC/DC50%1/2
!$$schema{'not'} || E($state, 'subschema is true')
!$$schema{'not'} E($state, 'subschema is true')
Truth table66%2/3
not(A) || B
A= !$$schema{'not'}B= E($state, 'subschema is true')
ABresult
1X1
011
000
137  
138 return 1 if not $class->eval($data, $schema->{not},
139 306 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/not',
Branch: 1 branch
BranchTrueFalseTotal
unless $class->eval($data, $$schema{"not"}, {%$state, "keyword_path", $$state{"keyword_path"} . '/not', "short_circuit", 1, "collect_annotations", 0, "errors", []}) 76 230 306
140 short_circuit => 1, # errors do not propagate upward from this subschema
141 collect_annotations => 0, # nor do annotations
142 errors => [] });
143  
144 230 return E($state, 'subschema is valid');
145 }
146  
147 410 ▶sub _traverse_keyword_if { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_if: called CC=1 SCAR=0.0
148 319 ▶sub _traverse_keyword_then { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_then: called CC=1 SCAR=0.0
149 268 ▶sub _traverse_keyword_else { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_else: called CC=1 SCAR=0.0
150  
151 368 ▶sub _eval_keyword_if ($class, $data, $schema, $state) {
Subroutine _eval_keyword_if: called CC=9 SCAR=22.0
152 return 1 if not exists $schema->{then} and not exists $schema->{else}
153 368 ▶ and not $state->{collect_annotations};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{"then"} or exists $$schema{"else"} or $$state{"collect_annotations"} 33 335 368
Condition100%6/6
exists $$schema{"then"} or exists $$schema{"else"} or $$state{"collect_annotations"}
l!l&&r!l&&!r
3152033
exists $$schema{"then"} or exists $$schema{"else"}
l!l&&r!l&&!r
2635253
MC/DC100%3/3
exists $$schema{"then"} or exists $$schema{"else"} or $$state{"collect_annotations"}
exists $$schema{"then"} exists $$schema{"else"} $$state{"collect_annotations"}
Truth table100%4/4
A or B or C
A= exists $$schema{"then"}B= exists $$schema{"else"}C= $$state{"collect_annotations"}
ABCresult
1XX1
01X1
0011
0000
154 my $keyword = $class->eval($data, $schema->{if},
155 335 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/if', short_circuit => 1, errors => [] })
Branch: 1 branch
BranchTrueFalseTotal
$class->eval($data, $$schema{'if'}, {%$state, 'keyword_path', $$state{'keyword_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? : 172 162 334
156 ? 'then' : 'else';
157  
158 334 ▶ return 1 if not exists $schema->{$keyword};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{$keyword} 78 256 334
159  
160 return $schema->{$keyword} || E({ %$state, keyword => $keyword }, 'subschema is false')
161 256 ▶ if is_type('boolean', $schema->{$keyword});
Branch: 1 branch
BranchTrueFalseTotal
if is_type("boolean", $$schema{$keyword}) 41 215 256
Condition66%2/3
$$schema{$keyword} || E({%$state, 'keyword', $keyword}, 'subschema is false')
l!l&&r!l&&!r
29012
MC/DC50%1/2
$$schema{$keyword} || E({%$state, 'keyword', $keyword}, 'subschema is false')
$$schema{$keyword} E({%$state, 'keyword', $keyword}, 'subschema is false')
Truth table66%2/3
A || B
A= $$schema{$keyword}B= E({%$state, 'keyword', $keyword}, 'subschema is false')
ABresult
1X1
011
000
162  
163 return 1 if $class->eval($data, $schema->{$keyword},
164 215 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/'.$keyword });
Branch: 1 branch
BranchTrueFalseTotal
if $class->eval($data, $$schema{$keyword}, {%$state, "keyword_path", $$state{"keyword_path"} . '/' . $keyword}) 125 90 215
165 90 return E({ %$state, keyword => $keyword }, 'subschema is not valid');
166 }
167  
168 350 ▶sub _traverse_keyword_dependentSchemas { shift->traverse_object_schemas(@_) }
Subroutine _traverse_keyword_dependentSchemas: called CC=1 SCAR=0.0
169  
170 328 ▶sub _eval_keyword_dependentSchemas ($class, $data, $schema, $state) {
Subroutine _eval_keyword_dependentSchemas: called CC=7 SCAR=19.5
171 328 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 106 222 328
172  
173 222 my $valid = 1;
174 222 foreach my $property (sort keys $schema->{dependentSchemas}->%*) {
175 272 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 134 138 272
176  
177 138 ▶ if ($class->eval($data, $schema->{dependentSchemas}{$property},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)})) 34 104 138
178 +{ %$state, keyword_path => jsonp($state->{keyword_path}, 'dependentSchemas', $property) })) {
179 34 next;
180 }
181  
182 104 $valid = 0;
183 104 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 49 55 104
184 }
185  
186 222 ▶ return E($state, 'not all dependencies are satisfied') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 104 118 222
187 118 return 1;
188 }
189  
190 315 ▶sub _traverse_keyword_dependencies ($class, $schema, $state) {
Subroutine _traverse_keyword_dependencies: called CC=10 SCAR=24.3
191 315 ▶ return if not assert_keyword_type($state, $schema, 'object');
Branch: 1 branch
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "object") 0 315 315
192  
193 315 my $valid = 1;
194 315 foreach my $property (sort keys $schema->{dependencies}->%*) {
195 459 ▶ if (is_type('array', $schema->{dependencies}{$property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('array', $$schema{'dependencies'}{$property})) { } 179 280 459
196 # as in dependentRequired
197  
198 179 foreach my $index (0..$schema->{dependencies}{$property}->$#*) {
199 $valid = E({ %$state, _keyword_path_suffix => [ $property, $index ] }, 'element #%d is not a string', $index)
200 205 ▶ if not is_type('string', $schema->{dependencies}{$property}[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $$schema{"dependencies"}{$property}[$index]) 0 205 205
201 }
202  
203 $valid = E({ %$state, _keyword_path_suffix => $property }, 'elements are not unique')
204 179 ▶ if not is_elements_unique($schema->{dependencies}{$property});
Branch: 1 branch
BranchTrueFalseTotal
unless is_elements_unique($$schema{"dependencies"}{$property}) 0 179 179
205  
206 $valid = E($state, '"dependencies" array for %s is empty', $property)
207 179 ▶ if $state->{specification_version} eq 'draft4' and not $schema->{dependencies}{$property}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"specification_version"} eq "draft4" and not @{$$schema{"dependencies"}{$property}} 0 179 179
Condition66%2/3
$$state{"specification_version"} eq "draft4" and not @{$$schema{"dependencies"}{$property}}
!ll&&!rl&&r
121580
MC/DC0%0/2
$$state{"specification_version"} eq "draft4" and not @{$$schema{"dependencies"}{$property}}
$$state{"specification_version"} eq "draft4" not @{$$schema{"dependencies"}{$property}}
Truth table66%2/3
A and not(B)
A= $$state{"specification_version"} eq "draft4"B= not @{$$schema{"dependencies"}{$property}}
ABresult
0X0
100
111
208 }
209 else {
210 # as in dependentSchemas
211 280 ▶ $valid = 0 if not $class->traverse_property_schema($schema, $state, $property);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->traverse_property_schema($schema, $state, $property) 0 280 280
212 }
213 }
214 315 return $valid;
215 }
216  
217 316 ▶sub _eval_keyword_dependencies ($class, $data, $schema, $state) {
Subroutine _eval_keyword_dependencies: called CC=10 SCAR=23.0
218 316 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 64 252 316
219  
220 252 my $valid = 1;
221 252 foreach my $property (sort keys $schema->{dependencies}->%*) {
222 396 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 225 171 396
223  
224 171 ▶ if (is_type('array', $schema->{dependencies}{$property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('array', $$schema{'dependencies'}{$property})) { } 65 106 171
225 # as in dependentRequired
226 65 ▶ if (my @missing = grep !exists($data->{$_}), $schema->{dependencies}{$property}->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependencies"}{$property}})) 37 28 65
227 37 ▶ $valid = E({ %$state, _keyword_path_suffix => $property },
Branch: 1 branch
BranchTrueFalseTotal
@missing > 1 ? : 7 30 37
228 'object is missing propert%s: %s', @missing > 1 ? 'ies' : 'y', join(', ', @missing));
229 }
230 }
231 else {
232 # as in dependentSchemas
233 106 ▶ if ($class->eval($data, $schema->{dependencies}{$property},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)})) 24 82 106
234 +{ %$state, keyword_path => jsonp($state->{keyword_path}, 'dependencies', $property) })) {
235 24 next;
236 }
237  
238 82 $valid = 0;
239 82 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 38 44 82
240 }
241 }
242  
243 252 ▶ return E($state, 'not all dependencies are satisfied') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 118 134 252
244 134 return 1;
245 }
246  
247 443 ▶sub _traverse_keyword_prefixItems { shift->traverse_array_schemas(@_) }
Subroutine _traverse_keyword_prefixItems: called CC=1 SCAR=0.0
248  
249 441 ▶sub _eval_keyword_prefixItems { goto \&_eval_keyword__items_array_schemas }
Subroutine _eval_keyword_prefixItems: called CC=1 SCAR=0.0
250  
251 # array- or schema-based before draft2020-12; schema-based only for draft2020-12+
252 1727 ▶sub _traverse_keyword_items ($class, $schema, $state) {
Subroutine _traverse_keyword_items: called CC=3 SCAR=11.0
253 1727 ▶ if (ref $schema->{items} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$schema{"items"} eq "ARRAY") 938 789 1727
254 return E($state, 'array form of "items" not supported in %s', $state->{specification_version})
255 938 ▶ if $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u 2 936 938
256  
257 936 return $class->traverse_array_schemas($schema, $state);
258 }
259  
260 789 $class->traverse_subschema($schema, $state);
261 }
262  
263 1956 ▶sub _eval_keyword_items ($class, $data, $schema, $state) {
Subroutine _eval_keyword_items: called CC=2 SCAR=6.9
264 1956 ▶ goto \&_eval_keyword__items_array_schemas if ref $schema->{items} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $$schema{"items"} eq "ARRAY" 985 971 1956
265 971 goto \&_eval_keyword__items_schema;
266 }
267  
268 # pre-draft2020-12 only
269 342 ▶sub _traverse_keyword_additionalItems { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_additionalItems: called CC=1 SCAR=0.0
270  
271 398 ▶sub _eval_keyword_additionalItems ($class, $data, $schema, $state) {
Subroutine _eval_keyword_additionalItems: called CC=2 SCAR=6.9
272 398 ▶ return 1 if not exists $state->{_last_items_index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"_last_items_index"} 45 353 398
273 353 goto \&_eval_keyword__items_schema;
274 }
275  
276 # "prefixItems" (draft 2020-12), array-based "items" (pre-draft2020-12))
277 1426 ▶sub _eval_keyword__items_array_schemas ($class, $data, $schema, $state) {
Subroutine _eval_keyword__items_array_schemas: called CC=19 SCAR=29.5
278 1426 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 185 1241 1426
279  
280 1241 my $valid = 1;
281  
282 1241 foreach my $idx (0 .. $data->$#*) {
283 2267 ▶ last if $idx > $schema->{$state->{keyword}}->$#*;
Branch: 1 branch
BranchTrueFalseTotal
if $idx > $$schema{$$state{"keyword"}}->$#* 390 1877 2267
284 1877 $state->{_last_items_index} = $idx;
285  
286 1877 ▶ if (is_type('boolean', $schema->{$state->{keyword}}[$idx])) {
Branch: 2 branches
BranchTrueFalseTotal
if (is_type('boolean', $$schema{$$state{'keyword'}}[$idx])) { } 339 1538 1877
elsif ($class->eval($$data[$idx], $$schema{$$state{'keyword'}}[$idx], {%$state, 'data_path', $$state{'data_path'} . '/' . $idx, 'keyword_path', $$state{'keyword_path'} . '/' . $$state{'keyword'} . '/' . $idx, 'collect_annotations', $$state{'collect_annotations'} & 18446744073709551614})) { } 1435 103 1538
287 339 ▶ next if $schema->{$state->{keyword}}[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{$$state{"keyword"}}[$idx] 226 113 339
288 $valid = E({ %$state, data_path => $state->{data_path}.'/'.$idx,
289 113 _keyword_path_suffix => $idx, collect_annotations => $state->{collect_annotations} & ~1 },
290 'item not permitted');
291 }
292 elsif ($class->eval($data->[$idx], $schema->{$state->{keyword}}[$idx],
293 +{ %$state, data_path => $state->{data_path}.'/'.$idx,
294 keyword_path => $state->{keyword_path}.'/'.$state->{keyword}.'/'.$idx,
295 collect_annotations => $state->{collect_annotations} & ~1 })) {
296 1435 next;
297 }
298  
299 216 $valid = 0;
300 last if $state->{short_circuit} and not exists $schema->{
301 $state->{keyword} eq 'prefixItems' ? 'items'
302 216 ▶ : $state->{keyword} eq 'items' ? 'additionalItems' : die
Branch: 3 branches
BranchTrueFalseTotal
if $$state{"short_circuit"} and not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())} 89 127 216
$$state{'keyword'} eq 'prefixItems' ? : 36 73 109
$$state{'keyword'} eq 'items' ? : 73 0 73
Condition100%3/3
$$state{"short_circuit"} and not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
!ll&&!rl&&r
1072089
MC/DC100%2/2
$$state{"short_circuit"} and not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
$$state{"short_circuit"} not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
Truth table100%3/3
A and not(B)
A= $$state{"short_circuit"}B= not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
ABresult
0X0
100
111
303 };
304 }
305  
306 1241 ▶ if ($state->{defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"defaults"}) 9 1232 1241
307 9 foreach my $idx ($data->$#*+1 .. $schema->{$state->{keyword}}->$#*) {
308 $state->{defaults}{$state->{data_path}.'/'.$idx} = $schema->{$state->{keyword}}[$idx]{default}
309 if $valid and ref $schema->{$state->{keyword}}[$idx] eq 'HASH'
310 9 ▶ and exists $schema->{$state->{keyword}}[$idx]{default};
Branch: 1 branch
BranchTrueFalseTotal
if $valid and ref $$schema{$$state{"keyword"}}[$idx] eq "HASH" and exists $$schema{$$state{"keyword"}}[$idx]{"default"} 8 1 9
Condition66%4/6
$valid and ref $$schema{$$state{"keyword"}}[$idx] eq "HASH" and exists $$schema{$$state{"keyword"}}[$idx]{"default"}
!ll&&!rl&&r
108
$valid and ref $$schema{$$state{"keyword"}}[$idx] eq "HASH"
!ll&&!rl&&r
018
MC/DC33%1/3
$valid and ref $$schema{$$state{"keyword"}}[$idx] eq "HASH" and exists $$schema{$$state{"keyword"}}[$idx]{"default"}
$valid ref $$schema{$$state{"keyword"}}[$idx] eq "HASH" exists $$schema{$$state{"keyword"}}[$idx]{"default"}
Truth table50%2/4
A and B and C
A= $validB= ref $$schema{$$state{"keyword"}}[$idx] eq "HASH"C= exists $$schema{$$state{"keyword"}}[$idx]{"default"}
ABCresult
0XX0
10X0
1100
1111
311 }
312 }
313  
314 A($state, $state->{_last_items_index} == $data->$#* ? true : $state->{_last_items_index})
315 1241 ▶ if exists $state->{_last_items_index};
Branch: 2 branches
BranchTrueFalseTotal
if exists $$state{"_last_items_index"} 1091 150 1241
$$state{'_last_items_index'} == $data->$#* ? : 684 407 1091
316 1241 ▶ return E($state, 'not all items are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 211 1030 1241
317 1030 return 1;
318 }
319  
320 # schema-based items (all drafts), and additionalItems (up to and including draft2019-09)
321 1324 ▶sub _eval_keyword__items_schema ($class, $data, $schema, $state) {
Subroutine _eval_keyword__items_schema: called CC=14 SCAR=26.4
322 1324 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 142 1182 1324
323 1182 ▶ return 1 if ($state->{_last_items_index}//-1) == $data->$#*;
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"_last_items_index"} // -1) == $data->$#* 369 813 1182
Condition100%2/2
$$state{"_last_items_index"} // -1
l!l
441741
MC/DC100%1/1
$$state{"_last_items_index"} // -1
$$state{"_last_items_index"}
Truth table100%2/2
A
A= $$state{"_last_items_index"}
Aresult
11
00
324  
325 813 my $valid = 1;
326  
327 813 ▶ foreach my $idx (($state->{_last_items_index}//-1)+1 .. $data->$#*) {
Condition100%2/2
$$state{"_last_items_index"} // -1
l!l
128685
MC/DC100%1/1
$$state{"_last_items_index"} // -1
$$state{"_last_items_index"}
Truth table100%2/2
A
A= $$state{"_last_items_index"}
Aresult
11
00
328 1337 ▶ if (is_type('boolean', $schema->{$state->{keyword}})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{$$state{'keyword'}})) { } 160 1177 1337
329 160 ▶ next if $schema->{$state->{keyword}};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{$$state{"keyword"}} 40 120 160
330 $valid = E({ %$state, data_path => $state->{data_path}.'/'.$idx },
331 '%sitem not permitted',
332 120 ▶ exists $schema->{prefixItems} || $state->{keyword} eq 'additionalItems' ? 'additional ' : '');
Branch: 1 branch
BranchTrueFalseTotal
exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? : 67 53 120
Condition100%3/3
exists $$schema{"prefixItems"} or $$state{"keyword"} eq "additionalItems"
l!l&&r!l&&!r
145353
MC/DC100%2/2
exists $$schema{"prefixItems"} or $$state{"keyword"} eq "additionalItems"
exists $$schema{"prefixItems"} $$state{"keyword"} eq "additionalItems"
Truth table100%3/3
A or B
A= exists $$schema{"prefixItems"}B= $$state{"keyword"} eq "additionalItems"
ABresult
1X1
011
000
333 }
334 else {
335 1177 ▶ if ($class->eval($data->[$idx], $schema->{$state->{keyword}},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($$data[$idx], $$schema{$$state{"keyword"}}, {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "keyword_path", $$state{"keyword_path"} . '/' . $$state{"keyword"}, "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 814 358 1172
336 +{ %$state, data_path => $state->{data_path}.'/'.$idx,
337 keyword_path => $state->{keyword_path}.'/'.$state->{keyword},
338 collect_annotations => $state->{collect_annotations} & ~1 })) {
339 814 next;
340 }
341  
342 358 $valid = 0;
343 }
344 478 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 176 302 478
345 }
346  
347 808 $state->{_last_items_index} = $data->$#*;
348  
349 808 A($state, true);
350 return E($state, 'subschema is not valid against all %sitems',
351 808 ▶ $state->{keyword} eq 'additionalItems' ? 'additional ' : '') if not $valid;
Branch: 2 branches
BranchTrueFalseTotal
unless $valid 401 407 808
$$state{'keyword'} eq 'additionalItems' ? : 77 324 401
352 407 return 1;
353 }
354  
355 823 ▶sub _traverse_keyword_contains { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_contains: called CC=1 SCAR=0.0
356  
357 756 ▶sub _eval_keyword_contains ($class, $data, $schema, $state) {
Subroutine _eval_keyword_contains: called CC=27 SCAR=33.1
358 756 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 186 570 756
359  
360 570 $state->{_num_contains} = 0;
361 570 my (@errors, @valid);
362  
363 570 foreach my $idx (0 .. $data->$#*) {
364 787 ▶ if ($class->eval($data->[$idx], $schema->{contains},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($$data[$idx], $$schema{"contains"}, {%$state, "errors", \@errors, "data_path", $$state{"data_path"} . '/' . $idx, "keyword_path", $$state{"keyword_path"} . '/contains', "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 458 329 787
365 +{ %$state, errors => \@errors,
366 data_path => $state->{data_path}.'/'.$idx,
367 keyword_path => $state->{keyword_path}.'/contains',
368 collect_annotations => $state->{collect_annotations} & ~1 })) {
369 458 ++$state->{_num_contains};
370 458 push @valid, $idx;
371  
372 last if $state->{short_circuit}
373 # must continue until maxContains fails, but once it does we are guaranteed to be invalid,
374 # so can always stop evaluating immediately
375 and (exists $schema->{maxContains} and $state->{_num_contains} > $schema->{maxContains})
376 # once minContains succeeds, we can stop evaluating if no unevaluatedItems present
377 # (but only draft2020-12 collects annotations for "contains" evaluations)
378 or (not exists $schema->{maxContains}
379 and (not $state->{collect_annotations} or $state->{specification_version} ne 'draft2020-12')
380 458 ▶ and $state->{_num_contains} >= ($schema->{minContains}//1));
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} and (exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}) or not exists $$schema{"maxContains"} and !$$state{"collect_annotations"} || $$state{"specification_version"} ne "draft2020-12" and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1) 229 229 458
Condition95%19/20
$$state{"short_circuit"} and (exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}) or not exists $$schema{"maxContains"} and !$$state{"collect_annotations"} || $$state{"specification_version"} ne "draft2020-12" and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
l!l&&r!l&&!r
20209229
$$state{"short_circuit"} and (exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"})
!ll&&!rl&&r
21921920
exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}
!ll&&!rl&&r
1665320
not exists $$schema{"maxContains"} and !$$state{"collect_annotations"} || $$state{"specification_version"} ne "draft2020-12" and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
!ll&&!rl&&r
20128209
not exists $$schema{"maxContains"} and !$$state{"collect_annotations"} || $$state{"specification_version"} ne "draft2020-12"
!ll&&!rl&&r
12972237
not $$state{"collect_annotations"} or $$state{"specification_version"} ne "draft2020-12"
l!l&&r!l&&!r
237072
$$schema{"minContains"} // 1
l!l
56181
MC/DC85%6/7
$$state{"short_circuit"} and (exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}) or not exists $$schema{"maxContains"} and !$$state{"collect_annotations"} || $$state{"specification_version"} ne "draft2020-12" and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
$$state{"short_circuit"} exists $$schema{"maxContains"} $$state{"_num_contains"} > $$schema{"maxContains"} not exists $$schema{"maxContains"} not $$state{"collect_annotations"} $$state{"specification_version"} ne "draft2020-12" $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
MC/DC100%1/1
$$schema{"minContains"} // 1
$$schema{"minContains"}
Truth table47%9/19
A and B and C or not(D) and not(E) or F and G
A= $$state{"short_circuit"}B= exists $$schema{"maxContains"}C= $$state{"_num_contains"} > $$schema{"maxContains"}D= not exists $$schema{"maxContains"}E= not $$state{"collect_annotations"}F= $$state{"specification_version"} ne "draft2020-12"G= $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
ABCDEFGresult
111XXXX1
0XX11X11
0XX10111
10X11X11
10X10111
11011X11
11010111
0XX0XXX0
0XX100X0
0XX11X00
0XX10100
10X0XXX0
10X100X0
10X11X00
10X10100
1100XXX0
110100X0
11011X00
11010100
Truth table100%2/2
A
A= $$schema{"minContains"}
Aresult
11
00
381 }
382 }
383  
384 # note: no items contained is only valid when minContains is explicitly 0
385 570 ▶ if (not $state->{_num_contains}
Branch: 1 branch
BranchTrueFalseTotal
if (not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} =~ /^draft[467]\z/u) 217 353 570
Condition87%7/8
not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} =~ /^draft[467]\z/u
!ll&&!rl&&r
33320217
($$schema{"minContains"} // 1) > 0 or $$state{"specification_version"} =~ /^draft[467]\z/u
l!l&&r!l&&!r
217020
$$schema{"minContains"} // 1
l!l
46191
MC/DC33%1/3
not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} =~ /^draft[467]\z/u
not $$state{"_num_contains"} $$schema{"minContains"} $$state{"specification_version"} =~ /^draft[467]\z/u
Truth table50%2/4
not(A) and B or C
A= not $$state{"_num_contains"}B= $$schema{"minContains"}C= $$state{"specification_version"} =~ /^draft[467]\z/u
ABCresult
0XX0
1000
11X1
1011
386 and (($schema->{minContains}//1) > 0 or $state->{specification_version} =~ /^draft[467]\z/)) {
387 217 push $state->{errors}->@*, @errors;
388 217 return E($state, 'subschema is not valid against any item');
389 }
390  
391 # only draft2020-12 and later can produce annotations
392 353 ▶ A($state, @valid == @$data ? true : \@valid) if $state->{specification_version} !~ /^draft(?:[467]|2019-09)\z/;
Branch: 2 branches
BranchTrueFalseTotal
unless $$state{"specification_version"} =~ /^draft(?:[467]|2019-09)\z/u 168 185 353
@valid == @$data ? : 101 67 168
393  
394 353 my $valid = 1;
395  
396 # 'maxContains' and 'minContains' are owned by the Validation vocabulary, but do nothing if the
397 # Applicator vocabulary is omitted and depend on the result of 'contains', so they are implemented
398 # here, to be evaluated after 'contains'
399 353 ▶ if ($state->{specification_version} !~ /^draft[467]\z/
Branch: 1 branch
BranchTrueFalseTotal
if (not $$state{"specification_version"} =~ /^draft[467]\z/u and grep(($_ eq "JSON::Schema::Modern::Vocabulary::Validation"), @{$$state{"vocabularies"}})) 285 68 353
Condition66%2/3
not $$state{"specification_version"} =~ /^draft[467]\z/u and grep(($_ eq "JSON::Schema::Modern::Vocabulary::Validation"), @{$$state{"vocabularies"}})
!ll&&!rl&&r
680285
MC/DC50%1/2
not $$state{"specification_version"} =~ /^draft[467]\z/u and grep(($_ eq "JSON::Schema::Modern::Vocabulary::Validation"), @{$$state{"vocabularies"}})
not $$state{"specification_version"} =~ /^draft[467]\z/u grep(($_ eq "JSON::Schema::Modern::Vocabulary::Validation"), @{$$state{"vocabularies"}})
Truth table66%2/3
not(A) and B
A= not $$state{"specification_version"} =~ /^draft[467]\z/uB= grep(($_ eq "JSON::Schema::Modern::Vocabulary::Validation"), @{$$state{"vocabularies"}})
ABresult
0X0
100
111
400 and grep $_ eq 'JSON::Schema::Modern::Vocabulary::Validation', $state->{vocabularies}->@*) {
401 $valid = E($state, 'array contains more than %d matching item%s', $schema->{maxContains}, $schema->{maxContains} != 1 ? 's' : '')
402 285 ▶ if exists $schema->{maxContains} and $state->{_num_contains} > $schema->{maxContains};
Branch: 2 branches
BranchTrueFalseTotal
if exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"} 40 245 285
$$schema{'maxContains'} != 1 ? : 16 24 40
Condition100%3/3
exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}
!ll&&!rl&&r
2014440
MC/DC100%2/2
exists $$schema{"maxContains"} and $$state{"_num_contains"} > $$schema{"maxContains"}
exists $$schema{"maxContains"} $$state{"_num_contains"} > $$schema{"maxContains"}
Truth table100%3/3
A and B
A= exists $$schema{"maxContains"}B= $$state{"_num_contains"} > $$schema{"maxContains"}
ABresult
0X0
100
111
403 $valid = E($state, 'array contains fewer than %d matching item%s', $schema->{minContains}, $schema->{minContains} != 1 ? 's' : '') && $valid
404 285 ▶ if exists $schema->{minContains} and $state->{_num_contains} < $schema->{minContains};
Branch: 2 branches
BranchTrueFalseTotal
if exists $$schema{"minContains"} and $$state{"_num_contains"} < $$schema{"minContains"} 28 257 285
$$schema{'minContains'} != 1 ? : 28 0 28
Condition66%4/6
exists $$schema{"minContains"} and $$state{"_num_contains"} < $$schema{"minContains"}
!ll&&!rl&&r
1718628
E($state, 'array contains fewer than %d matching item%s', $$schema{'minContains'}, $$schema{'minContains'} != 1 ? 's' : '') && $valid
!ll&&!rl&&r
2800
MC/DC100%2/2
exists $$schema{"minContains"} and $$state{"_num_contains"} < $$schema{"minContains"}
exists $$schema{"minContains"} $$state{"_num_contains"} < $$schema{"minContains"}
MC/DC0%0/2
E($state, 'array contains fewer than %d matching item%s', $$schema{'minContains'}, $$schema{'minContains'} != 1 ? 's' : '') && $valid
E($state, 'array contains fewer than %d matching item%s', $$schema{'minContains'}, $$schema{'minContains'} != 1 ? 's' : '') $valid
Truth table100%3/3
A and B
A= exists $$schema{"minContains"}B= $$state{"_num_contains"} < $$schema{"minContains"}
ABresult
0X0
100
111
Truth table33%1/3
A && B
A= E($state, 'array contains fewer than %d matching item%s', $$schema{'minContains'}, $$schema{'minContains'} != 1 ? 's' : '')B= $valid
ABresult
0X0
100
111
405 }
406  
407 353 return $valid;
408 }
409  
410 3863 ▶sub _traverse_keyword_properties { shift->traverse_object_schemas(@_) }
Subroutine _traverse_keyword_properties: called CC=1 SCAR=0.0
411  
412 4245 ▶sub _eval_keyword_properties ($class, $data, $schema, $state) {
Subroutine _eval_keyword_properties: called CC=15 SCAR=27.1
413 4245 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 301 3944 4245
414  
415 3944 my $valid = 1;
416 3944 my @properties;
417 3944 foreach my $property (sort keys $schema->{properties}->%*) {
418 11202 ▶ if (not exists $data->{$property} and $state->{defaults}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $$data{$property} and $$state{"defaults"}) 10 11192 11202
Condition100%3/3
not exists $$data{$property} and $$state{"defaults"}
!ll&&!rl&&r
3094809810
MC/DC100%2/2
not exists $$data{$property} and $$state{"defaults"}
not exists $$data{$property} $$state{"defaults"}
Truth table100%3/3
not(A) and B
A= not exists $$data{$property}B= $$state{"defaults"}
ABresult
0X0
100
111
419 $state->{defaults}{jsonp($state->{data_path}, $property)} = $schema->{properties}{$property}{default}
420 if $valid and $state->{defaults}
421 and ref $schema->{properties}{$property} eq 'HASH'
422 10 ▶ and exists $schema->{properties}{$property}{default};
Branch: 1 branch
BranchTrueFalseTotal
if $valid and $$state{"defaults"} and ref $$schema{"properties"}{$property} eq "HASH" and exists $$schema{"properties"}{$property}{"default"} 8 2 10
Condition77%7/9
$valid and $$state{"defaults"} and ref $$schema{"properties"}{$property} eq "HASH" and exists $$schema{"properties"}{$property}{"default"}
!ll&&!rl&&r
208
$valid and $$state{"defaults"} and ref $$schema{"properties"}{$property} eq "HASH"
!ll&&!rl&&r
118
$valid and $$state{"defaults"}
!ll&&!rl&&r
109
MC/DC50%2/4
$valid and $$state{"defaults"} and ref $$schema{"properties"}{$property} eq "HASH" and exists $$schema{"properties"}{$property}{"default"}
$valid $$state{"defaults"} ref $$schema{"properties"}{$property} eq "HASH" exists $$schema{"properties"}{$property}{"default"}
Truth table60%3/5
A and B and C and D
A= $validB= $$state{"defaults"}C= ref $$schema{"properties"}{$property} eq "HASH"D= exists $$schema{"properties"}{$property}{"default"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
423  
424 10 next;
425 }
426  
427 11192 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 8098 3094 11192
428 3094 push @properties, $property;
429  
430 3094 ▶ if (is_type('boolean', $schema->{properties}{$property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'properties'}{$property})) { } 431 2663 3094
431 431 ▶ next if $schema->{properties}{$property};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"properties"}{$property} 313 118 431
432 118 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property),
433 _keyword_path_suffix => $property }, 'property not permitted');
434 }
435 else {
436 2663 ▶ if ($class->eval($data->{$property}, $schema->{properties}{$property},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($$data{$property}, $$schema{"properties"}{$property}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", jsonp($$state{"keyword_path"}, "properties", $property), "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 1914 743 2657
437 +{ %$state, data_path => jsonp($state->{data_path}, $property),
438 keyword_path => jsonp($state->{keyword_path}, 'properties', $property),
439 collect_annotations => $state->{collect_annotations} & ~1 })) {
440 1914 next;
441 }
442  
443 743 $valid = 0;
444 }
445 861 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 399 462 861
446 }
447  
448 3938 A($state, \@properties);
449 3938 ▶ return E($state, 'not all properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 819 3119 3938
450 3119 return 1;
451 }
452  
453 1091 ▶sub _traverse_keyword_patternProperties ($class, $schema, $state) {
Subroutine _traverse_keyword_patternProperties: called CC=2 SCAR=6.9
454 1091 ▶ return if not $class->traverse_object_schemas($schema, $state);
Branch: 1 branch
BranchTrueFalseTotal
unless $class->traverse_object_schemas($schema, $state) 1 1090 1091
455  
456 0+!grep !assert_pattern({ %$state, _keyword_path_suffix => $_ }, $_),
457 1090 sort keys $schema->{patternProperties}->%*;
458 }
459  
460 1017 ▶sub _eval_keyword_patternProperties ($class, $data, $schema, $state) {
Subroutine _eval_keyword_patternProperties: called CC=9 SCAR=22.0
461 1017 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 188 829 1017
462  
463 829 my $valid = 1;
464 829 my @properties;
465 829 foreach my $property_pattern (sort keys $schema->{patternProperties}->%*) {
466 # ECMA-262 restricts \d, \s, \w to ascii ranges
467 1171 foreach my $property (sort grep m/(?:$property_pattern)/a, keys %$data) {
468 743 push @properties, $property;
469 743 ▶ if (is_type('boolean', $schema->{patternProperties}{$property_pattern})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'patternProperties'}{$property_pattern})) { } 336 407 743
470 336 ▶ next if $schema->{patternProperties}{$property_pattern};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"patternProperties"}{$property_pattern} 218 118 336
471 118 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property),
472 _keyword_path_suffix => $property_pattern }, 'property not permitted');
473 }
474 else {
475 407 ▶ if ($class->eval($data->{$property}, $schema->{patternProperties}{$property_pattern},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($$data{$property}, $$schema{"patternProperties"}{$property_pattern}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", jsonp($$state{"keyword_path"}, "patternProperties", $property_pattern), "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 264 143 407
476 +{ %$state, data_path => jsonp($state->{data_path}, $property),
477 keyword_path => jsonp($state->{keyword_path}, 'patternProperties', $property_pattern),
478 collect_annotations => $state->{collect_annotations} & ~1 })) {
479 264 next;
480 }
481  
482 143 $valid = 0;
483 }
484 261 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 121 140 261
485 }
486 }
487  
488 829 A($state, [ uniqstr @properties ]);
489 829 ▶ return E($state, 'not all properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 237 592 829
490 592 return 1;
491 }
492  
493 1200 ▶sub _traverse_keyword_additionalProperties { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_additionalProperties: called CC=1 SCAR=0.0
494  
495 1160 ▶sub _eval_keyword_additionalProperties ($class, $data, $schema, $state) {
Subroutine _eval_keyword_additionalProperties: called CC=12 SCAR=24.8
496 1160 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 250 910 1160
497  
498 910 my $valid = 1;
499 910 my @properties;
500 910 foreach my $property (sort keys %$data) {
501 989 ▶ next if exists $schema->{properties} and exists $schema->{properties}{$property};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"properties"} and exists $$schema{"properties"}{$property} 223 766 989
Condition100%3/3
exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
!ll&&!rl&&r
605161223
MC/DC100%2/2
exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
exists $$schema{"properties"} exists $$schema{"properties"}{$property}
Truth table100%3/3
A and B
A= exists $$schema{"properties"}B= exists $$schema{"properties"}{$property}
ABresult
0X0
100
111
502 next if exists $schema->{patternProperties}
503 766 ▶ and any { $property =~ /(?:$_)/a } keys $schema->{patternProperties}->%*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/a;} keys %{$$schema{"patternProperties"}} 117 649 766
Condition100%3/3
exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/a;} keys %{$$schema{"patternProperties"}}
!ll&&!rl&&r
518131117
MC/DC100%2/2
exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/a;} keys %{$$schema{"patternProperties"}}
exists $$schema{"patternProperties"} CORE::any {$property =~ /(?:$_)/a;} keys %{$$schema{"patternProperties"}}
Truth table100%3/3
A and B
A= exists $$schema{"patternProperties"}B= CORE::any {$property =~ /(?:$_)/a;} keys %{$$schema{"patternProperties"}}
ABresult
0X0
100
111
504  
505 649 push @properties, $property;
506 649 ▶ if (is_type('boolean', $schema->{additionalProperties})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'additionalProperties'})) { } 283 366 649
507 283 ▶ next if $schema->{additionalProperties};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"additionalProperties"} 17 266 283
508 266 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property) },
509 'additional property not permitted');
510 }
511 else {
512 366 ▶ if ($class->eval($data->{$property}, $schema->{additionalProperties},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($$data{$property}, $$schema{"additionalProperties"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", $$state{"keyword_path"} . '/additionalProperties', "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 219 147 366
513 +{ %$state, data_path => jsonp($state->{data_path}, $property),
514 keyword_path => $state->{keyword_path}.'/additionalProperties',
515 collect_annotations => $state->{collect_annotations} & ~1 })) {
516 219 next;
517 }
518  
519 147 $valid = 0;
520 }
521 413 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 176 237 413
522 }
523  
524 910 A($state, \@properties);
525 910 ▶ return E($state, 'not all additional properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 412 498 910
526 498 return 1;
527 }
528  
529 566 ▶sub _traverse_keyword_propertyNames { shift->traverse_subschema(@_) }
Subroutine _traverse_keyword_propertyNames: called CC=1 SCAR=0.0
530  
531 505 ▶sub _eval_keyword_propertyNames ($class, $data, $schema, $state) {
Subroutine _eval_keyword_propertyNames: called CC=6 SCAR=17.9
532 505 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 168 337 505
533  
534 337 my $valid = 1;
535 337 foreach my $property (sort keys %$data) {
536 264 ▶ if ($class->eval($property, $schema->{propertyNames},
Branch: 1 branch
BranchTrueFalseTotal
if ($class->eval($property, $$schema{"propertyNames"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", $$state{"keyword_path"} . '/propertyNames', "collect_annotations", $$state{"collect_annotations"} & '18446744073709551614'})) 131 133 264
537 +{ %$state, data_path => jsonp($state->{data_path}, $property),
538 keyword_path => $state->{keyword_path}.'/propertyNames',
539 collect_annotations => $state->{collect_annotations} & ~1 })) {
540 131 next;
541 }
542  
543 133 $valid = 0;
544 133 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 70 63 133
545 }
546  
547 337 ▶ return E($state, 'not all property names are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 133 204 337
548 204 return 1;
549 }
550  
551 38 1;
552  
553 __END__
« Modern/Utilities.pm ↑ Summary Modern.pm »