blib/lib/JSON/Schema/Tiny.pm

filter: Statementstmt 99.2% 622 / 627 Branchbran 91.8% 516 / 562 Conditioncond 81.8% 379 / 463 MC/DCmcdc 65.8% 152 / 231 Subroutinesub 100% 103 / 103 Podpod 5.2% 1 / 19 totaltotal 88.4% 1773 / 2005 CC 472 SCAR 28.6
CC
472
Cov
92%
_evaluate_subschema
55.1
_eval_keyword_type
38.0
evaluate
32.7
CRAP 17.5
↑ Summary
1 # vim: set ft=perl ts=8 sts=2 sw=2 tw=100 et :
2 17 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 17 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 17 ▶use if $ENV{AUTHOR_TESTING}, strictures => version => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 package JSON::Schema::Tiny; # git description: v0.034-5-gfc6ad52
6 # vim: set ts=8 sts=2 sw=2 tw=100 et :
7 # ABSTRACT: Validate data against a schema, minimally
8 # KEYWORDS: JSON Schema data validation structure specification tiny
9  
10 17 our $VERSION = '0.035';
11  
12 17 ▶use 5.020; # for unicode_strings, signatures, postderef features
Subroutine BEGIN: called CC=1 SCAR=0.0
13 17 ▶use stable 0.031 'postderef';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 17 ▶use experimental 0.026 qw(signatures args_array_with_signatures);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 17 ▶use if $ENV{AUTHOR_TESTING}, autovivification => warn => qw(fetch store exists delete);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 17 ▶use if "$]" >= 5.022, experimental => 're_strict';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 17 ▶no if "$]" >= 5.031009, feature => 'indirect';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 17 ▶no if "$]" >= 5.033001, feature => 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
19 17 ▶no if "$]" >= 5.033006, feature => 'bareword_filehandles';
Subroutine BEGIN: called CC=1 SCAR=0.0
20 17 ▶use B;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 17 ▶use Mojo::URL;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 17 ▶use Mojo::JSON::Pointer;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 17 ▶use Carp qw(croak carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 17 ▶use Mojo::JSON (); # for JSON_XS, MOJO_NO_JSON_XS environment variables
Subroutine BEGIN: called CC=1 SCAR=0.0
25 17 ▶use Feature::Compat::Try;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 17 ▶use JSON::PP ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 17 ▶use if "$]" < 5.041010, 'List::Util' => 'any';
Subroutine BEGIN: called CC=1 SCAR=0.0
28 17 ▶use if "$]" >= 5.041010, experimental => 'keyword_any';
Subroutine BEGIN: called CC=1 SCAR=0.0
29 17 ▶use Scalar::Util 'looks_like_number';
Subroutine BEGIN: called CC=1 SCAR=0.0
30 17 ▶use builtin::compat qw(blessed created_as_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 17 ▶use if "$]" >= 5.022, POSIX => 'isinf';
Subroutine BEGIN: called CC=1 SCAR=0.0
32 17 ▶use Math::BigFloat;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 17 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 17 our @EXPORT_OK = qw(evaluate);
36  
37 17 our $BOOLEAN_RESULT = 0;
38 17 our $SHORT_CIRCUIT = 0;
39 17 our $MAX_DEPTH = 50;
40 17 our $MAX_TRAVERSAL_DEPTH; # deprecated!
41 17 our $MOJO_BOOLEANS; # deprecated; renamed to $SCALARREF_BOOLEANS
42 17 our $SCALARREF_BOOLEANS;
43 17 our $STRINGY_NUMBERS;
44 17 our $SPECIFICATION_VERSION;
45  
46 17 my %version_uris = (
47 'https://json-schema.org/draft/2020-12/schema' => 'draft2020-12',
48 'https://json-schema.org/draft/2019-09/schema' => 'draft2019-09',
49 'http://json-schema.org/draft-07/schema#' => 'draft7',
50 );
51  
52 18 ▶sub new ($class, %args) {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
53 18 bless(\%args, $class);
54 }
55  
56 12895 ▶sub evaluate {
Subroutine evaluate: called CC=26 SCAR=34.9
Pod documented
57 12895 ▶ croak 'evaluate called in void context' if not defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 12895 12895
58  
59 12895 ▶ $SCALARREF_BOOLEANS = $SCALARREF_BOOLEANS // $MOJO_BOOLEANS;
Condition66%2/3
$JSON::Schema::Tiny::SCALARREF_BOOLEANS // $JSON::Schema::Tiny::MOJO_BOOLEANS
l!l&&r!l&&!r
32012863
MC/DC50%1/2
$JSON::Schema::Tiny::SCALARREF_BOOLEANS // $JSON::Schema::Tiny::MOJO_BOOLEANS
$JSON::Schema::Tiny::SCALARREF_BOOLEANS $JSON::Schema::Tiny::MOJO_BOOLEANS
Truth table66%2/3
A // B
A= $JSON::Schema::Tiny::SCALARREF_BOOLEANSB= $JSON::Schema::Tiny::MOJO_BOOLEANS
ABresult
1X1
011
000
60 local $BOOLEAN_RESULT = $_[0]->{boolean_result} // $BOOLEAN_RESULT,
61 local $SHORT_CIRCUIT = $_[0]->{short_circuit} // $SHORT_CIRCUIT,
62 local $MAX_DEPTH = $_[0]->{max_depth} // $_[0]->{max_traversal_depth} // $MAX_TRAVERSAL_DEPTH // $MAX_DEPTH,
63 local $SCALARREF_BOOLEANS = $_[0]->{scalarref_booleans} // $SCALARREF_BOOLEANS // $_[0]->{mojo_booleans},
64 local $STRINGY_NUMBERS = $_[0]->{stringy_numbers} // $STRINGY_NUMBERS,
65 12895 ▶ local $SPECIFICATION_VERSION = $_[0]->{specification_version} // $SPECIFICATION_VERSION,
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__) 12728 167 12895
Condition56%17/30
builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__)
!ll&&!rl&&r
1521512728
$_[0]{"boolean_result"} // $JSON::Schema::Tiny::BOOLEAN_RESULT
l!l&&r!l&&!r
0127280
$_[0]{"short_circuit"} // $JSON::Schema::Tiny::SHORT_CIRCUIT
l!l&&r!l&&!r
635963690
(($_[0]{"max_depth"} // $_[0]{"max_traversal_depth"}) // $JSON::Schema::Tiny::MAX_TRAVERSAL_DEPTH) // $JSON::Schema::Tiny::MAX_DEPTH
l!l&&r!l&&!r
3127250
($_[0]{"max_depth"} // $_[0]{"max_traversal_depth"}) // $JSON::Schema::Tiny::MAX_TRAVERSAL_DEPTH
l!l&&r!l&&!r
3012725
$_[0]{"max_depth"} // $_[0]{"max_traversal_depth"}
l!l&&r!l&&!r
0312725
($_[0]{"scalarref_booleans"} // $JSON::Schema::Tiny::SCALARREF_BOOLEANS) // $_[0]{"mojo_booleans"}
l!l&&r!l&&!r
0012728
$_[0]{"scalarref_booleans"} // $JSON::Schema::Tiny::SCALARREF_BOOLEANS
l!l&&r!l&&!r
0012728
$_[0]{"stringy_numbers"} // $JSON::Schema::Tiny::STRINGY_NUMBERS
l!l&&r!l&&!r
0012728
$_[0]{"specification_version"} // $JSON::Schema::Tiny::SPECIFICATION_VERSION
l!l&&r!l&&!r
1272503
MC/DC100%2/2
builtin::blessed($_[0]) and builtin::blessed($_[0])->isa(__PACKAGE__)
builtin::blessed($_[0]) builtin::blessed($_[0])->isa(__PACKAGE__)
MC/DC0%0/2
$_[0]{"boolean_result"} // $JSON::Schema::Tiny::BOOLEAN_RESULT
$_[0]{"boolean_result"} $JSON::Schema::Tiny::BOOLEAN_RESULT
MC/DC0%0/2
$_[0]{"short_circuit"} // $JSON::Schema::Tiny::SHORT_CIRCUIT
$_[0]{"short_circuit"} $JSON::Schema::Tiny::SHORT_CIRCUIT
MC/DC0%0/4
(($_[0]{"max_depth"} // $_[0]{"max_traversal_depth"}) // $JSON::Schema::Tiny::MAX_TRAVERSAL_DEPTH) // $JSON::Schema::Tiny::MAX_DEPTH
$_[0]{"max_depth"} $_[0]{"max_traversal_depth"} $JSON::Schema::Tiny::MAX_TRAVERSAL_DEPTH $JSON::Schema::Tiny::MAX_DEPTH
MC/DC0%0/3
($_[0]{"scalarref_booleans"} // $JSON::Schema::Tiny::SCALARREF_BOOLEANS) // $_[0]{"mojo_booleans"}
$_[0]{"scalarref_booleans"} $JSON::Schema::Tiny::SCALARREF_BOOLEANS $_[0]{"mojo_booleans"}
MC/DC0%0/2
$_[0]{"stringy_numbers"} // $JSON::Schema::Tiny::STRINGY_NUMBERS
$_[0]{"stringy_numbers"} $JSON::Schema::Tiny::STRINGY_NUMBERS
MC/DC50%1/2
$_[0]{"specification_version"} // $JSON::Schema::Tiny::SPECIFICATION_VERSION
$_[0]{"specification_version"} $JSON::Schema::Tiny::SPECIFICATION_VERSION
Truth table100%3/3
A and B
A= builtin::blessed($_[0])B= builtin::blessed($_[0])->isa(__PACKAGE__)
ABresult
0X0
100
111
Truth table33%1/3
A // B
A= $_[0]{"boolean_result"}B= $JSON::Schema::Tiny::BOOLEAN_RESULT
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $_[0]{"short_circuit"}B= $JSON::Schema::Tiny::SHORT_CIRCUIT
ABresult
1X1
011
000
Truth table40%2/5
A // B // C // D
A= $_[0]{"max_depth"}B= $_[0]{"max_traversal_depth"}C= $JSON::Schema::Tiny::MAX_TRAVERSAL_DEPTHD= $JSON::Schema::Tiny::MAX_DEPTH
ABCDresult
1XXX1
01XX1
001X1
00011
00000
Truth table25%1/4
A // B // C
A= $_[0]{"scalarref_booleans"}B= $JSON::Schema::Tiny::SCALARREF_BOOLEANSC= $_[0]{"mojo_booleans"}
ABCresult
1XX1
01X1
0011
0000
Truth table33%1/3
A // B
A= $_[0]{"stringy_numbers"}B= $JSON::Schema::Tiny::STRINGY_NUMBERS
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $_[0]{"specification_version"}B= $JSON::Schema::Tiny::SPECIFICATION_VERSION
ABresult
1X1
011
000
66 shift
67 if blessed($_[0]) and blessed($_[0])->isa(__PACKAGE__);
68  
69 12895 ▶ if (defined $SPECIFICATION_VERSION) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $JSON::Schema::Tiny::SPECIFICATION_VERSION) 12749 146 12895
70 $SPECIFICATION_VERSION = 'draft'.$SPECIFICATION_VERSION
71 12749 ▶ if $SPECIFICATION_VERSION !~ /^draft/ and any { 'draft'.$SPECIFICATION_VERSION eq $_ } values %version_uris;
Branch: 1 branch
BranchTrueFalseTotal
if not $JSON::Schema::Tiny::SPECIFICATION_VERSION =~ /^draft/u and CORE::any {'draft' . $JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris 3 12746 12749
Condition100%3/3
not $JSON::Schema::Tiny::SPECIFICATION_VERSION =~ /^draft/u and CORE::any {'draft' . $JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris
!ll&&!rl&&r
1274513
MC/DC100%2/2
not $JSON::Schema::Tiny::SPECIFICATION_VERSION =~ /^draft/u and CORE::any {'draft' . $JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris
not $JSON::Schema::Tiny::SPECIFICATION_VERSION =~ /^draft/u CORE::any {'draft' . $JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris
Truth table100%3/3
not(A) and B
A= not $JSON::Schema::Tiny::SPECIFICATION_VERSION =~ /^draft/uB= CORE::any {'draft' . $JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris
ABresult
0X0
100
111
72  
73 12749 ▶ croak '$SPECIFICATION_VERSION value is invalid' if not any { $SPECIFICATION_VERSION eq $_ } values %version_uris;
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::any {$JSON::Schema::Tiny::SPECIFICATION_VERSION eq $_;} values %version_uris 1 12748 12749
74 }
75  
76 12894 ▶ croak 'insufficient arguments' if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 0 12894 12894
77 12894 my ($data, $schema) = @_;
78  
79 12894 ▶ my $state = {
Condition100%3/3
$JSON::Schema::Tiny::BOOLEAN_RESULT || $JSON::Schema::Tiny::SHORT_CIRCUIT
l!l&&r!l&&!r
1463626518
MC/DC100%2/2
$JSON::Schema::Tiny::BOOLEAN_RESULT || $JSON::Schema::Tiny::SHORT_CIRCUIT
$JSON::Schema::Tiny::BOOLEAN_RESULT $JSON::Schema::Tiny::SHORT_CIRCUIT
Truth table100%3/3
A || B
A= $JSON::Schema::Tiny::BOOLEAN_RESULTB= $JSON::Schema::Tiny::SHORT_CIRCUIT
ABresult
1X1
011
000
80 depth => 0,
81 data_path => '',
82 traversed_keyword_path => '', # the accumulated traversal path up to the last $ref traversal
83 initial_schema_uri => Mojo::URL->new, # the canonical URI as of the start or the last traversed $ref
84 keyword_path => '', # the rest of the path, since the start or the last traversed $ref
85 errors => [],
86 seen => {},
87 short_circuit => $BOOLEAN_RESULT || $SHORT_CIRCUIT,
88 root_schema => $schema, # so we can do $refs within the same document
89 specification_version => $SPECIFICATION_VERSION,
90 };
91  
92 12894 my $valid;
93 12894 try {
94 12894 $valid = _evaluate_subschema($data, $schema, $state)
95 }
96 catch ($e) {
97 1696 ▶ if (ref $e eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $e eq 'HASH') { } 1695 1 1696
98 1695 push $state->{errors}->@*, $e;
99 }
100 else {
101 1 E($state, 'EXCEPTION: '.$e);
102 }
103  
104 1696 $valid = 0;
105 }
106  
107 12894 ▶ warn 'result is false but there are no errors' if not $valid and not $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid or @{$$state{"errors"}} 0 12894 12894
Condition66%2/3
$valid or @{$$state{"errors"}}
l!l&&r!l&&!r
631865760
MC/DC0%0/2
$valid or @{$$state{"errors"}}
$valid @{$$state{"errors"}}
Truth table66%2/3
A or B
A= $validB= @{$$state{"errors"}}
ABresult
1X1
011
000
108  
109 return $BOOLEAN_RESULT ? $valid : +{
110 valid => $valid ? JSON::PP::true : JSON::PP::false,
111 12894 ▶ $valid ? () : (errors => $state->{errors}),
Branch: 3 branches
BranchTrueFalseTotal
$JSON::Schema::Tiny::BOOLEAN_RESULT ? : 14 12880 12894
$valid ? : 6314 6566 12880
$valid ? : 6314 6566 12880
112 };
113 }
114  
115 ######## NO PUBLIC INTERFACES FOLLOW THIS POINT ########
116  
117 # current spec version => { keyword => undef, or arrayref of alternatives }
118 17 my %removed_keywords = (
119 'draft7' => {
120 id => [ '$id' ],
121 },
122 'draft2019-09' => {
123 id => [ '$id' ],
124 definitions => [ '$defs' ],
125 dependencies => [ qw(dependentSchemas dependentRequired) ],
126 },
127 'draft2020-12' => {
128 id => [ '$id' ],
129 definitions => [ '$defs' ],
130 dependencies => [ qw(dependentSchemas dependentRequired) ],
131 '$recursiveAnchor' => [ '$dynamicAnchor' ],
132 '$recursiveRef' => [ '$dynamicRef' ],
133 additionalItems => [ 'items' ],
134 },
135 );
136  
137 21805 ▶sub _evaluate_subschema ($data, $schema, $state) {
Subroutine _evaluate_subschema: called CC=55 SCAR=40.1
138 21805 ▶ croak '_evaluate_subschema called in void context' if not defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
unless defined wantarray 0 21805 21805
139  
140 # do not propagate upwards changes to depth, traversed paths,
141 # but additions to errors are by reference and will be retained
142 21805 $state = { %$state };
143 21805 delete $state->@{'keyword', grep /^_/, keys %$state};
144  
145 abort($state, 'EXCEPTION: maximum evaluation depth exceeded')
146 21805 ▶ if $state->{depth}++ > $MAX_DEPTH;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"depth"}++ > $JSON::Schema::Tiny::MAX_DEPTH 3 21802 21805
147  
148 21802 my $schema_type = get_type($schema);
149 21802 ▶ return $schema || E($state, 'subschema is false') if $schema_type eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $schema_type eq "boolean" 751 21051 21802
Condition66%2/3
$schema || E($state, 'subschema is false')
l!l&&r!l&&!r
3380413
MC/DC50%1/2
$schema || E($state, 'subschema is false')
$schema E($state, 'subschema is false')
Truth table66%2/3
A || B
A= $schemaB= E($state, 'subschema is false')
ABresult
1X1
011
000
150 21051 ▶ abort($state, 'invalid schema type: %s', $schema_type) if $schema_type ne 'object';
Branch: 1 branch
BranchTrueFalseTotal
if $schema_type ne "object" 19 21032 21051
151  
152 21032 ▶ return 1 if not keys %$schema;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %$schema 359 20673 21032
153  
154 # find all schema locations in effect at this data path + canonical_uri combination
155 # if any of them are absolute prefix of this schema location, we are in a loop.
156 20673 my $canonical_uri = canonical_uri($state);
157 20673 my $schema_location = $state->{traversed_keyword_path}.$state->{keyword_path};
158 {
159 17 ▶ use autovivification qw(fetch store);
Subroutine BEGIN: called CC=1 SCAR=0.0
160 abort($state, 'EXCEPTION: infinite loop detected (same location evaluated twice)')
161 if grep substr($schema_location, 0, length) eq $_,
162 20673 ▶ keys $state->{seen}{$state->{data_path}}{$canonical_uri}->%*;
Branch: 1 branch
BranchTrueFalseTotal
if grep((substr($schema_location, 0, length $_) eq $_), keys %{$$state{"seen"}{$$state{"data_path"}}{$canonical_uri}}) 2 20671 20673
163 20671 $state->{seen}{$state->{data_path}}{$canonical_uri}{$schema_location}++;
164 }
165  
166 20671 my $valid = 1;
167 20671 ▶ my $specification_version = $state->{specification_version}//'';
Condition100%2/2
$$state{"specification_version"} // ""
l!l
20339332
MC/DC100%1/1
$$state{"specification_version"} // ""
$$state{"specification_version"}
Truth table100%2/2
A
A= $$state{"specification_version"}
Aresult
11
00
168  
169 20671 ▶ foreach my $keyword (
Branch: 15 branches
BranchTrueFalseTotal
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version eq 'draft2019-09' ? : 8020 12651 20671
!$specification_version || $specification_version eq 'draft2020-12' ? : 7876 12795 20671
!$specification_version || $specification_version eq 'draft2019-09' ? : 8020 12651 20671
!$specification_version || $specification_version eq 'draft2020-12' ? : 7876 12795 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version eq 'draft7' ? : 5439 15232 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version eq 'draft7' ? : 5439 15232 20671
!($specification_version && $specification_version =~ qr/^draft(?:7|2019-09)\z/u) ? : 7876 12795 20671
!$specification_version || $specification_version =~ qr/^draft(?:7|2019-09)\z/u ? : 13127 7544 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
!$specification_version || $specification_version ne 'draft7' ? : 15564 5107 20671
Condition100%45/45
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version eq "draft2019-09"
l!l&&r!l&&!r
332768812651
not $specification_version or $specification_version eq "draft2020-12"
l!l&&r!l&&!r
332754412795
not $specification_version or $specification_version eq "draft2019-09"
l!l&&r!l&&!r
332768812651
not $specification_version or $specification_version eq "draft2020-12"
l!l&&r!l&&!r
332754412795
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version eq "draft7"
l!l&&r!l&&!r
332510715232
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version eq "draft7"
l!l&&r!l&&!r
332510715232
$specification_version && $specification_version =~ qr/^draft(?:7|2019-09)\z/u
!ll&&!rl&&r
332754412795
not $specification_version or $specification_version =~ qr/^draft(?:7|2019-09)\z/u
l!l&&r!l&&!r
332127957544
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
not $specification_version or $specification_version ne "draft7"
l!l&&r!l&&!r
332152325107
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft2019-09"
not $specification_version $specification_version eq "draft2019-09"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft2020-12"
not $specification_version $specification_version eq "draft2020-12"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft2019-09"
not $specification_version $specification_version eq "draft2019-09"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft2020-12"
not $specification_version $specification_version eq "draft2020-12"
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft7"
not $specification_version $specification_version eq "draft7"
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version eq "draft7"
not $specification_version $specification_version eq "draft7"
MC/DC100%2/2
$specification_version && $specification_version =~ qr/^draft(?:7|2019-09)\z/u
$specification_version $specification_version =~ qr/^draft(?:7|2019-09)\z/u
MC/DC100%2/2
not $specification_version or $specification_version =~ qr/^draft(?:7|2019-09)\z/u
not $specification_version $specification_version =~ qr/^draft(?:7|2019-09)\z/u
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
MC/DC100%2/2
not $specification_version or $specification_version ne "draft7"
not $specification_version $specification_version ne "draft7"
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft2019-09"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft2020-12"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft2019-09"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft2020-12"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version eq "draft7"
ABresult
1X1
011
000
Truth table100%3/3
A && B
A= $specification_versionB= $specification_version =~ qr/^draft(?:7|2019-09)\z/u
ABresult
0X0
100
111
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version =~ qr/^draft(?:7|2019-09)\z/u
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
Truth table100%3/3
not(A) or B
A= not $specification_versionB= $specification_version ne "draft7"
ABresult
1X1
011
000
170 # CORE KEYWORDS
171 qw($id $schema),
172 !$specification_version || $specification_version ne 'draft7' ? '$anchor' : (),
173 !$specification_version || $specification_version eq 'draft2019-09' ? '$recursiveAnchor' : (),
174 !$specification_version || $specification_version eq 'draft2020-12' ? '$dynamicAnchor' : (),
175 '$ref',
176 !$specification_version || $specification_version eq 'draft2019-09' ? '$recursiveRef' : (),
177 !$specification_version || $specification_version eq 'draft2020-12' ? '$dynamicRef' : (),
178 !$specification_version || $specification_version ne 'draft7' ? '$vocabulary' : (),
179 '$comment',
180 !$specification_version || $specification_version eq 'draft7' ? 'definitions' : (),
181 !$specification_version || $specification_version ne 'draft7' ? '$defs' : (),
182 # APPLICATOR KEYWORDS
183 qw(allOf anyOf oneOf not if),
184 !$specification_version || $specification_version ne 'draft7' ? 'dependentSchemas' : (),
185 !$specification_version || $specification_version eq 'draft7' ? 'dependencies' : (),
186 !$specification_version || $specification_version !~ qr/^draft(?:7|2019-09)\z/ ? 'prefixItems' : (),
187 'items',
188 !$specification_version || $specification_version =~ qr/^draft(?:7|2019-09)\z/ ? 'additionalItems' : (),
189 qw(contains properties patternProperties additionalProperties propertyNames),
190 # UNEVALUATED KEYWORDS
191 !$specification_version || $specification_version ne 'draft7' ? qw(unevaluatedItems unevaluatedProperties) : (),
192 # VALIDATOR KEYWORDS
193 qw(type enum const
194 multipleOf maximum exclusiveMaximum minimum exclusiveMinimum
195 maxLength minLength pattern
196 maxItems minItems uniqueItems),
197 !$specification_version || $specification_version ne 'draft7' ? qw(maxContains minContains) : (),
198 qw(maxProperties minProperties required),
199 !$specification_version || $specification_version ne 'draft7' ? 'dependentRequired' : (),
200 ) {
201 726775 ▶ next if not exists $schema->{$keyword};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{$keyword} 692114 34661 726775
202  
203 # keywords adjacent to $ref (except for definitions) are not evaluated before draft2019-09
204 next if $keyword ne '$ref' and $keyword ne 'definitions'
205 34661 ▶ and exists $schema->{'$ref'} and $specification_version eq 'draft7';
Branch: 1 branch
BranchTrueFalseTotal
if $keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $specification_version eq "draft7" 15 34646 34661
Condition100%9/9
$keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $specification_version eq "draft7"
!ll&&!rl&&r
3394070615
$keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"}
!ll&&!rl&&r
183732103721
$keyword ne "\$ref" and $keyword ne "definitions"
!ll&&!rl&&r
168715032824
MC/DC100%4/4
$keyword ne "\$ref" and $keyword ne "definitions" and exists $$schema{"\$ref"} and $specification_version eq "draft7"
$keyword ne "\$ref" $keyword ne "definitions" exists $$schema{"\$ref"} $specification_version eq "draft7"
Truth table100%5/5
A and B and C and D
A= $keyword ne "\$ref"B= $keyword ne "definitions"C= exists $$schema{"\$ref"}D= $specification_version eq "draft7"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
206  
207 34646 $state->{keyword} = $keyword;
208 34646 my $error_count = $state->{errors}->@*;
209  
210 34646 my $sub = __PACKAGE__->can('_eval_keyword_'.($keyword =~ s/^\$//r));
211 34646 ▶ if (not $sub->($data, $schema, $state)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&$sub($data, $schema, $state)) 7549 24477 32026
212 warn 'result is false but there are no errors (keyword: '.$keyword.')'
213 7549 ▶ if $error_count == $state->{errors}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if $error_count == @{$$state{"errors"}} 0 7549 7549
214 7549 $valid = 0;
215 }
216  
217 32026 ▶ last if not $valid and $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if not $valid and $$state{"short_circuit"} 3680 28346 32026
Condition100%3/3
not $valid and $$state{"short_circuit"}
!ll&&!rl&&r
2369946473680
MC/DC100%2/2
not $valid and $$state{"short_circuit"}
not $valid $$state{"short_circuit"}
Truth table100%3/3
not(A) and B
A= not $validB= $$state{"short_circuit"}
ABresult
0X0
100
111
218 }
219  
220 # check for previously-supported but now removed keywords
221 18051 ▶ foreach my $keyword (sort keys(($removed_keywords{$specification_version}//{})->%*)) {
Condition100%2/2
$removed_keywords{$specification_version} // {}
l!l
17777274
MC/DC100%1/1
$removed_keywords{$specification_version} // {}
$removed_keywords{$specification_version}
Truth table100%2/2
A
A= $removed_keywords{$specification_version}
Aresult
11
00
222 63260 ▶ next if not exists $schema->{$keyword};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{$keyword} 63046 214 63260
223 214 my $message ='no-longer-supported "'.$keyword.'" keyword present (at location "'
224 .canonical_uri($state).'")';
225 214 ▶ if (my $alternates = $removed_keywords{$specification_version}->{$keyword}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $alternates = $removed_keywords{$specification_version}{$keyword}) 214 0 214
226 214 my @list = map '"'.$_.'"', @$alternates;
227 214 ▶ @list = ((map $_.',', @list[0..$#list-1]), $list[-1]) if @list > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @list > 2 0 214 214
228 214 ▶ splice(@list, -1, 0, 'or') if @list > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @list > 1 162 52 214
229 214 $message .= ': this should be rewritten as '.join(' ', @list);
230 }
231 214 carp $message;
232 }
233  
234 18051 return $valid;
235 }
236  
237 # KEYWORD IMPLEMENTATIONS
238  
239 5766 ▶sub _eval_keyword_schema ($data, $schema, $state) {
Subroutine _eval_keyword_schema: called CC=7 SCAR=19.5
240 5766 assert_keyword_type($state, $schema, 'string');
241 5766 assert_uri($state, $schema);
242  
243 return abort($state, '$schema can only appear at the schema resource root')
244 5766 ▶ if length($state->{keyword_path});
Branch: 1 branch
BranchTrueFalseTotal
if length $$state{"keyword_path"} 1 5765 5766
245  
246 5765 my $specification_version = $version_uris{$schema->{'$schema'}};
247 5765 ▶ abort($state, 'custom $schema URIs are not supported (must be one of: %s',
Branch: 1 branch
BranchTrueFalseTotal
unless $specification_version 29 5736 5765
248 join(', ', map '"'.$_.'"', keys %version_uris))
249 if not $specification_version;
250  
251 5736 ▶ abort($state, '"$schema" indicates a different version than that requested by $JSON::Schema::Tiny::SPECIFICATION_VERSION')
Branch: 1 branch
BranchTrueFalseTotal
if defined $JSON::Schema::Tiny::SPECIFICATION_VERSION and $JSON::Schema::Tiny::SPECIFICATION_VERSION ne $specification_version 1 5735 5736
Condition100%3/3
defined $JSON::Schema::Tiny::SPECIFICATION_VERSION and $JSON::Schema::Tiny::SPECIFICATION_VERSION ne $specification_version
!ll&&!rl&&r
157341
MC/DC100%2/2
defined $JSON::Schema::Tiny::SPECIFICATION_VERSION and $JSON::Schema::Tiny::SPECIFICATION_VERSION ne $specification_version
defined $JSON::Schema::Tiny::SPECIFICATION_VERSION $JSON::Schema::Tiny::SPECIFICATION_VERSION ne $specification_version
Truth table100%3/3
A and B
A= defined $JSON::Schema::Tiny::SPECIFICATION_VERSIONB= $JSON::Schema::Tiny::SPECIFICATION_VERSION ne $specification_version
ABresult
0X0
100
111
252 if defined $SPECIFICATION_VERSION and $SPECIFICATION_VERSION ne $specification_version;
253  
254 # we special-case this because the check in _eval for older drafts + $ref has already happened
255 abort($state, '$schema and $ref cannot be used together in older drafts')
256 5735 ▶ if exists $schema->{'$ref'} and $specification_version eq 'draft7';
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"\$ref"} and $specification_version eq "draft7" 1 5734 5735
Condition100%3/3
exists $$schema{"\$ref"} and $specification_version eq "draft7"
!ll&&!rl&&r
53743601
MC/DC100%2/2
exists $$schema{"\$ref"} and $specification_version eq "draft7"
exists $$schema{"\$ref"} $specification_version eq "draft7"
Truth table100%3/3
A and B
A= exists $$schema{"\$ref"}B= $specification_version eq "draft7"
ABresult
0X0
100
111
257  
258 5734 $state->{specification_version} = $specification_version;
259 }
260  
261 1699 ▶sub _eval_keyword_ref ($data, $schema, $state) {
Subroutine _eval_keyword_ref: called CC=7 SCAR=19.5
262 1699 assert_keyword_type($state, $schema, 'string');
263 1699 assert_uri_reference($state, $schema);
264  
265 1699 my $uri = Mojo::URL->new($schema->{$state->{keyword}})->to_abs($state->{initial_schema_uri});
266 abort($state, '%ss to anchors are not supported', $state->{keyword})
267 1699 ▶ if ($uri->fragment//'') !~ m{^(?:/(?:[^~]|~[01])*)?$};
Branch: 1 branch
BranchTrueFalseTotal
unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u 98 1601 1699
Condition100%2/2
$uri->fragment // ""
l!l
1311388
MC/DC100%1/1
$uri->fragment // ""
$uri->fragment
Truth table100%2/2
A
A= $uri->fragment
Aresult
11
00
268  
269 # the base of the $ref uri must be the same as the base of the root schema
270 # unfortunately this means that many uses of $ref won't work, because we don't
271 # track the locations of $ids in this or other documents.
272 abort($state, 'only same-document, same-base JSON pointers are supported in %s', $state->{keyword})
273 1601 ▶ if $uri->clone->fragment(undef) ne Mojo::URL->new($state->{root_schema}{'$id'}//'');
Branch: 1 branch
BranchTrueFalseTotal
if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "") 469 1132 1601
Condition100%2/2
$$state{"root_schema"}{"\$id"} // ""
l!l
4181183
MC/DC100%1/1
$$state{"root_schema"}{"\$id"} // ""
$$state{"root_schema"}{"\$id"}
Truth table100%2/2
A
A= $$state{"root_schema"}{"\$id"}
Aresult
11
00
274  
275 1132 ▶ my $subschema = Mojo::JSON::Pointer->new($state->{root_schema})->get($uri->fragment//'');
Condition100%2/2
$uri->fragment // ""
l!l
111715
MC/DC100%1/1
$uri->fragment // ""
$uri->fragment
Truth table100%2/2
A
A= $uri->fragment
Aresult
11
00
276 1132 ▶ abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not defined $subschema;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subschema 5 1127 1132
277  
278 return _evaluate_subschema($data, $subschema,
279 +{ %$state,
280 traversed_keyword_path => $state->{traversed_keyword_path}.$state->{keyword_path}.'/'.$state->{keyword},
281 1127 initial_schema_uri => $uri,
282 keyword_path => '',
283 });
284 }
285  
286 52 ▶sub _eval_keyword_recursiveRef ($data, $schema, $state) {
Subroutine _eval_keyword_recursiveRef: called CC=10 SCAR=29.1
287 52 assert_keyword_type($state, $schema, 'string');
288 52 assert_uri_reference($state, $schema);
289  
290 52 my $uri = Mojo::URL->new($schema->{'$recursiveRef'})->to_abs($state->{initial_schema_uri});
291 52 ▶ abort($state, '$recursiveRefs to anchors are not supported')
Branch: 1 branch
BranchTrueFalseTotal
unless ($uri->fragment // "") =~ m[^(?:/(?:[^~]|~[01])*)?$]u 0 52 52
Condition50%1/2
$uri->fragment // ""
l!l
520
MC/DC0%0/1
$uri->fragment // ""
$uri->fragment
Truth table50%1/2
A
A= $uri->fragment
Aresult
11
00
292 if ($uri->fragment//'') !~ m{^(?:/(?:[^~]|~[01])*)?$};
293  
294 # the base of the $recursiveRef uri must be the same as the base of the root schema.
295 # unfortunately this means that nearly all usecases of $recursiveRef won't work, because we don't
296 # track the locations of $ids in this or other documents.
297 abort($state, 'only same-document, same-base JSON pointers are supported in $recursiveRef')
298 52 ▶ if $uri->clone->fragment(undef) ne Mojo::URL->new($state->{root_schema}{'$id'}//'');
Branch: 1 branch
BranchTrueFalseTotal
if $uri->clone->fragment(undef) ne "Mojo::URL"->new($$state{"root_schema"}{"\$id"} // "") 44 8 52
Condition100%2/2
$$state{"root_schema"}{"\$id"} // ""
l!l
448
MC/DC100%1/1
$$state{"root_schema"}{"\$id"} // ""
$$state{"root_schema"}{"\$id"}
Truth table100%2/2
A
A= $$state{"root_schema"}{"\$id"}
Aresult
11
00
299  
300 8 my $subschema = Mojo::JSON::Pointer->new($state->{root_schema})->get($uri->fragment);
301 8 ▶ abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not defined $subschema;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subschema 0 8 8
302  
303 8 ▶ if (is_type('boolean', $subschema->{'$recursiveAnchor'}) and $subschema->{'$recursiveAnchor'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"}) 0 8 8
Condition33%1/3
is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"}
!ll&&!rl&&r
800
MC/DC0%0/2
is_type("boolean", $$subschema{"\$recursiveAnchor"}) and $$subschema{"\$recursiveAnchor"}
is_type("boolean", $$subschema{"\$recursiveAnchor"}) $$subschema{"\$recursiveAnchor"}
Truth table33%1/3
A and B
A= is_type("boolean", $$subschema{"\$recursiveAnchor"})B= $$subschema{"\$recursiveAnchor"}
ABresult
0X0
100
111
304 $uri = Mojo::URL->new($schema->{'$recursiveRef'})
305 0 ▶ ->to_abs($state->{recursive_anchor_uri} // $state->{initial_schema_uri});
Condition0%0/3
$$state{"recursive_anchor_uri"} // $$state{"initial_schema_uri"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$$state{"recursive_anchor_uri"} // $$state{"initial_schema_uri"}
$$state{"recursive_anchor_uri"} $$state{"initial_schema_uri"}
Truth table0%0/3
A // B
A= $$state{"recursive_anchor_uri"}B= $$state{"initial_schema_uri"}
ABresult
1X1
011
000
306 0 $subschema = Mojo::JSON::Pointer->new($state->{root_schema})->get($uri->fragment);
307 0 ▶ abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not defined $subschema;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $subschema 0 0 0
308 }
309  
310 return _evaluate_subschema($data, $subschema,
311 +{ %$state,
312 8 traversed_keyword_path => $state->{traversed_keyword_path}.$state->{keyword_path}.'/$recursiveRef',
313 initial_schema_uri => $uri,
314 keyword_path => '',
315 });
316 }
317  
318 12 ▶sub _eval_keyword_dynamicRef { goto \&_eval_keyword_ref }
Subroutine _eval_keyword_dynamicRef: called CC=1 SCAR=0.0
319  
320 662 ▶sub _eval_keyword_id ($data, $schema, $state) {
Subroutine _eval_keyword_id: called CC=9 SCAR=22.0
321 662 assert_keyword_type($state, $schema, 'string');
322 662 assert_uri_reference($state, $schema);
323  
324 662 my $uri = Mojo::URL->new($schema->{'$id'});
325  
326 662 ▶ if (($state->{specification_version}//'') eq 'draft7') {
Branch: 1 branch
BranchTrueFalseTotal
if (($$state{'specification_version'} // '') eq 'draft7') { } 133 529 662
Condition100%2/2
$$state{"specification_version"} // ""
l!l
6539
MC/DC100%1/1
$$state{"specification_version"} // ""
$$state{"specification_version"}
Truth table100%2/2
A
A= $$state{"specification_version"}
Aresult
11
00
327 133 ▶ if (length($uri->fragment)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $uri->fragment) 3 130 133
328 3 ▶ abort($state, '$id cannot change the base uri at the same time as declaring an anchor')
Branch: 1 branch
BranchTrueFalseTotal
if length $uri->clone->fragment(undef) 0 3 3
329 if length($uri->clone->fragment(undef));
330  
331 3 ▶ abort($state, '$id value does not match required syntax')
Branch: 1 branch
BranchTrueFalseTotal
unless $uri->fragment =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/u 1 2 3
332 if $uri->fragment !~ m/^[A-Za-z][A-Za-z0-9_:.-]*\z/;
333  
334 2 return 1;
335 }
336 }
337 else {
338 529 ▶ abort($state, '$id value "%s" cannot have a non-empty fragment', $uri) if length $uri->fragment;
Branch: 1 branch
BranchTrueFalseTotal
if length $uri->fragment 2 527 529
339 }
340  
341 657 $uri->fragment(undef);
342 657 ▶ return E($state, '$id cannot be empty') if not length $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless length $uri 24 633 657
343  
344 633 ▶ $state->{initial_schema_uri} = $uri->is_abs ? $uri : $uri->to_abs($state->{initial_schema_uri});
Branch: 1 branch
BranchTrueFalseTotal
$uri->is_abs ? : 540 93 633
345 633 $state->{traversed_keyword_path} = $state->{traversed_keyword_path}.$state->{keyword_path};
346 633 $state->{keyword_path} = '';
347  
348 633 return 1;
349 }
350  
351 12 ▶sub _eval_keyword_anchor ($data, $schema, $state) {
Subroutine _eval_keyword_anchor: called CC=9 SCAR=28.2
352 12 assert_keyword_type($state, $schema, 'string');
353  
354 return 1 if
355 (!$state->{specification_version} or $state->{specification_version} eq 'draft2019-09')
356 and ($schema->{'$anchor'}//'') =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/
357 or
358 (!$state->{specification_version} or $state->{specification_version} eq 'draft2020-12')
359 12 ▶ and ($schema->{'$anchor'}//'') =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
if !$$state{"specification_version"} || $$state{"specification_version"} eq "draft2019-09" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/u or !$$state{"specification_version"} || $$state{"specification_version"} eq "draft2020-12" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/u 12 0 12
Condition52%10/19
!$$state{"specification_version"} || $$state{"specification_version"} eq "draft2019-09" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/u or !$$state{"specification_version"} || $$state{"specification_version"} eq "draft2020-12" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/u
l!l&&r!l&&!r
660
!$$state{"specification_version"} || $$state{"specification_version"} eq "draft2019-09" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/u
!ll&&!rl&&r
606
not $$state{"specification_version"} or $$state{"specification_version"} eq "draft2019-09"
l!l&&r!l&&!r
066
$$schema{"\$anchor"} // ""
l!l
60
!$$state{"specification_version"} || $$state{"specification_version"} eq "draft2020-12" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/u
!ll&&!rl&&r
006
not $$state{"specification_version"} or $$state{"specification_version"} eq "draft2020-12"
l!l&&r!l&&!r
060
$$schema{"\$anchor"} // ""
l!l
60
MC/DC0%0/6
!$$state{"specification_version"} || $$state{"specification_version"} eq "draft2019-09" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z][A-Za-z0-9_:.-]*\z/u or !$$state{"specification_version"} || $$state{"specification_version"} eq "draft2020-12" and ($$schema{"\$anchor"} // "") =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/u
not $$state{"specification_version"} $$state{"specification_version"} eq "draft2019-09" $$schema{"\$anchor"} not $$state{"specification_version"} $$state{"specification_version"} eq "draft2020-12" $$schema{"\$anchor"}
Truth table11%2/17
not(A) or B and C or not(D) or E and F
A= not $$state{"specification_version"}B= $$state{"specification_version"} eq "draft2019-09"C= $$schema{"\$anchor"}D= not $$state{"specification_version"}E= $$state{"specification_version"} eq "draft2020-12"F= $$schema{"\$anchor"}
ABCDEFresult
1X1XXX1
011XXX1
00X1X11
00X0111
1X01X11
1X00111
0101X11
0100111
00X00X0
00X1X00
00X0100
1X000X0
1X01X00
1X00100
01000X0
0101X00
0100100
360  
361 0 abort($state, '$anchor value does not match required syntax');
362 }
363  
364 92 ▶sub _eval_keyword_recursiveAnchor ($data, $schema, $state) {
Subroutine _eval_keyword_recursiveAnchor: called CC=4 SCAR=13.9
365 92 assert_keyword_type($state, $schema, 'boolean');
366 92 ▶ return 1 if not $schema->{'$recursiveAnchor'} or exists $state->{recursive_anchor_uri};
Branch: 1 branch
BranchTrueFalseTotal
if not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"} 41 51 92
Condition100%3/3
not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"}
l!l&&r!l&&!r
281351
MC/DC100%2/2
not $$schema{"\$recursiveAnchor"} or exists $$state{"recursive_anchor_uri"}
not $$schema{"\$recursiveAnchor"} exists $$state{"recursive_anchor_uri"}
Truth table100%3/3
not(A) or B
A= not $$schema{"\$recursiveAnchor"}B= exists $$state{"recursive_anchor_uri"}
ABresult
1X1
011
000
367  
368 # this is required because the location is used as the base URI for future resolution
369 # of $recursiveRef, and the fragment would be disregarded in the base
370 abort($state, '"$recursiveAnchor" keyword used without "$id"')
371 51 ▶ if not exists $schema->{'$id'};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{"\$id"} 0 51 51
372  
373 # record the canonical location of the current position, to be used against future resolution
374 # of a $recursiveRef uri -- as if it was the current location when we encounter a $ref.
375 51 $state->{recursive_anchor_uri} = canonical_uri($state);
376  
377 51 return 1;
378 }
379  
380 10 ▶sub _eval_keyword_dynamicAnchor ($data, $schema, $state) {
Subroutine _eval_keyword_dynamicAnchor: called CC=3 SCAR=11.7
381 10 ▶ return if not assert_keyword_type($state, $schema, 'string');
Branch: 1 branch
BranchTrueFalseTotal
unless assert_keyword_type($state, $schema, "string") 0 10 10
382  
383 abort($state, '$dynamicAnchor value does not match required syntax')
384 10 ▶ if $schema->{'$dynamicAnchor'} !~ /^[A-Za-z_][A-Za-z0-9._-]*\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$schema{"\$dynamicAnchor"} =~ /^[A-Za-z_][A-Za-z0-9._-]*\z/u 0 10 10
385 10 return 1;
386 }
387  
388 4 ▶sub _eval_keyword_vocabulary ($data, $schema, $state) {
Subroutine _eval_keyword_vocabulary: called CC=5 SCAR=16.7
389 4 assert_keyword_type($state, $schema, 'object');
390  
391 4 foreach my $uri (sort keys $schema->{'$vocabulary'}->%*) {
392 abort({ %$state, _keyword_path_suffix => $uri }, '$vocabulary value at "%s" is not a boolean', $uri)
393 4 ▶ if not is_type('boolean', $schema->{'$vocabulary'}{$uri});
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("boolean", $$schema{"\$vocabulary"}{$uri}) 0 4 4
394  
395 4 assert_uri($state, undef, $uri);
396 }
397  
398 abort($state, '$vocabulary can only appear at the schema resource root')
399 4 ▶ if length($state->{keyword_path});
Branch: 1 branch
BranchTrueFalseTotal
if length $$state{"keyword_path"} 0 4 4
400  
401 abort($state, '$vocabulary can only appear at the document root')
402 4 ▶ if length($state->{traversed_keyword_path}.$state->{keyword_path});
Branch: 1 branch
BranchTrueFalseTotal
if length $$state{"traversed_keyword_path"} . $$state{"keyword_path"} 0 4 4
403  
404 4 return 1;
405 }
406  
407 300 ▶sub _eval_keyword_comment ($data, $schema, $state) {
Subroutine _eval_keyword_comment: called CC=1 SCAR=0.0
408 300 assert_keyword_type($state, $schema, 'string');
409 300 return 1;
410 }
411  
412 150 ▶sub _eval_keyword_definitions { goto \&_eval_keyword_defs }
Subroutine _eval_keyword_definitions: called CC=1 SCAR=0.0
413  
414 677 ▶sub _eval_keyword_defs ($data, $schema, $state) {
Subroutine _eval_keyword_defs: called CC=1 SCAR=0.0
415 677 assert_keyword_type($state, $schema, 'object');
416 675 return 1;
417 }
418  
419 3748 ▶sub _eval_keyword_type ($data, $schema, $state) {
Subroutine _eval_keyword_type: called CC=35 SCAR=36.4
420 3748 ▶ if (ref $schema->{type} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$schema{'type'} eq 'ARRAY') { } 163 3585 3748
421 163 ▶ abort($state, 'type array is empty') if not $schema->{type}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$schema{"type"}} 0 163 163
422 163 foreach my $type ($schema->{type}->@*) {
423 abort($state, 'unrecognized type "%s"', $type//'<null>')
424 344 ▶ if not any { ($type//'') eq $_ } qw(null boolean object array string number integer);
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::any {($type // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer" 6 338 344
Condition75%3/4
$type // ""
l!l
135542
$type // "<null>"
l!l
06
MC/DC100%1/1
$type // ""
$type
MC/DC0%0/1
$type // "<null>"
$type
Truth table100%2/2
A
A= $type
Aresult
11
00
Truth table50%1/2
A
A= $type
Aresult
11
00
425 }
426 157 ▶ abort($state, '"type" values are not unique') if not is_elements_unique($schema->{type});
Branch: 1 branch
BranchTrueFalseTotal
unless is_elements_unique($$schema{"type"}) 0 157 157
427  
428 157 my $type = get_type($data);
429 return 1 if any {
430 292 ▶ $type eq $_ or ($_ eq 'number' and $type eq 'integer')
Condition84%28/33
$type eq $_ || $_ eq 'number' && $type eq 'integer' || $type eq 'string' && $JSON::Schema::Tiny::STRINGY_NUMBERS && &looks_like_number($data) && ($_ eq 'number' || $_ eq 'integer' && $data == int $data) || $_ eq 'boolean' && $JSON::Schema::Tiny::SCALARREF_BOOLEANS && $type eq 'reference to SCALAR'
l!l&&r!l&&!r
632227
$type eq $_ or $_ eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $_ eq "number" || $_ eq "integer" && $data == int $data
l!l&&r!l&&!r
621229
$type eq $_ or $_ eq "number" and $type eq "integer"
l!l&&r!l&&!r
620230
$_ eq "number" and $type eq "integer"
!ll&&!rl&&r
22730
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $_ eq "number" || $_ eq "integer" && $data == int $data
!ll&&!rl&&r
22631
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data)
!ll&&!rl&&r
22604
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS
!ll&&!rl&&r
158684
$_ eq "number" or $_ eq "integer" and $data == int $data
l!l&&r!l&&!r
103
$_ eq "integer" and $data == int $data
!ll&&!rl&&r
210
$_ eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
!ll&&!rl&&r
22072
$_ eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS
!ll&&!rl&&r
205159
MC/DC66%8/12
$type eq $_ || $_ eq 'number' && $type eq 'integer' || $type eq 'string' && $JSON::Schema::Tiny::STRINGY_NUMBERS && &looks_like_number($data) && ($_ eq 'number' || $_ eq 'integer' && $data == int $data) || $_ eq 'boolean' && $JSON::Schema::Tiny::SCALARREF_BOOLEANS && $type eq 'reference to SCALAR'
$type eq $_ $_ eq "number" $type eq "integer" $type eq "string" $JSON::Schema::Tiny::STRINGY_NUMBERS &looks_like_number($data) $_ eq "number" $_ eq "integer" $data == int $data $_ eq "boolean" $JSON::Schema::Tiny::SCALARREF_BOOLEANS $type eq "reference to SCALAR"
Truth table28%13/46
A or B and C or D and E and F and G or H and I || J and K and L
A= $type eq $_B= $_ eq "number"C= $type eq "integer"D= $type eq "string"E= $JSON::Schema::Tiny::STRINGY_NUMBERSF= &looks_like_number($data)G= $_ eq "number"H= $_ eq "integer"I= $data == int $dataJ= $_ eq "boolean"K= $JSON::Schema::Tiny::SCALARREF_BOOLEANSL= $type eq "reference to SCALAR"
ABCDEFGHIJKLresult
1XXXXXXXXXXX1
011XXXXXXXXX1
00X1111XXXXX1
00X111011XXX1
0101111XXXXX1
010111011XXX1
00X0XXXXX1111
00X10XXXX1111
00X110XXX1111
00X11100X1111
00X1110101111
0100XXXXX1111
01010XXXX1111
010110XXX1111
01011100X1111
0101110101111
00X0XXXXX0XX0
00X0XXXXX10X0
00X0XXXXX1100
00X10XXXX0XX0
00X10XXXX10X0
00X10XXXX1100
00X110XXX0XX0
00X110XXX10X0
00X110XXX1100
00X11100X0XX0
00X11100X10X0
00X11100X1100
00X1110100XX0
00X11101010X0
00X1110101100
0100XXXXX0XX0
0100XXXXX10X0
0100XXXXX1100
01010XXXX0XX0
01010XXXX10X0
01010XXXX1100
010110XXX0XX0
010110XXX10X0
010110XXX1100
01011100X0XX0
01011100X10X0
01011100X1100
0101110100XX0
01011101010X0
0101110101100
431 or ($type eq 'string' and $STRINGY_NUMBERS and looks_like_number($data)
432 and ($_ eq 'number' or ($_ eq 'integer' and $data == int($data))))
433 or ($_ eq 'boolean' and $SCALARREF_BOOLEANS and $type eq 'reference to SCALAR')
434 157 ▶ } $schema->{type}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {$type eq $_ or $_ eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $_ eq "number" || $_ eq "integer" && $data == int $data or $_ eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR";} @{$$schema{"type"}} 65 92 157
435 92 return E($state, 'got %s, not one of %s', $type, join(', ', $schema->{type}->@*));
436 }
437 else {
438 3585 assert_keyword_type($state, $schema, 'string');
439 abort($state, 'unrecognized type "%s"', $schema->{type}//'<null>')
440 3579 ▶ if not any { ($schema->{type}//'') eq $_ } qw(null boolean object array string number integer);
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::any {($$schema{"type"} // "") eq $_;} "null", "boolean", "object", "array", "string", "number", "integer" 2 3577 3579
Condition50%2/4
$$schema{"type"} // ""
l!l
167180
$$schema{"type"} // "<null>"
l!l
20
MC/DC0%0/1
$$schema{"type"} // ""
$$schema{"type"}
MC/DC0%0/1
$$schema{"type"} // "<null>"
$$schema{"type"}
Truth table50%1/2
A
A= $$schema{"type"}
Aresult
11
00
Truth table50%1/2
A
A= $$schema{"type"}
Aresult
11
00
441  
442 3577 my $type = get_type($data);
443 return 1 if $type eq $schema->{type} or ($schema->{type} eq 'number' and $type eq 'integer')
444 or ($type eq 'string' and $STRINGY_NUMBERS and looks_like_number($data)
445 and ($schema->{type} eq 'number' or ($schema->{type} eq 'integer' and $data == int($data))))
446 3577 ▶ or ($schema->{type} eq 'boolean' and $SCALARREF_BOOLEANS and $type eq 'reference to SCALAR');
Branch: 1 branch
BranchTrueFalseTotal
if $type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $$schema{"type"} eq "number" || $$schema{"type"} eq "integer" && $data == int $data or $$schema{"type"} eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR" 2592 985 3577
Condition87%29/33
$type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $$schema{"type"} eq "number" || $$schema{"type"} eq "integer" && $data == int $data or $$schema{"type"} eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
l!l&&r!l&&!r
25902985
$type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $$schema{"type"} eq "number" || $$schema{"type"} eq "integer" && $data == int $data
l!l&&r!l&&!r
25891987
$type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer"
l!l&&r!l&&!r
2373216988
$$schema{"type"} eq "number" and $type eq "integer"
!ll&&!rl&&r
836152216
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $$schema{"type"} eq "number" || $$schema{"type"} eq "integer" && $data == int $data
!ll&&!rl&&r
98611
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data)
!ll&&!rl&&r
98602
$type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS
!ll&&!rl&&r
6343522
$$schema{"type"} eq "number" or $$schema{"type"} eq "integer" and $data == int $data
l!l&&r!l&&!r
101
$$schema{"type"} eq "integer" and $data == int $data
!ll&&!rl&&r
010
$$schema{"type"} eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
!ll&&!rl&&r
97872
$$schema{"type"} eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS
!ll&&!rl&&r
8721069
MC/DC75%9/12
$type eq $$schema{"type"} or $$schema{"type"} eq "number" and $type eq "integer" or $type eq "string" and $JSON::Schema::Tiny::STRINGY_NUMBERS and &looks_like_number($data) and $$schema{"type"} eq "number" || $$schema{"type"} eq "integer" && $data == int $data or $$schema{"type"} eq "boolean" and $JSON::Schema::Tiny::SCALARREF_BOOLEANS and $type eq "reference to SCALAR"
$type eq $$schema{"type"} $$schema{"type"} eq "number" $type eq "integer" $type eq "string" $JSON::Schema::Tiny::STRINGY_NUMBERS &looks_like_number($data) $$schema{"type"} eq "number" $$schema{"type"} eq "integer" $data == int $data $$schema{"type"} eq "boolean" $JSON::Schema::Tiny::SCALARREF_BOOLEANS $type eq "reference to SCALAR"
Truth table28%13/46
A or B and C or D and E and F and G or H and I or J and K and L
A= $type eq $$schema{"type"}B= $$schema{"type"} eq "number"C= $type eq "integer"D= $type eq "string"E= $JSON::Schema::Tiny::STRINGY_NUMBERSF= &looks_like_number($data)G= $$schema{"type"} eq "number"H= $$schema{"type"} eq "integer"I= $data == int $dataJ= $$schema{"type"} eq "boolean"K= $JSON::Schema::Tiny::SCALARREF_BOOLEANSL= $type eq "reference to SCALAR"
ABCDEFGHIJKLresult
1XXXXXXXXXXX1
011XXXXXXXXX1
00X1111XXXXX1
00X111011XXX1
0101111XXXXX1
010111011XXX1
00X0XXXXX1111
00X10XXXX1111
00X110XXX1111
00X11100X1111
00X1110101111
0100XXXXX1111
01010XXXX1111
010110XXX1111
01011100X1111
0101110101111
00X0XXXXX0XX0
00X0XXXXX10X0
00X0XXXXX1100
00X10XXXX0XX0
00X10XXXX10X0
00X10XXXX1100
00X110XXX0XX0
00X110XXX10X0
00X110XXX1100
00X11100X0XX0
00X11100X10X0
00X11100X1100
00X1110100XX0
00X11101010X0
00X1110101100
0100XXXXX0XX0
0100XXXXX10X0
0100XXXXX1100
01010XXXX0XX0
01010XXXX10X0
01010XXXX1100
010110XXX0XX0
010110XXX10X0
010110XXX1100
01011100X0XX0
01011100X10X0
01011100X1100
0101110100XX0
01011101010X0
0101110101100
447 985 return E($state, 'got %s, not %s', $type, $schema->{type});
448 }
449 }
450  
451 519 ▶sub _eval_keyword_enum ($data, $schema, $state) {
Subroutine _eval_keyword_enum: called CC=3 SCAR=11.0
452 519 assert_keyword_type($state, $schema, 'array');
453  
454 519 my @s; my $idx = 0;
455 519 ▶ return 1 if any { is_equal($data, $_, $s[$idx++] = {}) } $schema->{enum}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {is_equal($data, $_, $s[$idx++] = {});} @{$$schema{"enum"}} 270 249 519
456  
457 return E($state, 'value does not match'
458 249 ▶ .(!(grep $_->{path}, @s) ? ''
Branch: 1 branch
BranchTrueFalseTotal
!grep($$_{'path'}, @s) ? : 206 43 249
459 : ' ('.join('; ', map "from enum $_ at '$s[$_]->{path}': $s[$_]->{error}", 0..$#s).')'));
460 }
461  
462 1059 ▶sub _eval_keyword_const ($data, $schema, $state) {
Subroutine _eval_keyword_const: called CC=3 SCAR=11.0
463 1059 ▶ return 1 if is_equal($data, $schema->{const}, my $s = {});
Branch: 1 branch
BranchTrueFalseTotal
if is_equal($data, $$schema{"const"}, scalar(my $s = {})) 580 479 1059
464 479 ▶ return E($state, 'value does not match'.($s->{path} ? " (at '$s->{path}': $s->{error})" : ''));
Branch: 1 branch
BranchTrueFalseTotal
$$s{'path'} ? : 55 424 479
465 }
466  
467 862 ▶sub _eval_keyword_multipleOf ($data, $schema, $state) {
Subroutine _eval_keyword_multipleOf: called CC=18 SCAR=29.4
468 862 assert_keyword_type($state, $schema, 'number');
469 860 ▶ abort($state, 'multipleOf value is not a positive number') if $schema->{multipleOf} <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"multipleOf"} <= 0 0 860 860
470  
471 return 1 if not is_type('number', $data)
472 and not ($STRINGY_NUMBERS and is_type('string', $data) and looks_like_number($data)
473 860 ▶ and do { $data = 0+$data; 1 });
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) and do { $data = 0 + $data; 1 } 190 670 860
Condition75%9/12
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) and do { $data = 0 + $data; 1 }
l!l&&r!l&&!r
6682190
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) and do { $data = 0 + $data; 1 }
!ll&&!rl&&r
19002
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
!ll&&!rl&&r
19002
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data)
!ll&&!rl&&r
19002
MC/DC40%2/5
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) and do { $data = 0 + $data; 1 }
is_type("number", $data) $JSON::Schema::Tiny::STRINGY_NUMBERS is_type("string", $data) &looks_like_number($data) do { $data = 0 + $data; 1 }
Truth table50%3/6
A or B and C and D and E
A= is_type("number", $data)B= $JSON::Schema::Tiny::STRINGY_NUMBERSC= is_type("string", $data)D= &looks_like_number($data)E= do { $data = 0 + $data; 1 }
ABCDEresult
1XXXX1
011111
00XXX0
010XX0
0110X0
011100
474  
475 # if either value is a float, use the bignum library for the calculation
476 670 ▶ if (is_bignum($data) or is_bignum($schema->{multipleOf})
Branch: 1 branch
BranchTrueFalseTotal
if (is_bignum($data) or is_bignum($$schema{'multipleOf'}) or get_type($data) eq 'number' or get_type($$schema{'multipleOf'}) eq 'number') { } 82 588 670
Condition88%8/9
is_bignum($data) or is_bignum($$schema{"multipleOf"}) or get_type($data) eq "number" or get_type($$schema{"multipleOf"}) eq "number"
l!l&&r!l&&!r
784588
is_bignum($data) or is_bignum($$schema{"multipleOf"}) or get_type($data) eq "number"
l!l&&r!l&&!r
780592
is_bignum($data) or is_bignum($$schema{"multipleOf"})
l!l&&r!l&&!r
6018592
MC/DC75%3/4
is_bignum($data) or is_bignum($$schema{"multipleOf"}) or get_type($data) eq "number" or get_type($$schema{"multipleOf"}) eq "number"
is_bignum($data) is_bignum($$schema{"multipleOf"}) get_type($data) eq "number" get_type($$schema{"multipleOf"}) eq "number"
Truth table80%4/5
A or B or C or D
A= is_bignum($data)B= is_bignum($$schema{"multipleOf"})C= get_type($data) eq "number"D= get_type($$schema{"multipleOf"}) eq "number"
ABCDresult
1XXX1
01XX1
001X1
00011
00000
477 or get_type($data) eq 'number' or get_type($schema->{multipleOf}) eq 'number') {
478 82 ▶ $data = is_bignum($data) ? $data->copy : Math::BigFloat->new($data);
Branch: 1 branch
BranchTrueFalseTotal
is_bignum($data) ? : 60 22 82
479 82 ▶ my $divisor = is_bignum($schema->{multipleOf}) ? $schema->{multipleOf} : Math::BigFloat->new($schema->{multipleOf});
Branch: 1 branch
BranchTrueFalseTotal
is_bignum($$schema{'multipleOf'}) ? : 66 16 82
480 82 my ($quotient, $remainder) = $data->bdiv($divisor);
481 82 ▶ return E($state, 'overflow while calculating quotient') if $quotient->is_inf;
Branch: 1 branch
BranchTrueFalseTotal
if $quotient->is_inf 0 82 82
482 82 ▶ return 1 if $remainder == 0;
Branch: 1 branch
BranchTrueFalseTotal
if $remainder == 0 48 34 82
483 }
484 else {
485 588 my $quotient = $data / $schema->{multipleOf};
486 588 ▶ return E($state, 'overflow while calculating quotient')
Branch: 2 branches
BranchTrueFalseTotal
if "$]" >= "5.022" ? isinf($quotient) : $quotient =~ /^-?Inf\z/iu 0 588 588
"$]" >= 5.022 ? : 588 0 588
487 if "$]" >= 5.022 ? isinf($quotient) : $quotient =~ /^-?Inf\z/i;
488 588 ▶ return 1 if int($quotient) == $quotient;
Branch: 1 branch
BranchTrueFalseTotal
if int $quotient == $quotient 313 275 588
489 }
490  
491 309 return E($state, 'value is not a multiple of %s', sprintf_num($schema->{multipleOf}));
492 }
493  
494 585 ▶sub _eval_keyword_maximum ($data, $schema, $state) {
Subroutine _eval_keyword_maximum: called CC=6 SCAR=18.0
495 585 assert_keyword_type($state, $schema, 'number');
496 583 ▶ return 1 if not is_type('number', $data)
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) 195 388 583
Condition77%7/9
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
l!l&&r!l&&!r
3871195
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
!ll&&!rl&&r
19501
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data)
!ll&&!rl&&r
19501
MC/DC50%2/4
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
is_type("number", $data) $JSON::Schema::Tiny::STRINGY_NUMBERS is_type("string", $data) &looks_like_number($data)
Truth table60%3/5
A or B and C and D
A= is_type("number", $data)B= $JSON::Schema::Tiny::STRINGY_NUMBERSC= is_type("string", $data)D= &looks_like_number($data)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
497 and not ($STRINGY_NUMBERS and is_type('string', $data) and looks_like_number($data));
498 388 ▶ return 1 if 0+$data <= $schema->{maximum};
Branch: 1 branch
BranchTrueFalseTotal
if 0 + $data <= $$schema{"maximum"} 216 172 388
499 172 return E($state, 'value is larger than %s', sprintf_num($schema->{maximum}));
500 }
501  
502 483 ▶sub _eval_keyword_exclusiveMaximum ($data, $schema, $state) {
Subroutine _eval_keyword_exclusiveMaximum: called CC=6 SCAR=18.0
503 483 assert_keyword_type($state, $schema, 'number');
504 481 ▶ return 1 if not is_type('number', $data)
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) 189 292 481
Condition77%7/9
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
l!l&&r!l&&!r
2911189
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
!ll&&!rl&&r
18901
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data)
!ll&&!rl&&r
18901
MC/DC50%2/4
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
is_type("number", $data) $JSON::Schema::Tiny::STRINGY_NUMBERS is_type("string", $data) &looks_like_number($data)
Truth table60%3/5
A or B and C and D
A= is_type("number", $data)B= $JSON::Schema::Tiny::STRINGY_NUMBERSC= is_type("string", $data)D= &looks_like_number($data)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
505 and not ($STRINGY_NUMBERS and is_type('string', $data) and looks_like_number($data));
506 292 ▶ return 1 if 0+$data < $schema->{exclusiveMaximum};
Branch: 1 branch
BranchTrueFalseTotal
if 0 + $data < $$schema{"exclusiveMaximum"} 138 154 292
507 154 return E($state, 'value is equal to or larger than %s', sprintf_num($schema->{exclusiveMaximum}));
508 }
509  
510 713 ▶sub _eval_keyword_minimum ($data, $schema, $state) {
Subroutine _eval_keyword_minimum: called CC=6 SCAR=18.0
511 713 assert_keyword_type($state, $schema, 'number');
512 711 ▶ return 1 if not is_type('number', $data)
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) 204 507 711
Condition77%7/9
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
l!l&&r!l&&!r
5061204
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
!ll&&!rl&&r
20401
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data)
!ll&&!rl&&r
20401
MC/DC50%2/4
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
is_type("number", $data) $JSON::Schema::Tiny::STRINGY_NUMBERS is_type("string", $data) &looks_like_number($data)
Truth table60%3/5
A or B and C and D
A= is_type("number", $data)B= $JSON::Schema::Tiny::STRINGY_NUMBERSC= is_type("string", $data)D= &looks_like_number($data)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
513 and not ($STRINGY_NUMBERS and is_type('string', $data) and looks_like_number($data));
514 507 ▶ return 1 if 0+$data >= $schema->{minimum};
Branch: 1 branch
BranchTrueFalseTotal
if 0 + $data >= $$schema{"minimum"} 265 242 507
515 242 return E($state, 'value is smaller than %s', sprintf_num($schema->{minimum}));
516 }
517  
518 423 ▶sub _eval_keyword_exclusiveMinimum ($data, $schema, $state) {
Subroutine _eval_keyword_exclusiveMinimum: called CC=6 SCAR=18.0
519 423 assert_keyword_type($state, $schema, 'number');
520 421 ▶ return 1 if not is_type('number', $data)
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data) 189 232 421
Condition77%7/9
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
l!l&&r!l&&!r
2311189
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
!ll&&!rl&&r
18901
$JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data)
!ll&&!rl&&r
18901
MC/DC50%2/4
is_type("number", $data) or $JSON::Schema::Tiny::STRINGY_NUMBERS and is_type("string", $data) and &looks_like_number($data)
is_type("number", $data) $JSON::Schema::Tiny::STRINGY_NUMBERS is_type("string", $data) &looks_like_number($data)
Truth table60%3/5
A or B and C and D
A= is_type("number", $data)B= $JSON::Schema::Tiny::STRINGY_NUMBERSC= is_type("string", $data)D= &looks_like_number($data)
ABCDresult
1XXX1
01111
00XX0
010X0
01100
521 and not ($STRINGY_NUMBERS and is_type('string', $data) and looks_like_number($data));
522 232 ▶ return 1 if 0+$data > $schema->{exclusiveMinimum};
Branch: 1 branch
BranchTrueFalseTotal
if 0 + $data > $$schema{"exclusiveMinimum"} 108 124 232
523 124 return E($state, 'value is equal to or smaller than %s', sprintf_num($schema->{exclusiveMinimum}));
524 }
525  
526 561 ▶sub _eval_keyword_maxLength ($data, $schema, $state) {
Subroutine _eval_keyword_maxLength: called CC=3 SCAR=11.0
527 561 assert_non_negative_integer($schema, $state);
528  
529 561 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 209 352 561
530 352 ▶ return 1 if length($data) <= $schema->{maxLength};
Branch: 1 branch
BranchTrueFalseTotal
if length $data <= $$schema{"maxLength"} 190 162 352
531 162 return E($state, 'length is greater than %d', $schema->{maxLength});
532 }
533  
534 512 ▶sub _eval_keyword_minLength ($data, $schema, $state) {
Subroutine _eval_keyword_minLength: called CC=3 SCAR=11.0
535 512 assert_non_negative_integer($schema, $state);
536  
537 512 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 210 302 512
538 302 ▶ return 1 if length($data) >= $schema->{minLength};
Branch: 1 branch
BranchTrueFalseTotal
if length $data >= $$schema{"minLength"} 160 142 302
539 142 return E($state, 'length is less than %d', $schema->{minLength});
540 }
541  
542 905 ▶sub _eval_keyword_pattern ($data, $schema, $state) {
Subroutine _eval_keyword_pattern: called CC=3 SCAR=11.0
543 905 assert_keyword_type($state, $schema, 'string');
544 905 assert_pattern($state, $schema->{pattern});
545  
546 904 ▶ return 1 if not is_type('string', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $data) 227 677 904
547 677 ▶ return 1 if $data =~ m/(?:$schema->{pattern})/;
Branch: 1 branch
BranchTrueFalseTotal
if $data =~ /(?:$$schema{"pattern"})/u 361 315 676
548 315 return E($state, 'pattern does not match');
549 }
550  
551 425 ▶sub _eval_keyword_maxItems ($data, $schema, $state) {
Subroutine _eval_keyword_maxItems: called CC=4 SCAR=13.9
552 425 assert_non_negative_integer($schema, $state);
553  
554 425 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 169 256 425
555 256 ▶ return 1 if @$data <= $schema->{maxItems};
Branch: 1 branch
BranchTrueFalseTotal
if @$data <= $$schema{"maxItems"} 134 122 256
556 122 ▶ return E($state, 'more than %d item%s', $schema->{maxItems}, $schema->{maxItems} > 1 ? 's' : '');
Branch: 1 branch
BranchTrueFalseTotal
$$schema{'maxItems'} > 1 ? : 22 100 122
557 }
558  
559 424 ▶sub _eval_keyword_minItems ($data, $schema, $state) {
Subroutine _eval_keyword_minItems: called CC=4 SCAR=13.9
560 424 assert_non_negative_integer($schema, $state);
561  
562 424 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 167 257 424
563 257 ▶ return 1 if @$data >= $schema->{minItems};
Branch: 1 branch
BranchTrueFalseTotal
if @$data >= $$schema{"minItems"} 133 124 257
564 124 ▶ return E($state, 'fewer than %d item%s', $schema->{minItems}, $schema->{minItems} > 1 ? 's' : '');
Branch: 1 branch
BranchTrueFalseTotal
$$schema{'minItems'} > 1 ? : 112 12 124
565 }
566  
567 751 ▶sub _eval_keyword_uniqueItems ($data, $schema, $state) {
Subroutine _eval_keyword_uniqueItems: called CC=4 SCAR=13.9
568 751 assert_keyword_type($state, $schema, 'boolean');
569 751 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 161 590 751
570 590 ▶ return 1 if not $schema->{uniqueItems};
Branch: 1 branch
BranchTrueFalseTotal
unless $$schema{"uniqueItems"} 153 437 590
571 437 ▶ return 1 if is_elements_unique($data, my $equal_indices = []);
Branch: 1 branch
BranchTrueFalseTotal
if is_elements_unique($data, scalar(my $equal_indices = [])) 230 207 437
572 207 return E($state, 'items at indices %d and %d are not unique', @$equal_indices);
573 }
574  
575 92 ▶sub _eval_keyword_maxContains ($data, $schema, $state) {
Subroutine _eval_keyword_maxContains: called CC=4 SCAR=13.9
576 92 assert_non_negative_integer($schema, $state);
577 92 ▶ return 1 if not exists $state->{_num_contains};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"_num_contains"} 8 84 92
578 84 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 0 84 84
579  
580 return E($state, 'contains too many matching items')
581 84 ▶ if $state->{_num_contains} > $schema->{maxContains};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"_num_contains"} > $$schema{"maxContains"} 36 48 84
582  
583 48 return 1;
584 }
585  
586 108 ▶sub _eval_keyword_minContains ($data, $schema, $state) {
Subroutine _eval_keyword_minContains: called CC=4 SCAR=13.9
587 108 assert_non_negative_integer($schema, $state);
588 108 ▶ return 1 if not exists $state->{_num_contains};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"_num_contains"} 8 100 108
589 100 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 0 100 100
590  
591 return E($state, 'contains too few matching items')
592 100 ▶ if $state->{_num_contains} < $schema->{minContains};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"_num_contains"} < $$schema{"minContains"} 34 66 100
593  
594 66 return 1;
595 }
596  
597 340 ▶sub _eval_keyword_maxProperties ($data, $schema, $state) {
Subroutine _eval_keyword_maxProperties: called CC=4 SCAR=13.9
598 340 assert_non_negative_integer($schema, $state);
599  
600 340 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 138 202 340
601 202 ▶ return 1 if keys %$data <= $schema->{maxProperties};
Branch: 1 branch
BranchTrueFalseTotal
if keys %$data <= $$schema{"maxProperties"} 104 98 202
602 return E($state, 'more than %d propert%s', $schema->{maxProperties},
603 98 ▶ $schema->{maxProperties} > 1 ? 'ies' : 'y');
Branch: 1 branch
BranchTrueFalseTotal
$$schema{'maxProperties'} > 1 ? : 12 86 98
604 }
605  
606 352 ▶sub _eval_keyword_minProperties ($data, $schema, $state) {
Subroutine _eval_keyword_minProperties: called CC=4 SCAR=13.9
607 352 assert_non_negative_integer($schema, $state);
608  
609 352 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 150 202 352
610 202 ▶ return 1 if keys %$data >= $schema->{minProperties};
Branch: 1 branch
BranchTrueFalseTotal
if keys %$data >= $$schema{"minProperties"} 104 98 202
611 return E($state, 'fewer than %d propert%s', $schema->{minProperties},
612 98 ▶ $schema->{minProperties} > 1 ? 'ies' : 'y');
Branch: 1 branch
BranchTrueFalseTotal
$$schema{'minProperties'} > 1 ? : 6 92 98
613 }
614  
615 1426 ▶sub _eval_keyword_required ($data, $schema, $state) {
Subroutine _eval_keyword_required: called CC=6 SCAR=18.0
616 1426 assert_keyword_type($state, $schema, 'array');
617 abort($state, '"required" element is not a string')
618 1426 ▶ if any { !is_type('string', $_) } $schema->{required}->@*;
Branch: 1 branch
BranchTrueFalseTotal
if CORE::any {not is_type("string", $_);} @{$$schema{"required"}} 0 1426 1426
619 1426 ▶ abort($state, '"required" values are not unique') if not is_elements_unique($schema->{required});
Branch: 1 branch
BranchTrueFalseTotal
unless is_elements_unique($$schema{"required"}) 0 1426 1426
620  
621 1426 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 162 1264 1426
622  
623 1264 my @missing = grep !exists $data->{$_}, $schema->{required}->@*;
624 1264 ▶ return 1 if not @missing;
Branch: 1 branch
BranchTrueFalseTotal
unless @missing 698 566 1264
625 566 ▶ return E($state, 'missing propert%s: %s', @missing > 1 ? 'ies' : 'y', join(', ', @missing));
Branch: 1 branch
BranchTrueFalseTotal
@missing > 1 ? : 36 530 566
626 }
627  
628 271 ▶sub _eval_keyword_dependentRequired ($data, $schema, $state) {
Subroutine _eval_keyword_dependentRequired: called CC=12 SCAR=24.9
629 271 assert_keyword_type($state, $schema, 'object');
630  
631 271 foreach my $property (sort keys $schema->{dependentRequired}->%*) {
632 E({ %$state, _keyword_path_suffix => $property }, 'value is not an array'), next
633 287 ▶ if not is_type('array', $schema->{dependentRequired}{$property});
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $$schema{"dependentRequired"}{$property}) 0 287 287
634  
635 287 foreach my $index (0..$schema->{dependentRequired}{$property}->$#*) {
636 abort({ %$state, _keyword_path_suffix => [ $property, $index ] }, 'element #%d is not a string', $index)
637 301 ▶ if not is_type('string', $schema->{dependentRequired}{$property}[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $$schema{"dependentRequired"}{$property}[$index]) 1 300 301
638 }
639  
640 abort({ %$state, _keyword_path_suffix => $property }, 'elements are not unique')
641 286 ▶ if not is_elements_unique($schema->{dependentRequired}{$property});
Branch: 1 branch
BranchTrueFalseTotal
unless is_elements_unique($$schema{"dependentRequired"}{$property}) 0 286 286
642 }
643  
644 270 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 97 173 270
645  
646 173 my $valid = 1;
647 173 foreach my $property (sort keys $schema->{dependentRequired}->%*) {
648 189 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 36 153 189
649  
650 153 ▶ if (my @missing = grep !exists($data->{$_}), $schema->{dependentRequired}{$property}->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependentRequired"}{$property}})) 79 74 153
651 79 ▶ $valid = E({ %$state, _keyword_path_suffix => $property },
Branch: 1 branch
BranchTrueFalseTotal
@missing > 1 ? : 5 74 79
652 'missing propert%s: %s', @missing > 1 ? 'ies' : 'y', join(', ', @missing));
653 }
654 }
655  
656 173 ▶ return 1 if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 94 79 173
657 79 return E($state, 'not all dependencies are satisfied');
658 }
659  
660 575 ▶sub _eval_keyword_allOf ($data, $schema, $state) {
Subroutine _eval_keyword_allOf: called CC=7 SCAR=19.5
661 575 assert_array_schemas($schema, $state);
662  
663 575 my @invalid;
664 575 foreach my $idx (0..$schema->{allOf}->$#*) {
665 next if _evaluate_subschema($data, $schema->{allOf}[$idx],
666 843 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/allOf/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($data, $$schema{"allOf"}[$idx], {%$state, "keyword_path", $$state{"keyword_path"} . '/allOf/' . $idx}) 463 209 672
667  
668 209 push @invalid, $idx;
669 209 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 71 138 209
670 }
671  
672 404 ▶ return 1 if @invalid == 0;
Branch: 1 branch
BranchTrueFalseTotal
if @invalid == 0 235 169 404
673  
674 169 my $pl = @invalid > 1;
675 169 ▶ return E($state, 'subschema%s %s %s not valid', $pl?'s':'', join(', ', @invalid), $pl?'are':'is');
Branch: 2 branches
BranchTrueFalseTotal
$pl ? : 36 133 169
$pl ? : 36 133 169
676 }
677  
678 433 ▶sub _eval_keyword_anyOf ($data, $schema, $state) {
Subroutine _eval_keyword_anyOf: called CC=5 SCAR=16.1
679 433 assert_array_schemas($schema, $state);
680  
681 433 my $valid = 0;
682 433 my @errors;
683 433 foreach my $idx (0..$schema->{anyOf}->$#*) {
684 next if not _evaluate_subschema($data, $schema->{anyOf}[$idx],
685 760 ▶ +{ %$state, errors => \@errors, keyword_path => $state->{keyword_path}.'/anyOf/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
unless _evaluate_subschema($data, $$schema{"anyOf"}[$idx], {%$state, "errors", \@errors, "keyword_path", $$state{"keyword_path"} . '/anyOf/' . $idx}) 382 239 621
686 239 ++$valid;
687 239 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 98 141 239
688 }
689  
690 294 ▶ return 1 if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 202 92 294
691 92 push $state->{errors}->@*, @errors;
692 92 return E($state, 'no subschemas are valid');
693 }
694  
695 509 ▶sub _eval_keyword_oneOf ($data, $schema, $state) {
Subroutine _eval_keyword_oneOf: called CC=7 SCAR=19.5
696 509 assert_array_schemas($schema, $state);
697  
698 509 my (@valid, @errors);
699 509 foreach my $idx (0..$schema->{oneOf}->$#*) {
700 next if not _evaluate_subschema($data, $schema->{oneOf}[$idx],
701 1061 ▶ +{ %$state, errors => \@errors, keyword_path => $state->{keyword_path}.'/oneOf/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
unless _evaluate_subschema($data, $$schema{"oneOf"}[$idx], {%$state, "errors", \@errors, "keyword_path", $$state{"keyword_path"} . '/oneOf/' . $idx}) 533 377 910
702 377 push @valid, $idx;
703 377 ▶ last if @valid > 1 and $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if @valid > 1 and $$state{"short_circuit"} 44 333 377
Condition100%3/3
@valid > 1 and $$state{"short_circuit"}
!ll&&!rl&&r
2864744
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
704 }
705  
706 358 ▶ return 1 if @valid == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @valid == 1 157 201 358
707  
708 201 ▶ if (not @valid) {
Branch: 1 branch
BranchTrueFalseTotal
if (not @valid) { } 123 78 201
709 123 push $state->{errors}->@*, @errors;
710 123 return E($state, 'no subschemas are valid');
711 }
712 else {
713 78 return E($state, 'multiple subschemas are valid: '.join(', ', @valid));
714 }
715 }
716  
717 293 ▶sub _eval_keyword_not ($data, $schema, $state) {
Subroutine _eval_keyword_not: called CC=4 SCAR=13.9
718 293 ▶ return !$schema->{not} || E($state, 'subschema is true') if is_type('boolean', $schema->{not});
Branch: 1 branch
BranchTrueFalseTotal
if is_type("boolean", $$schema{"not"}) 112 181 293
Condition66%2/3
!$$schema{'not'} || E($state, 'subschema is true')
l!l&&r!l&&!r
55057
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
719  
720 return 1 if not _evaluate_subschema($data, $schema->{not},
721 181 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/not', short_circuit => 1, errors => [] });
Branch: 1 branch
BranchTrueFalseTotal
unless _evaluate_subschema($data, $$schema{"not"}, {%$state, "keyword_path", $$state{"keyword_path"} . '/not', "short_circuit", 1, "errors", []}) 38 135 173
722  
723 135 return E($state, 'subschema is valid');
724 }
725  
726 326 ▶sub _eval_keyword_if ($data, $schema, $state) {
Subroutine _eval_keyword_if: called CC=8 SCAR=20.8
727 326 ▶ return 1 if not exists $schema->{then} and not exists $schema->{else};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{"then"} or exists $$schema{"else"} 44 282 326
Condition100%3/3
exists $$schema{"then"} or exists $$schema{"else"}
l!l&&r!l&&!r
2305244
MC/DC100%2/2
exists $$schema{"then"} or exists $$schema{"else"}
exists $$schema{"then"} exists $$schema{"else"}
Truth table100%3/3
A or B
A= exists $$schema{"then"}B= exists $$schema{"else"}
ABresult
1X1
011
000
728 my $keyword = _evaluate_subschema($data, $schema->{if},
729 282 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/if', short_circuit => 1, errors => [] })
Branch: 1 branch
BranchTrueFalseTotal
_evaluate_subschema($data, $$schema{'if'}, {%$state, 'keyword_path', $$state{'keyword_path'} . '/if', 'short_circuit', 1, 'errors', []}) ? : 138 144 282
730 ? 'then' : 'else';
731  
732 282 ▶ return 1 if not exists $schema->{$keyword};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$schema{$keyword} 58 224 282
733  
734 return $schema->{$keyword} || E({ %$state, keyword => $keyword }, 'subschema is false')
735 224 ▶ if is_type('boolean', $schema->{$keyword});
Branch: 1 branch
BranchTrueFalseTotal
if is_type("boolean", $$schema{$keyword}) 32 192 224
Condition66%2/3
$$schema{$keyword} || E({%$state, 'keyword', $keyword}, 'subschema is false')
l!l&&r!l&&!r
20012
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
736  
737 return 1 if _evaluate_subschema($data, $schema->{$keyword},
738 192 ▶ +{ %$state, keyword_path => $state->{keyword_path}.'/'.$keyword });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($data, $$schema{$keyword}, {%$state, "keyword_path", $$state{"keyword_path"} . '/' . $keyword}) 108 62 170
739 62 return E({ %$state, keyword => $keyword }, 'subschema is not valid');
740 }
741  
742 337 ▶sub _eval_keyword_dependentSchemas ($data, $schema, $state) {
Subroutine _eval_keyword_dependentSchemas: called CC=7 SCAR=19.5
743 337 assert_keyword_type($state, $schema, 'object');
744  
745 337 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 124 213 337
746  
747 213 my $valid = 1;
748 213 foreach my $property (sort keys $schema->{dependentSchemas}->%*) {
749 next if not exists $data->{$property}
750 or _evaluate_subschema($data, $schema->{dependentSchemas}{$property},
751 263 ▶ +{ %$state, keyword_path => jsonp($state->{keyword_path}, 'dependentSchemas', $property) });
Branch: 1 branch
BranchTrueFalseTotal
if not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)}) 166 97 263
Condition100%3/3
not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)})
l!l&&r!l&&!r
1323497
MC/DC100%2/2
not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)})
not exists $$data{$property} _evaluate_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)})
Truth table100%3/3
not(A) or B
A= not exists $$data{$property}B= _evaluate_subschema($data, $$schema{"dependentSchemas"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependentSchemas", $property)})
ABresult
1X1
011
000
752  
753 97 $valid = 0;
754 97 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 48 49 97
755 }
756  
757 213 ▶ return E($state, 'not all dependencies are satisfied') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 97 116 213
758 116 return 1;
759 }
760  
761 186 ▶sub _eval_keyword_dependencies ($data, $schema, $state) {
Subroutine _eval_keyword_dependencies: called CC=14 SCAR=26.4
762 186 assert_keyword_type($state, $schema, 'object');
763  
764 186 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 67 119 186
765  
766 119 my $valid = 1;
767 119 foreach my $property (sort keys $schema->{dependencies}->%*) {
768 166 ▶ if (is_type('array', $schema->{dependencies}{$property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('array', $$schema{'dependencies'}{$property})) { } 52 114 166
769 # as in dependentRequired
770  
771 52 foreach my $index (0..$schema->{dependencies}{$property}->$#*) {
772 $valid = E({ %$state, _keyword_path_suffix => [ $property, $index ] }, 'element #%d is not a string', $index)
773 62 ▶ if not is_type('string', $schema->{dependencies}{$property}[$index]);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("string", $$schema{"dependencies"}{$property}[$index]) 0 62 62
774 }
775  
776 abort({ %$state, _keyword_path_suffix => $property }, 'elements are not unique')
777 52 ▶ if not is_elements_unique($schema->{dependencies}{$property});
Branch: 1 branch
BranchTrueFalseTotal
unless is_elements_unique($$schema{"dependencies"}{$property}) 0 52 52
778  
779 52 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 28 24 52
780  
781 24 ▶ if (my @missing = grep !exists($data->{$_}), $schema->{dependencies}{$property}->@*) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@missing) = grep((!exists($$data{$_})), @{$$schema{"dependencies"}{$property}})) 14 10 24
782 14 ▶ $valid = E({ %$state, _keyword_path_suffix => $property },
Branch: 1 branch
BranchTrueFalseTotal
@missing > 1 ? : 3 11 14
783 'missing propert%s: %s', @missing > 1 ? 'ies' : 'y', join(', ', @missing));
784 }
785 }
786 else {
787 # as in dependentSchemas
788 next if not exists $data->{$property}
789 or _evaluate_subschema($data, $schema->{dependencies}{$property},
790 114 ▶ +{ %$state, keyword_path => jsonp($state->{keyword_path}, 'dependencies', $property) });
Branch: 1 branch
BranchTrueFalseTotal
if not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)}) 67 47 114
Condition100%3/3
not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)})
l!l&&r!l&&!r
58947
MC/DC100%2/2
not exists $$data{$property} or _evaluate_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)})
not exists $$data{$property} _evaluate_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)})
Truth table100%3/3
not(A) or B
A= not exists $$data{$property}B= _evaluate_subschema($data, $$schema{"dependencies"}{$property}, {%$state, "keyword_path", jsonp($$state{"keyword_path"}, "dependencies", $property)})
ABresult
1X1
011
000
791  
792 47 $valid = 0;
793 47 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 23 24 47
794 }
795 }
796  
797 119 ▶ return 1 if $valid;
Branch: 1 branch
BranchTrueFalseTotal
if $valid 60 59 119
798 59 return E($state, 'not all dependencies are satisfied');
799 }
800  
801 411 ▶sub _eval_keyword_prefixItems ($data, $schema, $state) {
Subroutine _eval_keyword_prefixItems: called CC=2 SCAR=7.2
802 411 ▶ return if not assert_array_schemas($schema, $state);
Branch: 1 branch
BranchTrueFalseTotal
unless assert_array_schemas($schema, $state) 0 411 411
803 411 goto \&_eval_keyword__items_array_schemas;
804 }
805  
806 1304 ▶sub _eval_keyword_items ($data, $schema, $state) {
Subroutine _eval_keyword_items: called CC=5 SCAR=16.1
807 1304 ▶ if (ref $schema->{items} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $$schema{"items"} eq "ARRAY") 700 604 1304
808 abort($state, 'array form of "items" not supported in %s', $state->{specification_version})
809 700 ▶ if ($state->{specification_version}//'') eq 'draft2020-12';
Branch: 1 branch
BranchTrueFalseTotal
if ($$state{"specification_version"} // "") eq "draft2020-12" 1 699 700
Condition100%2/2
$$state{"specification_version"} // ""
l!l
6991
MC/DC100%1/1
$$state{"specification_version"} // ""
$$state{"specification_version"}
Truth table100%2/2
A
A= $$state{"specification_version"}
Aresult
11
00
810  
811 699 goto \&_eval_keyword__items_array_schemas;
812 }
813  
814 604 ▶ $state->{_last_items_index} //= -1;
Condition100%2/2
$$state{"_last_items_index"} //= -1
l!l
88516
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
815 604 goto \&_eval_keyword__items_schema;
816 }
817  
818 219 ▶sub _eval_keyword_additionalItems ($data, $schema, $state) {
Subroutine _eval_keyword_additionalItems: called CC=2 SCAR=6.9
819 219 ▶ return 1 if not exists $state->{_last_items_index};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$state{"_last_items_index"} 28 191 219
820 191 goto \&_eval_keyword__items_schema;
821 }
822  
823 # prefixItems (draft 2020-12), array-based items (all drafts)
824 1110 ▶sub _eval_keyword__items_array_schemas ($data, $schema, $state) {
Subroutine _eval_keyword__items_array_schemas: called CC=13 SCAR=25.7
825 1110 ▶ abort($state, '%s array is empty', $state->{keyword}) if not $schema->{$state->{keyword}}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$schema{$$state{"keyword"}}} 0 1110 1110
826 1110 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 213 897 1110
827  
828 897 my $valid = 1;
829  
830 897 foreach my $idx (0..$data->$#*) {
831 1581 ▶ last if $idx > $schema->{$state->{keyword}}->$#*;
Branch: 1 branch
BranchTrueFalseTotal
if $idx > $$schema{$$state{"keyword"}}->$#* 287 1294 1581
832 1294 $state->{_last_items_index} = $idx;
833  
834 1294 ▶ if (is_type('boolean', $schema->{$state->{keyword}}[$idx])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{$$state{'keyword'}}[$idx])) { } 286 1008 1294
835 286 ▶ next if $schema->{$state->{keyword}}[$idx];
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{$$state{"keyword"}}[$idx] 178 108 286
836 108 $valid = E({ %$state, data_path => $state->{data_path}.'/'.$idx,
837 _keyword_path_suffix => $idx }, 'item not permitted');
838 }
839 else {
840 next if _evaluate_subschema($data->[$idx], $schema->{$state->{keyword}}[$idx],
841 +{ %$state, data_path => $state->{data_path}.'/'.$idx,
842 1008 ▶ keyword_path => $state->{keyword_path}.'/'.$state->{keyword}.'/'.$idx });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($$data[$idx], $$schema{$$state{"keyword"}}[$idx], {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "keyword_path", $$state{"keyword_path"} . '/' . $$state{"keyword"} . '/' . $idx}) 941 67 1008
843 }
844  
845 175 $valid = 0;
846 last if $state->{short_circuit} and not exists $schema->{
847 $state->{keyword} eq 'prefixItems' ? 'items'
848 175 ▶ : $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())} 75 100 175
$$state{'keyword'} eq 'prefixItems' ? : 31 56 87
$$state{'keyword'} eq 'items' ? : 56 0 56
Condition100%3/3
$$state{"short_circuit"} and not exists $$schema{$$state{"keyword"} eq "prefixItems" ? "items" : ($$state{"keyword"} eq "items" ? "additionalItems" : die())}
!ll&&!rl&&r
881275
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
849 };
850 }
851  
852 897 ▶ return E($state, 'not all items are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 172 725 897
853 725 return 1;
854 }
855  
856 # schema-based items (all drafts), and additionalItems (drafts 4,6,7,2019-09)
857 795 ▶sub _eval_keyword__items_schema ($data, $schema, $state) {
Subroutine _eval_keyword__items_schema: called CC=14 SCAR=26.4
858 795 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 104 691 795
859 691 ▶ return 1 if $state->{_last_items_index} == $data->$#*;
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"_last_items_index"} == $data->$#* 244 447 691
860  
861 447 my $valid = 1;
862 447 foreach my $idx ($state->{_last_items_index}+1 .. $data->$#*) {
863 676 ▶ if (is_type('boolean', $schema->{$state->{keyword}})
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{$$state{'keyword'}}) and $$state{'keyword'} eq 'additionalItems') { } 32 644 676
Condition100%3/3
is_type("boolean", $$schema{$$state{"keyword"}}) and $$state{"keyword"} eq "additionalItems"
!ll&&!rl&&r
5618332
MC/DC100%2/2
is_type("boolean", $$schema{$$state{"keyword"}}) and $$state{"keyword"} eq "additionalItems"
is_type("boolean", $$schema{$$state{"keyword"}}) $$state{"keyword"} eq "additionalItems"
Truth table100%3/3
A and B
A= is_type("boolean", $$schema{$$state{"keyword"}})B= $$state{"keyword"} eq "additionalItems"
ABresult
0X0
100
111
864 and ($state->{keyword} eq 'additionalItems')) {
865 32 ▶ next if $schema->{$state->{keyword}};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{$$state{"keyword"}} 6 26 32
866 $valid = E({ %$state, data_path => $state->{data_path}.'/'.$idx },
867 '%sitem not permitted',
868 26 ▶ exists $schema->{prefixItems} || $state->{keyword} eq 'additionalItems' ? 'additional ' : '');
Branch: 1 branch
BranchTrueFalseTotal
exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? : 26 0 26
Condition33%1/3
exists $$schema{"prefixItems"} or $$state{"keyword"} eq "additionalItems"
l!l&&r!l&&!r
0260
MC/DC0%0/2
exists $$schema{"prefixItems"} or $$state{"keyword"} eq "additionalItems"
exists $$schema{"prefixItems"} $$state{"keyword"} eq "additionalItems"
Truth table33%1/3
A or B
A= exists $$schema{"prefixItems"}B= $$state{"keyword"} eq "additionalItems"
ABresult
1X1
011
000
869 }
870 else {
871 next if _evaluate_subschema($data->[$idx], $schema->{$state->{keyword}},
872 +{ %$state, data_path => $state->{data_path}.'/'.$idx,
873 644 ▶ keyword_path => $state->{keyword_path}.'/'.$state->{keyword} });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($$data[$idx], $$schema{$$state{"keyword"}}, {%$state, "data_path", $$state{"data_path"} . '/' . $idx, "keyword_path", $$state{"keyword_path"} . '/' . $$state{"keyword"}}) 360 219 579
874 219 $valid = 0;
875 }
876  
877 245 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 90 155 245
878 }
879  
880 382 $state->{_last_items_index} = $data->$#*;
881  
882 return E($state, 'subschema is not valid against all %sitems',
883 382 ▶ exists $schema->{prefixItems} || $state->{keyword} eq 'additionalItems' ? 'additional ' : '')
Branch: 2 branches
BranchTrueFalseTotal
unless $valid 203 179 382
exists $$schema{'prefixItems'} || $$state{'keyword'} eq 'additionalItems' ? : 59 144 203
Condition100%3/3
exists $$schema{"prefixItems"} or $$state{"keyword"} eq "additionalItems"
l!l&&r!l&&!r
1940144
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
884 if not $valid;
885 179 return 1;
886 }
887  
888 725 ▶sub _eval_keyword_contains ($data, $schema, $state) {
Subroutine _eval_keyword_contains: called CC=14 SCAR=26.4
889 725 ▶ return 1 if not is_type('array', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("array", $data) 213 512 725
890  
891 512 $state->{_num_contains} = 0;
892 512 my @errors;
893 512 foreach my $idx (0..$data->$#*) {
894 626 ▶ if (_evaluate_subschema($data->[$idx], $schema->{contains},
Branch: 1 branch
BranchTrueFalseTotal
if (_evaluate_subschema($$data[$idx], $$schema{"contains"}, {%$state, "errors", \@errors, "data_path", $$state{"data_path"} . '/' . $idx, "keyword_path", $$state{"keyword_path"} . '/contains'})) 394 232 626
895 +{ %$state, errors => \@errors,
896 data_path => $state->{data_path}.'/'.$idx,
897 keyword_path => $state->{keyword_path}.'/contains' })) {
898 394 ++$state->{_num_contains};
899  
900 last if $state->{short_circuit}
901 and (not exists $schema->{maxContains} or $state->{_num_contains} > $schema->{maxContains})
902 394 ▶ and ($state->{_num_contains} >= ($schema->{minContains}//1));
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} and !exists($$schema{"maxContains"}) || $$state{"_num_contains"} > $$schema{"maxContains"} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1) 128 266 394
Condition100%11/11
$$state{"short_circuit"} and !exists($$schema{"maxContains"}) || $$state{"_num_contains"} > $$schema{"maxContains"} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
!ll&&!rl&&r
24818128
$$state{"short_circuit"} and !exists($$schema{"maxContains"}) || $$state{"_num_contains"} > $$schema{"maxContains"}
!ll&&!rl&&r
20642146
not exists $$schema{"maxContains"} or $$state{"_num_contains"} > $$schema{"maxContains"}
l!l&&r!l&&!r
1262042
$$schema{"minContains"} // 1
l!l
44102
MC/DC100%4/4
$$state{"short_circuit"} and !exists($$schema{"maxContains"}) || $$state{"_num_contains"} > $$schema{"maxContains"} and $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
$$state{"short_circuit"} not exists $$schema{"maxContains"} $$state{"_num_contains"} > $$schema{"maxContains"} $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
MC/DC100%1/1
$$schema{"minContains"} // 1
$$schema{"minContains"}
Truth table100%6/6
A and not(B) or C and D
A= $$state{"short_circuit"}B= not exists $$schema{"maxContains"}C= $$state{"_num_contains"} > $$schema{"maxContains"}D= $$state{"_num_contains"} >= ($$schema{"minContains"} // 1)
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
Truth table100%2/2
A
A= $$schema{"minContains"}
Aresult
11
00
903 }
904 }
905  
906 # note: no items contained is only valid when minContains is explicitly 0
907 512 ▶ if (not $state->{_num_contains} and (($schema->{minContains}//1) > 0
Branch: 1 branch
BranchTrueFalseTotal
if (not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} && $$state{"specification_version"} eq "draft7") 195 317 512
Condition72%8/11
not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} && $$state{"specification_version"} eq "draft7"
!ll&&!rl&&r
29720195
($$schema{"minContains"} // 1) > 0 or $$state{"specification_version"} and $$state{"specification_version"} eq "draft7"
l!l&&r!l&&!r
195020
$$schema{"minContains"} // 1
l!l
44171
$$state{"specification_version"} and $$state{"specification_version"} eq "draft7"
!ll&&!rl&&r
0200
MC/DC25%1/4
not $$state{"_num_contains"} and ($$schema{"minContains"} // 1) > 0 || $$state{"specification_version"} && $$state{"specification_version"} eq "draft7"
not $$state{"_num_contains"} $$schema{"minContains"} $$state{"specification_version"} $$state{"specification_version"} eq "draft7"
Truth table40%2/5
not(A) and B or C and D
A= not $$state{"_num_contains"}B= $$schema{"minContains"}C= $$state{"specification_version"}D= $$state{"specification_version"} eq "draft7"
ABCDresult
0XXX0
100X0
10100
11XX1
10111
908 or $state->{specification_version} and $state->{specification_version} eq 'draft7')) {
909 195 push $state->{errors}->@*, @errors;
910 195 return E($state, 'subschema is not valid against any item');
911 }
912  
913 317 return 1;
914 }
915  
916 2441 ▶sub _eval_keyword_properties ($data, $schema, $state) {
Subroutine _eval_keyword_properties: called CC=9 SCAR=22.0
917 2441 assert_keyword_type($state, $schema, 'object');
918 2441 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 263 2178 2441
919  
920 2178 my $valid = 1;
921 2178 foreach my $property (sort keys $schema->{properties}->%*) {
922 2742 ▶ next if not exists $data->{$property};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$data{$property} 1044 1698 2742
923  
924 1698 ▶ if (is_type('boolean', $schema->{properties}{$property})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'properties'}{$property})) { } 323 1375 1698
925 323 ▶ next if $schema->{properties}{$property};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"properties"}{$property} 217 106 323
926 106 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property),
927 _keyword_path_suffix => $property }, 'property not permitted');
928 }
929 else {
930 next if _evaluate_subschema($data->{$property}, $schema->{properties}{$property},
931 +{ %$state,
932 data_path => jsonp($state->{data_path}, $property),
933 1375 ▶ keyword_path => jsonp($state->{keyword_path}, 'properties', $property) });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($$data{$property}, $$schema{"properties"}{$property}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", jsonp($$state{"keyword_path"}, "properties", $property)}) 891 329 1220
934  
935 329 $valid = 0;
936 }
937 435 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 210 225 435
938 }
939  
940 2023 ▶ return E($state, 'not all properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 413 1610 2023
941 1610 return 1;
942 }
943  
944 823 ▶sub _eval_keyword_patternProperties ($data, $schema, $state) {
Subroutine _eval_keyword_patternProperties: called CC=10 SCAR=23.0
945 823 assert_keyword_type($state, $schema, 'object');
946  
947 823 foreach my $property (sort keys $schema->{patternProperties}->%*) {
948 1264 assert_pattern({ %$state, _keyword_path_suffix => $property }, $property);
949 }
950  
951 821 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 193 628 821
952  
953 628 my $valid = 1;
954 628 foreach my $property_pattern (sort keys $schema->{patternProperties}->%*) {
955 912 foreach my $property (sort grep m/(?:$property_pattern)/, keys %$data) {
956 569 ▶ if (is_type('boolean', $schema->{patternProperties}{$property_pattern})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'patternProperties'}{$property_pattern})) { } 319 250 569
957 319 ▶ next if $schema->{patternProperties}{$property_pattern};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"patternProperties"}{$property_pattern} 211 108 319
958 108 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property),
959 _keyword_path_suffix => $property_pattern }, 'property not permitted');
960 }
961 else {
962 next if _evaluate_subschema($data->{$property}, $schema->{patternProperties}{$property_pattern},
963 +{ %$state,
964 data_path => jsonp($state->{data_path}, $property),
965 250 ▶ keyword_path => jsonp($state->{keyword_path}, 'patternProperties', $property_pattern) });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($$data{$property}, $$schema{"patternProperties"}{$property_pattern}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", jsonp($$state{"keyword_path"}, "patternProperties", $property_pattern)}) 161 89 250
966  
967 89 $valid = 0;
968 }
969 197 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 93 104 197
970 }
971 }
972  
973 628 ▶ return E($state, 'not all properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 182 446 628
974 446 return 1;
975 }
976  
977 767 ▶sub _eval_keyword_additionalProperties ($data, $schema, $state) {
Subroutine _eval_keyword_additionalProperties: called CC=12 SCAR=24.8
978 767 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 199 568 767
979  
980 568 my $valid = 1;
981 568 foreach my $property (sort keys %$data) {
982 567 ▶ next if exists $schema->{properties} and exists $schema->{properties}{$property};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"properties"} and exists $$schema{"properties"}{$property} 126 441 567
Condition100%3/3
exists $$schema{"properties"} and exists $$schema{"properties"}{$property}
!ll&&!rl&&r
34695126
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
983 next if exists $schema->{patternProperties}
984 441 ▶ and any { $property =~ /(?:$_)/ } keys $schema->{patternProperties}->%*;
Branch: 1 branch
BranchTrueFalseTotal
if exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}} 88 353 441
Condition100%3/3
exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
!ll&&!rl&&r
2936088
MC/DC100%2/2
exists $$schema{"patternProperties"} and CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
exists $$schema{"patternProperties"} CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
Truth table100%3/3
A and B
A= exists $$schema{"patternProperties"}B= CORE::any {$property =~ /(?:$_)/u;} keys %{$$schema{"patternProperties"}}
ABresult
0X0
100
111
985  
986 353 ▶ if (is_type('boolean', $schema->{additionalProperties})) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_type('boolean', $$schema{'additionalProperties'})) { } 188 165 353
987 188 ▶ next if $schema->{additionalProperties};
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{"additionalProperties"} 16 172 188
988  
989 172 $valid = E({ %$state, data_path => jsonp($state->{data_path}, $property) },
990 'additional property not permitted');
991 }
992 else {
993 next if _evaluate_subschema($data->{$property}, $schema->{additionalProperties},
994 +{ %$state,
995 data_path => jsonp($state->{data_path}, $property),
996 165 ▶ keyword_path => $state->{keyword_path}.'/additionalProperties' });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($$data{$property}, $$schema{"additionalProperties"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", $$state{"keyword_path"} . '/additionalProperties'}) 72 41 113
997  
998 41 $valid = 0;
999 }
1000 213 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 104 109 213
1001 }
1002  
1003 516 ▶ return E($state, 'not all additional properties are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 212 304 516
1004 304 return 1;
1005 }
1006  
1007 475 ▶sub _eval_keyword_propertyNames ($data, $schema, $state) {
Subroutine _eval_keyword_propertyNames: called CC=6 SCAR=17.9
1008 475 ▶ return 1 if not is_type('object', $data);
Branch: 1 branch
BranchTrueFalseTotal
unless is_type("object", $data) 187 288 475
1009  
1010 288 my $valid = 1;
1011 288 foreach my $property (sort keys %$data) {
1012 next if _evaluate_subschema($property, $schema->{propertyNames},
1013 +{ %$state,
1014 data_path => jsonp($state->{data_path}, $property),
1015 202 ▶ keyword_path => $state->{keyword_path}.'/propertyNames' });
Branch: 1 branch
BranchTrueFalseTotal
if _evaluate_subschema($property, $$schema{"propertyNames"}, {%$state, "data_path", jsonp($$state{"data_path"}, $property), "keyword_path", $$state{"keyword_path"} . '/propertyNames'}) 86 116 202
1016  
1017 116 $valid = 0;
1018 116 ▶ last if $state->{short_circuit};
Branch: 1 branch
BranchTrueFalseTotal
if $$state{"short_circuit"} 60 56 116
1019 }
1020  
1021 288 ▶ return E($state, 'not all property names are valid') if not $valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 116 172 288
1022 172 return 1;
1023 }
1024  
1025 384 ▶sub _eval_keyword_unevaluatedItems ($data, $schema, $state) {
Subroutine _eval_keyword_unevaluatedItems: called CC=1 SCAR=0.0
1026 384 abort($state, 'keyword not yet supported');
1027 }
1028  
1029 605 ▶sub _eval_keyword_unevaluatedProperties ($data, $schema, $state) {
Subroutine _eval_keyword_unevaluatedProperties: called CC=1 SCAR=0.0
1030 605 abort($state, 'keyword not yet supported');
1031 }
1032  
1033 # UTILITIES
1034  
1035 # supports the six core types, plus integer (which is also a number)
1036 # we do NOT check $STRINGY_NUMBERS here -- you must do that in the caller
1037 # note that sometimes a value may return true for more than one type, e.g. integer+number,
1038 # or number+string, depending on its internal flags.
1039 # copied from JSON::Schema::Modern::Utilities::is_type
1040 53393 ▶sub is_type ($type, $value) {
Subroutine is_type: called CC=21 SCAR=30.5
Pod undocumented
1041 53393 ▶ if ($type eq 'null') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "null") 83 53310 53393
1042 83 return !(defined $value);
1043 }
1044 53310 ▶ if ($type eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "boolean") 6041 47269 53310
1045 6041 return is_bool($value);
1046 }
1047 47269 ▶ if ($type eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "object") 12244 35025 47269
1048 12244 return ref $value eq 'HASH';
1049 }
1050 35025 ▶ if ($type eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "array") 8836 26189 35025
1051 8836 return ref $value eq 'ARRAY';
1052 }
1053  
1054 26189 ▶ if ($type eq 'string' or $type eq 'number' or $type eq 'integer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "string" or $type eq "number" or $type eq "integer") 26173 16 26189
Condition100%6/6
$type eq "string" or $type eq "number" or $type eq "integer"
l!l&&r!l&&!r
23256291716
$type eq "string" or $type eq "number"
l!l&&r!l&&!r
1705162052933
MC/DC100%3/3
$type eq "string" or $type eq "number" or $type eq "integer"
$type eq "string" $type eq "number" $type eq "integer"
Truth table100%4/4
A or B or C
A= $type eq "string"B= $type eq "number"C= $type eq "integer"
ABCresult
1XX1
01X1
0011
0000
1055 26173 ▶ return 0 if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 18 26155 26173
1056 26155 my $flags = B::svref_2object(\$value)->FLAGS;
1057  
1058 # dualvars with the same string and (stringified) numeric value could be either a string or a
1059 # number, and before 5.36 we can't tell the difference, so we will answer yes for both.
1060 # in 5.36+, stringified numbers still get a PV but don't have POK set, whereas
1061 # numified strings do have POK set, so we can tell which one came first.
1062  
1063 26155 ▶ if ($type eq 'string') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "string") 17037 9118 26155
1064 # like created_as_string, but rejects dualvars with stringwise-unequal string and numeric parts
1065 return !length ref($value)
1066 && $flags & B::SVf_POK
1067 && (!($flags & (B::SVf_IOK | B::SVf_NOK))
1068 17 ▶ || do { no warnings 'numeric'; 0+$value eq $value });
Subroutine BEGIN: called CC=1 SCAR=0.0
Condition100%9/9
!length(ref $value) && $flags & 1024 && (!($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value })
!ll&&!rl&&r
698316336
not length ref $value and $flags & 1024
!ll&&!rl&&r
49919916339
not $flags & 768 or do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
l!l&&r!l&&!r
1633243
MC/DC100%4/4
!length(ref $value) && $flags & 1024 && (!($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value })
not length ref $value $flags & 1024 not $flags & 768 do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
Truth table100%5/5
not(A) and B && not(C) or D
A= not length ref $valueB= $flags & 1024C= not $flags & 768D= do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
ABCDresult
0XXX0
10XX0
11000
111X1
11011
1069 }
1070  
1071 9118 ▶ if ($type eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number") 6203 2915 9118
1072 # floats in json will always be parsed into Math::BigFloat, when allow_bignum is enabled
1073 6203 ▶ return is_bignum($value) || created_as_number($value);
Condition100%3/3
is_bignum($value) || &created_as_number($value)
l!l&&r!l&&!r
41147671025
MC/DC100%2/2
is_bignum($value) || &created_as_number($value)
is_bignum($value) &created_as_number($value)
Truth table100%3/3
A || B
A= is_bignum($value)B= &created_as_number($value)
ABresult
1X1
011
000
1074 }
1075  
1076 2915 ▶ if ($type eq 'integer') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "integer") 2915 0 2915
1077 # note: values that are larger than $Config{ivsize} will be represented as an NV, not IV,
1078 # therefore they will fail this check
1079 2915 ▶ return is_bignum($value) && $value->is_int
Condition100%9/9
is_bignum($value) && $value->is_int || &created_as_number($value) && int $value == $value
l!l&&r!l&&!r
100276748
is_bignum($value) and $value->is_int
!ll&&!rl&&r
28123100
&created_as_number($value) and int $value == $value
!ll&&!rl&&r
4532767
MC/DC100%4/4
is_bignum($value) && $value->is_int || &created_as_number($value) && int $value == $value
is_bignum($value) $value->is_int &created_as_number($value) int $value == $value
Truth table71%5/7
A and B || C and D
A= is_bignum($value)B= $value->is_intC= &created_as_number($value)D= int $value == $value
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1080 # if dualvar, PV and stringified NV/IV must be identical
1081 || created_as_number($value) && int($value) == $value;
1082 }
1083 }
1084  
1085 16 ▶ if ($type =~ /^reference to (.+)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^reference to (.+)\z/u) 11 5 16
1086 11 ▶ return !blessed($value) && ref($value) eq $1;
Condition33%1/3
!builtin::blessed($value) && ref $value eq $1
!ll&&!rl&&r
0011
MC/DC0%0/2
!builtin::blessed($value) && ref $value eq $1
!builtin::blessed($value) ref $value eq $1
Truth table33%1/3
not(A) && B
A= !builtin::blessed($value)B= ref $value eq $1
ABresult
0X0
100
111
1087 }
1088  
1089 5 return ref($value) eq $type;
1090 }
1091  
1092 # returns one of the six core types, plus integer
1093 # we do NOT check $STRINGY_NUMBERS here -- you must do that in the caller
1094 # copied from JSON::Schema::Modern::Utilities::get_type
1095 35307 ▶sub get_type ($value) {
Subroutine get_type: called CC=15 SCAR=27.1
Pod undocumented
1096 35307 ▶ return 'object' if ref $value eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "HASH" 22221 13086 35307
1097 13086 ▶ return 'boolean' if is_bool($value);
Branch: 1 branch
BranchTrueFalseTotal
if is_bool($value) 1967 11119 13086
1098 11119 ▶ return 'null' if not defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 298 10821 11119
1099 10821 ▶ return 'array' if ref $value eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $value eq "ARRAY" 1283 9538 10821
1100  
1101 # floats in json will always be parsed into Math::BigFloat, when allow_bignum is enabled
1102 9538 ▶ if (length(my $ref = ref $value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length(my $ref = ref $value)) 455 9083 9538
1103 455 ▶ return $ref eq 'Math::BigInt' ? 'integer'
Branch: 4 branches
BranchTrueFalseTotal
$ref eq 'Math::BigInt' ? : 105 350 455
$ref eq 'Math::BigFloat' ? : 276 74 350
$value->is_int ? : 195 81 276
defined builtin::blessed($value) ? : 4 70 74
1104 : $ref eq 'Math::BigFloat' ? ($value->is_int ? 'integer' : 'number')
1105 : (defined blessed($value) ? '' : 'reference to ').$ref;
1106 }
1107  
1108 9083 my $flags = B::svref_2object(\$value)->FLAGS;
1109  
1110 # dualvars with the same string and (stringified) numeric value could be either a string or a
1111 # number, and before 5.36 we can't tell the difference, so we choose number because it has been
1112 # evaluated as a number already.
1113 # in 5.36+, stringified numbers still get a PV but don't have POK set, whereas
1114 # numified strings do have POK set, so we can tell which one came first.
1115  
1116 # like created_as_string, but rejects dualvars with stringwise-unequal string and numeric parts
1117 return 'string'
1118 if $flags & B::SVf_POK
1119 && (!($flags & (B::SVf_IOK | B::SVf_NOK))
1120 17 ▶ || do { no warnings 'numeric'; 0+$value eq $value });
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
if $flags & 1024 and !($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value } 4700 4383 9083
Condition100%6/6
$flags & 1024 and !($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
!ll&&!rl&&r
4368154700
not $flags & 768 or do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
l!l&&r!l&&!r
4692815
MC/DC100%3/3
$flags & 1024 and !($flags & 768) || do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
$flags & 1024 not $flags & 768 do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
Truth table100%4/4
A and not(B) or C
A= $flags & 1024B= not $flags & 768C= do { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x15\x55\x55\x05\x54\x55\x51\x55\x55\x55"} 0 + $value eq $value }
ABCresult
0XX0
1000
11X1
1011
1121  
1122 # note: values that are larger than $Config{ivsize} will be represented as an NV, not IV,
1123 # therefore they will fail this check
1124 4383 ▶ return int($value) == $value ? 'integer' : 'number' if created_as_number($value);
Branch: 2 branches
BranchTrueFalseTotal
if &created_as_number($value) 4368 15 4383
int $value == $value ? : 4351 17 4368
1125  
1126 # this might be a scalar with POK|IOK or POK|NOK set
1127 15 return 'ambiguous type';
1128 }
1129  
1130 # lifted from JSON::MaybeXS
1131 # note: unlike builtin::compat::is_bool on older perls, we do not accept
1132 # dualvar(0,"") or dualvar(1,"1") because JSON::PP and Cpanel::JSON::XS
1133 # do not encode these as booleans.
1134 17 ▶use constant HAVE_BUILTIN => "$]" >= 5.035010;
Subroutine BEGIN: called CC=1 SCAR=0.0
1135 17 ▶use if HAVE_BUILTIN, experimental => 'builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
1136 19127 ▶sub is_bool ($value) {
Subroutine is_bool: called CC=5 SCAR=17.0
Pod undocumented
1137 19127 ▶ HAVE_BUILTIN and builtin::is_bool($value)
Branch: 1 branch
BranchTrueFalseTotal
builtin::is_bool($value) or not !builtin::blessed($value) and $value->isa("JSON::PP::Boolean") || $value->isa("Cpanel::JSON::XS::Boolean") || $value->isa("JSON::XS::Boolean") 0 19127 19127
Condition75%9/12
builtin::is_bool($value) || !!builtin::blessed($value) && ($value->isa('JSON::PP::Boolean') || $value->isa('Cpanel::JSON::XS::Boolean') || $value->isa('JSON::XS::Boolean'))
l!l&&r!l&&!r
0420014927
not !builtin::blessed($value) and $value->isa("JSON::PP::Boolean") || $value->isa("Cpanel::JSON::XS::Boolean") || $value->isa("JSON::XS::Boolean")
!ll&&!rl&&r
145254024200
$value->isa("JSON::PP::Boolean") or $value->isa("Cpanel::JSON::XS::Boolean") or $value->isa("JSON::XS::Boolean")
l!l&&r!l&&!r
42000402
$value->isa("JSON::PP::Boolean") or $value->isa("Cpanel::JSON::XS::Boolean")
l!l&&r!l&&!r
42000402
MC/DC40%2/5
builtin::is_bool($value) || !!builtin::blessed($value) && ($value->isa('JSON::PP::Boolean') || $value->isa('Cpanel::JSON::XS::Boolean') || $value->isa('JSON::XS::Boolean'))
builtin::is_bool($value) not !builtin::blessed($value) $value->isa("JSON::PP::Boolean") $value->isa("Cpanel::JSON::XS::Boolean") $value->isa("JSON::XS::Boolean")
Truth table50%3/6
A || B and C or D or E
A= builtin::is_bool($value)B= not !builtin::blessed($value)C= $value->isa("JSON::PP::Boolean")D= $value->isa("Cpanel::JSON::XS::Boolean")E= $value->isa("JSON::XS::Boolean")
ABCDEresult
1XXXX1
011XX1
0101X1
010011
00XXX0
010000
1138 or
1139 !!blessed($value)
1140 and ($value->isa('JSON::PP::Boolean')
1141 or $value->isa('Cpanel::JSON::XS::Boolean')
1142 or $value->isa('JSON::XS::Boolean'));
1143 }
1144  
1145 11563 ▶sub is_bignum ($value) {
Subroutine is_bignum: called CC=1 SCAR=0.0
Pod undocumented
1146 11563 ref($value) =~ /^Math::Big(?:Int|Float)\z/;
1147 }
1148  
1149 # compares two arbitrary data payloads for equality, as per
1150 # https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.4.2.2
1151 # $state hashref supports the following fields/configs:
1152 # - path: location of the first difference
1153 # - error: description of the difference
1154 # - $SCALARREF_BOOLEANS: treats \0 and \1 as boolean values
1155 # - $STRINGY_NUMBERS: strings will be typed as numbers if looks_like_number() is true
1156 # copied from JSON::Schema::Modern::Utilities::is_equal
1157 4175 ▶sub is_equal ($x, $y, $state = {}) {
Subroutine is_equal: called CC=29 SCAR=33.7
Pod undocumented
1158 4175 ▶ $state->{path} //= '';
Condition100%2/2
$$state{"path"} //= ""
l!l
6723503
MC/DC100%1/1
$$state{"path"} //= ""
$$state{"path"}
Truth table100%2/2
A
A= $$state{"path"}
Aresult
11
00
1159  
1160 4175 my @types = map get_type($_), $x, $y;
1161  
1162 4175 ▶ $state->{error} = 'ambiguous type encountered', return 0
Branch: 1 branch
BranchTrueFalseTotal
if grep(($types[$_] eq "ambiguous type"), (0, 1)) 3 4172 4175
1163 if grep $types[$_] eq 'ambiguous type', 0..1;
1164  
1165 4172 ▶ if ($SCALARREF_BOOLEANS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JSON::Schema::Tiny::SCALARREF_BOOLEANS) 99 4073 4172
1166 99 ▶ ($x, $types[0]) = (0+!!$$x, 'boolean') if $types[0] eq 'reference to SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if $types[0] eq "reference to SCALAR" 14 85 99
1167 99 ▶ ($y, $types[1]) = (0+!!$$y, 'boolean') if $types[1] eq 'reference to SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if $types[1] eq "reference to SCALAR" 18 81 99
1168 }
1169  
1170 4172 ▶ if ($STRINGY_NUMBERS) {
Branch: 1 branch
BranchTrueFalseTotal
if ($JSON::Schema::Tiny::STRINGY_NUMBERS) 18 4154 4172
1171 18 ▶ ($x, $types[0]) = (0+$x, int(0+$x) == $x ? 'integer' : 'number')
Branch: 2 branches
BranchTrueFalseTotal
if $types[0] eq "string" and &looks_like_number($x) 8 10 18
int 0 + $x == $x ? : 5 3 8
Condition100%3/3
$types[0] eq "string" and &looks_like_number($x)
!ll&&!rl&&r
558
MC/DC100%2/2
$types[0] eq "string" and &looks_like_number($x)
$types[0] eq "string" &looks_like_number($x)
Truth table100%3/3
A and B
A= $types[0] eq "string"B= &looks_like_number($x)
ABresult
0X0
100
111
1172 if $types[0] eq 'string' and looks_like_number($x);
1173  
1174 18 ▶ ($y, $types[1]) = (0+$y, int(0+$y) == $y ? 'integer' : 'number')
Branch: 2 branches
BranchTrueFalseTotal
if $types[1] eq "string" and &looks_like_number($y) 5 13 18
int 0 + $y == $y ? : 4 1 5
Condition100%3/3
$types[1] eq "string" and &looks_like_number($y)
!ll&&!rl&&r
855
MC/DC100%2/2
$types[1] eq "string" and &looks_like_number($y)
$types[1] eq "string" &looks_like_number($y)
Truth table100%3/3
A and B
A= $types[1] eq "string"B= &looks_like_number($y)
ABresult
0X0
100
111
1175 if $types[1] eq 'string' and looks_like_number($y);
1176 }
1177  
1178 4172 ▶ $state->{error} = "wrong type: $types[0] vs $types[1]", return 0 if $types[0] ne $types[1];
Branch: 1 branch
BranchTrueFalseTotal
if $types[0] ne $types[1] 831 3341 4172
1179 3341 ▶ return 1 if $types[0] eq 'null';
Branch: 1 branch
BranchTrueFalseTotal
if $types[0] eq "null" 14 3327 3341
1180 3327 ▶ ($x eq $y and return 1), $state->{error} = 'strings not equal', return 0
Branch: 1 branch
BranchTrueFalseTotal
if $types[0] eq "string" 1545 1782 3327
Condition100%2/2
$x eq $y and return 1
!ll
861684
MC/DC100%1/1
$x eq $y and return 1
$x eq $y
Truth table100%2/2
A
A= $x eq $y
Aresult
00
11
1181 if $types[0] eq 'string';
1182 1782 ▶ ($x == $y and return 1), $state->{error} = "$types[0]s not equal", return 0
Branch: 1 branch
BranchTrueFalseTotal
if grep(($types[0] eq $_), ("boolean", "number", "integer")) 1159 623 1782
Condition100%2/2
$x == $y and return 1
!ll
497662
MC/DC100%1/1
$x == $y and return 1
$x == $y
Truth table100%2/2
A
A= $x == $y
Aresult
00
11
1183 if grep $types[0] eq $_, qw(boolean number integer);
1184  
1185 623 my $path = $state->{path};
1186 623 ▶ if ($types[0] eq 'object') {
Branch: 1 branch
BranchTrueFalseTotal
if ($types[0] eq "object") 217 406 623
1187 217 ▶ $state->{error} = 'property count differs: '.keys(%$x).' vs '.keys(%$y), return 0
Branch: 1 branch
BranchTrueFalseTotal
if keys %$x != keys %$y 17 200 217
1188 if keys %$x != keys %$y;
1189  
1190 200 ▶ if (not is_equal(my $arr_x = [ sort keys %$x ], my $arr_y = [ sort keys %$y ], my $s={})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (is_equal(my $arr_x = [sort(keys %$x)], my $arr_y = [sort(keys %$y)], scalar(my $s = {}))) 7 193 200
1191 7 my $pos = substr($s->{path}, 1);
1192 7 $state->{error} = 'property names differ starting at position '.$pos.' ("'.$arr_x->[$pos].'" vs "'.$arr_y->[$pos].'")';
1193 7 return 0;
1194 }
1195  
1196 193 foreach my $property (sort keys %$x) {
1197 231 $state->{path} = jsonp($path, $property);
1198 231 ▶ return 0 if not is_equal($x->{$property}, $y->{$property}, $state);
Branch: 1 branch
BranchTrueFalseTotal
unless is_equal($$x{$property}, $$y{$property}, $state) 87 144 231
1199 }
1200  
1201 106 return 1;
1202 }
1203  
1204 406 ▶ if ($types[0] eq 'array') {
Branch: 1 branch
BranchTrueFalseTotal
if ($types[0] eq "array") 406 0 406
1205 406 ▶ $state->{error} = 'element count differs: '.@$x.' vs '.@$y, return 0 if @$x != @$y;
Branch: 1 branch
BranchTrueFalseTotal
if @$x != @$y 9 397 406
1206 397 foreach my $idx (0 .. $x->$#*) {
1207 441 $state->{path} = $path.'/'.$idx;
1208 441 ▶ return 0 if not is_equal($x->[$idx], $y->[$idx], $state);
Branch: 1 branch
BranchTrueFalseTotal
unless is_equal($$x[$idx], $$y[$idx], $state) 128 313 441
1209 }
1210 269 return 1;
1211 }
1212  
1213 0 $state->{error} = 'uh oh', return 0; # should never get here
1214 }
1215  
1216 # checks array elements for uniqueness. short-circuits on first pair of matching elements
1217 # if second arrayref is provided, it is populated with the indices of identical items
1218 # supports the following configs:
1219 # - $SCALARREF_BOOLEANS: treats \0 and \1 as boolean values
1220 # - $STRINGY_NUMBERS: strings will be typed as numbers if looks_like_number() is true
1221 # copied from JSON::Schema::Modern::Utilities::is_elements_unique
1222 2358 ▶sub is_elements_unique ($array, $equal_indices = undef) {
Subroutine is_elements_unique: called CC=6 SCAR=18.0
Pod undocumented
1223 2358 foreach my $idx0 (0 .. $array->$#*-1) {
1224 834 foreach my $idx1 ($idx0+1 .. $array->$#*) {
1225 1239 ▶ if (is_equal($array->[$idx0], $array->[$idx1])) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_equal($$array[$idx0], $$array[$idx1])) 207 1032 1239
1226 207 ▶ push @$equal_indices, $idx0, $idx1 if defined $equal_indices;
Branch: 1 branch
BranchTrueFalseTotal
if defined $equal_indices 207 0 207
1227 207 return 0;
1228 }
1229 }
1230 }
1231 2151 return 1;
1232 }
1233  
1234 # shorthand for creating and appending json pointers
1235 # the first argument is a json pointer; remaining arguments are path segments to be encoded and
1236 # appended
1237 # copied from JSON::Schema::Modern::Utilities::jsonp
1238 24245 ▶sub jsonp {
Subroutine jsonp: called CC=1 SCAR=0.0
Pod undocumented
1239 24245 return join('/', shift, map s/~/~0/gr =~ s!/!~1!gr, grep defined, @_);
1240 }
1241  
1242 # shorthand for finding the canonical uri of the present schema location
1243 # copied from JSON::Schema::Modern::Utilities::canonical_uri
1244 30850 ▶sub canonical_uri ($state, @extra_path) {
Subroutine canonical_uri: called CC=6 SCAR=17.9
Pod undocumented
1245 30850 ▶ return $state->{initial_schema_uri} if not @extra_path and not length($state->{keyword_path});
Branch: 1 branch
BranchTrueFalseTotal
unless @extra_path or length $$state{"keyword_path"} 14129 16721 30850
Condition100%3/3
@extra_path or length $$state{"keyword_path"}
l!l&&r!l&&!r
9912680914129
MC/DC100%2/2
@extra_path or length $$state{"keyword_path"}
@extra_path length $$state{"keyword_path"}
Truth table100%3/3
A or B
A= @extra_pathB= length $$state{"keyword_path"}
ABresult
1X1
011
000
1246 16721 my $uri = $state->{initial_schema_uri}->clone;
1247 16721 ▶ my $fragment = ($uri->fragment//'').(@extra_path ? jsonp($state->{keyword_path}, @extra_path) : $state->{keyword_path});
Branch: 1 branch
BranchTrueFalseTotal
@extra_path ? : 9912 6809 16721
Condition100%2/2
$uri->fragment // ""
l!l
149815223
MC/DC100%1/1
$uri->fragment // ""
$uri->fragment
Truth table100%2/2
A
A= $uri->fragment
Aresult
11
00
1248 16721 ▶ undef $fragment if not length($fragment);
Branch: 1 branch
BranchTrueFalseTotal
unless length $fragment 78 16643 16721
1249 16721 $uri->fragment($fragment);
1250 16721 $uri;
1251 }
1252  
1253 # shorthand for creating error objects
1254 # based on JSON::Schema::Modern::Utilities::E
1255 9912 ▶sub E ($state, $error_string, @args) {
Subroutine E: called CC=11 SCAR=24.0
Pod undocumented
1256 # sometimes the keyword shouldn't be at the very end of the schema path
1257 9912 my $sps = delete $state->{_keyword_path_suffix};
1258 9912 ▶ my @keyword_path_suffix = defined $sps && ref $sps eq 'ARRAY' ? $sps->@* : $sps//();
Branch: 1 branch
BranchTrueFalseTotal
defined $sps && ref $sps eq 'ARRAY' ? : 1 9911 9912
Condition100%6/6
defined $sps and ref $sps eq "ARRAY"
!ll&&!rl&&r
94944171
$sps // ()
l!l&&r!l&&!r
417941777
MC/DC100%2/2
defined $sps and ref $sps eq "ARRAY"
defined $sps ref $sps eq "ARRAY"
MC/DC100%2/2
$sps // ()
$sps ()
Truth table100%3/3
A and B
A= defined $spsB= ref $sps eq "ARRAY"
ABresult
0X0
100
111
Truth table100%3/3
A // B
A= $spsB= ()
ABresult
1X1
011
000
1259  
1260 9912 my $uri = canonical_uri($state, $state->{keyword}, @keyword_path_suffix);
1261  
1262 my $keyword_location = $state->{traversed_keyword_path}
1263 9912 .jsonp($state->{keyword_path}, $state->{keyword}, @keyword_path_suffix);
1264  
1265 9912 ▶ undef $uri if $uri eq '' and $keyword_location eq ''
Branch: 1 branch
BranchTrueFalseTotal
if $uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq "" 8585 1327 9912
Condition100%11/11
$uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
l!l&&r!l&&!r
7785081327
$uri eq "" and $keyword_location eq ""
!ll&&!rl&&r
9834177
($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
!ll&&!rl&&r
8754528508
$uri->fragment // ""
l!l
98341
MC/DC75%3/4
$uri eq "" and $keyword_location eq "" or ($uri->fragment // "") eq $keyword_location and $uri->clone->fragment(undef) eq ""
$uri eq "" $keyword_location eq "" $uri->fragment $uri->clone->fragment(undef) eq ""
Truth table57%4/7
A and B or C and D
A= $uri eq ""B= $keyword_location eq ""C= $uri->fragmentD= $uri->clone->fragment(undef) eq ""
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1266 or ($uri->fragment//'') eq $keyword_location and $uri->clone->fragment(undef) eq '';
1267  
1268 push $state->{errors}->@*, {
1269 instanceLocation => $state->{data_path},
1270 9912 ▶ keywordLocation => $keyword_location,
Branch: 2 branches
BranchTrueFalseTotal
defined $uri ? : 1327 8585 9912
@args ? : 4738 5174 9912
1271 defined $uri ? ( absoluteKeywordLocation => $uri->to_string) : (),
1272 error => @args ? sprintf($error_string, @args) : $error_string,
1273 };
1274  
1275 9912 return 0;
1276 }
1277  
1278 # creates an error object, but also aborts evaluation immediately
1279 # only this error is returned, because other errors on the stack might not actually be "real"
1280 # errors (consider if we were in the middle of evaluating a "not" or "if")
1281 1695 ▶sub abort ($state, $error_string, @args) {
Subroutine abort: called CC=1 SCAR=0.0
Pod undocumented
1282 1695 E($state, $error_string, @args);
1283 1695 die pop $state->{errors}->@*;
1284 }
1285  
1286 # one common usecase of abort()
1287 28326 ▶sub assert_keyword_type ($state, $schema, $type) {
Subroutine assert_keyword_type: called CC=3 SCAR=11.0
Pod undocumented
1288 28326 ▶ return 1 if is_type($type, $schema->{$state->{keyword}});
Branch: 1 branch
BranchTrueFalseTotal
if is_type($type, $$schema{$$state{"keyword"}}) 28308 18 28326
1289 18 ▶ abort($state, '%s value is not a%s %s', $state->{keyword}, ($type =~ /^[aeiou]/ ? 'n' : ''), $type);
Branch: 1 branch
BranchTrueFalseTotal
$type =~ /^[aeiou]/u ? : 2 16 18
1290 }
1291  
1292 2169 ▶sub assert_pattern ($state, $pattern) {
Subroutine assert_pattern: called CC=1 SCAR=0.0
Pod undocumented
1293 2169 try {
1294 2169 ▶ local $SIG{__WARN__} = sub { die @_ };
Subroutine __ANON__: called CC=1 SCAR=0.0
1295 2169 qr/$pattern/;
1296 }
1297 3 catch ($e) { abort($state, $e); }
1298 2166 return 1;
1299 }
1300  
1301 # based on JSON::Schema::Modern::Utilities::assert_uri_reference
1302 2413 ▶sub assert_uri_reference ($state, $schema) {
Subroutine assert_uri_reference: called CC=7 SCAR=21.2
Pod undocumented
1303 2413 my $string = $schema->{$state->{keyword}};
1304 abort($state, '%s value is not a valid URI reference', $state->{keyword})
1305 # see also uri-reference format sub
1306 2413 ▶ if fc(Mojo::URL->new($string)->to_unsafe_string) ne fc($string)
Branch: 1 branch
BranchTrueFalseTotal
if fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u 0 2413 2413
Condition66%10/15
fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
l!l&&r!l&&!r
002413
fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u
l!l&&r!l&&!r
002413
$string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
!ll&&!rl&&r
128411290
$string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u
!ll&&!rl&&r
11841001129
$string =~ /#/u and not $string =~ /#$/u
!ll&&!rl&&r
10331511229
MC/DC0%0/6
fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $string $string =~ /[^[:ascii:]]/u $string =~ /#/u not $string =~ /#$/u not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u not $string =~ m[#/(?:[^~]|~[01])*$]u
Truth table57%4/7
A or B or C and not(D) and not(E) and not(F)
A= fc "Mojo::URL"->new($string)->to_unsafe_string ne fc $stringB= $string =~ /[^[:ascii:]]/uC= $string =~ /#/uD= not $string =~ /#$/uE= not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/uF= not $string =~ m[#/(?:[^~]|~[01])*$]u
ABCDEFresult
1XXXXX1
01XXXX1
0011111
000XXX0
0010XX0
00110X0
0011100
1307 or $string =~ /[^[:ascii:]]/ # ascii characters only
1308 or $string =~ /#/ # no fragment, except...
1309 and $string !~ m{#$} # allow empty fragment
1310 and $string !~ m{#[A-Za-z][A-Za-z0-9_:.-]*$} # allow plain-name fragment
1311 and $string !~ m{#/(?:[^~]|~[01])*$}; # allow json pointer fragment
1312  
1313 2413 return 1;
1314 }
1315  
1316 # based on JSON::Schema::Modern::Utilities::assert_uri
1317 5770 ▶sub assert_uri ($state, $schema, $override = undef) {
Subroutine assert_uri: called CC=10 SCAR=30.0
Pod undocumented
1318 5770 ▶ my $string = $override // $schema->{$state->{keyword}};
Condition66%2/3
$override // $$schema{$$state{"keyword"}}
l!l&&r!l&&!r
457660
MC/DC0%0/2
$override // $$schema{$$state{"keyword"}}
$override $$schema{$$state{"keyword"}}
Truth table66%2/3
A // B
A= $overrideB= $$schema{$$state{"keyword"}}
ABresult
1X1
011
000
1319 5770 my $uri = Mojo::URL->new($string);
1320  
1321 5770 ▶ abort($state, '"%s" is not a valid URI', $string)
Branch: 1 branch
BranchTrueFalseTotal
if fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or not $uri->is_abs or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u 0 5770 5770
Condition38%7/18
fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or not $uri->is_abs or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
l!l&&r!l&&!r
005770
fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or not $uri->is_abs
l!l&&r!l&&!r
005770
fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u
l!l&&r!l&&!r
005770
$string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
!ll&&!rl&&r
577000
$string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u
!ll&&!rl&&r
577000
$string =~ /#/u and not $string =~ /#$/u
!ll&&!rl&&r
576910
MC/DC0%0/7
fc $uri->to_unsafe_string ne fc $string or $string =~ /[^[:ascii:]]/u or not $uri->is_abs or $string =~ /#/u and not $string =~ /#$/u and not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u and not $string =~ m[#/(?:[^~]|~[01])*$]u
fc $uri->to_unsafe_string ne fc $string $string =~ /[^[:ascii:]]/u not $uri->is_abs $string =~ /#/u not $string =~ /#$/u not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/u not $string =~ m[#/(?:[^~]|~[01])*$]u
Truth table25%2/8
A or B or not(C) or D and not(E) and not(F) and not(G)
A= fc $uri->to_unsafe_string ne fc $stringB= $string =~ /[^[:ascii:]]/uC= not $uri->is_absD= $string =~ /#/uE= not $string =~ /#$/uF= not $string =~ /#[A-Za-z][A-Za-z0-9_:.-]*$/uG= not $string =~ m[#/(?:[^~]|~[01])*$]u
ABCDEFGresult
1XXXXXX1
01XXXXX1
001XXXX1
00011111
0000XXX0
00010XX0
000110X0
00011100
1322 # see also uri format sub
1323 if fc($uri->to_unsafe_string) ne fc($string)
1324 or $string =~ /[^[:ascii:]]/ # ascii characters only
1325 or not $uri->is_abs # must have a schema
1326 or $string =~ /#/ # no fragment, except...
1327 and $string !~ m{#$} # empty fragment
1328 and $string !~ m{#[A-Za-z][A-Za-z0-9_:.-]*$} # plain-name fragment
1329 and $string !~ m{#/(?:[^~]|~[01])*$}; # json pointer fragment
1330  
1331 5770 return 1;
1332 }
1333  
1334 2814 ▶sub assert_non_negative_integer ($schema, $state) {
Subroutine assert_non_negative_integer: called CC=2 SCAR=7.1
Pod undocumented
1335 2814 assert_keyword_type($state, $schema, 'integer');
1336 abort($state, '%s value is not a non-negative integer', $state->{keyword})
1337 2814 ▶ if $schema->{$state->{keyword}} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $$schema{$$state{"keyword"}} < 0 0 2814 2814
1338 2814 return 1;
1339 }
1340  
1341 1928 ▶sub assert_array_schemas ($schema, $state) {
Subroutine assert_array_schemas: called CC=2 SCAR=7.1
Pod undocumented
1342 1928 assert_keyword_type($state, $schema, 'array');
1343 1928 ▶ abort($state, '%s array is empty', $state->{keyword}) if not $schema->{$state->{keyword}}->@*;
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$schema{$$state{"keyword"}}} 0 1928 1928
1344 1928 return 1;
1345 }
1346  
1347 # copied from JSON::Schema::Modern::Utilities::sprintf_num
1348 1001 ▶sub sprintf_num ($value) {
Subroutine sprintf_num: called CC=2 SCAR=6.9
Pod undocumented
1349 # use original value as stored in the NV, without losing precision
1350 1001 ▶ is_bignum($value) ? $value->bstr : sprintf('%s', $value);
Branch: 1 branch
BranchTrueFalseTotal
is_bignum($value) ? : 72 929 1001
1351 }
1352  
1353 {
1354 # avoid dependency on namespace::clean
1355 17 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1356 17 delete @{__PACKAGE__.'::'}{qw(croak carp any looks_like_number isinf)};
1357 }
1358  
1359 17 1;
1360  
1361 __END__
↑ Summary