| 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::Unevaluated; | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: Implementation of the JSON Schema Unevaluated 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 '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 'max'; | ||||||||||||||||||||||||||||||||||||||||
|
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 local_annotations E A abort true); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 38 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 38 | with 'JSON::Schema::Modern::Vocabulary'; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 22 | ▶ | sub vocabulary ($class) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
vocabulary: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 22 | 'https://json-schema.org/draft/2020-12/vocab/unevaluated' => 'draft2020-12'; | |||||||||||||||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | sub evaluation_order ($class) { 7 } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
evaluation_order: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # This vocabulary should be evaluated after the Applicator vocabulary. | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 62 | ▶ | sub keywords ($class, $spec_version) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
keywords: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 62 | ▶ | die 'Unevaluated not implemented in '.$spec_version if $spec_version =~ /^draft(?:[467]|2019-09)\z/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 58 | qw(unevaluatedItems unevaluatedProperties); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 587 | ▶ | sub _traverse_keyword_unevaluatedItems ($class, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_keyword_unevaluatedItems: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 587 | $class->traverse_subschema($schema, $state); | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 554 | ▶ | sub _eval_keyword_unevaluatedItems ($class, $data, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eval_keyword_unevaluatedItems: called CC=19 SCAR=29.5
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 554 | ▶ | return 1 if not is_type('array', $data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # these should never happen | ||||||||||||||||||||||||||||||||||||||||||
| 49 | die '"unevaluatedItems" keyword present, but annotation collection is disabled' | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 420 | ▶ | if not $state->{collect_annotations}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 420 | my @annotations = local_annotations($state); | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | # a relevant keyword already produced a 'true' annotation at this location | ||||||||||||||||||||||||||||||||||||||||||
| 55 | my @boolean_annotation_keywords = | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 420 | ▶ | $state->{specification_version} eq 'draft2019-09' ? qw(items additionalItems unevaluatedItems) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | : qw(prefixItems items contains unevaluatedItems); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 420 | my %bools; @bools{@boolean_annotation_keywords} = (1)x@boolean_annotation_keywords; | |||||||||||||||||||||||||||||||||||||||||
| 59 | return 1 | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 420 | ▶ | if any { $bools{$_->{keyword}} && is_type('boolean', $_->{annotation}) && $_->{annotation} } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$bools{$our $_{'keyword'}} && is_type('boolean', $our $_{'annotation'}) && $our $_{'annotation'}
$bools{$our $_{"keyword"}} and is_type("boolean", $our $_{"annotation"})
MC/DC33%1/3
$bools{$our $_{'keyword'}} && is_type('boolean', $our $_{'annotation'}) && $our $_{'annotation'}
$bools{$our $_{"keyword"}}
is_type("boolean", $our $_{"annotation"})
$our $_{'annotation'}
Truth table50%2/4
A and B && C
A= $bools{$our $_{"keyword"}}B= is_type("boolean", $our $_{"annotation"})C= $our $_{'annotation'}
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | @annotations; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # otherwise, evaluate at every instance item greater than the max of all 'prefixItems'/numeric | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # 'items' annotations that isn't in a 'contains' annotation | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 317 | ▶ | my $max_index_annotation_keyword = $state->{specification_version} eq 'draft2019-09' ? 'items' : 'prefixItems'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | my $last_index = max(-1, grep is_type('integer', $_), | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 317 | ▶ | map +($_->{keyword} eq $max_index_annotation_keyword ? $_->{annotation} : ()), @annotations); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 317 | ▶ | return 1 if $last_index == $data->$#*; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | my @contains_annotation_indexes = $state->{specification_version} eq 'draft2019-09' ? () | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 223 | ▶ | : map +($_->{keyword} eq 'contains' ? $_->{annotation}->@* : ()), @annotations; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 223 | my $valid = 1; | |||||||||||||||||||||||||||||||||||||||||
| 75 | 223 | foreach my $idx ($last_index+1 .. $data->$#*) { | |||||||||||||||||||||||||||||||||||||||||
| 76 | 312 | ▶ | next if any { $idx == $_ } @contains_annotation_indexes; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 256 | ▶ | if (is_type('boolean', $schema->{unevaluatedItems})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 194 | ▶ | next if $schema->{unevaluatedItems}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 79 | 174 | $valid = E({ %$state, data_path => $state->{data_path}.'/'.$idx }, | |||||||||||||||||||||||||||||||||||||||||
| 80 | 'additional item not permitted') | ||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 62 | ▶ | if ($class->eval($data->[$idx], $schema->{unevaluatedItems}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | +{ %$state, data_path => $state->{data_path}.'/'.$idx, | ||||||||||||||||||||||||||||||||||||||||||
| 85 | keyword_path => $state->{keyword_path}.'/unevaluatedItems', | ||||||||||||||||||||||||||||||||||||||||||
| 86 | collect_annotations => $state->{collect_annotations} & ~1 })) { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 44 | next; | |||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 18 | $valid = 0; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 192 | ▶ | last if $state->{short_circuit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 223 | A($state, true); | |||||||||||||||||||||||||||||||||||||||||
| 96 | 223 | ▶ | return E($state, 'subschema is not valid against all additional items') if not $valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 40 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 1014 | ▶ | sub _traverse_keyword_unevaluatedProperties ($class, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_traverse_keyword_unevaluatedProperties: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1014 | $class->traverse_subschema($schema, $state); | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | 953 | ▶ | sub _eval_keyword_unevaluatedProperties ($class, $data, $schema, $state) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_eval_keyword_unevaluatedProperties: called CC=11 SCAR=24.0
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 953 | ▶ | return 1 if not is_type('object', $data); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | # these should never happen | ||||||||||||||||||||||||||||||||||||||||||
| 108 | die '"unevaluatedProperties" keyword present, but annotation collection is disabled' | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 840 | ▶ | if not $state->{collect_annotations}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 840 | my @evaluated_properties = map do { | |||||||||||||||||||||||||||||||||||||||||
| 112 | 740 | my $keyword = $_->{keyword}; | |||||||||||||||||||||||||||||||||||||||||
| 113 | (grep $keyword eq $_, qw(properties additionalProperties patternProperties unevaluatedProperties)) | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 740 | ▶ | ? $_->{annotation}->@* : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | }, local_annotations($state); | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 840 | my $valid = 1; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 840 | my @properties; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 840 | foreach my $property (sort keys %$data) { | |||||||||||||||||||||||||||||||||||||||||
| 120 | 1081 | ▶ | next if any { $_ eq $property } @evaluated_properties; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 493 | push @properties, $property; | |||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | 493 | ▶ | if (is_type('boolean', $schema->{unevaluatedProperties})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 458 | ▶ | next if $schema->{unevaluatedProperties}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 325 | $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property) }, | |||||||||||||||||||||||||||||||||||||||||
| 126 | 'additional property not permitted'); | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 35 | ▶ | if ($class->eval($data->{$property}, $schema->{unevaluatedProperties}, | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | +{ %$state, data_path => jsonp($state->{data_path}, $property), | ||||||||||||||||||||||||||||||||||||||||||
| 131 | keyword_path => $state->{keyword_path}.'/unevaluatedProperties', | ||||||||||||||||||||||||||||||||||||||||||
| 132 | collect_annotations => $state->{collect_annotations} & ~1 })) { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 22 | next; | |||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | 13 | $valid = 0; | |||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||
| 138 | 338 | ▶ | last if $state->{short_circuit}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 840 | A($state, \@properties); | |||||||||||||||||||||||||||||||||||||||||
| 142 | 840 | ▶ | return E($state, 'not all additional properties are valid') if not $valid; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 524 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 38 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | __END__ | ||||||||||||||||||||||||||||||||||||||||||