lib/JSON/Schema/Validate.pm

filter: Statementstmt 64.0% 1178 / 1839 Branchbran 54.6% 693 / 1268 Conditioncond 36.9% 243 / 657 MC/DCmcdc 15.3% 58 / 377 Subroutinesub 85.1% 120 / 141 Podpod 100% 30 / 30 totaltotal 53.8% 2322 / 4312 CC 938 SCAR 77.2
CC
938
Cov
56%
_compile_js_node
16770.0
__ANON__
2599.1
_compile_node
523.7
CRAP 2246.3
↑ Summary
1 ##----------------------------------------------------------------------------
2 ## JSON Schema Validator - ~/lib/m
3 ## Version v0.9.1
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2025/11/07
7 ## Modified 2026/08/20
8 ## All rights reserved
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.##
13 ##----------------------------------------------------------------------------##
14 package JSON::Schema::Validate;
15 BEGIN
16 44 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
17 44 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 44 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 44 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 44 ▶ use vars qw( $VERSION $DEBUG );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 44 ▶ use B ();
Subroutine BEGIN: called CC=1 SCAR=0.0
22 44 ▶ use JSON ();
Subroutine BEGIN: called CC=1 SCAR=0.0
23 44 ▶ use Scalar::Util qw( blessed looks_like_number reftype refaddr );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 44 ▶ use List::Util qw( first any all );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 44 ▶ use Encode ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 44 our $VERSION = 'v0.9.1';
27 };
28  
29 44 ▶use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 sub new
34 121 ▶{
Subroutine new: called CC=26 SCAR=34.1
Pod documented
35 121 my $class = shift( @_ );
36 121 my $schema = shift( @_ );
37 121 ▶ if( defined( $schema ) && ( !ref( $schema ) || ref( $schema ) ne 'HASH' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $schema and !ref($schema) || ref $schema ne "HASH") 0 121 121
Condition33%2/6
defined $schema and !ref($schema) || ref $schema ne "HASH"
!ll&&!rl&&r
01210
not ref $schema or ref $schema ne "HASH"
l!l&&r!l&&!r
00121
MC/DC0%0/3
defined $schema and !ref($schema) || ref $schema ne "HASH"
defined $schema not ref $schema ref $schema ne "HASH"
Truth table25%1/4
A and not(B) or C
A= defined $schemaB= not ref $schemaC= ref $schema ne "HASH"
ABCresult
0XX0
1000
11X1
1011
38 {
39 0 die( "You provided a value (", overload::StrVal( $schema ), "), but it is not an hash reference. You must create a new $class object like this: $class->new( \$schema, \%opts );" );
40 }
41  
42 121 my $self =
43 {
44 comment_handler => undef,
45 # boolean
46 compile_on => 0,
47 # { schema, anchors, id_index, base }
48 compiled => undef,
49 # boolean; when 0, failures don’t invalidate; when 1, they do
50 content_assert => 0,
51 content_decoders => {},
52 errors => [],
53 # boolean; when true, then non-standard extensions are enabled.
54 extensions => 0,
55 formats => {},
56 # boolean
57 ignore_req_vocab => 0,
58 last_error => '',
59 last_trace => [],
60 max_errors => 200,
61 media_validators => {},
62 # boolean
63 normalize_instance => 1,
64 # boolean: when true, prune unknown properties before validate()
65 prune_unknown => 0,
66 # ($abs_uri) -> $schema_hashref
67 resolver => undef,
68 schema => _clone( $schema ),
69 # 0 = unlimited
70 trace_limit => 0,
71 # boolean
72 trace_on => 0,
73 # 0 = record all
74 trace_sample => 0,
75 # boolean; when true, 'uniqueKeys' extension is enabled.
76 unique_keys => 0,
77 # internal boolean; not an option
78 vocab_checked => 0,
79 vocab_support => {},
80 };
81  
82 121 bless( $self, $class );
83 121 my $opts = $self->_get_args_as_hash( @_ );
84 121 my @bool_options = qw(
85 content_assert
86 extensions
87 ignore_req_vocab
88 normalize_instance
89 prune_unknown
90 unique_keys
91 );
92 121 foreach my $opt ( @bool_options )
93 {
94 726 ▶ next unless( exists( $opts->{ $opt } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$opt} 718 8 726
95 8 ▶ $self->{ $opt } = $opts->{ $opt } ? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
$opts->{$opt} ? : 8 0 8
96 }
97 # Make sure the boolean value for 'extensions' is propagated to 'unique_keys' unless the option 'unique_keys' has been explicitly specified, and then we do not want to overwrite it.
98 121 ▶ $self->{unique_keys} = $self->{extensions} unless( exists( $opts->{unique_keys} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{"unique_keys"} 121 0 121
99 121 ▶ if( exists( $opts->{ignore_unknown_required_vocab} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"ignore_unknown_required_vocab"}) 1 120 121
100 {
101 1 ▶ $self->{ignore_req_vocab} = $opts->{ignore_unknown_required_vocab} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'ignore_unknown_required_vocab'} ? : 1 0 1
102 }
103 121 ▶ if( exists( $opts->{compile} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"compile"}) 11 110 121
104 {
105 11 ▶ $self->{compile_on} = $opts->{compile} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'compile'} ? : 10 1 11
106 }
107 121 ▶ if( exists( $opts->{trace} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"trace"}) 6 115 121
108 {
109 6 ▶ $self->{trace_on} = $opts->{trace} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'trace'} ? : 6 0 6
110 }
111  
112 121 my @other_options = qw( max_errors trace_limit );
113 121 foreach my $opt ( @other_options )
114 {
115 242 ▶ next unless( exists( $opts->{ $opt } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $opts->{$opt} 235 7 242
116 7 $self->{ $opt } = $opts->{ $opt };
117 }
118  
119 121 ▶ if( exists( $opts->{trace_sample} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $opts->{"trace_sample"}) 1 120 121
120 {
121 # Check for percentage integer (0 to 100)
122 1 ▶ if( $opts->{trace_sample} =~ /^([0-9]{1,2}|100)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{'trace_sample'} =~ /^([0-9]{1,2}|100)$/u) { } 1 0 1
123 {
124 1 $self->{trace_sample} = $opts->{trace_sample};
125 }
126 else
127 {
128 0 ▶ warn( "Warning only: invalid value for option 'trace_sample'." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
129 }
130 }
131  
132 # User-supplied format callbacks (override precedence left to caller order)
133 121 ▶ if( $opts->{format} && ref( $opts->{format} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"format"} and ref $opts->{"format"} eq "HASH") 3 118 121
Condition66%2/3
$opts->{"format"} and ref $opts->{"format"} eq "HASH"
!ll&&!rl&&r
11803
MC/DC50%1/2
$opts->{"format"} and ref $opts->{"format"} eq "HASH"
$opts->{"format"} ref $opts->{"format"} eq "HASH"
Truth table66%2/3
A and B
A= $opts->{"format"}B= ref $opts->{"format"} eq "HASH"
ABresult
0X0
100
111
134 {
135 3 $self->{formats}->{ $_ } = $opts->{format}->{ $_ } for( keys( %{$opts->{format}} ) );
136 }
137 121 ▶ $self->{vocab_support} = $opts->{vocab_support} ? { %{$opts->{vocab_support}} } : {};
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'vocab_support'} ? : 1 120 121
138  
139 121 ▶ $self->_check_vocabulary_required unless( $self->{ignore_req_vocab} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"ignore_req_vocab"} 120 1 121
140 120 ▶ $self->_register_builtin_media_validators() if( $self->{content_assert} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content_assert"} 1 119 120
141 120 ▶ $self->{compiled} = _compile_root( $self->{schema} ) if( $self->{compile_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"compile_on"} 10 110 120
142 120 return( $self );
143 }
144  
145 # $js->compile -> enables it
146 # $js->compile(1) -> enables it
147 # $js->compile(0) -> disables it
148 sub compile
149 1 ▶{
Subroutine compile: called CC=4 SCAR=15.0
Pod documented
150 1 my( $self, $bool ) = @_;
151 1 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 0 1 1
152 1 $self->{compile_on} = $on;
153  
154 1 ▶ if( $self->{compile_on} && !$self->{compiled} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compile_on"} and not $self->{"compiled"}) 1 0 1
Condition33%1/3
$self->{"compile_on"} and not $self->{"compiled"}
!ll&&!rl&&r
001
MC/DC0%0/2
$self->{"compile_on"} and not $self->{"compiled"}
$self->{"compile_on"} not $self->{"compiled"}
Truth table33%1/3
A and not(B)
A= $self->{"compile_on"}B= not $self->{"compiled"}
ABresult
0X0
100
111
155 {
156 1 $self->{compiled} = _compile_root( $self->{schema} );
157 }
158 1 return( $self );
159 }
160  
161 sub compile_js
162 0 ▶{
Subroutine compile_js: not called CC=7 SCAR=40.3
Pod documented
163 0 my $self = shift( @_ );
164 0 my $opts = $self->_get_args_as_hash( @_ );
165  
166 my $schema = $self->{schema}
167 0 ▶ or die( "No schema loaded; cannot compile to JavaScript" );
Branch: 1 branch
BranchTrueFalseTotal
my $schema = $self->{"schema"} or die "No schema loaded; cannot compile to JavaScript" 0 0 0
168  
169 # Public JS API name, e.g. "validateIncorporation"
170 my $name = exists( $opts->{name} ) && defined( $opts->{name} ) && length( $opts->{name} )
171 ? $opts->{name}
172 0 ▶ : 'validate';
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'name'} && defined $opts->{'name'} && length $opts->{'name'} ? : 0 0 0
Condition0%0/6
exists $opts->{"name"} and defined $opts->{"name"} and length $opts->{"name"}
!ll&&!rl&&r
000
exists $opts->{"name"} and defined $opts->{"name"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $opts->{"name"} and defined $opts->{"name"} and length $opts->{"name"}
exists $opts->{"name"} defined $opts->{"name"} length $opts->{"name"}
Truth table0%0/4
A and B and C
A= exists $opts->{"name"}B= defined $opts->{"name"}C= length $opts->{"name"}
ABCresult
0XX0
10X0
1100
1111
173  
174 # Max errors to collect on the client side
175 0 ▶ my $max_errors = exists( $opts->{max_errors} ) ? int( $opts->{max_errors} ) : 200;
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'max_errors'} ? : 0 0 0
176 0 ▶ $max_errors = 0 if( $max_errors < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $max_errors < 0 0 0 0
177  
178 0 my %seen; # schema_pointer -> function name
179 0 my $counter = 0; # for generating unique function names
180 0 my @funcs; # accumulated JS validator functions
181  
182 0 my $root_ptr = '#';
183  
184 # Pass $opts down so we can see ecma => ... inside the compiler.
185 0 my $root_fn = $self->_compile_js_node( $schema, $root_ptr, \%seen, \@funcs, \$counter, $schema, $opts );
186  
187 0 my $js = '';
188  
189 0 $js .= <<'JS_RUNTIME';
190 (function(global)
191 {
192 "use strict";
193  
194 function _jsv_err(ctx, path, keyword, message, schemaPtr)
195 {
196 if(ctx.maxErrors && ctx.errors.length >= ctx.maxErrors)
197 {
198 return;
199 }
200 ctx.errors.push({
201 path: path,
202 keyword: keyword,
203 message: message,
204 schema_pointer: schemaPtr
205 });
206 }
207  
208 function _jsv_typeOf(x)
209 {
210 if(x === null)
211 {
212 return "null";
213 }
214 if(Array.isArray ? Array.isArray(x) : Object.prototype.toString.call(x) === "[object Array]")
215 {
216 return "array";
217 }
218 var t = typeof x;
219 if(t === "number" && isFinite(x) && Math.floor(x) === x)
220 {
221 // distinguish "integer" for convenience
222 return "integer";
223 }
224 return t;
225 }
226  
227 function _jsv_hasOwn(obj, prop)
228 {
229 return Object.prototype.hasOwnProperty.call(obj, prop);
230 }
231  
232 JS_RUNTIME
233  
234 # Public entry point
235 0 $js .= <<"JS_RUNTIME";
236 function $name(instance)
237 {
238 var ctx = { errors: [], maxErrors: $max_errors };
239 $root_fn(instance, "#", ctx);
240 return ctx.errors;
241 }
242  
243 JS_RUNTIME
244  
245 # Attach to global (browser: window) in a conservative way
246 0 $js .= <<"JS_RUNTIME";
247 if(typeof global === 'object' && global)
248 {
249 global.$name = $name;
250 }
251  
252 JS_RUNTIME
253  
254 # Emit all compiled validator functions, indented one level
255 0 $js .= join( "\n\n", map{ ' ' . join( "\n ", split( /\n/, $_ ) ) } @funcs );
256  
257 0 $js .= <<'JS_RUNTIME';
258  
259 })(this);
260 JS_RUNTIME
261  
262 0 return( $js );
263 }
264  
265 # $js->content_checks -> enables it
266 # $js->content_checks(1) -> enables it
267 # $js->content_checks(0) -> disables it
268 sub content_checks
269 3 ▶{
Subroutine content_checks: called CC=4 SCAR=14.6
Pod documented
270 3 my( $self, $bool ) = @_;
271 3 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 3 0 3
272 3 ▶ $self->{content_assert} = $on ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$on ? : 3 0 3
273 3 ▶ $self->_register_builtin_media_validators() if( $self->{content_assert} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"content_assert"} 3 0 3
274 3 return( $self );
275 }
276  
277 # TODO: Backward compatibility, but need to remove it
278 {
279 44 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
280 44 *enable_content_checks = \&content_checks;
281 }
282  
283 21 ▶sub error { $_[0]->{last_error} }
Subroutine error: called CC=1 SCAR=0.0
Pod documented
284  
285 # We return a copy of the array reference containing the error objects
286 3 ▶sub errors { return( [@{$_[0]->{errors}}] ); }
Subroutine errors: called CC=1 SCAR=0.0
Pod documented
287  
288 sub extensions
289 1 ▶{
Subroutine extensions: called CC=2 SCAR=7.0
Pod documented
290 1 my( $self, $bool ) = @_;
291 1 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 1 0 1
292 1 $self->{extensions} = $on;
293 1 $self->unique_keys( $on );
294 1 return( $self );
295 }
296  
297 sub get_trace
298 3 ▶{
Subroutine get_trace: called CC=2 SCAR=7.1
Pod documented
299 3 my( $self ) = @_;
300 3 ▶ return( [@{ $self->{last_trace} || [] }] );
Condition50%1/2
$self->{'last_trace'} || []
l!l
30
MC/DC0%0/1
$self->{'last_trace'} || []
$self->{'last_trace'}
Truth table50%1/2
A
A= $self->{'last_trace'}
Aresult
11
00
301 }
302  
303 # Accessor-only method. See trace_limit for its mutator alter ego.
304 0 ▶sub get_trace_limit { 0 + ( $_[0]->{trace_limit} // 0 ) }
Subroutine get_trace_limit: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/2
$_[0]{"trace_limit"} // 0
l!l
00
MC/DC0%0/1
$_[0]{"trace_limit"} // 0
$_[0]{"trace_limit"}
Truth table0%0/2
A
A= $_[0]{"trace_limit"}
Aresult
11
00
305  
306 # $js->ignore_unknown_required_vocab -> enables it
307 # $js->ignore_unknown_required_vocab(1) -> enables it
308 # $js->ignore_unknown_required_vocab(0) -> disables it
309 sub ignore_unknown_required_vocab
310 0 ▶{
Subroutine ignore_unknown_required_vocab: not called CC=2 SCAR=17.9
Pod documented
311 0 my( $self, $bool ) = @_;
312 0 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 0 0 0
313 0 $self->{ignore_req_vocab} = $on;
314 0 return( $self );
315 }
316  
317 0 ▶sub is_compile_enabled { $_[0]->{compile_on} ? 1 : 0 }
Subroutine is_compile_enabled: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'compile_on'} ? : 0 0 0
318  
319 0 ▶sub is_content_checks_enabled { $_[0]->{content_assert} ? 1 : 0 }
Subroutine is_content_checks_enabled: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'content_assert'} ? : 0 0 0
320  
321 # Accessor only method. See trace or the mutator vession.
322 0 ▶sub is_trace_on { $_[0]->{trace_on} ? 1 : 0 }
Subroutine is_trace_on: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'trace_on'} ? : 0 0 0
323  
324 0 ▶sub is_unique_keys_enabled { $_[0]->{unique_keys} ? 1 : 0 }
Subroutine is_unique_keys_enabled: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'unique_keys'} ? : 0 0 0
325  
326 0 ▶sub is_unknown_required_vocab_ignored { $_[0]->{ignore_req_vocab} ? 1 : 0 }
Subroutine is_unknown_required_vocab_ignored: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{'ignore_req_vocab'} ? : 0 0 0
327  
328 sub is_valid
329 2 ▶{
Subroutine is_valid: called CC=3 SCAR=11.0
Pod documented
330 2 my $self = shift( @_ );
331 2 my $data = shift( @_ );
332  
333 2 my $opts = $self->_get_args_as_hash( @_ );
334 # Optional: allow overriding max_errors for this call only
335 # (e.g. $v->is_valid( $data, max_errors => 1 );)
336 2 ▶ $opts->{max_errors} //= 1;
Condition50%1/2
$opts->{"max_errors"} //= 1
l!l
02
MC/DC0%0/1
$opts->{"max_errors"} //= 1
$opts->{"max_errors"}
Truth table50%1/2
A
A= $opts->{"max_errors"}
Aresult
11
00
337  
338 # validate already populates $self->{errors}; is_valid just returns boolean
339 2 ▶ return( $self->validate( $data, $opts ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$self->validate($data, $opts) ? : 1 1 2
340 }
341  
342 # Example:
343 # my $pruned = $js->prune_instance( $incoming_data );
344 sub prune_instance
345 5 ▶{
Subroutine prune_instance: called CC=2 SCAR=7.0
Pod documented
346 5 my( $self, $data ) = @_;
347  
348 # Work on a cloned copy if normalize_instance is on,
349 # to remain consistent with validate().
350 5 ▶ if( $self->{normalize_instance} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"normalize_instance"}) 5 0 5
351 {
352 5 $data = _clone( $data );
353 }
354  
355 5 return( $self->_prune_with_schema( $self->{schema}, $data ) );
356 }
357  
358 sub prune_unknown
359 0 ▶{
Subroutine prune_unknown: not called CC=3 SCAR=24.8
Pod documented
360 0 my( $self, $bool ) = @_;
361 0 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 0 0 0
362 0 ▶ $self->{prune_unknown} = $on ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$on ? : 0 0 0
363 0 return( $self );
364 }
365  
366 sub register_builtin_formats
367 47 ▶{
Subroutine register_builtin_formats: called CC=7 SCAR=23.4
Pod documented
368 47 my( $self ) = @_;
369  
370 47 local $@;
371 0 ▶ my $has_iso = eval{ require DateTime::Format::ISO8601; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DateTime::Format::ISO8601; 1 } } ? : 0 47 47
372 47 ▶ my $has_tp = eval{ require Time::Piece; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Time::Piece; 1 } } ? : 47 0 47
373 0 ▶ my $has_dt = eval{ require DateTime; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DateTime; 1 } } ? : 0 47 47
374 0 ▶ my $has_idn = eval{ require Net::IDN::Encode; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Net::IDN::Encode; 1 } } ? : 0 47 47
375 # perl -MRegexp::Common=Email::Address -lE 'say $Regexp::Common::RE{Email}{Address}'
376 47 state $email_re = qr/\A(?:(?^u:(?:(?^u:(?>(?^u:(?^u:(?>(?^u:(?>(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|\.|\s*"(?^u:(?^u:[^\\"])|(?^u:\\(?^u:[^\x0A\x0D])))+"\s*))+))|(?>(?^u:(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*"(?^u:(?^u:[^\\"])|(?^u:\\(?^u:[^\x0A\x0D])))*"(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*)))+))?)(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*<(?^u:(?^u:(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*(?^u:(?>[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?:\.[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+)*))(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*"(?^u:(?^u:[^\\"])|(?^u:\\(?^u:[^\x0A\x0D])))*"(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*)))\@(?^u:(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*(?^u:(?>[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?:\.[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+)*))(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*\[(?:\s*(?^u:(?^u:[^\[\]\\])|(?^u:\\(?^u:[^\x0A\x0D]))))*\s*\](?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))))>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*)))|(?^u:(?^u:(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*(?^u:(?>[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?:\.[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+)*))(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*"(?^u:(?^u:[^\\"])|(?^u:\\(?^u:[^\x0A\x0D])))*"(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*)))\@(?^u:(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*(?^u:(?>[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+(?:\.[^\x00-\x1F\x7F()<>\[\]:;@\\,."\s]+)*))(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*))|(?^u:(?>(?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*\[(?:\s*(?^u:(?^u:[^\[\]\\])|(?^u:\\(?^u:[^\x0A\x0D]))))*\s*\](?^u:(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))|(?>\s+))*)))))(?>(?^u:(?>\s*\((?:\s*(?^u:(?^u:(?>[^()\\]+))|(?^u:\\(?^u:[^\x0A\x0D]))|))*\s*\)\s*))*)))\z/;
377  
378 47 my %F;
379  
380 # RFC3339 date-time / date / time
381 $F{'date-time'} = sub
382 2 ▶ {
Subroutine __ANON__: called CC=11 SCAR=34.5
383 2 my( $s ) = @_;
384 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
385  
386 # Preferred path when DateTime::Format::ISO8601 is available
387 2 ▶ if( $has_iso )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_iso) 0 2 2
388 {
389 0 ▶ return( eval{ DateTime::Format::ISO8601->parse_datetime( $s ) ? 1 : 0 } ? 1 : 0 );
Branch: 2 branches
BranchTrueFalseTotal
eval { do { 'DateTime::Format::ISO8601'->parse_datetime($s) ? 1 : 0 } } ? : 0 0 0
'DateTime::Format::ISO8601'->parse_datetime($s) ? : 0 0 0
390 }
391  
392 # YYYY-MM-DDThh:mm:ss[.fraction](Z|±hh:mm)
393 2 ▶ return(0) unless( $s =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\A (\d{4})-(\d{2})-(\d{2}) # date T (\d{2}):(\d{2}):(\d{2}) # time (?:\.\d+)? # optional fraction (?:Z|[+\-]\d{2}:\d{2}) # offset \z/ux 0 2 2
394 (\d{4})-(\d{2})-(\d{2}) # date
395 T
396 (\d{2}):(\d{2}):(\d{2}) # time
397 (?:\.\d+)? # optional fraction
398 (?:Z|[+\-]\d{2}:\d{2}) # offset
399 \z/x );
400  
401 2 my( $y, $m, $d, $H, $M, $S ) = ( $1, $2, $3, $4, $5, $6 );
402  
403 # Time::Piece is a core module (available since perl 5.10): use it first
404 2 ▶ if( $has_tp )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_tp) 2 0 2
405 {
406 # strptime validates calendar correctness (e.g. rejects Feb 30)
407 # We feed it the bare datetime without offset/fraction (already captured above)
408 2 my $bare = sprintf( '%04d-%02d-%02dT%02d:%02d:%02d', $y, $m, $d, $H, $M, $S );
409 2 ▶ return( eval{ Time::Piece->strptime( $bare, '%Y-%m-%dT%H:%M:%S' ); 1 } ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'Time::Piece'->strptime($bare, '%Y-%m-%dT%H:%M:%S'); 1 } } ? : 1 1 2
410 }
411  
412 # Fall back to DateTime if available
413 0 ▶ if( $has_dt )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dt) 0 0 0
414 {
415 return( eval
416 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'DateTime'->new('year', $y, 'month', $m, 'day', $d, 'hour', $H, 'minute', $M, 'second', $S); 1 } } ? : 0 0 0
417 0 DateTime->new(
418 year => $y,
419 month => $m,
420 day => $d,
421 hour => $H,
422 minute => $M,
423 second => $S
424 );
425 0 1
426 } ? 1 : 0 );
427 }
428  
429 # Last resort: the regex above was already sufficient for structural checks
430 0 return(1);
431 47 };
432  
433 $F{'date'} = sub
434 2 ▶ {
Subroutine __ANON__: called CC=8 SCAR=27.7
435 2 my( $s ) = @_;
436 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
437 2 ▶ return(0) unless( $s =~ /\A(\d{4})-(\d{2})-(\d{2})\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\A(\d{4})-(\d{2})-(\d{2})\z/u 0 2 2
438 2 my( $y, $m, $d ) = ( $1, $2, $3 );
439  
440 # Time::Piece is core - prefer it
441 2 ▶ if( $has_tp )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_tp) 2 0 2
442 {
443 2 ▶ return( eval{ Time::Piece->strptime( $s, '%Y-%m-%d' ); 1 } ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'Time::Piece'->strptime($s, '%Y-%m-%d'); 1 } } ? : 1 1 2
444 }
445  
446 # Fall back to DateTime if available
447 0 ▶ if( $has_dt )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_dt) 0 0 0
448 {
449 0 ▶ return( eval{ DateTime->new( year => $y, month => $m, day => $d ); 1 } ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { 'DateTime'->new('year', $y, 'month', $m, 'day', $d); 1 } } ? : 0 0 0
450 }
451  
452 # Last resort: structural regex already passed above
453 0 return(1);
454 47 };
455  
456 $F{'time'} = sub
457 2 ▶ {
Subroutine __ANON__: called CC=7 SCAR=26.5
458 2 my( $s ) = @_;
459 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
460 2 ▶ if( $has_iso )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_iso) 0 2 2
461 {
462 0 ▶ return eval{ DateTime::Format::ISO8601->parse_datetime( "1970-01-01T$s" ) ? 1 : 0 } ? 1 : 0;
Branch: 2 branches
BranchTrueFalseTotal
eval { do { 'DateTime::Format::ISO8601'->parse_datetime("1970-01-01T$s") ? 1 : 0 } } ? : 0 0 0
'DateTime::Format::ISO8601'->parse_datetime("1970-01-01T$s") ? : 0 0 0
463 }
464 2 ▶ return $s =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A (?:[01]\d|2[0-3]) # HH : (?:[0-5]\d) # MM : (?:[0-5]\d) # SS (?:\.\d+)? # .fraction (?:Z|[+\-](?:[01]\d|2[0-3]):[0-5]\d)? # offset \z/ux ? : 1 1 2
465 (?:[01]\d|2[0-3]) # HH
466 :
467 (?:[0-5]\d) # MM
468 :
469 (?:[0-5]\d) # SS
470 (?:\.\d+)? # .fraction
471 (?:Z|[+\-](?:[01]\d|2[0-3]):[0-5]\d)? # offset
472 \z/x ? 1 : 0;
473 47 };
474  
475 # Duration (RFC 3339 §5.6 / ISO 8601)
476 # Valid: P1Y, P3M, P1Y2M3DT4H5M6S, PT10S, P1W
477 # Invalid: P, PT, P1Y2M3DT (T with nothing after it, or no designator at all)
478 $F{'duration'} = sub
479 2 ▶ {
Subroutine __ANON__: called CC=11 SCAR=32.1
480 2 my( $s ) = @_;
481 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
482  
483 # Week form: PnW (stands alone; no mixing with other designators per ISO 8601)
484 2 ▶ return(1) if( $s =~ /\AP\d+W\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\AP\d+W\z/u 0 2 2
485  
486 # Full form: at least one date *or* time component must be present
487 # The T separator must be followed by at least one time designator
488 2 ▶ return( $s =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A P (?:(\d+)Y)? (?:(\d+)M)? (?:(\d+)D)? (?:T (?=\d) # T must be followed by at least one digit (?:(\d+)H)? (?:(\d+)M)? (?:(\d+(?:\.\d+)?)S)? )? \z/ux && (defined $1 || defined $2 || defined $3 || defined $4 || defined $5 || defined $6) ? : 1 1 2
Condition38%7/18
$s =~ /\A P (?:(\d+)Y)? (?:(\d+)M)? (?:(\d+)D)? (?:T (?=\d) # T must be followed by at least one digit (?:(\d+)H)? (?:(\d+)M)? (?:(\d+(?:\.\d+)?)S)? )? \z/ux and defined $1 || defined $2 || defined $3 || defined $4 || defined $5 || defined $6
!ll&&!rl&&r
101
defined $1 or defined $2 or defined $3 or defined $4 or defined $5 or defined $6
l!l&&r!l&&!r
100
defined $1 or defined $2 or defined $3 or defined $4 or defined $5
l!l&&r!l&&!r
100
defined $1 or defined $2 or defined $3 or defined $4
l!l&&r!l&&!r
100
defined $1 or defined $2 or defined $3
l!l&&r!l&&!r
100
defined $1 or defined $2
l!l&&r!l&&!r
100
MC/DC14%1/7
$s =~ /\A P (?:(\d+)Y)? (?:(\d+)M)? (?:(\d+)D)? (?:T (?=\d) # T must be followed by at least one digit (?:(\d+)H)? (?:(\d+)M)? (?:(\d+(?:\.\d+)?)S)? )? \z/ux and defined $1 || defined $2 || defined $3 || defined $4 || defined $5 || defined $6
$s =~ /\A P (?:(\d+)Y)? (?:(\d+)M)? (?:(\d+)D)? (?:T (?=\d) # T must be followed by at least one digit (?:(\d+)H)? (?:(\d+)M)? (?:(\d+(?:\.\d+)?)S)? )? \z/ux defined $1 defined $2 defined $3 defined $4 defined $5 defined $6
Truth table25%2/8
A and B or C or D or E or F or G
A= $s =~ /\A P (?:(\d+)Y)? (?:(\d+)M)? (?:(\d+)D)? (?:T (?=\d) # T must be followed by at least one digit (?:(\d+)H)? (?:(\d+)M)? (?:(\d+(?:\.\d+)?)S)? )? \z/uxB= defined $1C= defined $2D= defined $3E= defined $4F= defined $5G= defined $6
ABCDEFGresult
0XXXXXX0
10000000
11XXXXX1
101XXXX1
1001XXX1
10001XX1
100001X1
10000011
489 P
490 (?:(\d+)Y)?
491 (?:(\d+)M)?
492 (?:(\d+)D)?
493 (?:T
494 (?=\d) # T must be followed by at least one digit
495 (?:(\d+)H)?
496 (?:(\d+)M)?
497 (?:(\d+(?:\.\d+)?)S)?
498 )?
499 \z/x && ( defined($1) || defined($2) || defined($3) || defined($4) || defined($5) || defined($6) )
500 ? 1 : 0 );
501 47 };
502  
503 # Email / IDN email
504 # Plain email (ASCII) - unchanged
505 $F{'email'} = sub
506 13 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.9
507 13 my( $s ) = @_;
508 13 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 13 13
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
0013
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
509 13 ▶ return( $s =~ $email_re ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /$email_re/u ? : 12 1 13
510 47 };
511  
512 # IDN email: punycode the domain, validate with same regex
513 $F{'idn-email'} = sub
514 1 ▶ {
Subroutine __ANON__: called CC=10 SCAR=34.5
515 1 my( $s ) = @_;
516 1 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 1 1
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
517 1 ▶ return(0) unless( $s =~ /\A(.+)\@(.+)\z/s ); # keep local-part as-is (EAI allows UTF-8)
Branch: 1 branch
BranchTrueFalseTotal
unless $s =~ /\A(.+)\@(.+)\z/su 0 1 1
518 1 my( $local, $domain ) = ( $1, $2 );
519  
520 1 ▶ if( $has_idn )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_idn) 0 1 1
521 {
522 0 local $@;
523 0 my $ascii = eval{ Net::IDN::Encode::domain_to_ascii( $domain ) };
524 0 ▶ return(0) unless( defined( $ascii ) && length( $ascii ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ascii and length $ascii 0 0 0
Condition0%0/3
defined $ascii and length $ascii
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ascii and length $ascii
defined $ascii length $ascii
Truth table0%0/3
A and B
A= defined $asciiB= length $ascii
ABresult
0X0
100
111
525  
526 0 my $candidate = "$local\@$ascii";
527 0 ▶ return( $candidate =~ $email_re ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$candidate =~ /$email_re/u ? : 0 0 0
528 }
529  
530 # Fallback: if the domain already *looks* ASCII, validate directly
531 1 ▶ if( $domain =~ /\A[[:ascii:]]+\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($domain =~ /\A[[:ascii:]]+\z/u) 1 0 1
532 {
533 1 my $candidate = "$local\@$domain";
534 1 ▶ return( $candidate =~ $email_re ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$candidate =~ /$email_re/u ? : 1 0 1
535 }
536  
537 # Without IDN module, fall back to permissive Unicode domain check + ASCII regex
538 0 return(0);
539 47 };
540  
541 # Hostnames
542 $F{'hostname'} = sub
543 2 ▶ {
Subroutine __ANON__: called CC=8 SCAR=23.4
544 2 my( $s ) = @_;
545 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
546 2 ▶ return(0) if( length( $s ) > 253 );
Branch: 1 branch
BranchTrueFalseTotal
if length $s > 253 0 2 2
547 2 for my $label ( split( /\./, $s ) )
548 {
549 3 ▶ return(0) unless( length( $label ) >= 1 && length( $label ) <= 63 );
Branch: 1 branch
BranchTrueFalseTotal
unless length $label >= 1 and length $label <= 63 0 3 3
Condition33%1/3
length $label >= 1 and length $label <= 63
!ll&&!rl&&r
003
MC/DC0%0/2
length $label >= 1 and length $label <= 63
length $label >= 1 length $label <= 63
Truth table33%1/3
A and B
A= length $label >= 1B= length $label <= 63
ABresult
0X0
100
111
550 3 ▶ return(0) unless( $label =~ /\A[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $label =~ /\A[a-zA-Z0-9](?:[a-zA-Z0-9\-]*[a-zA-Z0-9])?\z/u 1 2 3
551 }
552 1 return(1);
553 47 };
554  
555 $F{'idn-hostname'} = sub
556 1 ▶ {
Subroutine __ANON__: called CC=12 SCAR=37.0
557 1 my( $s ) = @_;
558 1 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 1 1
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
559 1 ▶ if( $has_idn )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_idn) 0 1 1
560 {
561 0 local $@;
562 0 my $ascii = eval{ Net::IDN::Encode::domain_to_ascii( $s ) };
563 0 ▶ return(0) unless( defined( $ascii ) && length( $ascii ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $ascii and length $ascii 0 0 0
Condition0%0/3
defined $ascii and length $ascii
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ascii and length $ascii
defined $ascii length $ascii
Truth table0%0/3
A and B
A= defined $asciiB= length $ascii
ABresult
0X0
100
111
564 0 ▶ return( $F{'hostname'}->( $ascii ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$F{'hostname'}->($ascii) ? : 0 0 0
565 }
566  
567 # Fallback: permissive Unicode label check (as you had), then ASCII hostname rule
568 1 ▶ return(0) if( length( $s ) > 253 );
Branch: 1 branch
BranchTrueFalseTotal
if length $s > 253 0 1 1
569 1 for my $label ( split( /\./, $s ) )
570 {
571 2 ▶ return(0) unless( length( $label ) >= 1 && length( $label ) <= 63 );
Branch: 1 branch
BranchTrueFalseTotal
unless length $label >= 1 and length $label <= 63 0 2 2
Condition33%1/3
length $label >= 1 and length $label <= 63
!ll&&!rl&&r
002
MC/DC0%0/2
length $label >= 1 and length $label <= 63
length $label >= 1 length $label <= 63
Truth table33%1/3
A and B
A= length $label >= 1B= length $label <= 63
ABresult
0X0
100
111
572 2 ▶ return(0) unless( $label =~ /\A[[:alnum:]\pL\pN](?:[[:alnum:]\pL\pN\-]*[[:alnum:]\pL\pN])?\z/u );
Branch: 1 branch
BranchTrueFalseTotal
unless $label =~ /\A[[:alnum:]\pL\pN](?:[[:alnum:]\pL\pN\-]*[[:alnum:]\pL\pN])?\z/u 0 2 2
573 }
574 1 return(1);
575 47 };
576  
577 # IP addresses
578 $F{'ipv4'} = sub
579 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.9
580 2 my( $s ) = @_;
581 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
582 2 ▶ return $s =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\. (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\. (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\. (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d) \z/ux ? : 1 1 2
583 (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.
584 (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.
585 (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)\.
586 (25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)
587 \z/x ? 1 : 0;
588 47 };
589  
590 $F{'ipv6'} = sub
591 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.9
592 2 my( $s ) = @_;
593 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
594 2 ▶ return $s =~ /\A
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A (?: (?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4} | (?:[0-9A-Fa-f]{1,4}:){1,7}: | (?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4} | (?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2} | (?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3} | (?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4} | (?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5} | [0-9A-Fa-f]{1,4}:(?:(?::[0-9A-Fa-f]{1,4}){1,6}) | :(?:(?::[0-9A-Fa-f]{1,4}){1,7}|:) | (?:[0-9A-Fa-f]{1,4}:){6} (?:\d{1,3}\.){3}\d{1,3} | ::(?:[0-9A-Fa-f]{1,4}:){0,5} (?:\d{1,3}\.){3}\d{1,3} | (?:[0-9A-Fa-f]{1,4}:){1,5}: (?:\d{1,3}\.){3}\d{1,3} ) \z/ux ? : 1 1 2
595 (?: (?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}
596 | (?:[0-9A-Fa-f]{1,4}:){1,7}:
597 | (?:[0-9A-Fa-f]{1,4}:){1,6}:[0-9A-Fa-f]{1,4}
598 | (?:[0-9A-Fa-f]{1,4}:){1,5}(?::[0-9A-Fa-f]{1,4}){1,2}
599 | (?:[0-9A-Fa-f]{1,4}:){1,4}(?::[0-9A-Fa-f]{1,4}){1,3}
600 | (?:[0-9A-Fa-f]{1,4}:){1,3}(?::[0-9A-Fa-f]{1,4}){1,4}
601 | (?:[0-9A-Fa-f]{1,4}:){1,2}(?::[0-9A-Fa-f]{1,4}){1,5}
602 | [0-9A-Fa-f]{1,4}:(?:(?::[0-9A-Fa-f]{1,4}){1,6})
603 | :(?:(?::[0-9A-Fa-f]{1,4}){1,7}|:)
604 | (?:[0-9A-Fa-f]{1,4}:){6}
605 (?:\d{1,3}\.){3}\d{1,3}
606 | ::(?:[0-9A-Fa-f]{1,4}:){0,5}
607 (?:\d{1,3}\.){3}\d{1,3}
608 | (?:[0-9A-Fa-f]{1,4}:){1,5}:
609 (?:\d{1,3}\.){3}\d{1,3}
610 )
611 \z/x ? 1 : 0;
612 47 };
613  
614 # URI/IRI
615 $F{'uri'} = sub
616 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.9
617 2 my( $s ) = @_;
618 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
619 2 ▶ return( $s =~ /\A[A-Za-z][A-Za-z0-9+\-.]*:[^\s]+\z/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A[A-Za-z][A-Za-z0-9+\-.]*:[^\s]+\z/u ? : 1 1 2
620 47 };
621  
622 $F{'uri-reference'} = sub
623 1 ▶ {
Subroutine __ANON__: called CC=4 SCAR=16.1
624 1 my( $s ) = @_;
625 1 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 1 1
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
626 1 ▶ return( $s =~ /\A(?:[A-Za-z][A-Za-z0-9+\-.]*:)?[^\s]+\z/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A(?:[A-Za-z][A-Za-z0-9+\-.]*:)?[^\s]+\z/u ? : 1 0 1
627 47 };
628  
629 $F{'iri'} = sub
630 1 ▶ {
Subroutine __ANON__: called CC=4 SCAR=16.1
631 1 my( $s ) = @_;
632 1 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 1 1
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
001
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
633 # Must have a scheme (letters followed by colon) per RFC 3987 §2.2
634 # Scheme: ALPHA *( ALPHA / DIGIT / "+" / "-" / "." )
635 # After scheme: at least one non-whitespace character
636 1 ▶ return( $s =~ /\A[A-Za-z][A-Za-z0-9+\-.]*:[^\s]+\z/u ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A[A-Za-z][A-Za-z0-9+\-.]*:[^\s]+\z/u ? : 1 0 1
637 47 };
638  
639 # UUID
640 $F{'uuid'} = sub
641 3 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.9
642 3 my( $s ) = @_;
643 3 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 3 3
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
003
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
644 3 ▶ return( $s =~ /\A[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}\z/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ /\A[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12}\z/u ? : 1 2 3
645 47 };
646  
647 # JSON Pointer / Relative JSON Pointer
648 $F{'json-pointer'} = sub
649 3 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.7
650 3 my( $s ) = @_;
651 3 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 3 3
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
003
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
652 3 ▶ return(1) if( $s eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if $s eq "" 1 2 3
653 2 ▶ return( $s =~ m{\A/(?:[^~/]|~[01])*(?:/(?:[^~/]|~[01])*)*\z} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ m[\A/(?:[^~/]|~[01])*(?:/(?:[^~/]|~[01])*)*\z]u ? : 1 1 2
654 47 };
655  
656 $F{'relative-json-pointer'} = sub
657 3 ▶ {
Subroutine __ANON__: called CC=5 SCAR=16.7
658 3 my( $s ) = @_;
659 3 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 3 3
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
003
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
660 3 ▶ return(1) if( $s =~ /\A0\z/ );
Branch: 1 branch
BranchTrueFalseTotal
if $s =~ /\A0\z/u 1 2 3
661 2 ▶ return( $s =~ m,\A[1-9]\d*(?:#|(?:/(?:[^~/]|~[01])*)*)\z, ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s =~ m[\A[1-9]\d*(?:#|(?:/(?:[^~/]|~[01])*)*)\z]u ? : 1 1 2
662 47 };
663  
664 # Regex
665 $F{'regex'} = sub
666 2 ▶ {
Subroutine __ANON__: called CC=4 SCAR=14.3
667 2 my( $s ) = @_;
668 2 ▶ return(0) unless( defined( $s ) && !ref( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s and not ref $s 0 2 2
Condition33%1/3
defined $s and not ref $s
!ll&&!rl&&r
002
MC/DC0%0/2
defined $s and not ref $s
defined $s not ref $s
Truth table33%1/3
A and not(B)
A= defined $sB= not ref $s
ABresult
0X0
100
111
669 2 local $@;
670 2 ▶ return( eval{ "" =~ /$s/; 1 } ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { '' =~ /$s/u; 1 } } ? : 1 1 2
671 47 };
672  
673 47 ▶ while( my( $k, $v ) = each( %F ) )
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %F) 799 47 846
674 {
675 799 ▶ $self->{formats}->{ $k } = $v unless( exists( $self->{formats}->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"formats"}{$k} 799 0 799
676 }
677  
678 47 return( $self );
679 }
680  
681 sub register_content_decoder
682 1 ▶{
Subroutine register_content_decoder: called CC=2 SCAR=7.4
Pod documented
683 1 my( $self, $name, $cb ) = @_;
684 1 ▶ if( ref( $cb ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cb eq 'CODE') { } 1 0 1
685 {
686 1 $self->{content_decoders}->{ lc( "$name" ) } = $cb;
687 }
688 else
689 {
690 0 die( "content decoder must be a code reference" );
691 }
692 1 return( $self );
693 }
694  
695 sub register_format
696 0 ▶{
Subroutine register_format: not called CC=4 SCAR=30.0
Pod documented
697 0 my( $self, $name, $code ) = @_;
698 0 ▶ die( "format name required" ) unless( defined( $name ) && length( $name ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 0 0
Condition0%0/3
defined $name and length $name
!ll&&!rl&&r
000
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table0%0/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
699 0 ▶ die( "format validator must be a coderef" ) unless( ref( $code ) eq 'CODE' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $code eq "CODE" 0 0 0
700 0 $self->{formats}->{ $name } = $code;
701 0 return( $self );
702 }
703  
704 sub register_media_validator
705 5 ▶{
Subroutine register_media_validator: called CC=2 SCAR=7.4
Pod documented
706 5 my( $self, $type, $cb ) = @_;
707 5 ▶ if( ref( $cb ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $cb eq 'CODE') { } 5 0 5
708 {
709 5 $self->{media_validators}->{ lc( "$type" ) } = $cb;
710 }
711 else
712 {
713 0 die( "media validator must be a code reference" );
714 }
715 5 return( $self );
716 }
717  
718 sub set_comment_handler
719 4 ▶{
Subroutine set_comment_handler: called CC=5 SCAR=16.2
Pod documented
720 4 my( $self, $code ) = @_;
721 4 ▶ if( @_ > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 4 0 4
722 {
723 4 ▶ if( defined( $code ) && ref( $code ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and ref $code ne "CODE") 1 3 4
Condition100%3/3
defined $code and ref $code ne "CODE"
!ll&&!rl&&r
121
MC/DC100%2/2
defined $code and ref $code ne "CODE"
defined $code ref $code ne "CODE"
Truth table100%3/3
A and B
A= defined $codeB= ref $code ne "CODE"
ABresult
0X0
100
111
724 {
725 1 ▶ warn( "Warning only: the handler provided is not a code reference." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 1 0 1
726 1 return( $self );
727 }
728 3 $self->{comment_handler} = $code;
729 }
730 3 return( $self );
731 }
732  
733 sub set_resolver
734 2 ▶{
Subroutine set_resolver: called CC=5 SCAR=20.9
Pod documented
735 2 my( $self, $code ) = @_;
736 2 ▶ if( @_ > 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 2 0 2
737 {
738 2 ▶ if( defined( $code ) && ref( $code ) ne 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $code and ref $code ne "CODE") 0 2 2
Condition33%1/3
defined $code and ref $code ne "CODE"
!ll&&!rl&&r
020
MC/DC0%0/2
defined $code and ref $code ne "CODE"
defined $code ref $code ne "CODE"
Truth table33%1/3
A and B
A= defined $codeB= ref $code ne "CODE"
ABresult
0X0
100
111
739 {
740 0 ▶ warn( "Warning only: the handler provided is not a code reference." ) if( warnings::enabled() );
Branch: 1 branch
BranchTrueFalseTotal
if warnings::enabled() 0 0 0
741 0 return( $self );
742 }
743 2 $self->{resolver} = $code;
744 }
745 2 return( $self );
746 }
747  
748 sub set_vocabulary_support
749 0 ▶{
Subroutine set_vocabulary_support: not called CC=2 SCAR=17.9
Pod documented
750 0 my( $self, $h ) = @_;
751 0 ▶ $self->{vocab_support} = { %{ $h || {} } };
Condition0%0/2
$h || {}
l!l
00
MC/DC0%0/1
$h || {}
$h
Truth table0%0/2
A
A= $h
Aresult
11
00
752 0 $self->{vocab_checked} = 0;
753 0 return( $self );
754 }
755  
756 # This is a mutator only method
757 # $js->trace -> enables it
758 # $js->trace(1) -> enables it
759 # $js->trace(0) -> disables it
760 # Always returns the object
761 # See is_trace_on for the accessor method
762 sub trace
763 1 ▶{
Subroutine trace: called CC=2 SCAR=7.0
Pod documented
764 1 my( $self, $bool ) = @_;
765 1 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 1 0 1
766 1 $self->{trace_on} = $on;
767 1 return( $self );
768 }
769  
770 sub trace_limit
771 0 ▶{
Subroutine trace_limit: not called CC=2 SCAR=17.9
Pod documented
772 0 my( $self, $n ) = @_;
773 0 ▶ $self->{trace_limit} = 0 + ( $n || 0 );
Condition0%0/2
$n || 0
l!l
00
MC/DC0%0/1
$n || 0
$n
Truth table0%0/2
A
A= $n
Aresult
11
00
774 0 return( $self );
775 }
776  
777 sub trace_sample
778 0 ▶{
Subroutine trace_sample: not called CC=2 SCAR=17.9
Pod documented
779 0 my( $self, $pct ) = @_;
780 0 ▶ $self->{trace_sample} = 0 + ( $pct || 0 );
Condition0%0/2
$pct || 0
l!l
00
MC/DC0%0/1
$pct || 0
$pct
Truth table0%0/2
A
A= $pct
Aresult
11
00
781 0 return( $self );
782 }
783  
784 sub unique_keys
785 9 ▶{
Subroutine unique_keys: called CC=2 SCAR=7.0
Pod documented
786 9 my( $self, $bool ) = @_;
787 9 ▶ my $on = defined( $bool ) ? $bool : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $bool ? : 9 0 9
788 9 $self->{unique_keys} = $on;
789 9 return( $self );
790 }
791  
792 sub validate
793 218 ▶{
Subroutine validate: called CC=30 SCAR=46.1
Pod documented
794 218 my $self = shift( @_ );
795 218 my $data = shift( @_ );
796 218 my $opts = $self->_get_args_as_hash( @_ );
797  
798 218 $self->{errors} = [];
799 218 $self->{last_error} = '';
800  
801 # Ensure we have the compiled root (indexing/anchors) even in lazy mode
802 218 ▶ $self->{compiled} = _compile_root( $self->{schema} ) unless( $self->{compiled} );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"compiled"} 103 115 218
803  
804 # One-time $vocabulary check (Draft 2020-12)
805 218 ▶ if( !$self->{vocab_checked} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"vocab_checked"}) 0 218 218
806 {
807 0 my $root = $self->{schema};
808 0 ▶ if( ref( $root ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH") 0 0 0
Condition0%0/3
ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH"
ref $root eq "HASH" ref $root->{"\$vocabulary"} eq "HASH"
Truth table0%0/3
A and B
A= ref $root eq "HASH"B= ref $root->{"\$vocabulary"} eq "HASH"
ABresult
0X0
100
111
809 ref( $root->{'$vocabulary'} ) eq 'HASH' )
810 {
811 0 my $decl = $root->{'$vocabulary'}; # { uri => JSON::true|false, ... }
812 0 ▶ my $support = $self->{vocab_support} || {};
Condition0%0/2
$self->{'vocab_support'} || {}
l!l
00
MC/DC0%0/1
$self->{'vocab_support'} || {}
$self->{'vocab_support'}
Truth table0%0/2
A
A= $self->{'vocab_support'}
Aresult
11
00
813 0 for my $uri ( keys( %$decl ) )
814 {
815 0 ▶ next unless( $decl->{ $uri } ); # only enforce for required=true
Branch: 1 branch
BranchTrueFalseTotal
unless $decl->{$uri} 0 0 0
816 0 ▶ next if( $support->{ $uri } ); # caller says it's supported
Branch: 1 branch
BranchTrueFalseTotal
if $support->{$uri} 0 0 0
817 0 ▶ unless( $self->{ignore_req_vocab} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"ignore_req_vocab"}) 0 0 0
818 {
819 0 die( "Required vocabulary not supported: $uri" );
820 }
821 }
822 }
823 0 $self->{vocab_checked} = 1;
824 }
825  
826 # Because Perl scalar are not JSON scalar, we force the Perl structure into strict JSON types, eliminating all Perl duality and guaranteeing predictable validation semantics.
827 218 ▶ if( $self->{normalize_instance} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"normalize_instance"}) 218 0 218
828 {
829 218 $data = _clone( $data );
830 }
831  
832 # Optional pre-validation pruning of unknown properties / nested objects.
833 # This only happens if explicitly enabled via prune_unknown => 1.
834 218 ▶ if( $self->{prune_unknown} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"prune_unknown"}) 1 217 218
835 {
836 1 $data = $self->_prune_with_schema( $self->{schema}, $data );
837 }
838  
839 my $ctx =
840 {
841 root => $self->{compiled},
842 instance_root => $data,
843 resolver => $self->{resolver},
844 formats => $self->{formats},
845 errors => $self->{errors},
846 max_errors => ( ( defined( $opts->{max_errors} ) && $opts->{max_errors} =~ /^\d+$/ ) ? $opts->{max_errors} : $self->{max_errors} ),
847 error_count => 0,
848  
849 # paths / recursion
850 ptr_stack => ['#'],
851 id_stack => [ $self->{compiled}->{base} ],
852 dyn_stack => [ {} ], # dynamicAnchor scope frames
853 visited => {}, # "schema_ptr|inst_addr" => 1
854  
855 # annotation (for unevaluated*)
856 ann_mode => 1,
857 compile_on => ( defined( $opts->{compile_on} ) ? ( $opts->{compile_on} ? 1 : 0 ) : ( $self->{compile_on} ? 1 : 0 ) ),
858  
859 # trace
860 trace_on => ( defined( $opts->{trace_on} ) ? ( $opts->{trace_on} ? 1 : 0 ) : ( $self->{trace_on} ? 1 : 0 ) ),
861 trace_sample => $self->{trace_sample} || 0,
862 trace_limit => ( defined( $opts->{trace_limit} ) && $opts->{trace_limit} =~ /^\d+$/ ) ? $opts->{trace_limit} : ( $self->{trace_limit} || 0 ),
863 trace => [],
864  
865 # content assertion & helpers
866 content_assert => ( defined( $opts->{content_assert} ) ? ( $opts->{content_assert} ? 1 : 0 ) : ( $self->{content_assert} ? 1 : 0 ) ),
867 media_validators => $self->{media_validators},
868 content_decoders => $self->{content_decoders},
869  
870 comment_handler => $self->{comment_handler},
871  
872 # extensions
873 unique_keys => $self->{unique_keys},
874 extensions => $self->{extensions},
875 218 ▶ };
Branch: 11 branches
BranchTrueFalseTotal
defined $opts->{'max_errors'} && $opts->{'max_errors'} =~ /^\d+$/u ? : 3 215 218
defined $opts->{'compile_on'} ? : 0 218 218
$opts->{'compile_on'} ? : 0 0 0
$self->{'compile_on'} ? : 13 205 218
defined $opts->{'trace_on'} ? : 0 218 218
$opts->{'trace_on'} ? : 0 0 0
$self->{'trace_on'} ? : 6 212 218
defined $opts->{'trace_limit'} && $opts->{'trace_limit'} =~ /^\d+$/u ? : 0 218 218
defined $opts->{'content_assert'} ? : 0 218 218
$opts->{'content_assert'} ? : 0 0 0
$self->{'content_assert'} ? : 6 212 218
Condition70%7/10
defined $opts->{"max_errors"} and $opts->{"max_errors"} =~ /^\d+$/u
!ll&&!rl&&r
21503
$self->{'trace_sample'} || 0
l!l
2216
defined $opts->{"trace_limit"} and $opts->{"trace_limit"} =~ /^\d+$/u
!ll&&!rl&&r
21800
$self->{"trace_limit"} or 0
l!l
7211
MC/DC50%1/2
defined $opts->{"max_errors"} and $opts->{"max_errors"} =~ /^\d+$/u
defined $opts->{"max_errors"} $opts->{"max_errors"} =~ /^\d+$/u
MC/DC100%1/1
$self->{'trace_sample'} || 0
$self->{'trace_sample'}
MC/DC0%0/2
defined $opts->{"trace_limit"} and $opts->{"trace_limit"} =~ /^\d+$/u
defined $opts->{"trace_limit"} $opts->{"trace_limit"} =~ /^\d+$/u
MC/DC100%1/1
$self->{"trace_limit"} or 0
$self->{"trace_limit"}
Truth table66%2/3
A and B
A= defined $opts->{"max_errors"}B= $opts->{"max_errors"} =~ /^\d+$/u
ABresult
0X0
100
111
Truth table100%2/2
A
A= $self->{'trace_sample'}
Aresult
11
00
Truth table33%1/3
A and B
A= defined $opts->{"trace_limit"}B= $opts->{"trace_limit"} =~ /^\d+$/u
ABresult
0X0
100
111
Truth table100%2/2
A
A= $self->{"trace_limit"}
Aresult
11
00
876  
877 # Guarantee at least one trace entry when trace is enabled
878 218 ▶ if( $ctx->{trace_on} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"trace_on"}) 6 212 218
879 {
880 6 push( @{$ctx->{trace}},
881 {
882 schema_ptr => '#',
883 keyword => 'validate',
884 inst_path => '#',
885 outcome => 'start',
886 note => 'start',
887 });
888 }
889  
890 218 my $res = _v( $ctx, '#', $self->{compiled}->{schema}, $data );
891  
892 218 $self->{last_trace} = $ctx->{trace};
893  
894 218 ▶ if( !$res->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($res->{"ok"}) 106 112 218
895 {
896 # $self->{last_error} = _first_error_text( $self->{errors} );
897 106 ▶ $self->{last_error} = scalar( @{$self->{errors}} ) ? $self->{errors}->[0] : '';
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$self->{'errors'};} ? : 106 0 106
898 106 return(0);
899 }
900 112 return(1);
901 }
902  
903 sub _apply_dynamic_ref
904 5 ▶{
Subroutine _apply_dynamic_ref: called CC=4 SCAR=14.5
905 5 my( $ctx, $schema_ptr, $ref, $inst ) = @_;
906  
907 5 ▶ if( $ref =~ /\#(.+)\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /\#(.+)\z/u) 5 0 5
908 {
909 5 my $name = $1;
910 5 ▶ for( my $i = $#{ $ctx->{dyn_stack} }; $i >= 0; $i-- )
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= 0) 5 0 5
911 {
912 5 my $frame = $ctx->{dyn_stack}->[$i];
913 5 ▶ if( my $node = $frame->{ $name } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $frame->{$name}) 5 0 5
914 {
915 5 my $sp = _ptr_of_node( $ctx->{root}, $node );
916 5 return( _v( $ctx, $sp, $node, $inst ) );
917 }
918 }
919 }
920  
921 0 return( _apply_ref( $ctx, $schema_ptr, $ref, $inst ) );
922 }
923  
924 # $ref and $dynamicRef
925 sub _apply_ref
926 22 ▶{
Subroutine _apply_ref: called CC=21 SCAR=40.4
927 22 my( $ctx, $schema_ptr, $ref, $inst ) = @_;
928  
929 22 my $base = $ctx->{id_stack}->[-1];
930 22 my $abs = _resolve_uri( $base, $ref );
931  
932 # Direct absolute ID/anchor hit
933 22 ▶ if( my $node = $ctx->{root}->{id_index}->{ $abs } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $ctx->{"root"}{"id_index"}{$abs}) 3 19 22
934 {
935 3 my $sp = _ptr_of_node( $ctx->{root}, $node );
936 3 return( _v( $ctx, $sp, $node, $inst ) );
937 }
938  
939 # Local fragment
940 19 ▶ if( $ref =~ /^\#/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /^\#/u) 14 5 19
941 {
942 # 1) Try anchors (e.g. "#foo" / "#MyAnchor")
943 14 ▶ if( my $n = $ctx->{root}->{anchors}->{ $ref } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $n = $ctx->{"root"}{"anchors"}{$ref}) 5 9 14
944 {
945 5 return( _v( $ctx, $ref, $n, $inst ) );
946 }
947 9 ▶ if( $ref =~ /^\#([A-Za-z0-9._-]+)\z/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /^\#([A-Za-z0-9._-]+)\z/u) 0 9 9
948 {
949 0 my $cand = $base . '#' . $1;
950 0 ▶ if( my $node = $ctx->{root}->{id_index}->{ $cand } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $ctx->{"root"}{"id_index"}{$cand}) 0 0 0
951 {
952 0 my $sp = _ptr_of_node( $ctx->{root}, $node );
953 0 return( _v( $ctx, $sp, $node, $inst ) );
954 }
955 }
956 # 2) If it’s a JSON Pointer ( "#/..." ), use _jsv_resolve_internal_ref
957 9 ▶ if( $ref =~ m{\A\#/(?:[^~/]|~[01])} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ m[\A\#/(?:[^~/]|~[01])]u) 9 0 9
958 {
959 # or pulled from id_index; same one used in compile_js
960 9 ▶ my $root_schema = $ctx->{root}->{schema} or return( _err_res( $ctx, $schema_ptr, "missing schema", '$ref' ) );
Branch: 1 branch
BranchTrueFalseTotal
my $root_schema = $ctx->{"root"}{"schema"} or return _err_res($ctx, $schema_ptr, "missing schema", "\$ref") 9 0 9
961  
962 9 my $node = _jsv_resolve_internal_ref( $root_schema, $ref );
963 9 ▶ if( $node )
Branch: 1 branch
BranchTrueFalseTotal
if ($node) 8 1 9
964 {
965 8 return( _v( $ctx, $ref, $node, $inst ) );
966 }
967  
968 1 return _err_res(
969 $ctx,
970 $schema_ptr,
971 "unresolved JSON Pointer fragment in \$ref: $abs",
972 '$ref'
973 );
974 }
975 # 3) If not a JSON Pointer and not an anchor, fall through to external resolver / error
976 }
977  
978 # External resolver hook
979 5 ▶ if( $ctx->{resolver} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"resolver"}) 5 0 5
980 {
981 5 local $@;
982 5 my $ext = eval{ $ctx->{resolver}->( $abs ) };
983 5 ▶ return( _err_res( $ctx, $schema_ptr, "resolver failed for \$ref: $abs", '$ref' ) ) unless( $ext && ref( $ext ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $ext and ref $ext 0 5 5
Condition33%1/3
$ext and ref $ext
!ll&&!rl&&r
005
MC/DC0%0/2
$ext and ref $ext
$ext ref $ext
Truth table33%1/3
A and B
A= $extB= ref $ext
ABresult
0X0
100
111
984  
985 5 ▶ my $ext_base = _normalize_uri( ( ref( $ext ) eq 'HASH' && $ext->{'$id'} ) ? $ext->{'$id'} : $abs );
Branch: 1 branch
BranchTrueFalseTotal
ref $ext eq 'HASH' && $ext->{'$id'} ? : 5 0 5
Condition33%1/3
ref $ext eq "HASH" and $ext->{"\$id"}
!ll&&!rl&&r
005
MC/DC0%0/2
ref $ext eq "HASH" and $ext->{"\$id"}
ref $ext eq "HASH" $ext->{"\$id"}
Truth table33%1/3
A and B
A= ref $ext eq "HASH"B= $ext->{"\$id"}
ABresult
0X0
100
111
986  
987 5 my( $frag ) = ( $abs =~ /(\#.*)\z/ );
988 5 my ( $anchors, $ids ) = ( {}, {} );
989 5 _index_schema_202012( $ext, $ext_base, '#', $anchors, $ids );
990  
991 5 push( @{$ctx->{id_stack}}, $ext_base );
992  
993 # If the abs URI included a JSON Pointer fragment, honor it here
994 5 my $target_ptr = '#';
995 5 ▶ if( defined( $frag ) && length( $frag ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $frag and length $frag) 5 0 5
Condition33%1/3
defined $frag and length $frag
!ll&&!rl&&r
005
MC/DC0%0/2
defined $frag and length $frag
defined $frag length $frag
Truth table33%1/3
A and B
A= defined $fragB= length $frag
ABresult
0X0
100
111
996 {
997 5 ▶ if( $frag =~ m{\A\#/(?:[^~/]|~[01])} )
Branch: 2 branches
BranchTrueFalseTotal
if ($frag =~ m[\A\#/(?:[^~/]|~[01])]u) { } 5 0 5
elsif ($frag =~ /\A\#([A-Za-z0-9._-]+)\z/u) { } 0 0 0
998 {
999 # JSON Pointer fragment
1000 5 ▶ if( my $node = $anchors->{ $frag } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $anchors->{$frag}) { } 5 0 5
1001 {
1002 5 my $r = _v( $ctx, $frag, $node, $inst );
1003 5 pop( @{$ctx->{id_stack}} );
1004 5 return( $r );
1005 }
1006 else
1007 {
1008 0 pop( @{$ctx->{id_stack}} );
1009 0 return( _err_res( $ctx, $schema_ptr, "unresolved JSON Pointer fragment in \$ref: $abs", '$ref' ) );
1010 }
1011 }
1012 elsif( $frag =~ /\A\#([A-Za-z0-9._-]+)\z/ )
1013 {
1014 0 my $cand = $ext_base . '#' . $1;
1015 0 ▶ if( my $node = $ids->{ $cand } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $ids->{$cand}) 0 0 0
1016 {
1017 0 ▶ my $sp = _ptr_of_node( { anchors => $anchors }, $node ) || '#';
Condition0%0/2
_ptr_of_node({'anchors', $anchors}, $node) || '#'
l!l
00
MC/DC0%0/1
_ptr_of_node({'anchors', $anchors}, $node) || '#'
_ptr_of_node({'anchors', $anchors}, $node)
Truth table0%0/2
A
A= _ptr_of_node({'anchors', $anchors}, $node)
Aresult
11
00
1018 0 my $r = _v( $ctx, $sp, $node, $inst );
1019 0 pop( @{$ctx->{id_stack}} );
1020 0 return( $r );
1021 }
1022 }
1023 }
1024  
1025 0 my $r = _v( $ctx, '#', $ext, $inst );
1026 0 pop( @{$ctx->{id_stack}} );
1027 0 return( $r );
1028 }
1029  
1030 0 return( _err_res( $ctx, $schema_ptr, "unresolved \$ref: $ref (abs: $abs)", '$ref' ) );
1031 }
1032  
1033 sub _canon
1034 86 ▶{
Subroutine _canon: called CC=1 SCAR=0.0
1035 86 my( $v ) = @_;
1036 86 state $json = JSON->new->allow_nonref(1)->canonical(1)->convert_blessed(1);
1037 86 return( $json->encode( $v ) );
1038 }
1039  
1040 sub _check_vocabulary_required
1041 120 ▶{
Subroutine _check_vocabulary_required: called CC=8 SCAR=21.2
1042 120 my( $self ) = @_;
1043 120 ▶ return(1) if( $self->{vocab_checked} );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"vocab_checked"} 0 120 120
1044  
1045 120 my $root = $self->{schema};
1046 120 ▶ if( ref( $root ) eq 'HASH' && ref( $root->{'$vocabulary'} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH") 2 118 120
Condition66%2/3
ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH"
!ll&&!rl&&r
01182
MC/DC50%1/2
ref $root eq "HASH" and ref $root->{"\$vocabulary"} eq "HASH"
ref $root eq "HASH" ref $root->{"\$vocabulary"} eq "HASH"
Truth table66%2/3
A and B
A= ref $root eq "HASH"B= ref $root->{"\$vocabulary"} eq "HASH"
ABresult
0X0
100
111
1047 {
1048 2 my $decl = $root->{'$vocabulary'};
1049 2 ▶ my $support = $self->{vocab_support} || {};
Condition50%1/2
$self->{'vocab_support'} || {}
l!l
20
MC/DC0%0/1
$self->{'vocab_support'} || {}
$self->{'vocab_support'}
Truth table50%1/2
A
A= $self->{'vocab_support'}
Aresult
11
00
1050 2 for my $uri ( keys( %$decl ) )
1051 {
1052 # required only
1053 2 ▶ next unless( $decl->{ $uri } );
Branch: 1 branch
BranchTrueFalseTotal
unless $decl->{$uri} 1 1 2
1054 1 ▶ next if( $support->{ $uri } );
Branch: 1 branch
BranchTrueFalseTotal
if $support->{$uri} 0 1 1
1055 # TODO: Maybe we should return an exception rather than dying; it would be more user-friendly
1056 1 die( "Required vocabulary not supported: $uri" );
1057 }
1058 }
1059 119 return( $self->{vocab_checked} = 1 );
1060 }
1061  
1062 sub _clone
1063 344 ▶{
Subroutine _clone: called CC=1 SCAR=0.0
1064 344 my( $v ) = @_;
1065 344 state $json = JSON->new->allow_nonref(1)->canonical(1);
1066 344 return( $json->decode( $json->encode( $v ) ) );
1067 }
1068  
1069 sub _compile_js_node
1070 0 ▶{
Subroutine _compile_js_node: not called CC=129 SCAR=97.3
1071 0 my $self = shift( @_ );
1072 0 my( $S, $sp, $seen, $funcs, $counter_ref, $root, $opts ) = @_;
1073  
1074 0 ▶ $opts ||= {};
Condition0%0/2
$opts ||= {}
l!l
00
MC/DC0%0/1
$opts ||= {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
1075 0 ▶ my $ecma = exists( $opts->{ecma} ) ? $opts->{ecma} : 'auto';
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'ecma'} ? : 0 0 0
1076 0 ▶ my $force_unicode =
Condition0%0/6
defined $ecma && $ecma =~ /^\d+$/u && $ecma >= 2018
!ll&&!rl&&r
000
defined $ecma and $ecma =~ /^\d+$/u
!ll&&!rl&&r
000
MC/DC0%0/3
defined $ecma && $ecma =~ /^\d+$/u && $ecma >= 2018
defined $ecma $ecma =~ /^\d+$/u $ecma >= 2018
Truth table0%0/4
A and B && C
A= defined $ecmaB= $ecma =~ /^\d+$/uC= $ecma >= 2018
ABCresult
0XX0
10X0
1100
1111
1077 defined( $ecma ) &&
1078 $ecma =~ /^\d+$/ &&
1079 $ecma >= 2018;
1080  
1081 # Re-use same JS function for the same schema pointer
1082 0 ▶ if( exists( $seen->{ $sp } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen->{$sp}) 0 0 0
1083 {
1084 0 return( $seen->{ $sp } );
1085 }
1086  
1087 # Support pointer-alias schemas such as:
1088 # definitions => { address => "#/definitions/jp_address" }
1089 0 ▶ if( defined( $S ) && !ref( $S ) && $S =~ /^#\// )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $S and not ref $S and $S =~ m[^#/]u) 0 0 0
Condition0%0/6
defined $S and not ref $S and $S =~ m[^#/]u
!ll&&!rl&&r
000
defined $S and not ref $S
!ll&&!rl&&r
000
MC/DC0%0/3
defined $S and not ref $S and $S =~ m[^#/]u
defined $S not ref $S $S =~ m[^#/]u
Truth table0%0/4
A and not(B) and C
A= defined $SB= not ref $SC= $S =~ m[^#/]u
ABCresult
0XX0
10X0
1100
1111
1090 {
1091 0 my $target_ptr = $S;
1092  
1093 # If we already compiled that pointer, just alias it
1094 0 ▶ if( exists( $seen->{ $target_ptr } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen->{$target_ptr}) 0 0 0
1095 {
1096 0 $seen->{ $sp } = $seen->{ $target_ptr };
1097 0 return( $seen->{ $target_ptr } );
1098 }
1099  
1100 0 my $target_schema = _jsv_resolve_internal_ref( $root, $target_ptr );
1101  
1102 # Follow chains of pointer-aliases
1103 0 ▶ if( defined( $target_schema ) && !ref( $target_schema ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_schema and not ref $target_schema) 0 0 0
Condition0%0/3
defined $target_schema and not ref $target_schema
!ll&&!rl&&r
000
MC/DC0%0/2
defined $target_schema and not ref $target_schema
defined $target_schema not ref $target_schema
Truth table0%0/3
A and not(B)
A= defined $target_schemaB= not ref $target_schema
ABresult
0X0
100
111
1104 {
1105 0 my %followed;
1106 0 ▶ while(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u) 0 0 0
Condition0%0/6
defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u
!ll&&!rl&&r
000
defined $target_schema and not ref $target_schema
!ll&&!rl&&r
000
MC/DC0%0/3
defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u
defined $target_schema not ref $target_schema $target_schema =~ m[^#/]u
Truth table0%0/4
A and not(B) and C
A= defined $target_schemaB= not ref $target_schemaC= $target_schema =~ m[^#/]u
ABCresult
0XX0
10X0
1100
1111
1107 defined( $target_schema ) &&
1108 !ref( $target_schema ) &&
1109 $target_schema =~ /^#\//
1110 )
1111 {
1112 0 ▶ last if( $followed{ $target_schema }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $followed{$target_schema}++ 0 0 0
1113 0 $target_ptr = $target_schema;
1114 0 $target_schema = _jsv_resolve_internal_ref( $root, $target_ptr );
1115 }
1116 }
1117  
1118 0 ▶ unless( defined( $target_schema ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target_schema) 0 0 0
1119 {
1120 # Could not resolve: emit a no-op validator (server still enforces)
1121 0 my $id = $$counter_ref++;
1122 0 my $fn = "jsv_node_${id}";
1123 0 $seen->{ $sp } = $fn;
1124 0 push( @$funcs, <<JS_RUNTIME );
1125 // $sp (unresolved pointer-alias $S)
1126 function $fn(inst, path, ctx)
1127 {
1128 }
1129 JS_RUNTIME
1130 0 return( $fn );
1131 }
1132  
1133 0 ▶ unless( ref( $target_schema ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $target_schema eq "HASH") 0 0 0
1134 {
1135 0 ▶ die(
Condition0%0/2
ref $target_schema || 'scalar'
l!l
00
MC/DC0%0/1
ref $target_schema || 'scalar'
ref $target_schema
Truth table0%0/2
A
A= ref $target_schema
Aresult
11
00
1136 "Internal error: pointer-alias '$S' at '$sp' did not resolve to an object schema " .
1137 "(got " . ( ref( $target_schema ) || 'scalar' ) . ")."
1138 );
1139 }
1140  
1141 0 my $base_fn = $self->_compile_js_node( $target_schema, $target_ptr, $seen, $funcs, $counter_ref, $root, $opts );
1142  
1143 # Alias this pointer to the target validator
1144 0 $seen->{ $sp } = $base_fn;
1145 0 return( $base_fn );
1146 }
1147  
1148 # NOTE: $ref
1149 # 0) $ref handling (internal refs only)
1150 0 ▶ if( ref( $S ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S eq "HASH" and exists $S->{"\$ref"}) 0 0 0
Condition0%0/3
ref $S eq "HASH" and exists $S->{"\$ref"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $S eq "HASH" and exists $S->{"\$ref"}
ref $S eq "HASH" exists $S->{"\$ref"}
Truth table0%0/3
A and B
A= ref $S eq "HASH"B= exists $S->{"\$ref"}
ABresult
0X0
100
111
1151 exists( $S->{'$ref'} ) )
1152 {
1153 0 my $ref = $S->{'$ref'};
1154  
1155 # Only support internal refs ("#/...") in JS
1156 0 ▶ if( defined( $ref ) && $ref =~ /^#/ )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $ref and $ref =~ /^#/u) 0 0 0
Condition0%0/3
defined $ref and $ref =~ /^#/u
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ref and $ref =~ /^#/u
defined $ref $ref =~ /^#/u
Truth table0%0/3
A and B
A= defined $refB= $ref =~ /^#/u
ABresult
0X0
100
111
1157 {
1158 0 my $target_ptr = $ref;
1159  
1160 # If we already compiled that pointer, just alias and return it
1161 0 ▶ if( exists( $seen->{ $target_ptr } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen->{$target_ptr}) 0 0 0
1162 {
1163 0 $seen->{ $sp } = $seen->{ $target_ptr };
1164 0 return( $seen->{ $target_ptr } );
1165 }
1166  
1167 # Otherwise, resolve pointer against the root schema
1168 0 my $target_schema = _jsv_resolve_internal_ref( $root, $target_ptr );
1169  
1170  
1171 # Support "pointer alias" schemas such as:
1172 # definitions => { address => "#/definitions/jp_address" }
1173 # Keep resolving until we reach a real schema hash.
1174 0 ▶ if( defined( $target_schema ) && !ref( $target_schema ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_schema and not ref $target_schema) 0 0 0
Condition0%0/3
defined $target_schema and not ref $target_schema
!ll&&!rl&&r
000
MC/DC0%0/2
defined $target_schema and not ref $target_schema
defined $target_schema not ref $target_schema
Truth table0%0/3
A and not(B)
A= defined $target_schemaB= not ref $target_schema
ABresult
0X0
100
111
1175 {
1176 0 my %followed;
1177 0 ▶ while(
Branch: 1 branch
BranchTrueFalseTotal
if (defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u) 0 0 0
Condition0%0/6
defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u
!ll&&!rl&&r
000
defined $target_schema and not ref $target_schema
!ll&&!rl&&r
000
MC/DC0%0/3
defined $target_schema and not ref $target_schema and $target_schema =~ m[^#/]u
defined $target_schema not ref $target_schema $target_schema =~ m[^#/]u
Truth table0%0/4
A and not(B) and C
A= defined $target_schemaB= not ref $target_schemaC= $target_schema =~ m[^#/]u
ABCresult
0XX0
10X0
1100
1111
1178 defined( $target_schema ) &&
1179 !ref( $target_schema ) &&
1180 $target_schema =~ /^#\//
1181 )
1182 {
1183 0 ▶ last if( $followed{ $target_schema }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $followed{$target_schema}++ 0 0 0
1184 0 $target_ptr = $target_schema;
1185 0 $target_schema = _jsv_resolve_internal_ref( $root, $target_ptr );
1186 }
1187 }
1188  
1189 0 ▶ unless( defined( $target_schema ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $target_schema) 0 0 0
1190 {
1191 # Pointer could not be resolved. As a safety fallback,
1192 # make this node a no-op on the client (server will still enforce).
1193 0 my $id = $$counter_ref++;
1194 0 my $fn = "jsv_node_${id}";
1195 0 $seen->{ $sp } = $fn;
1196 0 push( @$funcs, <<JS_RUNTIME );
1197 // $sp
1198 function $fn(inst, path, ctx)
1199 {
1200 }
1201  
1202 JS_RUNTIME
1203 0 return( $fn );
1204 }
1205  
1206 0 ▶ unless( ref( $target_schema ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $target_schema eq "HASH") 0 0 0
1207 {
1208 0 ▶ die( "Internal error: \$ref target '$target_ptr' did not resolve to a schema object (got " .
Branch: 1 branch
BranchTrueFalseTotal
defined $target_schema ? : 0 0 0
Condition0%0/2
ref $target_schema or "scalar"
l!l
00
MC/DC0%0/1
ref $target_schema or "scalar"
ref $target_schema
Truth table0%0/2
A
A= ref $target_schema
Aresult
11
00
1209 ( defined( $target_schema ) ? ref( $target_schema ) || 'scalar' : 'undef' ) .
1210 "). If you are using pointer-alias definitions, they must ultimately resolve to an object schema." );
1211 }
1212  
1213 # Compile the target, then merge sibling keywords
1214 0 my $base_fn = $self->_compile_js_node( $target_schema, $target_ptr, $seen, $funcs, $counter_ref, $root, $opts );
1215  
1216 # Create a wrapper that runs both the referenced schema AND local keywords
1217 0 my $id = $$counter_ref++;
1218 0 my $wrapper_fn = "jsv_node_$id";
1219 0 $seen->{ $sp } = $wrapper_fn;
1220  
1221 0 my @wrapper_body;
1222 0 push( @wrapper_body, <<JS_RUNTIME );
1223 // $sp (\$ref + siblings)
1224 function $wrapper_fn(inst, path, ctx)
1225 {
1226 $base_fn(inst, path, ctx);
1227 if(ctx.errors.length >= ctx.maxErrors) return;
1228 JS_RUNTIME
1229  
1230 # Now compile the current node again, but skip the $ref
1231 0 my $local_S = { %$S }; # shallow copy
1232 0 delete( $local_S->{'$ref'} );
1233 0 my $local_sp = _join_ptr( $sp, '__local__' );
1234 0 my $local_fn = $self->_compile_js_node( $local_S, $local_sp, $seen, $funcs, $counter_ref, $root, $opts );
1235  
1236 0 ▶ if( $local_fn ne $wrapper_fn )
Branch: 1 branch
BranchTrueFalseTotal
if ($local_fn ne $wrapper_fn) 0 0 0
1237 {
1238 0 push( @wrapper_body, <<JS_RUNTIME );
1239 $local_fn(inst, path, ctx);
1240 JS_RUNTIME
1241 }
1242  
1243 0 push( @wrapper_body, <<JS_RUNTIME );
1244 }
1245 JS_RUNTIME
1246 0 push( @$funcs, join( '', @wrapper_body ) );
1247 0 return( $wrapper_fn );
1248 }
1249  
1250 # External refs (URLs, etc.) are not resolved on the client.
1251 # Full resolution is done server-side.
1252 }
1253  
1254 0 my $id = $$counter_ref++;
1255 0 my $fn = "jsv_node_$id";
1256 0 $seen->{ $sp } = $fn;
1257  
1258 0 my @body;
1259  
1260 0 push( @body, <<JS_RUNTIME );
1261 // $sp
1262 function $fn(inst, path, ctx)
1263 {
1264 JS_RUNTIME
1265  
1266 # NOTE: combinator (allOf / anyOf / oneOf / not / if-then-else)
1267 0 ▶ if( ref( $S ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S eq "HASH") 0 0 0
1268 {
1269 # allOf – AND of subschemas
1270 0 ▶ if( exists( $S->{allOf} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY" and @{$S->{"allOf"};}) 0 0 0
Condition0%0/6
exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY" and @{$S->{"allOf"};}
!ll&&!rl&&r
000
exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY" and @{$S->{"allOf"};}
exists $S->{"allOf"} ref $S->{"allOf"} eq "ARRAY" @{$S->{"allOf"};}
Truth table0%0/4
A and B and C
A= exists $S->{"allOf"}B= ref $S->{"allOf"} eq "ARRAY"C= @{$S->{"allOf"};}
ABCresult
0XX0
10X0
1100
1111
1271 ref( $S->{allOf} ) eq 'ARRAY' &&
1272 0 @{$S->{allOf}} )
1273 {
1274 0 for my $i ( 0 .. $#{$S->{allOf}} )
1275 {
1276 0 my $sub_sp = _join_ptr( $sp, 'allOf', $i );
1277 0 my $sub_fn = $self->_compile_js_node( $S->{allOf}->[ $i ], $sub_sp, $seen, $funcs, $counter_ref, $root, $opts );
1278  
1279 0 push( @body, <<JS_RUNTIME );
1280 // $sub_sp
1281 $sub_fn(inst, path, ctx);
1282 if(ctx.maxErrors && ctx.errors.length >= ctx.maxErrors) return;
1283 JS_RUNTIME
1284 }
1285  
1286 # IMPORTANT: we do *not* return here.
1287 # Other local keywords (type, properties, contains, ...) must still run.
1288 }
1289  
1290 # anyOf – at least one must validate (we only emit a single anyOf error)
1291 0 ▶ if( exists( $S->{anyOf} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY" and @{$S->{"anyOf"};}) 0 0 0
Condition0%0/6
exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY" and @{$S->{"anyOf"};}
!ll&&!rl&&r
000
exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY" and @{$S->{"anyOf"};}
exists $S->{"anyOf"} ref $S->{"anyOf"} eq "ARRAY" @{$S->{"anyOf"};}
Truth table0%0/4
A and B and C
A= exists $S->{"anyOf"}B= ref $S->{"anyOf"} eq "ARRAY"C= @{$S->{"anyOf"};}
ABCresult
0XX0
10X0
1100
1111
1292 ref( $S->{anyOf} ) eq 'ARRAY' &&
1293 0 @{$S->{anyOf}} )
1294 {
1295 0 push( @body, <<JS_RUNTIME );
1296 (function()
1297 {
1298 var baseErrors = ctx.errors;
1299 var matched = false;
1300  
1301 JS_RUNTIME
1302  
1303 0 for my $i ( 0 .. $#{$S->{anyOf}} )
1304 {
1305 0 my $sub_sp = _join_ptr( $sp, 'anyOf', $i );
1306 0 my $sub_fn = $self->_compile_js_node( $S->{anyOf}->[ $i ], $sub_sp, $seen, $funcs, $counter_ref, $root, $opts );
1307  
1308 0 push( @body, <<JS_RUNTIME );
1309 if(matched) return;
1310 ctx.errors = [];
1311 // $sub_sp
1312 $sub_fn(inst, path, ctx);
1313 if(ctx.errors.length === 0)
1314 {
1315 matched = true;
1316 ctx.errors = baseErrors;
1317 return;
1318 }
1319 JS_RUNTIME
1320 }
1321  
1322 0 my $sp_qp = _js_quote( $sp );
1323 0 push( @body, <<JS_RUNTIME );
1324 ctx.errors = baseErrors;
1325 if(!matched)
1326 {
1327 _jsv_err(ctx, path, 'anyOf', 'no subschema matched', $sp_qp);
1328 }
1329 })();
1330 // return;
1331 JS_RUNTIME
1332 }
1333  
1334 # oneOf – exactly one must validate
1335 0 ▶ if( exists( $S->{oneOf} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY" and @{$S->{"oneOf"};}) 0 0 0
Condition0%0/6
exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY" and @{$S->{"oneOf"};}
!ll&&!rl&&r
000
exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY" and @{$S->{"oneOf"};}
exists $S->{"oneOf"} ref $S->{"oneOf"} eq "ARRAY" @{$S->{"oneOf"};}
Truth table0%0/4
A and B and C
A= exists $S->{"oneOf"}B= ref $S->{"oneOf"} eq "ARRAY"C= @{$S->{"oneOf"};}
ABCresult
0XX0
10X0
1100
1111
1336 ref( $S->{oneOf} ) eq 'ARRAY' &&
1337 0 @{$S->{oneOf}} )
1338 {
1339 0 push( @body, <<JS_RUNTIME );
1340 (function()
1341 {
1342 var baseErrors = ctx.errors;
1343 var hits = 0;
1344  
1345 JS_RUNTIME
1346  
1347 0 for my $i ( 0 .. $#{$S->{oneOf}} )
1348 {
1349 0 my $sub_sp = _join_ptr( $sp, 'oneOf', $i );
1350 0 my $sub_fn = $self->_compile_js_node( $S->{oneOf}->[ $i ], $sub_sp, $seen, $funcs, $counter_ref, $root, $opts );
1351  
1352 0 push( @body, <<JS_RUNTIME );
1353 ctx.errors = [];
1354 // $sub_sp
1355 $sub_fn(inst, path, ctx);
1356 if(ctx.errors.length === 0)
1357 {
1358 hits++;
1359 }
1360 JS_RUNTIME
1361 }
1362  
1363 0 my $sp_qp = _js_quote( $sp );
1364 0 push( @body, <<JS_RUNTIME );
1365 ctx.errors = baseErrors;
1366 if(hits !== 1)
1367 {
1368 _jsv_err(ctx, path, 'oneOf', 'exactly one subschema must match, but ' + hits + ' did', $sp_qp);
1369 }
1370 })();
1371 // return;
1372 JS_RUNTIME
1373 }
1374  
1375 # not – but we SKIP "negative required" patterns on the client
1376 0 ▶ if( exists( $S->{not} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"not"}) 0 0 0
1377 {
1378 0 my $skip_not = 0;
1379  
1380 0 ▶ if( ref( $S->{not} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"not"} eq "HASH") 0 0 0
1381 {
1382 0 my $N = $S->{not};
1383  
1384 # Direct: { "not": { "required": [...] } }
1385 0 ▶ if( exists( $N->{required} ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (exists $N->{'required'} and ref $N->{'required'} eq 'ARRAY') { } 0 0 0
elsif (exists $N->{'anyOf'} and ref $N->{'anyOf'} eq 'ARRAY') { } 0 0 0
Condition0%0/3
exists $N->{"required"} and ref $N->{"required"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $N->{"required"} and ref $N->{"required"} eq "ARRAY"
exists $N->{"required"} ref $N->{"required"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $N->{"required"}B= ref $N->{"required"} eq "ARRAY"
ABresult
0X0
100
111
1386 ref( $N->{required} ) eq 'ARRAY' )
1387 {
1388 0 $skip_not = 1;
1389 }
1390 # Or: { "not": { "anyOf": [ {required:...}, ... ] } }
1391 ▶ elsif( exists( $N->{anyOf} ) &&
Condition0%0/3
exists $N->{"anyOf"} and ref $N->{"anyOf"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $N->{"anyOf"} and ref $N->{"anyOf"} eq "ARRAY"
exists $N->{"anyOf"} ref $N->{"anyOf"} eq "ARRAY"
Truth table0%0/3
A and B
A= exists $N->{"anyOf"}B= ref $N->{"anyOf"} eq "ARRAY"
ABresult
0X0
100
111
1392 ref( $N->{anyOf} ) eq 'ARRAY' )
1393 {
1394 0 my $all_req = 1;
1395 0 for my $elt ( @{$N->{anyOf}} )
1396 {
1397 0 ▶ if( !( ref( $elt ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $elt eq "HASH" and exists $elt->{"required"} and ref $elt->{"required"} eq "ARRAY") 0 0 0
Condition0%0/6
ref $elt eq "HASH" and exists $elt->{"required"} and ref $elt->{"required"} eq "ARRAY"
!ll&&!rl&&r
000
ref $elt eq "HASH" and exists $elt->{"required"}
!ll&&!rl&&r
000
MC/DC0%0/3
ref $elt eq "HASH" and exists $elt->{"required"} and ref $elt->{"required"} eq "ARRAY"
ref $elt eq "HASH" exists $elt->{"required"} ref $elt->{"required"} eq "ARRAY"
Truth table0%0/4
A and B and C
A= ref $elt eq "HASH"B= exists $elt->{"required"}C= ref $elt->{"required"} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
1398 exists( $elt->{required} ) &&
1399 ref( $elt->{required} ) eq 'ARRAY' ) )
1400 {
1401 0 $all_req = 0;
1402 0 last;
1403 }
1404 }
1405 0 ▶ $skip_not = 1 if( $all_req );
Branch: 1 branch
BranchTrueFalseTotal
if $all_req 0 0 0
1406 }
1407 }
1408  
1409 0 ▶ if( !$skip_not )
Branch: 1 branch
BranchTrueFalseTotal
if (not $skip_not) { } 0 0 0
1410 {
1411 0 my $sub_sp = _join_ptr( $sp, 'not' );
1412 0 my $sub_fn = $self->_compile_js_node( $S->{not}, $sub_sp, $seen, $funcs, $counter_ref, $root, $opts );
1413 0 my $sp_qp = _js_quote( $sp );
1414 0 push( @body, <<JS_RUNTIME );
1415 (function()
1416 {
1417 var baseErrors = ctx.errors;
1418 ctx.errors = [];
1419 // $sub_sp
1420 $sub_fn(inst, path, ctx);
1421 var failed = (ctx.errors.length > 0);
1422 ctx.errors = baseErrors;
1423 if(!failed)
1424 {
1425 _jsv_err(ctx, path, 'not', 'instance matched forbidden schema', $sp_qp);
1426 }
1427 })();
1428 // return;
1429 JS_RUNTIME
1430 }
1431 else
1432 {
1433 # Skip "not + required" style rules on the client;
1434 # they are enforced server-side only.
1435 0 push( @body, <<JS_RUNTIME );
1436 // NOTE: 'not' at $sp is a negative-required pattern; skipped client-side.
1437 JS_RUNTIME
1438 }
1439 }
1440  
1441 # if / then / else (branch errors are enforced, "if" errors are not)
1442 0 ▶ if( exists( $S->{if} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"if"}) 0 0 0
1443 {
1444 0 my $if_sp = _join_ptr( $sp, 'if' );
1445 0 my $if_fn = $self->_compile_js_node( $S->{if}, $if_sp, $seen, $funcs, $counter_ref, $root, $opts );
1446  
1447 0 push( @body, <<JS_RUNTIME );
1448 (function()
1449 {
1450 var baseErrors = ctx.errors;
1451 var tmp = [];
1452 ctx.errors = tmp;
1453 // $if_sp
1454 $if_fn(inst, path, ctx);
1455 var failed = (tmp.length > 0);
1456 ctx.errors = baseErrors;
1457 JS_RUNTIME
1458  
1459 0 ▶ if( $S->{then} )
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"then"}) 0 0 0
1460 {
1461 0 my $then_sp = _join_ptr( $sp, 'then' );
1462 0 my $then_fn = $self->_compile_js_node( $S->{then}, $then_sp, $seen, $funcs, $counter_ref, $root, $opts );
1463 0 push( @body, <<JS_RUNTIME );
1464 if(!failed)
1465 {
1466 $then_fn(inst, path, ctx);
1467 }
1468 JS_RUNTIME
1469 }
1470 0 ▶ if( $S->{else} )
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"else"}) 0 0 0
1471 {
1472 0 my $else_sp = _join_ptr( $sp, 'else' );
1473 0 my $else_fn = $self->_compile_js_node( $S->{else}, $else_sp, $seen, $funcs, $counter_ref, $root, $opts );
1474 0 push( @body, <<JS_RUNTIME );
1475 else
1476 {
1477 $else_fn(inst, path, ctx);
1478 }
1479 JS_RUNTIME
1480 }
1481  
1482 0 push( @body, <<JS_RUNTIME );
1483 })();
1484 JS_RUNTIME
1485 # Do NOT return here; this node can also have local constraints
1486 }
1487  
1488 # uniqueKeys extension when enabled
1489 0 ▶ if( $self->{unique_keys} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"unique_keys"} and exists $S->{"uniqueKeys"} and ref $S->{"uniqueKeys"} eq "ARRAY") 0 0 0
Condition0%0/6
$self->{"unique_keys"} and exists $S->{"uniqueKeys"} and ref $S->{"uniqueKeys"} eq "ARRAY"
!ll&&!rl&&r
000
$self->{"unique_keys"} and exists $S->{"uniqueKeys"}
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"unique_keys"} and exists $S->{"uniqueKeys"} and ref $S->{"uniqueKeys"} eq "ARRAY"
$self->{"unique_keys"} exists $S->{"uniqueKeys"} ref $S->{"uniqueKeys"} eq "ARRAY"
Truth table0%0/4
A and B and C
A= $self->{"unique_keys"}B= exists $S->{"uniqueKeys"}C= ref $S->{"uniqueKeys"} eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
1490 exists( $S->{uniqueKeys} ) &&
1491 ref( $S->{uniqueKeys} ) eq 'ARRAY' )
1492 {
1493 0 for my $keyset_ref ( @{$S->{uniqueKeys}} )
1494 {
1495 0 ▶ next unless( ref( $keyset_ref ) eq 'ARRAY' && @$keyset_ref );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $keyset_ref eq "ARRAY" and @$keyset_ref 0 0 0
Condition0%0/3
ref $keyset_ref eq "ARRAY" and @$keyset_ref
!ll&&!rl&&r
000
MC/DC0%0/2
ref $keyset_ref eq "ARRAY" and @$keyset_ref
ref $keyset_ref eq "ARRAY" @$keyset_ref
Truth table0%0/3
A and B
A= ref $keyset_ref eq "ARRAY"B= @$keyset_ref
ABresult
0X0
100
111
1496  
1497 0 my @keys = map{ _js_quote( $_ ) } @$keyset_ref;
1498 0 my $qsp = _js_quote( $sp );
1499  
1500 0 push( @body, <<JS_RUNTIME );
1501 if(Array.isArray(inst))
1502 {
1503 var seen = {};
1504 for(var i = 0; i < inst.length; i++)
1505 {
1506 var item = inst[i];
1507 var key = '';
1508 try
1509 {
1510 key = [ @keys ].map(function(k){ return item[k]; }).join('\x1E'); // RS separator
1511 }
1512 catch(e) {}
1513 if(seen.hasOwnProperty(key))
1514 {
1515 _jsv_err(ctx, path, 'uniqueKeys', 'duplicate items with keys [@$keyset_ref]', $qsp);
1516 break;
1517 }
1518 seen[key] = true;
1519 }
1520 }
1521 JS_RUNTIME
1522 }
1523 }
1524 }
1525  
1526 0 ▶ my $has_type_keyword = ( ref( $S ) eq 'HASH' && exists( $S->{type} ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
ref $S eq 'HASH' && exists $S->{'type'} ? : 0 0 0
Condition0%0/3
ref $S eq "HASH" and exists $S->{"type"}
!ll&&!rl&&r
000
MC/DC0%0/2
ref $S eq "HASH" and exists $S->{"type"}
ref $S eq "HASH" exists $S->{"type"}
Truth table0%0/3
A and B
A= ref $S eq "HASH"B= exists $S->{"type"}
ABresult
0X0
100
111
1527  
1528 # NOTE: type
1529 # 1) type
1530 0 ▶ if( exists( $S->{type} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"type"}) 0 0 0
1531 {
1532 0 ▶ my @types = ref( $S->{type} ) eq 'ARRAY' ? @{$S->{type}} : ( $S->{type} );
Branch: 1 branch
BranchTrueFalseTotal
ref $S->{'type'} eq 'ARRAY' ? : 0 0 0
1533  
1534 # Special-case "number" vs "integer": _jsv_typeOf returns "integer" for ints
1535 0 my @checks;
1536 0 for my $t ( @types )
1537 {
1538 0 ▶ if( $t eq 'number' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq 'number') { } 0 0 0
1539 {
1540 # accept "number" or "integer" from _jsv_typeOf
1541 0 push( @checks, q{tt === 'number' || tt === 'integer'} );
1542 }
1543 else
1544 {
1545 0 my $qt = _js_quote( $t );
1546 0 push( @checks, "tt === $qt" );
1547 }
1548 }
1549  
1550 0 my $cond = join( ' || ', @checks );
1551 0 ▶ my $msg = 'expected type ' .
Branch: 1 branch
BranchTrueFalseTotal
@types == 1 ? : 0 0 0
1552 ( @types == 1 ? $types[0] : '[' . join( ',', @types ) . ']' ) .
1553 ' but found ';
1554 0 my $qmsg = _js_quote( $msg );
1555 0 my $qsp = _js_quote( $sp );
1556  
1557 0 push( @body, <<JS_RUNTIME );
1558 var tt = _jsv_typeOf(inst);
1559 if(!( $cond ))
1560 {
1561 _jsv_err(ctx, path, 'type', $qmsg + tt, $qsp);
1562 return;
1563 }
1564 JS_RUNTIME
1565 }
1566  
1567 # NOTE: enum
1568 # 2) enum
1569 0 ▶ if( exists( $S->{enum} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"enum"} and ref $S->{"enum"} eq "ARRAY" and @{$S->{"enum"};}) 0 0 0
Condition0%0/6
exists $S->{"enum"} and ref $S->{"enum"} eq "ARRAY" and @{$S->{"enum"};}
!ll&&!rl&&r
000
exists $S->{"enum"} and ref $S->{"enum"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"enum"} and ref $S->{"enum"} eq "ARRAY" and @{$S->{"enum"};}
exists $S->{"enum"} ref $S->{"enum"} eq "ARRAY" @{$S->{"enum"};}
Truth table0%0/4
A and B and C
A= exists $S->{"enum"}B= ref $S->{"enum"} eq "ARRAY"C= @{$S->{"enum"};}
ABCresult
0XX0
10X0
1100
1111
1570 ref( $S->{enum} ) eq 'ARRAY' &&
1571 0 @{$S->{enum}} )
1572 {
1573 0 my @vals = @{$S->{enum}};
1574 0 my @vs_js = map{ _js_quote( $_ ) } @vals;
1575 0 my $qsp = _js_quote( $sp );
1576  
1577 0 local $" = ', ';
1578 0 push( @body, <<JS_RUNTIME );
1579 (function()
1580 {
1581 var ok = false;
1582 var v = inst;
1583 var list = [ @vs_js ];
1584 for(var i = 0; i < list.length; i++)
1585 {
1586 if(v === list[i])
1587 {
1588 ok = true;
1589 break;
1590 }
1591 }
1592 if(!ok)
1593 {
1594 _jsv_err(ctx, path, 'enum', 'value is not in enum list', $qsp);
1595 }
1596 })();
1597 JS_RUNTIME
1598 }
1599  
1600 # NOTE: const
1601 # 3) const (primitive only)
1602 0 ▶ if( exists( $S->{const} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"const"}) 0 0 0
1603 {
1604 # For simplicity on the JS side, only support primitive const reliably.
1605 # (Object/array equality is non-trivial; we keep it minimal for now.)
1606 0 my $c = $S->{const};
1607 0 my $qsp = _js_quote( $sp );
1608  
1609 0 ▶ if( !ref( $c ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $c) { } 0 0 0
1610 {
1611 0 my $cv = _js_quote( $c );
1612 0 push( @body, <<JS_RUNTIME );
1613 if(inst !== $cv)
1614 {
1615 _jsv_err(ctx, path, 'const', 'value does not match const', $qsp);
1616 }
1617 JS_RUNTIME
1618 }
1619 else
1620 {
1621 # Complex const -> skip in JS (server will still enforce)
1622 0 push( @body, <<JS_RUNTIME );
1623 // NOTE: const at $sp is non-primitive; not enforced client-side.
1624  
1625 JS_RUNTIME
1626 }
1627 }
1628  
1629 # NOTE: required
1630 # 4) required (objects)
1631 0 ▶ if( exists( $S->{required} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"required"} and ref $S->{"required"} eq "ARRAY" and @{$S->{"required"};}) 0 0 0
Condition0%0/6
exists $S->{"required"} and ref $S->{"required"} eq "ARRAY" and @{$S->{"required"};}
!ll&&!rl&&r
000
exists $S->{"required"} and ref $S->{"required"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"required"} and ref $S->{"required"} eq "ARRAY" and @{$S->{"required"};}
exists $S->{"required"} ref $S->{"required"} eq "ARRAY" @{$S->{"required"};}
Truth table0%0/4
A and B and C
A= exists $S->{"required"}B= ref $S->{"required"} eq "ARRAY"C= @{$S->{"required"};}
ABCresult
0XX0
10X0
1100
1111
1632 ref( $S->{required} ) eq 'ARRAY' &&
1633 0 @{$S->{required}} )
1634 {
1635 0 push( @body, <<JS_RUNTIME );
1636 if(_jsv_typeOf(inst) === 'object')
1637 {
1638 JS_RUNTIME
1639  
1640 0 for my $p ( @{$S->{required}} )
1641 {
1642 0 my $qp = _js_quote( $p );
1643 0 my $sp2 = _join_ptr( $sp, 'properties', $p );
1644 0 my $qsp2 = _js_quote( $sp2 );
1645  
1646 0 my $msg = "required property '$p' is missing";
1647 0 my $qmsg = _js_quote( $msg );
1648  
1649 0 push( @body, <<JS_RUNTIME );
1650 if(!_jsv_hasOwn(inst, $qp))
1651 {
1652 _jsv_err(ctx, path, 'required', $qmsg, $qsp2);
1653 }
1654 JS_RUNTIME
1655 }
1656  
1657 0 push( @body, <<JS_RUNTIME );
1658 }
1659 JS_RUNTIME
1660 }
1661  
1662 # NOTE: string && pattern
1663 # 5) string length & pattern
1664 my $has_string_constraints =
1665 exists( $S->{minLength} ) ||
1666 exists( $S->{maxLength} ) ||
1667 0 ▶ exists( $S->{pattern} );
Condition0%0/6
exists $S->{'minLength'} || exists $S->{'maxLength'} || exists $S->{'pattern'}
l!l&&r!l&&!r
000
exists $S->{"minLength"} or exists $S->{"maxLength"}
l!l&&r!l&&!r
000
MC/DC0%0/3
exists $S->{'minLength'} || exists $S->{'maxLength'} || exists $S->{'pattern'}
exists $S->{"minLength"} exists $S->{"maxLength"} exists $S->{'pattern'}
Truth table0%0/4
A or B || C
A= exists $S->{"minLength"}B= exists $S->{"maxLength"}C= exists $S->{'pattern'}
ABCresult
1XX1
01X1
0011
0000
1668  
1669 0 ▶ if( $has_string_constraints )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_string_constraints) 0 0 0
1670 {
1671 0 my $qsp = _js_quote( $sp );
1672  
1673 0 push( @body, <<JS_RUNTIME );
1674 if(_jsv_typeOf(inst) === 'string')
1675 {
1676 JS_RUNTIME
1677  
1678 0 ▶ if( exists( $S->{minLength} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"minLength"}) 0 0 0
1679 {
1680 0 my $min = int( $S->{minLength} );
1681 0 push( @body, <<JS_RUNTIME );
1682 if(inst.length < $min)
1683 {
1684 _jsv_err(ctx, path, 'minLength', 'string shorter than minLength $min', $qsp);
1685 }
1686 JS_RUNTIME
1687 }
1688  
1689 0 ▶ if( exists( $S->{maxLength} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"maxLength"}) 0 0 0
1690 {
1691 0 my $max = int( $S->{maxLength} );
1692 0 push( @body, <<JS_RUNTIME );
1693 if(inst.length > $max)
1694 {
1695 _jsv_err(ctx, path, 'maxLength', 'string longer than maxLength $max', $qsp);
1696 }
1697 JS_RUNTIME
1698 }
1699  
1700 0 ▶ if( exists( $S->{pattern} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"pattern"} and defined $S->{"pattern"} and length $S->{"pattern"}) 0 0 0
Condition0%0/6
exists $S->{"pattern"} and defined $S->{"pattern"} and length $S->{"pattern"}
!ll&&!rl&&r
000
exists $S->{"pattern"} and defined $S->{"pattern"}
!ll&&!rl&&r
000
MC/DC0%0/3
exists $S->{"pattern"} and defined $S->{"pattern"} and length $S->{"pattern"}
exists $S->{"pattern"} defined $S->{"pattern"} length $S->{"pattern"}
Truth table0%0/4
A and B and C
A= exists $S->{"pattern"}B= defined $S->{"pattern"}C= length $S->{"pattern"}
ABCresult
0XX0
10X0
1100
1111
1701 defined( $S->{pattern} ) &&
1702 length( $S->{pattern} ) )
1703 {
1704 0 my $pat = $S->{pattern};
1705 # my $qpat = _js_quote( $pat );
1706 # from \x{FF70} to \uFF70
1707 # from \p{Katakana} to \p{sc=Katakana}
1708 0 my $qpat = _re_to_js( $pat );
1709  
1710 0 ▶ if( $force_unicode )
Branch: 1 branch
BranchTrueFalseTotal
if ($force_unicode) { } 0 0 0
1711 {
1712 # ecma >= 2018: always try with "u" flag (Unicode mode)
1713 0 push( @body, <<JS_RUNTIME );
1714 try
1715 {
1716 var re = new RegExp("$qpat", "u");
1717 if(!re.test(inst))
1718 {
1719 _jsv_err(ctx, path, 'pattern', 'string does not match pattern', $qsp);
1720 }
1721 }
1722 catch(e)
1723 {
1724 // Browser does not support Unicode property escapes or this pattern.
1725 }
1726 JS_RUNTIME
1727 }
1728 else
1729 {
1730 # auto / ES5 mode: detect "advanced" patterns
1731 0 ▶ if( $pat =~ /\\p\{|\\P\{|\\X|\\R|\(\?[A-Za-z]/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($pat =~ /\\p\{|\\P\{|\\X|\\R|\(\?[A-Za-z]/u) { } 0 0 0
1732 {
1733 # Attempt Unicode mode with "u" flag, but gracefully fall back
1734 0 push( @body, <<JS_RUNTIME );
1735 (function()
1736 {
1737 var re = null;
1738 try
1739 {
1740 re = new RegExp("$qpat", "u");
1741 }
1742 catch(e)
1743 {
1744 // Older browser; skip Unicode-property-based pattern on client.
1745 }
1746 if(re && !re.test(inst))
1747 {
1748 _jsv_err(ctx, path, 'pattern', 'string does not match pattern', $qsp);
1749 }
1750 })();
1751 JS_RUNTIME
1752 }
1753 else
1754 {
1755 # Simple ECMA 5-compatible pattern
1756 0 push( @body, <<JS_RUNTIME );
1757 try
1758 {
1759 var re = new RegExp("$qpat");
1760 if(!re.test(inst))
1761 {
1762 _jsv_err(ctx, path, 'pattern', 'string does not match pattern', $qsp);
1763 }
1764 }
1765 catch(e)
1766 {
1767 // If pattern is not JS-compatible, we silently skip on the client.
1768 }
1769 JS_RUNTIME
1770 }
1771 }
1772 }
1773  
1774 0 push( @body, <<JS_RUNTIME );
1775 }
1776 JS_RUNTIME
1777 }
1778  
1779 # NOTE: minimum, maximum, etc
1780 # 6) numeric bounds (minimum/maximum/exclusive*)
1781 my $has_num_constraints =
1782 exists( $S->{minimum} ) ||
1783 exists( $S->{maximum} ) ||
1784 exists( $S->{exclusiveMinimum} ) ||
1785 0 ▶ exists( $S->{exclusiveMaximum} );
Condition0%0/9
exists $S->{'minimum'} || exists $S->{'maximum'} || exists $S->{'exclusiveMinimum'} || exists $S->{'exclusiveMaximum'}
l!l&&r!l&&!r
000
exists $S->{"minimum"} or exists $S->{"maximum"} or exists $S->{"exclusiveMinimum"}
l!l&&r!l&&!r
000
exists $S->{"minimum"} or exists $S->{"maximum"}
l!l&&r!l&&!r
000
MC/DC0%0/4
exists $S->{'minimum'} || exists $S->{'maximum'} || exists $S->{'exclusiveMinimum'} || exists $S->{'exclusiveMaximum'}
exists $S->{"minimum"} exists $S->{"maximum"} exists $S->{"exclusiveMinimum"} exists $S->{'exclusiveMaximum'}
Truth table0%0/5
A or B or C || D
A= exists $S->{"minimum"}B= exists $S->{"maximum"}C= exists $S->{"exclusiveMinimum"}D= exists $S->{'exclusiveMaximum'}
ABCDresult
1XXX1
01XX1
001X1
00011
00000
1786  
1787 0 ▶ if( $has_num_constraints )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_num_constraints) 0 0 0
1788 {
1789 # For consistency with string/pattern/etc, we report the
1790 # schema pointer of the *owning schema* ($sp), not the
1791 # child keyword location (.../minimum).
1792 0 my $qsp_num = _js_quote( $sp );
1793 0 my $qmsg_expected_num = _js_quote( 'expected number but found ' );
1794  
1795 0 push( @body, <<'JS_RUNTIME' );
1796 var t = _jsv_typeOf(inst);
1797  
1798 // Coerce numeric-looking strings to numbers, for friendlier UX
1799 if(t === 'string' && /^[+-]?(?:\d+|\d*\.\d+)$/.test(inst))
1800 {
1801 inst = +inst;
1802 t = _jsv_typeOf(inst);
1803 }
1804  
1805 if(t === 'number' || t === 'integer')
1806 {
1807 JS_RUNTIME
1808  
1809 0 ▶ if( exists( $S->{minimum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"minimum"}) 0 0 0
1810 {
1811 0 my $min = 0 + $S->{minimum};
1812 0 push( @body, <<JS_RUNTIME );
1813 if(inst < $min)
1814 {
1815 _jsv_err(ctx, path, 'minimum', 'number is less than minimum $min', $qsp_num);
1816 }
1817 JS_RUNTIME
1818 }
1819  
1820 0 ▶ if( exists( $S->{maximum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"maximum"}) 0 0 0
1821 {
1822 0 my $max = 0 + $S->{maximum};
1823 0 push( @body, <<JS_RUNTIME );
1824 if(inst > $max)
1825 {
1826 _jsv_err(ctx, path, 'maximum', 'number is greater than maximum $max', $qsp_num);
1827 }
1828 JS_RUNTIME
1829 }
1830  
1831 0 ▶ if( exists( $S->{exclusiveMinimum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"exclusiveMinimum"}) 0 0 0
1832 {
1833 0 my $emin = 0 + $S->{exclusiveMinimum};
1834 0 push( @body, <<JS_RUNTIME );
1835 if(inst <= $emin)
1836 {
1837 _jsv_err(ctx, path, 'exclusiveMinimum',
1838 'number is <= exclusiveMinimum $emin', $qsp_num);
1839 }
1840 JS_RUNTIME
1841 }
1842  
1843 0 ▶ if( exists( $S->{exclusiveMaximum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"exclusiveMaximum"}) 0 0 0
1844 {
1845 0 my $emax = 0 + $S->{exclusiveMaximum};
1846 0 push( @body, <<JS_RUNTIME );
1847 if(inst >= $emax)
1848 {
1849 _jsv_err(ctx, path, 'exclusiveMaximum',
1850 'number is >= exclusiveMaximum $emax', $qsp_num);
1851 }
1852 JS_RUNTIME
1853 }
1854  
1855 # Close the "if(t === 'number' || t === 'integer')" and, if needed,
1856 # add a fallback type error when no explicit "type" keyword exists.
1857 0 ▶ if( $has_type_keyword )
Branch: 1 branch
BranchTrueFalseTotal
if ($has_type_keyword) { } 0 0 0
1858 {
1859 0 push( @body, <<'JS_RUNTIME' );
1860 }
1861 JS_RUNTIME
1862 }
1863 else
1864 {
1865 0 push( @body, <<JS_RUNTIME );
1866 }
1867 else
1868 {
1869 _jsv_err(ctx, path, 'type', $qmsg_expected_num + t, $qsp_num);
1870 }
1871 JS_RUNTIME
1872 }
1873 }
1874  
1875 # NOTE: items / minItems / maxItems
1876 # 7) array items & minItems/maxItems
1877 my $has_array_len =
1878 exists( $S->{minItems} ) ||
1879 0 ▶ exists( $S->{maxItems} );
Condition0%0/3
exists $S->{'minItems'} || exists $S->{'maxItems'}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $S->{'minItems'} || exists $S->{'maxItems'}
exists $S->{'minItems'} exists $S->{'maxItems'}
Truth table0%0/3
A || B
A= exists $S->{'minItems'}B= exists $S->{'maxItems'}
ABresult
1X1
011
000
1880  
1881 0 ▶ if( exists( $S->{items} ) || $has_array_len )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"items"} or $has_array_len) 0 0 0
Condition0%0/3
exists $S->{"items"} or $has_array_len
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $S->{"items"} or $has_array_len
exists $S->{"items"} $has_array_len
Truth table0%0/3
A or B
A= exists $S->{"items"}B= $has_array_len
ABresult
1X1
011
000
1882 {
1883 0 my $qsp = _js_quote( $sp );
1884  
1885 # Precompile single-schema "items"
1886 0 my $items_fn;
1887 0 ▶ if( exists( $S->{items} ) && ref( $S->{items} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"items"} and ref $S->{"items"} eq "HASH") 0 0 0
Condition0%0/3
exists $S->{"items"} and ref $S->{"items"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $S->{"items"} and ref $S->{"items"} eq "HASH"
exists $S->{"items"} ref $S->{"items"} eq "HASH"
Truth table0%0/3
A and B
A= exists $S->{"items"}B= ref $S->{"items"} eq "HASH"
ABresult
0X0
100
111
1888 {
1889 0 my $items_ptr = _join_ptr( $sp, 'items' );
1890 0 $items_fn = $self->_compile_js_node( $S->{items}, $items_ptr, $seen, $funcs, $counter_ref, $root, $opts );
1891 }
1892  
1893 0 ▶ my $min_items = exists( $S->{minItems} ) ? int( $S->{minItems} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $S->{'minItems'} ? : 0 0 0
1894 0 ▶ my $max_items = exists( $S->{maxItems} ) ? int( $S->{maxItems} ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $S->{'maxItems'} ? : 0 0 0
1895  
1896 0 my( $qmsg_min, $qmsg_max );
1897 0 ▶ if( defined( $min_items ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min_items) 0 0 0
1898 {
1899 0 my $msg_min = "array has fewer than $min_items items";
1900 0 $qmsg_min = _js_quote( $msg_min );
1901 }
1902 0 ▶ if( defined( $max_items ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_items) 0 0 0
1903 {
1904 0 my $msg_max = "array has more than $max_items items";
1905 0 $qmsg_max = _js_quote( $msg_max );
1906 }
1907  
1908 0 push( @body, <<JS_RUNTIME );
1909 if(_jsv_typeOf(inst) === 'array')
1910 {
1911 JS_RUNTIME
1912  
1913 0 ▶ if( defined( $min_items ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $min_items) 0 0 0
1914 {
1915 0 push( @body, <<JS_RUNTIME );
1916 if(inst.length < $min_items)
1917 {
1918 _jsv_err(ctx, path, 'minItems', $qmsg_min, $qsp);
1919 }
1920 JS_RUNTIME
1921 }
1922  
1923 0 ▶ if( defined( $max_items ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_items) 0 0 0
1924 {
1925 0 push( @body, <<JS_RUNTIME );
1926 if(inst.length > $max_items)
1927 {
1928 _jsv_err(ctx, path, 'maxItems', $qmsg_max, $qsp);
1929 }
1930 JS_RUNTIME
1931 }
1932  
1933 0 ▶ if( $items_fn )
Branch: 1 branch
BranchTrueFalseTotal
if ($items_fn) 0 0 0
1934 {
1935 0 push( @body, <<JS_RUNTIME );
1936 for(var i = 0; i < inst.length; i++)
1937 {
1938 $items_fn(inst[i], path + '/' + i, ctx);
1939 if(ctx.maxErrors && ctx.errors && ctx.errors.length >= ctx.maxErrors)
1940 {
1941 return;
1942 }
1943 }
1944 JS_RUNTIME
1945 }
1946  
1947 0 push( @body, <<JS_RUNTIME );
1948 }
1949 JS_RUNTIME
1950 }
1951  
1952 # NOTE: properties
1953 # 8) properties (objects) – recurse into children
1954 0 ▶ if( exists( $S->{properties} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"properties"} and ref $S->{"properties"} eq "HASH") 0 0 0
Condition0%0/3
exists $S->{"properties"} and ref $S->{"properties"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $S->{"properties"} and ref $S->{"properties"} eq "HASH"
exists $S->{"properties"} ref $S->{"properties"} eq "HASH"
Truth table0%0/3
A and B
A= exists $S->{"properties"}B= ref $S->{"properties"} eq "HASH"
ABresult
0X0
100
111
1955 ref( $S->{properties} ) eq 'HASH' )
1956 {
1957 0 push( @body, <<JS_RUNTIME );
1958 if(_jsv_typeOf(inst) === 'object')
1959 {
1960 JS_RUNTIME
1961  
1962 0 for my $p ( sort( keys( %{$S->{properties}} ) ) )
1963 {
1964 0 my $child = $S->{properties}->{ $p };
1965 0 my $child_ptr = _join_ptr( $sp, 'properties', $p );
1966 0 my $child_fn = $self->_compile_js_node( $child, $child_ptr, $seen, $funcs, $counter_ref, $root, $opts );
1967  
1968 0 my $qp = _js_quote( $p );
1969 0 my $path_suffix = '/' . $p;
1970 0 my $path_suffix_q = _js_quote( $path_suffix );
1971  
1972 0 push( @body, <<JS_RUNTIME );
1973 if(_jsv_hasOwn(inst, $qp))
1974 {
1975 // $child_ptr
1976 $child_fn(inst[$qp], path + $path_suffix_q, ctx);
1977 }
1978 JS_RUNTIME
1979 }
1980  
1981 0 push( @body, <<JS_RUNTIME );
1982 }
1983 JS_RUNTIME
1984 }
1985  
1986 # NOTE: definitions – recurse into named schemas
1987 0 ▶ if( exists( $S->{definitions} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"definitions"} and ref $S->{"definitions"} eq "HASH") 0 0 0
Condition0%0/3
exists $S->{"definitions"} and ref $S->{"definitions"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
exists $S->{"definitions"} and ref $S->{"definitions"} eq "HASH"
exists $S->{"definitions"} ref $S->{"definitions"} eq "HASH"
Truth table0%0/3
A and B
A= exists $S->{"definitions"}B= ref $S->{"definitions"} eq "HASH"
ABresult
0X0
100
111
1988 ref( $S->{definitions} ) eq 'HASH' )
1989 {
1990 0 for my $name ( sort keys %{ $S->{definitions} } )
1991 {
1992 0 my $child = $S->{definitions}->{ $name };
1993 0 my $child_ptr = _join_ptr( $sp, 'definitions', $name );
1994 0 my $child_fn = $self->_compile_js_node( $child, $child_ptr, $seen, $funcs, $counter_ref, $root, $opts );
1995  
1996 # No runtime call needed here - definitions don't validate by themselves.
1997 # We just need them compiled so pointer-based lookup can see them.
1998 }
1999 }
2000  
2001 # NOTE: contains
2002 # 9) contains / minContains / maxContains (arrays)
2003 0 ▶ if( exists( $S->{contains} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contains"}) 0 0 0
2004 {
2005 0 my $contains_schema = $S->{contains};
2006 0 my $contains_ptr = _join_ptr( $sp, 'contains' );
2007 0 my $contains_fn = $self->_compile_js_node( $contains_schema, $contains_ptr, $seen, $funcs, $counter_ref, $root, $opts );
2008 0 my $qsp_contains = _js_quote( $contains_ptr );
2009  
2010 0 my $have_min = exists( $S->{minContains} );
2011 0 my $have_max = exists( $S->{maxContains} );
2012 0 ▶ my $min = $have_min ? int( $S->{minContains} ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$have_min ? : 0 0 0
2013 0 ▶ my $max = $have_max ? int( $S->{maxContains} ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$have_max ? : 0 0 0
2014  
2015 0 my $msg_min = "array has fewer than $min items matching contains subschema";
2016 0 my $qmsg_min = _js_quote( $msg_min );
2017 0 my $msg_max = "array has more than $max items matching contains subschema";
2018 0 my $qmsg_max = _js_quote( $msg_max );
2019 0 my $msg_cont = "array does not contain any item matching contains subschema";
2020 0 my $qmsg_cont= _js_quote( $msg_cont );
2021  
2022 0 push( @body, <<JS_RUNTIME );
2023 if(_jsv_typeOf(inst) === 'array')
2024 {
2025 var matchCount = 0;
2026 for(var i = 0; i < inst.length; i++)
2027 {
2028 var tmpCtx = { errors: [], maxErrors: ctx.maxErrors };
2029 // $contains_ptr
2030 $contains_fn(inst[i], path + '/' + i, tmpCtx);
2031 if(tmpCtx.errors.length === 0)
2032 {
2033 matchCount++;
2034 }
2035 }
2036 JS_RUNTIME
2037  
2038 0 ▶ if( $have_min )
Branch: 1 branch
BranchTrueFalseTotal
if ($have_min) 0 0 0
2039 {
2040 0 push( @body, <<JS_RUNTIME );
2041 if(matchCount < $min)
2042 {
2043 _jsv_err(ctx, path, 'minContains', $qmsg_min, $qsp_contains);
2044 }
2045 JS_RUNTIME
2046 }
2047  
2048 0 ▶ if( $have_max )
Branch: 1 branch
BranchTrueFalseTotal
if ($have_max) 0 0 0
2049 {
2050 0 push( @body, <<JS_RUNTIME );
2051 if(matchCount > $max)
2052 {
2053 _jsv_err(ctx, path, 'maxContains', $qmsg_max, $qsp_contains);
2054 }
2055 JS_RUNTIME
2056 }
2057  
2058 # Plain "contains" only if no min/max are present
2059 0 ▶ if( !$have_min && !$have_max )
Branch: 1 branch
BranchTrueFalseTotal
unless ($have_min or $have_max) 0 0 0
Condition0%0/3
$have_min or $have_max
l!l&&r!l&&!r
000
MC/DC0%0/2
$have_min or $have_max
$have_min $have_max
Truth table0%0/3
A or B
A= $have_minB= $have_max
ABresult
1X1
011
000
2060 {
2061 0 push( @body, <<JS_RUNTIME );
2062 if(matchCount === 0)
2063 {
2064 _jsv_err(ctx, path, 'contains', $qmsg_cont, $qsp_contains);
2065 }
2066 JS_RUNTIME
2067 }
2068  
2069 0 push( @body, <<JS_RUNTIME );
2070 }
2071 JS_RUNTIME
2072 }
2073  
2074 0 push( @body, <<JS_RUNTIME );
2075 }
2076 JS_RUNTIME
2077  
2078 0 push( @$funcs, join( '', @body ) );
2079  
2080 0 return( $fn );
2081 }
2082  
2083 sub _compile_node
2084 38 ▶{
Subroutine _compile_node: called CC=40 SCAR=62.6
2085 38 my( $root, $ptr, $S ) = @_;
2086  
2087 # Non-hash schemas (incl. booleans) => trivial pass
2088 return sub
2089 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2090 0 my( $ctx, $inst ) = @_;
2091 0 return( { ok => 1, props => {}, items => {} } );
2092 38 ▶ } unless( ref( $S ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $S eq "HASH" 0 38 38
2093  
2094 # NOTE: $ref / $dynamicRef must not be compiled inline
2095 # A child node carrying a reference has no local keywords of its own, so
2096 # compiling it would produce a closure that trivially succeeds and the
2097 # referenced schema would never be applied. Referenced nodes are therefore
2098 # delegated back to _v_node(), which resolves the reference before it
2099 # considers the compiled path. There is no recursion risk here, because
2100 # _v_node() handles the reference before it looks up the compiled index.
2101 38 ▶ if( exists( $S->{'$ref'} ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"\$ref"} or exists $S->{"\$dynamicRef"}) 3 35 38
Condition66%2/3
exists $S->{"\$ref"} or exists $S->{"\$dynamicRef"}
l!l&&r!l&&!r
3035
MC/DC50%1/2
exists $S->{"\$ref"} or exists $S->{"\$dynamicRef"}
exists $S->{"\$ref"} exists $S->{"\$dynamicRef"}
Truth table66%2/3
A or B
A= exists $S->{"\$ref"}B= exists $S->{"\$dynamicRef"}
ABresult
1X1
011
000
2102 exists( $S->{'$dynamicRef'} ) )
2103 {
2104 return sub
2105 0 ▶ {
Subroutine __ANON__: not called CC=1 SCAR=6.9
2106 0 my( $ctx, $inst ) = @_;
2107 0 return( _v_node( $ctx, $ptr, $S, $inst ) );
2108 3 };
2109 }
2110  
2111 # Capture presence and values so runtime avoids hash lookups
2112 35 my $has_type = exists( $S->{type} );
2113 35 my $type_spec = $S->{type};
2114  
2115 35 my $has_const = exists( $S->{const} );
2116 35 my $const_val = $S->{const};
2117  
2118 35 my $has_enum = exists( $S->{enum} );
2119 35 my $enum_vals = $S->{enum};
2120  
2121 35 my %numk = map{ $_ => $S->{ $_ } } grep{ exists( $S->{ $_ } ) }
2122 qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum );
2123  
2124 35 ▶ my $has_strlen = ( exists( $S->{minLength} ) || exists( $S->{maxLength} ) || exists( $S->{pattern} ) ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
exists $S->{'minLength'} || exists $S->{'maxLength'} || exists $S->{'pattern'} ? : 2 33 35
Condition66%4/6
exists $S->{"minLength"} or exists $S->{"maxLength"} or exists $S->{"pattern"}
l!l&&r!l&&!r
2033
exists $S->{"minLength"} or exists $S->{"maxLength"}
l!l&&r!l&&!r
2033
MC/DC33%1/3
exists $S->{"minLength"} or exists $S->{"maxLength"} or exists $S->{"pattern"}
exists $S->{"minLength"} exists $S->{"maxLength"} exists $S->{"pattern"}
Truth table50%2/4
A or B or C
A= exists $S->{"minLength"}B= exists $S->{"maxLength"}C= exists $S->{"pattern"}
ABCresult
1XX1
01X1
0011
0000
2125 35 my $has_format = exists( $S->{format} );
2126 35 my $format_name = $S->{format};
2127  
2128 my $has_unique_keys =
2129 exists( $S->{uniqueKeys} ) &&
2130 35 ▶ ref( $S->{uniqueKeys} ) eq 'ARRAY';
Condition33%1/3
exists $S->{'uniqueKeys'} && ref $S->{'uniqueKeys'} eq 'ARRAY'
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{'uniqueKeys'} && ref $S->{'uniqueKeys'} eq 'ARRAY'
exists $S->{'uniqueKeys'} ref $S->{'uniqueKeys'} eq 'ARRAY'
Truth table33%1/3
A && B
A= exists $S->{'uniqueKeys'}B= ref $S->{'uniqueKeys'} eq 'ARRAY'
ABresult
0X0
100
111
2131  
2132 # Precompile child closures (same structure our interpreter walks)
2133 35 my %child;
2134  
2135 # Arrays
2136 35 ▶ if( ref( $S->{prefixItems} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"prefixItems"} eq "ARRAY") 0 35 35
2137 {
2138 0 for my $i ( 0 .. $#{ $S->{prefixItems} } )
2139 {
2140 0 my $cp = _join_ptr( $ptr, "prefixItems/$i" );
2141 0 $child{ "prefix:$i" } = _compile_node( $root, $cp, $S->{prefixItems}->[$i] );
2142 }
2143 }
2144 35 ▶ if( ref( $S->{items} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"items"} eq "HASH") 0 35 35
2145 {
2146 0 $child{ "items" } = _compile_node( $root, _join_ptr( $ptr, "items" ), $S->{items} );
2147 }
2148 35 ▶ if( exists( $S->{contains} ) && ref( $S->{contains} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contains"} and ref $S->{"contains"}) 0 35 35
Condition33%1/3
exists $S->{"contains"} and ref $S->{"contains"}
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"contains"} and ref $S->{"contains"}
exists $S->{"contains"} ref $S->{"contains"}
Truth table33%1/3
A and B
A= exists $S->{"contains"}B= ref $S->{"contains"}
ABresult
0X0
100
111
2149 {
2150 0 $child{ "contains" } = _compile_node( $root, _join_ptr( $ptr, "contains" ), $S->{contains} );
2151 }
2152 35 ▶ if( exists( $S->{unevaluatedItems} ) && ref( $S->{unevaluatedItems} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedItems"} and ref $S->{"unevaluatedItems"} eq "HASH") 0 35 35
Condition33%1/3
exists $S->{"unevaluatedItems"} and ref $S->{"unevaluatedItems"} eq "HASH"
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"unevaluatedItems"} and ref $S->{"unevaluatedItems"} eq "HASH"
exists $S->{"unevaluatedItems"} ref $S->{"unevaluatedItems"} eq "HASH"
Truth table33%1/3
A and B
A= exists $S->{"unevaluatedItems"}B= ref $S->{"unevaluatedItems"} eq "HASH"
ABresult
0X0
100
111
2153 {
2154 0 $child{ "unevaluatedItems" } = _compile_node( $root, _join_ptr( $ptr, "unevaluatedItems" ), $S->{unevaluatedItems} );
2155 }
2156  
2157 # Objects
2158 35 ▶ if( ref( $S->{properties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"properties"} eq "HASH") 11 24 35
2159 {
2160 11 for my $k ( keys( %{$S->{properties}} ) )
2161 {
2162 15 my $cp = _join_ptr( $ptr, "properties/$k" );
2163 15 $child{ "prop:$k" } = _compile_node( $root, $cp, $S->{properties}->{ $k } );
2164 }
2165 }
2166 35 ▶ if( ref( $S->{patternProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"patternProperties"} eq "HASH") 0 35 35
2167 {
2168 0 for my $re ( keys( %{ $S->{patternProperties} } ) )
2169 {
2170 0 my $cp = _join_ptr( $ptr, "patternProperties/$re" );
2171 0 $child{ "pat:$re" } = _compile_node( $root, $cp, $S->{patternProperties}->{ $re } );
2172 }
2173 }
2174 35 ▶ if( exists( $S->{additionalProperties} ) && ref( $S->{additionalProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"additionalProperties"} and ref $S->{"additionalProperties"} eq "HASH") 0 35 35
Condition66%2/3
exists $S->{"additionalProperties"} and ref $S->{"additionalProperties"} eq "HASH"
!ll&&!rl&&r
25100
MC/DC0%0/2
exists $S->{"additionalProperties"} and ref $S->{"additionalProperties"} eq "HASH"
exists $S->{"additionalProperties"} ref $S->{"additionalProperties"} eq "HASH"
Truth table66%2/3
A and B
A= exists $S->{"additionalProperties"}B= ref $S->{"additionalProperties"} eq "HASH"
ABresult
0X0
100
111
2175 {
2176 0 $child{ "additional" } = _compile_node( $root, _join_ptr( $ptr, "additionalProperties" ), $S->{additionalProperties} );
2177 }
2178 35 ▶ if( exists( $S->{propertyNames} ) && ref( $S->{propertyNames} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH") 0 35 35
Condition33%1/3
exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH"
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH"
exists $S->{"propertyNames"} ref $S->{"propertyNames"} eq "HASH"
Truth table33%1/3
A and B
A= exists $S->{"propertyNames"}B= ref $S->{"propertyNames"} eq "HASH"
ABresult
0X0
100
111
2179 {
2180 0 $child{ "propnames" } = _compile_node( $root, _join_ptr( $ptr, "propertyNames" ), $S->{propertyNames} );
2181 }
2182 35 ▶ if( exists( $S->{dependentSchemas} ) && ref( $S->{dependentSchemas} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"dependentSchemas"} and ref $S->{"dependentSchemas"} eq "HASH") 0 35 35
Condition33%1/3
exists $S->{"dependentSchemas"} and ref $S->{"dependentSchemas"} eq "HASH"
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"dependentSchemas"} and ref $S->{"dependentSchemas"} eq "HASH"
exists $S->{"dependentSchemas"} ref $S->{"dependentSchemas"} eq "HASH"
Truth table33%1/3
A and B
A= exists $S->{"dependentSchemas"}B= ref $S->{"dependentSchemas"} eq "HASH"
ABresult
0X0
100
111
2183 {
2184 0 for my $k ( keys( %{$S->{dependentSchemas}} ) )
2185 {
2186 0 my $cp = _join_ptr( $ptr, "dependentSchemas/$k" );
2187 0 $child{ "deps:$k" } = _compile_node( $root, $cp, $S->{dependentSchemas}->{ $k } );
2188 }
2189 }
2190 35 ▶ if( exists( $S->{unevaluatedProperties} ) && ref( $S->{unevaluatedProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedProperties"} and ref $S->{"unevaluatedProperties"} eq "HASH") 0 35 35
Condition33%1/3
exists $S->{"unevaluatedProperties"} and ref $S->{"unevaluatedProperties"} eq "HASH"
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"unevaluatedProperties"} and ref $S->{"unevaluatedProperties"} eq "HASH"
exists $S->{"unevaluatedProperties"} ref $S->{"unevaluatedProperties"} eq "HASH"
Truth table33%1/3
A and B
A= exists $S->{"unevaluatedProperties"}B= ref $S->{"unevaluatedProperties"} eq "HASH"
ABresult
0X0
100
111
2191 {
2192 0 $child{ "ueprops" } = _compile_node( $root, _join_ptr( $ptr, "unevaluatedProperties" ), $S->{unevaluatedProperties} );
2193 }
2194  
2195 # Combinators
2196 35 for my $kw ( qw( allOf anyOf oneOf not ) )
2197 {
2198 140 ▶ next unless( exists( $S->{ $kw } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{$kw} 140 0 140
2199 0 ▶ if( $kw eq 'not' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "not") 0 0 0
2200 {
2201 0 ▶ $child{ "not" } = _compile_node( $root, _join_ptr( $ptr, "not" ), $S->{not} ) if( ref( $S->{not} ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $S->{"not"} 0 0 0
2202 0 next;
2203 }
2204 0 ▶ if( ref( $S->{ $kw } ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{$kw} eq "ARRAY") 0 0 0
2205 {
2206 0 for my $i ( 0 .. $#{$S->{ $kw }} )
2207 {
2208 0 my $cp = _join_ptr( $ptr, "$kw/$i" );
2209 0 $child{ "$kw:$i" } = _compile_node( $root, $cp, $S->{ $kw }->[$i] );
2210 }
2211 }
2212 }
2213  
2214 # Conditionals
2215 35 ▶ if( exists( $S->{if} ) && ref( $S->{if} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"if"} and ref $S->{"if"} eq "HASH") 0 35 35
Condition33%1/3
exists $S->{"if"} and ref $S->{"if"} eq "HASH"
!ll&&!rl&&r
3500
MC/DC0%0/2
exists $S->{"if"} and ref $S->{"if"} eq "HASH"
exists $S->{"if"} ref $S->{"if"} eq "HASH"
Truth table33%1/3
A and B
A= exists $S->{"if"}B= ref $S->{"if"} eq "HASH"
ABresult
0X0
100
111
2216 {
2217 0 $child{ "if" } = _compile_node( $root, _join_ptr( $ptr, 'if' ), $S->{if} );
2218 0 ▶ $child{ "then" } = _compile_node( $root, _join_ptr( $ptr, 'then' ), $S->{then} ) if( exists( $S->{then} ) && ref( $S->{then} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $S->{"then"} and ref $S->{"then"} 0 0 0
Condition0%0/3
exists $S->{"then"} and ref $S->{"then"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $S->{"then"} and ref $S->{"then"}
exists $S->{"then"} ref $S->{"then"}
Truth table0%0/3
A and B
A= exists $S->{"then"}B= ref $S->{"then"}
ABresult
0X0
100
111
2219 0 ▶ $child{ "else" } = _compile_node( $root, _join_ptr( $ptr, 'else' ), $S->{else} ) if( exists( $S->{else} ) && ref( $S->{else} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $S->{"else"} and ref $S->{"else"} 0 0 0
Condition0%0/3
exists $S->{"else"} and ref $S->{"else"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $S->{"else"} and ref $S->{"else"}
exists $S->{"else"} ref $S->{"else"}
Truth table0%0/3
A and B
A= exists $S->{"else"}B= ref $S->{"else"}
ABresult
0X0
100
111
2220 }
2221  
2222 # Return specialized validator
2223 return sub
2224 35 ▶ {
Subroutine __ANON__: called CC=79 SCAR=78.6
2225 35 my( $ctx, $inst ) = @_;
2226  
2227 # Parity with interpreter: trace node visit
2228 35 ▶ _t( $ctx, $ptr, 'node', undef, 'visit' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 12 23 35
2229  
2230 # Type / const / enum
2231 35 ▶ if( $has_type ) { _k_type( $ctx, $inst, $type_spec, $ptr ) or return( _fail() ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($has_type) 35 0 35
_k_type($ctx, $inst, $type_spec, $ptr) or return _fail() 35 0 35
2232 0 ▶ if( $has_const ) { _k_const( $ctx, $inst, $const_val, $ptr ) or return( _fail() ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($has_const) 0 35 35
_k_const($ctx, $inst, $const_val, $ptr) or return _fail() 0 0 0
2233 0 ▶ if( $has_enum ) { _k_enum( $ctx, $inst, $enum_vals, $ptr ) or return( _fail() ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($has_enum) 0 35 35
_k_enum($ctx, $inst, $enum_vals, $ptr) or return _fail() 0 0 0
2234  
2235 # uniqueKeys extension (compiled path)
2236 35 ▶ if( $ctx->{unique_keys} && $has_unique_keys && ref( $inst ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"unique_keys"} and $has_unique_keys and ref $inst eq "ARRAY") 0 35 35
Condition33%2/6
$ctx->{"unique_keys"} and $has_unique_keys and ref $inst eq "ARRAY"
!ll&&!rl&&r
3500
$ctx->{"unique_keys"} and $has_unique_keys
!ll&&!rl&&r
3500
MC/DC0%0/3
$ctx->{"unique_keys"} and $has_unique_keys and ref $inst eq "ARRAY"
$ctx->{"unique_keys"} $has_unique_keys ref $inst eq "ARRAY"
Truth table25%1/4
A and B and C
A= $ctx->{"unique_keys"}B= $has_unique_keysC= ref $inst eq "ARRAY"
ABCresult
0XX0
10X0
1100
1111
2237 {
2238 0 my $r = _k_unique_keys( $ctx, $ptr, $S->{uniqueKeys}, $inst );
2239 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2240 }
2241  
2242 # Numbers
2243 35 ▶ if( _is_number( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (_is_number($inst)) 6 29 35
2244 {
2245 6 for my $k ( qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum ) )
2246 {
2247 27 ▶ next unless( exists( $numk{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $numk{$k} 25 2 27
2248 2 ▶ _k_number( $ctx, $inst, $k, $numk{$k}, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_number($ctx, $inst, $k, $numk{$k}, $ptr) or return _fail() 1 1 2
2249 }
2250 }
2251  
2252 # Strings
2253 34 ▶ if( !ref( $inst ) && defined( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $inst and defined $inst) 17 17 34
Condition66%2/3
not ref $inst and defined $inst
!ll&&!rl&&r
17017
MC/DC50%1/2
not ref $inst and defined $inst
not ref $inst defined $inst
Truth table66%2/3
not(A) and B
A= not ref $instB= defined $inst
ABresult
0X0
100
111
2254 {
2255 17 ▶ if( $has_strlen ) { _k_string( $ctx, $inst, $S, $ptr ) or return( _fail() ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($has_strlen) 2 15 17
_k_string($ctx, $inst, $S, $ptr) or return _fail() 1 1 2
2256 16 ▶ if( $has_format ) { _k_format( $ctx, $inst, $format_name, $ptr ) or return( _fail() ); }
Branch: 2 branches
BranchTrueFalseTotal
if ($has_format) 2 14 16
_k_format($ctx, $inst, $format_name, $ptr) or return _fail() 1 1 2
2257  
2258 # contentEncoding / contentMediaType / contentSchema (compiled path)
2259 15 ▶ if( exists( $S->{contentEncoding} ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentEncoding"} or exists $S->{"contentMediaType"} or exists $S->{"contentSchema"}) 0 15 15
Condition33%2/6
exists $S->{"contentEncoding"} or exists $S->{"contentMediaType"} or exists $S->{"contentSchema"}
l!l&&r!l&&!r
0015
exists $S->{"contentEncoding"} or exists $S->{"contentMediaType"}
l!l&&r!l&&!r
0015
MC/DC0%0/3
exists $S->{"contentEncoding"} or exists $S->{"contentMediaType"} or exists $S->{"contentSchema"}
exists $S->{"contentEncoding"} exists $S->{"contentMediaType"} exists $S->{"contentSchema"}
Truth table25%1/4
A or B or C
A= exists $S->{"contentEncoding"}B= exists $S->{"contentMediaType"}C= exists $S->{"contentSchema"}
ABCresult
1XX1
01X1
0011
0000
2260 exists( $S->{contentMediaType} ) ||
2261 exists( $S->{contentSchema} ) )
2262 {
2263 0 ▶ my $assert = $ctx->{content_assert} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'content_assert'} ? : 0 0 0
2264 0 my $bytes = "$inst";
2265 0 my $decoded_ref;
2266  
2267 0 ▶ if( exists( $S->{contentEncoding} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentEncoding"}) 0 0 0
2268 {
2269 0 my $dec = _content_decode( $ctx, $S->{contentEncoding}, $bytes );
2270 0 ▶ if( !defined( $dec ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dec) { } 0 0 0
2271 {
2272 0 ▶ return( _err_res( $ctx, $ptr, "contentEncoding '$S->{contentEncoding}' decode failed", 'contentEncoding' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 0 0 0
2273 }
2274 else
2275 {
2276 0 $bytes = $dec;
2277 }
2278 }
2279  
2280 0 ▶ if( exists( $S->{contentMediaType} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentMediaType"}) 0 0 0
2281 {
2282 0 my( $mt, $params ) = _parse_media_type( $S->{contentMediaType} );
2283 0 ▶ if( my $cb = $ctx->{media_validators}->{ $mt } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{'media_validators'}{$mt}) { } 0 0 0
2284 {
2285 0 my( $ok, $msg, $maybe_decoded ) = _safe_invoke( $cb, $bytes, $params );
2286 0 ▶ if( !$ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2287 {
2288 0 ▶ return( _err_res( $ctx, $ptr, ( $msg || "contentMediaType '$mt' validation failed" ), 'contentMediaType' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 0 0 0
Condition0%0/2
$msg || "contentMediaType '${mt}' validation failed"
l!l
00
MC/DC0%0/1
$msg || "contentMediaType '${mt}' validation failed"
$msg
Truth table0%0/2
A
A= $msg
Aresult
11
00
2289 }
2290 # If the media validator decoded into a Perl structure, keep it
2291 0 ▶ $decoded_ref = $maybe_decoded if( ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $maybe_decoded 0 0 0
2292 # If it produced new octets/text, keep that too
2293 0 ▶ $bytes = $maybe_decoded if( defined( $maybe_decoded ) && !ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $maybe_decoded and not ref $maybe_decoded 0 0 0
Condition0%0/3
defined $maybe_decoded and not ref $maybe_decoded
!ll&&!rl&&r
000
MC/DC0%0/2
defined $maybe_decoded and not ref $maybe_decoded
defined $maybe_decoded not ref $maybe_decoded
Truth table0%0/3
A and not(B)
A= defined $maybe_decodedB= not ref $maybe_decoded
ABresult
0X0
100
111
2294 }
2295 else
2296 {
2297 0 ▶ if( $mt =~ m{\Atext/} && ( ( $params->{charset} || '' ) =~ /\Autf-?8\z/i ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu) 0 0 0
Condition0%0/5
$mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu
!ll&&!rl&&r
000
$params->{'charset'} || ''
l!l
00
MC/DC0%0/2
$mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu
$mt =~ m[\Atext/]u $params->{'charset'}
Truth table0%0/3
A and B
A= $mt =~ m[\Atext/]uB= $params->{'charset'}
ABresult
0X0
100
111
2298 {
2299 0 local $@;
2300 my $ok = eval
2301 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; &Encode::decode('UTF-8', $bytes, 1); 1 } } ? : 0 0 0
2302 0 require Encode;
2303 0 Encode::decode( 'UTF-8', $bytes, Encode::FB_CROAK );
2304 0 1;
2305 } ? 1 : 0;
2306 0 ▶ if( !$ok && $assert )
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok and $assert) 0 0 0
Condition0%0/3
not $ok and $assert
!ll&&!rl&&r
000
MC/DC0%0/2
not $ok and $assert
not $ok $assert
Truth table0%0/3
not(A) and B
A= not $okB= $assert
ABresult
0X0
100
111
2307 {
2308 0 return( _err_res( $ctx, $ptr, "contentMediaType '$mt' invalid UTF-8", 'contentMediaType' ) );
2309 }
2310 }
2311 }
2312 }
2313  
2314 0 ▶ if( exists( $S->{contentSchema} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentSchema"}) 0 0 0
2315 {
2316 0 my $val;
2317  
2318 0 ▶ if( ref( $decoded_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decoded_ref) { } 0 0 0
2319 {
2320 # already decoded by media validator (e.g. application/json)
2321 0 $val = $decoded_ref;
2322 }
2323 else
2324 {
2325 0 local $@;
2326 # still a string of bytes; try JSON decode now
2327 0 $val = eval{ JSON->new->allow_nonref(1)->utf8(1)->decode( $bytes ) };
2328 }
2329  
2330 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 0 0 0
2331 {
2332 0 ▶ return( _err_res( $ctx, $ptr, "contentSchema present but payload not JSON-decodable", 'contentSchema' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 0 0 0
2333 }
2334 else
2335 {
2336 0 my $r = _v( $ctx, _join_ptr( $ptr, 'contentSchema' ), $S->{contentSchema}, $val );
2337 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2338 }
2339 }
2340 }
2341 }
2342  
2343 32 my %ann_props;
2344 my %ann_items;
2345  
2346 # Arrays
2347 32 ▶ if( ref( $inst ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "ARRAY") 0 32 32
2348 {
2349 0 my $r = _k_array_all( $ctx, $ptr, $S, $inst );
2350 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2351 0 %ann_items = ( %ann_items, %{$r->{items}} );
2352 }
2353  
2354 # Objects
2355 32 ▶ if( ref( $inst ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "HASH") 17 15 32
2356 {
2357 17 my $r = _k_object_all( $ctx, $ptr, $S, $inst );
2358 17 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 7 10 17
2359 10 %ann_props = ( %ann_props, %{$r->{props}} );
2360 }
2361  
2362 # Combinators
2363 # allOf: all subschemas must pass, and we merge their annotations.
2364 25 ▶ if( exists( $S->{allOf} ) && ref( $S->{allOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY") 0 25 25
Condition33%1/3
exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY"
!ll&&!rl&&r
2500
MC/DC0%0/2
exists $S->{"allOf"} and ref $S->{"allOf"} eq "ARRAY"
exists $S->{"allOf"} ref $S->{"allOf"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $S->{"allOf"}B= ref $S->{"allOf"} eq "ARRAY"
ABresult
0X0
100
111
2365 {
2366 0 my( %p, %it );
2367 0 for my $i ( 0 .. $#{ $S->{allOf} } )
2368 {
2369 0 my $r = $child{ "allOf:$i" }->( $ctx, $inst );
2370 0 ▶ return $r unless $r->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2371 0 %p = ( %p, %{$r->{props}} );
2372 0 %it = ( %it, %{$r->{items}} );
2373 }
2374 0 %ann_props = ( %ann_props, %p );
2375 0 %ann_items = ( %ann_items, %it );
2376 }
2377  
2378 # anyOf: at least one subschema must pass; do NOT leak errors from
2379 # non-selected branches into the main context.
2380 25 ▶ if( exists( $S->{anyOf} ) && ref( $S->{anyOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY") 0 25 25
Condition33%1/3
exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY"
!ll&&!rl&&r
2500
MC/DC0%0/2
exists $S->{"anyOf"} and ref $S->{"anyOf"} eq "ARRAY"
exists $S->{"anyOf"} ref $S->{"anyOf"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $S->{"anyOf"}B= ref $S->{"anyOf"} eq "ARRAY"
ABresult
0X0
100
111
2381 {
2382 0 my $ok = 0;
2383 0 my( %p, %it );
2384 0 my @branch_errs;
2385  
2386 0 for my $i ( 0 .. $#{ $S->{anyOf} } )
2387 {
2388 # Shadow context for this branch
2389 0 my %shadow = %$ctx;
2390 0 my @errs;
2391 0 $shadow{errors} = \@errs;
2392 0 $shadow{error_count} = 0;
2393  
2394 0 my $r = $child{ "anyOf:$i" }->( \%shadow, $inst );
2395  
2396 0 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"ok"}) 0 0 0
2397 {
2398 0 $ok = 1;
2399 0 %p = ( %p, %{$r->{props}} );
2400 0 %it = ( %it, %{$r->{items}} );
2401 0 last;
2402 }
2403  
2404 0 push( @branch_errs, \@errs );
2405 }
2406  
2407 0 ▶ unless( $ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2408 {
2409 # No branch matched: merge collected branch errors into main context
2410 0 for my $aref ( @branch_errs )
2411 {
2412 0 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 0 0
2413 0 push( @{$ctx->{errors}}, @$aref );
2414 0 $ctx->{error_count} += scalar( @$aref );
2415 }
2416  
2417 0 return( _err_res( $ctx, $ptr, "instance does not satisfy anyOf", 'anyOf' ) );
2418 }
2419  
2420 0 %ann_props = ( %ann_props, %p );
2421 0 %ann_items = ( %ann_items, %it );
2422 }
2423  
2424 # oneOf: exactly one subschema must pass; again, isolate branch errors.
2425 25 ▶ if( exists( $S->{oneOf} ) && ref( $S->{oneOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY") 0 25 25
Condition33%1/3
exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY"
!ll&&!rl&&r
2500
MC/DC0%0/2
exists $S->{"oneOf"} and ref $S->{"oneOf"} eq "ARRAY"
exists $S->{"oneOf"} ref $S->{"oneOf"} eq "ARRAY"
Truth table33%1/3
A and B
A= exists $S->{"oneOf"}B= ref $S->{"oneOf"} eq "ARRAY"
ABresult
0X0
100
111
2426 {
2427 0 my $hits = 0;
2428  
2429 0 for my $i ( 0 .. $#{ $S->{oneOf} } )
2430 {
2431 0 my %shadow = %$ctx;
2432 0 my @errs;
2433 0 $shadow{errors} = \@errs;
2434 0 $shadow{error_count} = 0;
2435  
2436 0 my $r = $child{ "oneOf:$i" }->( \%shadow, $inst );
2437 0 ▶ $hits++ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 0 0 0
2438 }
2439  
2440 0 ▶ return( _err_res( $ctx, $ptr, "instance satisfies $hits subschemas in oneOf (expected exactly 1)", 'oneOf' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless $hits == 1 0 0 0
2441 unless( $hits == 1 );
2442 }
2443  
2444 # not: the inner schema must **fail**; its own errors are irrelevant
2445 # on success, so we run it entirely in a shadow context.
2446 25 ▶ if( exists( $S->{not} ) && ref( $S->{not} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"not"} and ref $S->{"not"}) 0 25 25
Condition33%1/3
exists $S->{"not"} and ref $S->{"not"}
!ll&&!rl&&r
2500
MC/DC0%0/2
exists $S->{"not"} and ref $S->{"not"}
exists $S->{"not"} ref $S->{"not"}
Truth table33%1/3
A and B
A= exists $S->{"not"}B= ref $S->{"not"}
ABresult
0X0
100
111
2447 {
2448 0 my %shadow = %$ctx;
2449 0 my @errs;
2450 0 $shadow{errors} = \@errs;
2451 0 $shadow{error_count} = 0;
2452  
2453 0 my $r = $child{ "not" }->( \%shadow, $inst );
2454  
2455 # If inner schema passes, then "not" fails
2456 return( _err_res( $ctx, $ptr, "instance matches forbidden not-schema", 'not' ) )
2457 0 ▶ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 0 0 0
2458  
2459 # Otherwise, "not" is satisfied; ignore inner errors entirely
2460 }
2461  
2462 # Conditionals
2463 25 ▶ if( exists( $S->{if} ) && ref( $S->{if} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"if"} and ref $S->{"if"}) 0 25 25
Condition33%1/3
exists $S->{"if"} and ref $S->{"if"}
!ll&&!rl&&r
2500
MC/DC0%0/2
exists $S->{"if"} and ref $S->{"if"}
exists $S->{"if"} ref $S->{"if"}
Truth table33%1/3
A and B
A= exists $S->{"if"}B= ref $S->{"if"}
ABresult
0X0
100
111
2464 {
2465 # NOTE: the if branch is evaluated in a shadow context
2466 # Parity with the interpreted path and with the documented behaviour: 'if' is a
2467 # selector, never an assertion, so the errors it produces while probing the
2468 # instance must not leak into the caller's error list. Only 'then' and 'else'
2469 # report against the main context.
2470 0 my %if_shadow = %$ctx;
2471 0 my @if_errs;
2472 0 $if_shadow{errors} = \@if_errs;
2473 0 $if_shadow{error_count} = 0;
2474  
2475 0 my $cond = $child{ "if" }->( \%if_shadow, $inst );
2476 0 ▶ if( $cond->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cond->{'ok'}) { } 0 0 0
2477 {
2478 0 ▶ if( exists( $child{ "then" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $child{"then"}) 0 0 0
2479 {
2480 0 my $r = $child{ "then" }->( $ctx, $inst );
2481 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2482 }
2483 }
2484 else
2485 {
2486 0 ▶ if( exists( $child{ "else" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $child{"else"}) 0 0 0
2487 {
2488 0 my $r = $child{ "else" }->( $ctx, $inst );
2489 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2490 }
2491 }
2492 }
2493  
2494 25 ▶ _t( $ctx, $ptr, 'node', undef, 'pass' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 8 17 25
2495 25 return( { ok => 1, props => \%ann_props, items => \%ann_items } );
2496 35 };
2497 }
2498  
2499 # Compilation / Indexing
2500 sub _compile_root
2501 114 ▶{
Subroutine _compile_root: called CC=6 SCAR=18.4
2502 114 my( $schema ) = @_;
2503  
2504 114 ▶ if( ref( $schema ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH") 114 0 114
2505 {
2506 114 ▶ $schema->{'$defs'} ||= delete( $schema->{definitions} ) if( exists( $schema->{definitions} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $schema->{"definitions"} 2 112 114
Condition33%1/3
$schema->{"\$defs"} ||= delete $schema->{"definitions"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$schema->{"\$defs"} ||= delete $schema->{"definitions"}
$schema->{"\$defs"} delete $schema->{"definitions"}
Truth table33%1/3
A ||= B
A= $schema->{"\$defs"}B= delete $schema->{"definitions"}
ABresult
1X1
011
000
2507 }
2508  
2509 114 ▶ my $base = _normalize_uri( ( ref( $schema ) eq 'HASH' && $schema->{'$id'} ) ? $schema->{'$id'} : '#' );
Branch: 1 branch
BranchTrueFalseTotal
ref $schema eq 'HASH' && $schema->{'$id'} ? : 9 105 114
Condition66%2/3
ref $schema eq "HASH" and $schema->{"\$id"}
!ll&&!rl&&r
01059
MC/DC50%1/2
ref $schema eq "HASH" and $schema->{"\$id"}
ref $schema eq "HASH" $schema->{"\$id"}
Truth table66%2/3
A and B
A= ref $schema eq "HASH"B= $schema->{"\$id"}
ABresult
0X0
100
111
2510  
2511 114 my $anchors = {};
2512 114 my $id_index = {};
2513  
2514 114 _index_schema_202012( $schema, $base, '#', $anchors, $id_index );
2515  
2516 return({
2517 114 schema => $schema,
2518 anchors => $anchors, # "#/a/b/0"
2519 id_index => $id_index, # absolute IDs and #anchors
2520 base => $base,
2521 fn_index => {}, # cache of ptr => compiled closure
2522 });
2523 }
2524  
2525 sub _content_decode
2526 9 ▶{
Subroutine _content_decode: called CC=5 SCAR=16.7
2527 9 my( $ctx, $enc, $s ) = @_;
2528 9 ▶ $enc = lc( $enc // '' );
Condition50%1/2
$enc // ""
l!l
90
MC/DC0%0/1
$enc // ""
$enc
Truth table50%1/2
A
A= $enc
Aresult
11
00
2529  
2530 9 ▶ if( my $cb = $ctx->{content_decoders}->{ $enc } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{"content_decoders"}{$enc}) 3 6 9
2531 {
2532 3 my( $ok, $msg, $out ) = _safe_invoke( $cb, $s );
2533 3 ▶ return( $ok ? $out : undef );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 3 0 3
2534 }
2535  
2536 6 ▶ if( $enc eq 'base64' )
Branch: 1 branch
BranchTrueFalseTotal
if ($enc eq "base64") 6 0 6
2537 {
2538 6 my $out = _strict_base64_decode( $s );
2539 # undef on failure is exactly what we want
2540 6 return( $out );
2541 }
2542  
2543 # Unknown encoding (annotation only unless assert)
2544 0 return;
2545 }
2546  
2547 # Errors, utils, pointers, URIs
2548 sub _err
2549 176 ▶{
Subroutine _err: called CC=5 SCAR=17.3
2550 176 my( $ctx, $schema_ptr, $msg, $keyword ) = @_;
2551 176 ▶ return(0) if( $ctx->{error_count} >= $ctx->{max_errors} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"error_count"} >= $ctx->{"max_errors"} 0 176 176
2552  
2553 # Instance path: use current ptr_stack top if available, else '#'
2554 176 ▶ my $inst_path = $ctx->{ptr_stack} && @{$ctx->{ptr_stack}}
Condition50%1/2
$ctx->{"ptr_stack"}[-1] // "#"
l!l
1760
MC/DC0%0/1
$ctx->{"ptr_stack"}[-1] // "#"
$ctx->{"ptr_stack"}[-1]
Truth table50%1/2
A
A= $ctx->{"ptr_stack"}[-1]
Aresult
11
00
2555 176 ▶ ? ( $ctx->{ptr_stack}->[-1] // '#' )
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'ptr_stack'} && @{$ctx->{'ptr_stack'};} ? : 176 0 176
Condition33%1/3
$ctx->{"ptr_stack"} and @{$ctx->{"ptr_stack"};}
!ll&&!rl&&r
00176
MC/DC0%0/2
$ctx->{"ptr_stack"} and @{$ctx->{"ptr_stack"};}
$ctx->{"ptr_stack"} @{$ctx->{"ptr_stack"};}
Truth table33%1/3
A and B
A= $ctx->{"ptr_stack"}B= @{$ctx->{"ptr_stack"};}
ABresult
0X0
100
111
2556 : '#';
2557  
2558 176 push( @{$ctx->{errors}}, JSON::Schema::Validate::Error->new(
2559 path => $inst_path,
2560 message => $msg,
2561 keyword => $keyword, # may be undef (back-compat)
2562 schema_pointer => $schema_ptr, # where in the schema this came from
2563 ));
2564 176 $ctx->{error_count}++;
2565 176 return(0);
2566 }
2567  
2568 sub _err_res
2569 85 ▶{
Subroutine _err_res: called CC=1 SCAR=0.0
2570 85 my( $ctx, $schema_ptr, $msg, $keyword ) = @_;
2571 85 _err( $ctx, $schema_ptr, $msg, $keyword );
2572 85 return( { ok => 0, props => {}, items => {} } );
2573 }
2574  
2575 # Used by _prune* methods
2576 sub _extract_array_shape
2577 1 ▶{
Subroutine _extract_array_shape: called CC=10 SCAR=28.2
2578 1 my( $self, $schema, $out ) = @_;
2579  
2580 1 ▶ return unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 1 1
2581  
2582 1 ▶ if( ref( $schema->{prefixItems} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"prefixItems"} eq "ARRAY") 1 0 1
2583 {
2584 1 my $src = $schema->{prefixItems};
2585 1 for my $i ( 0 .. $#$src )
2586 {
2587 # First win: do not override an existing prefix schema at this index
2588 $out->{prefix_items}->[ $i ] = $src->[ $i ]
2589 1 ▶ unless( defined( $out->{prefix_items}->[ $i ] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out->{"prefix_items"}[$i] 1 0 1
2590 }
2591 }
2592  
2593 1 ▶ if( exists( $schema->{items} ) && ref( $schema->{items} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"items"} and ref $schema->{"items"} eq "HASH") 1 0 1
Condition33%1/3
exists $schema->{"items"} and ref $schema->{"items"} eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
exists $schema->{"items"} and ref $schema->{"items"} eq "HASH"
exists $schema->{"items"} ref $schema->{"items"} eq "HASH"
Truth table33%1/3
A and B
A= exists $schema->{"items"}B= ref $schema->{"items"} eq "HASH"
ABresult
0X0
100
111
2594 {
2595 # Again, first win: if we already have items from another branch, keep it.
2596 1 ▶ $out->{items} = $schema->{items} unless( $out->{items} );
Branch: 1 branch
BranchTrueFalseTotal
unless $out->{"items"} 1 0 1
2597 }
2598  
2599 # allOf mixins for arrays as well
2600 1 ▶ if( ref( $schema->{allOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"allOf"} eq "ARRAY") 0 1 1
2601 {
2602 0 foreach my $sub ( @{$schema->{allOf}} )
2603 {
2604 0 $self->_extract_array_shape( $sub, $out );
2605 }
2606 }
2607  
2608 # anyOf / oneOf / not ignored for same reason as objects.
2609 }
2610  
2611 # Used by _prune* methods
2612 sub _extract_object_shape
2613 8 ▶{
Subroutine _extract_object_shape: called CC=17 SCAR=31.1
2614 8 my( $self, $schema, $out ) = @_;
2615  
2616 8 ▶ return unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 8 8
2617  
2618 # Direct properties
2619 8 ▶ if( ref( $schema->{properties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"properties"} eq "HASH") 6 2 8
2620 {
2621 6 foreach my $k ( keys( %{$schema->{properties}} ) )
2622 {
2623 # First win: do not override an already-collected subschema
2624 $out->{props}->{ $k } = $schema->{properties}->{ $k }
2625 7 ▶ unless( exists( $out->{props}->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $out->{"props"}{$k} 7 0 7
2626 }
2627 }
2628  
2629 # patternProperties
2630 8 ▶ if( ref( $schema->{patternProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"patternProperties"} eq "HASH") 1 7 8
2631 {
2632 1 foreach my $re ( keys( %{$schema->{patternProperties}} ) )
2633 {
2634 1 push( @{$out->{patterns}}, [ $re, $schema->{patternProperties}->{ $re } ] );
2635 }
2636 }
2637  
2638 # additionalProperties
2639 8 ▶ if( exists( $schema->{additionalProperties} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"additionalProperties"}) 7 1 8
2640 {
2641 7 my $ap = $schema->{additionalProperties};
2642  
2643 # JSON booleans or plain scalars
2644 7 ▶ if( !ref( $ap ) || ( blessed( $ap ) && $ap->isa( 'JSON::PP::Boolean' ) ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $ap or builtin::blessed($ap) and $ap->isa('JSON::PP::Boolean')) { } 7 0 7
elsif (ref $ap eq 'HASH') { } 0 0 0
Condition33%2/6
not ref $ap or builtin::blessed($ap) and $ap->isa("JSON::PP::Boolean")
l!l&&r!l&&!r
070
builtin::blessed($ap) and $ap->isa("JSON::PP::Boolean")
!ll&&!rl&&r
007
MC/DC0%0/3
not ref $ap or builtin::blessed($ap) and $ap->isa("JSON::PP::Boolean")
not ref $ap builtin::blessed($ap) $ap->isa("JSON::PP::Boolean")
Truth table25%1/4
not(A) or B and C
A= not ref $apB= builtin::blessed($ap)C= $ap->isa("JSON::PP::Boolean")
ABCresult
1XX1
0111
00X0
0100
2645 {
2646 7 ▶ if( $ap )
Branch: 1 branch
BranchTrueFalseTotal
if ($ap) { } 1 6 7
2647 {
2648 # true: additionalProperties allowed; keep any stricter setting we might already have
2649 1 ▶ $out->{allow_ap} = 1 unless( defined( $out->{allow_ap} ) && !$out->{allow_ap} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out->{"allow_ap"} and not $out->{"allow_ap"} 1 0 1
Condition33%1/3
defined $out->{"allow_ap"} and not $out->{"allow_ap"}
!ll&&!rl&&r
010
MC/DC0%0/2
defined $out->{"allow_ap"} and not $out->{"allow_ap"}
defined $out->{"allow_ap"} not $out->{"allow_ap"}
Truth table33%1/3
A and not(B)
A= defined $out->{"allow_ap"}B= not $out->{"allow_ap"}
ABresult
0X0
100
111
2650 # do not touch ap_schema here
2651 }
2652 else
2653 {
2654 # false: forbidden regardless of earlier "true"
2655 6 $out->{allow_ap} = 0;
2656 6 $out->{ap_schema} = undef;
2657 }
2658 }
2659 elsif( ref( $ap ) eq 'HASH' )
2660 {
2661 # Schema for additionals
2662 0 $out->{allow_ap} = 1;
2663 0 $out->{ap_schema} = $ap;
2664 }
2665 }
2666  
2667 # allOf mixins: merge their object keywords as well.
2668 8 ▶ if( ref( $schema->{allOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"allOf"} eq "ARRAY") 1 7 8
2669 {
2670 1 foreach my $sub ( @{$schema->{allOf}} )
2671 {
2672 2 $self->_extract_object_shape( $sub, $out );
2673 }
2674 }
2675  
2676 # NOTE:
2677 # We intentionally ignore anyOf / oneOf / not for pruning.
2678 # Without performing full validation against each branch, we cannot
2679 # safely decide which properties are truly forbidden, so we err on
2680 # the side of *keeping* more rather than over-pruning.
2681 }
2682  
2683 91 ▶sub _fail { return( { ok => 0, props => {}, items => {} } ); }
Subroutine _fail: called CC=1 SCAR=0.0
2684  
2685 sub _first_error_text
2686 0 ▶{
Subroutine _first_error_text: not called CC=2 SCAR=17.9
2687 0 my( $errs ) = @_;
2688 0 ▶ return( '' ) unless( @$errs );
Branch: 1 branch
BranchTrueFalseTotal
unless @$errs 0 0 0
2689 0 my $e = $errs->[0];
2690 0 return( "$e" );
2691 }
2692  
2693 sub _get_args_as_hash
2694 341 ▶{
Subroutine _get_args_as_hash: called CC=7 SCAR=20.2
2695 341 my $self = shift( @_ );
2696 341 ▶ return( {} ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 320 21 341
2697 21 my $ref = {};
2698 21 ▶ if( scalar( @_ ) == 1 &&
Branch: 2 branches
BranchTrueFalseTotal
if (scalar @_ == 1 and defined $_[0] and (ref $_[0] || '') eq 'HASH') { } 2 19 21
elsif (not scalar(@_) % 2) { } 19 0 19
Condition62%5/8
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
!ll&&!rl&&r
1902
scalar @_ == 1 and defined $_[0]
!ll&&!rl&&r
1902
ref $_[0] || ''
l!l
20
MC/DC33%1/3
scalar @_ == 1 and defined $_[0] and (ref $_[0] || "") eq "HASH"
scalar @_ == 1 defined $_[0] ref $_[0]
Truth table50%2/4
A and B and C
A= scalar @_ == 1B= defined $_[0]C= ref $_[0]
ABCresult
0XX0
10X0
1100
1111
2699 defined( $_[0] ) &&
2700 ( ref( $_[0] ) || '' ) eq 'HASH' )
2701 {
2702 2 $ref = shift( @_ );
2703 }
2704 elsif( !( scalar( @_ ) % 2 ) )
2705 {
2706 19 $ref = { @_ };
2707 }
2708 else
2709 {
2710 0 die( "Uneven number of parameters provided: '", join( "', '", map( overload::StrVal( $_ ), @_ ) ), "'" );
2711 }
2712 21 return( $ref );
2713 }
2714  
2715 sub _index_schema_202012
2716 1999 ▶{
Subroutine _index_schema_202012: called CC=14 SCAR=26.6
2717 1999 my( $node, $base_uri, $ptr, $anchors, $id_index ) = @_;
2718  
2719 1999 $anchors->{ $ptr } = $node;
2720  
2721 1999 my $here_base = $base_uri;
2722  
2723 1999 ▶ if( ref( $node ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node eq 'HASH') { } 790 1209 1999
elsif (ref $node eq 'ARRAY') { } 233 976 1209
2724 {
2725 790 ▶ if( exists( $node->{'$id'} ) && defined( $node->{'$id'} ) && $node->{'$id'} ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"\$id"} and defined $node->{"\$id"} and $node->{"\$id"} ne "") 15 775 790
Condition66%4/6
exists $node->{"\$id"} and defined $node->{"\$id"} and $node->{"\$id"} ne ""
!ll&&!rl&&r
775015
exists $node->{"\$id"} and defined $node->{"\$id"}
!ll&&!rl&&r
775015
MC/DC33%1/3
exists $node->{"\$id"} and defined $node->{"\$id"} and $node->{"\$id"} ne ""
exists $node->{"\$id"} defined $node->{"\$id"} $node->{"\$id"} ne ""
Truth table50%2/4
A and B and C
A= exists $node->{"\$id"}B= defined $node->{"\$id"}C= $node->{"\$id"} ne ""
ABCresult
0XX0
10X0
1100
1111
2726 {
2727 15 $here_base = _resolve_uri( $base_uri, $node->{'$id'} );
2728 15 $id_index->{ $here_base } = $node;
2729 }
2730  
2731 790 ▶ if( exists( $node->{'$anchor'} ) && defined( $node->{'$anchor'} ) && $node->{'$anchor'} ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"\$anchor"} and defined $node->{"\$anchor"} and $node->{"\$anchor"} ne "") 1 789 790
Condition66%4/6
exists $node->{"\$anchor"} and defined $node->{"\$anchor"} and $node->{"\$anchor"} ne ""
!ll&&!rl&&r
78901
exists $node->{"\$anchor"} and defined $node->{"\$anchor"}
!ll&&!rl&&r
78901
MC/DC33%1/3
exists $node->{"\$anchor"} and defined $node->{"\$anchor"} and $node->{"\$anchor"} ne ""
exists $node->{"\$anchor"} defined $node->{"\$anchor"} $node->{"\$anchor"} ne ""
Truth table50%2/4
A and B and C
A= exists $node->{"\$anchor"}B= defined $node->{"\$anchor"}C= $node->{"\$anchor"} ne ""
ABCresult
0XX0
10X0
1100
1111
2732 {
2733 1 my $abs = $here_base . '#' . $node->{'$anchor'};
2734 1 $id_index->{ $abs } = $node;
2735 }
2736  
2737 790 ▶ if( exists( $node->{'$dynamicAnchor'} ) && defined( $node->{'$dynamicAnchor'} ) && $node->{'$dynamicAnchor'} ne '' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $node->{"\$dynamicAnchor"} and defined $node->{"\$dynamicAnchor"} and $node->{"\$dynamicAnchor"} ne "") 2 788 790
Condition66%4/6
exists $node->{"\$dynamicAnchor"} and defined $node->{"\$dynamicAnchor"} and $node->{"\$dynamicAnchor"} ne ""
!ll&&!rl&&r
78802
exists $node->{"\$dynamicAnchor"} and defined $node->{"\$dynamicAnchor"}
!ll&&!rl&&r
78802
MC/DC33%1/3
exists $node->{"\$dynamicAnchor"} and defined $node->{"\$dynamicAnchor"} and $node->{"\$dynamicAnchor"} ne ""
exists $node->{"\$dynamicAnchor"} defined $node->{"\$dynamicAnchor"} $node->{"\$dynamicAnchor"} ne ""
Truth table50%2/4
A and B and C
A= exists $node->{"\$dynamicAnchor"}B= defined $node->{"\$dynamicAnchor"}C= $node->{"\$dynamicAnchor"} ne ""
ABCresult
0XX0
10X0
1100
1111
2738 {
2739 2 my $abs = $here_base . '#dyn:' . $node->{'$dynamicAnchor'};
2740 2 $id_index->{ $abs } = $node;
2741 }
2742  
2743 790 for my $k ( sort( keys( %$node ) ) )
2744 {
2745 1569 my $child = $node->{ $k };
2746 1569 my $child_ptr = _join_ptr( $ptr, $k );
2747 1569 _index_schema_202012( $child, $here_base, $child_ptr, $anchors, $id_index );
2748 }
2749 }
2750 elsif( ref( $node ) eq 'ARRAY' )
2751 {
2752 233 for my $i ( 0 .. $#$node )
2753 {
2754 311 my $child = $node->[$i];
2755 311 my $child_ptr = _join_ptr( $ptr, $i );
2756 311 _index_schema_202012( $child, $here_base, $child_ptr, $anchors, $id_index );
2757 }
2758 }
2759 }
2760  
2761 sub _inst_addr
2762 364 ▶{
Subroutine _inst_addr: called CC=2 SCAR=7.1
2763 364 my( $inst, $ptr ) = @_;
2764 364 ▶ return( "SCALAR:$ptr" ) unless( ref( $inst ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $inst 0 364 364
2765 364 return( ref( $inst ) . ':' . refaddr( $inst ) );
2766 }
2767  
2768 # truthy helpers
2769 28 ▶sub _is_hash { my $v = shift; return ref($v) eq 'HASH' ? 1 : 0; }
Subroutine _is_hash: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $v eq 'HASH' ? : 5 23 28
2770  
2771 sub _is_number
2772 923 ▶{
Subroutine _is_number: called CC=6 SCAR=18.0
2773 923 my( $v ) = @_;
2774  
2775 923 ▶ return(0) if( ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 335 588 923
2776 588 ▶ return(0) unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 6 582 588
2777  
2778 # Strict JSON typing: accept only scalars that actually carry numeric flags.
2779 # JSON marks numbers with IOK/NOK; plain strings (even "12") will not have them.
2780 582 my $sv = B::svref_2object( \$v );
2781 582 my $flags = $sv->FLAGS;
2782  
2783 582 local $@;
2784 # SVf_IOK = 0x02000000, SVf_NOK = 0x04000000 on most builds;
2785 # we do not hardcode constants-B::SV’s FLAGS is stable to test with these bitmasks.
2786 # Use string eval to avoid importing platform-specific constants.
2787 582 ▶ my $SVf_IOK = eval{ B::SVf_IOK() } || 0x02000000;
Condition50%1/2
eval { do { 256 } } || 33554432
l!l
5820
MC/DC0%0/1
eval { do { 256 } } || 33554432
eval { do { 256 } }
Truth table50%1/2
A
A= eval { do { 256 } }
Aresult
11
00
2788 582 ▶ my $SVf_NOK = eval{ B::SVf_NOK() } || 0x04000000;
Condition50%1/2
eval { do { 512 } } || 67108864
l!l
5820
MC/DC0%0/1
eval { do { 512 } } || 67108864
eval { do { 512 } }
Truth table50%1/2
A
A= eval { do { 512 } }
Aresult
11
00
2789  
2790 582 ▶ return( ( $flags & ( $SVf_IOK | $SVf_NOK ) ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$flags & ($SVf_IOK | $SVf_NOK) ? : 278 304 582
2791 }
2792  
2793 28 ▶sub _is_true { my $v = shift( @_ ); return( ref( $v ) eq 'HASH' ? 0 : $v ? 1 : 0 ); }
Subroutine _is_true: called CC=3 SCAR=11.1
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'HASH' ? : 5 23 28
$v ? : 0 23 23
2794  
2795 sub _join_ptr
2796 2917 ▶{
Subroutine _join_ptr: called CC=6 SCAR=18.4
2797 2917 my( $base, @tokens ) = @_;
2798  
2799 # Default base to '#' if not provided
2800 2917 ▶ $base = '#' unless( defined( $base ) && length( $base ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $base and length $base 0 2917 2917
Condition33%1/3
defined $base and length $base
!ll&&!rl&&r
002917
MC/DC0%0/2
defined $base and length $base
defined $base length $base
Truth table33%1/3
A and B
A= defined $baseB= length $base
ABresult
0X0
100
111
2801  
2802 2917 my $ptr = $base;
2803  
2804 2917 for my $token ( @tokens )
2805 {
2806 2917 ▶ next unless( defined( $token ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 2917 2917
2807  
2808 # Proper rfc6901 JSON Pointer escaping
2809 2917 $token =~ s/~/~0/g;
2810 2917 $token =~ s/\//~1/g;
2811  
2812 2917 ▶ if( $ptr eq '#' )
Branch: 1 branch
BranchTrueFalseTotal
if ($ptr eq '#') { } 1032 1885 2917
2813 {
2814 1032 $ptr = "#/$token";
2815 }
2816 else
2817 {
2818 1885 $ptr .= "/$token";
2819 }
2820 }
2821  
2822 2917 return( $ptr );
2823 }
2824  
2825 sub _js_quote
2826 0 ▶{
Subroutine _js_quote: not called CC=2 SCAR=17.9
2827 0 my $s = shift( @_ );
2828 0 ▶ $s = '' unless( defined( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
2829 0 $s =~ s/\\/\\\\/g;
2830 0 $s =~ s/'/\\'/g;
2831 0 $s =~ s/\r\n/\n/g;
2832 0 $s =~ s/\r/\n/g;
2833 0 $s =~ s/\n/\\n/g;
2834 0 return( "'$s'" );
2835 }
2836  
2837 sub _json_equal
2838 21 ▶{
Subroutine _json_equal: called CC=1 SCAR=0.0
2839 21 my( $a, $b ) = @_;
2840 21 return( _canon( $a ) eq _canon( $b ) );
2841 }
2842  
2843 # Very small JSON Pointer resolver for internal refs ("#/...") for JS compile
2844 sub _jsv_resolve_internal_ref
2845 9 ▶{
Subroutine _jsv_resolve_internal_ref: called CC=18 SCAR=39.0
2846 9 my( $root, $ptr ) = @_;
2847  
2848 9 ▶ return( $root ) if( !defined( $ptr ) || $ptr eq '' || $ptr eq '#' );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ptr or $ptr eq "" or $ptr eq "#" 0 9 9
Condition33%2/6
not defined $ptr or $ptr eq "" or $ptr eq "#"
l!l&&r!l&&!r
009
not defined $ptr or $ptr eq ""
l!l&&r!l&&!r
009
MC/DC0%0/3
not defined $ptr or $ptr eq "" or $ptr eq "#"
not defined $ptr $ptr eq "" $ptr eq "#"
Truth table25%1/4
not(A) or B or C
A= not defined $ptrB= $ptr eq ""C= $ptr eq "#"
ABCresult
1XX1
01X1
0011
0000
2849  
2850 # Expect something like "#/definitions/address"
2851 9 $ptr =~ s/^#//;
2852  
2853 9 my @tokens = split( /\//, $ptr );
2854 9 ▶ shift( @tokens ) if( @tokens && $tokens[0] eq '' );
Branch: 1 branch
BranchTrueFalseTotal
if @tokens and $tokens[0] eq "" 9 0 9
Condition33%1/3
@tokens and $tokens[0] eq ""
!ll&&!rl&&r
009
MC/DC0%0/2
@tokens and $tokens[0] eq ""
@tokens $tokens[0] eq ""
Truth table33%1/3
A and B
A= @tokensB= $tokens[0] eq ""
ABresult
0X0
100
111
2855  
2856 9 my $node = $root;
2857  
2858 TOKEN:
2859 9 for my $tok ( @tokens )
2860 {
2861 # rfc6901 JSON Pointer unescaping
2862 17 $tok =~ s/~1/\//g;
2863 17 $tok =~ s/~0/~/g;
2864  
2865 17 ▶ if( ref( $node ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $node eq 'HASH') { } 17 0 17
elsif (ref $node eq 'ARRAY') { } 0 0 0
2866 {
2867 # Draft 2020-12 alias: allow "definitions" to hit "$defs" if needed
2868 17 ▶ if( $tok eq 'definitions' &&
Branch: 1 branch
BranchTrueFalseTotal
if ($tok eq "definitions" and not exists $node->{"definitions"} and exists $node->{"\$defs"}) 8 9 17
Condition83%5/6
$tok eq "definitions" and not exists $node->{"definitions"} and exists $node->{"\$defs"}
!ll&&!rl&&r
818
$tok eq "definitions" and not exists $node->{"definitions"}
!ll&&!rl&&r
809
MC/DC66%2/3
$tok eq "definitions" and not exists $node->{"definitions"} and exists $node->{"\$defs"}
$tok eq "definitions" not exists $node->{"definitions"} exists $node->{"\$defs"}
Truth table75%3/4
A and not(B) and C
A= $tok eq "definitions"B= not exists $node->{"definitions"}C= exists $node->{"\$defs"}
ABCresult
0XX0
10X0
1100
1111
2869 !exists( $node->{definitions} ) &&
2870 exists( $node->{'$defs'} ) )
2871 {
2872 8 $tok = '$defs';
2873 }
2874  
2875 17 ▶ unless( exists( $node->{ $tok } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $node->{$tok}) 1 16 17
2876 {
2877 # Optional: help debug resolution problems
2878 1 ▶ warn( "_jsv_resolve_internal_ref: token '$tok' not found in current hash for pointer '$ptr'\n" )
Branch: 1 branch
BranchTrueFalseTotal
if $JSON::Schema::Validate::DEBUG 0 1 1
2879 if( $JSON::Schema::Validate::DEBUG );
2880 1 return;
2881 }
2882 16 $node = $node->{ $tok };
2883 }
2884 elsif( ref( $node ) eq 'ARRAY' )
2885 {
2886 0 ▶ unless( $tok =~ /^\d+$/ && $tok < @$node )
Branch: 1 branch
BranchTrueFalseTotal
unless ($tok =~ /^\d+$/u and $tok < @$node) 0 0 0
Condition0%0/3
$tok =~ /^\d+$/u and $tok < @$node
!ll&&!rl&&r
000
MC/DC0%0/2
$tok =~ /^\d+$/u and $tok < @$node
$tok =~ /^\d+$/u $tok < @$node
Truth table0%0/3
A and B
A= $tok =~ /^\d+$/uB= $tok < @$node
ABresult
0X0
100
111
2887 {
2888 0 ▶ warn( "_jsv_resolve_internal_ref: array index '$tok' out of range for pointer '$ptr'\n" )
Branch: 1 branch
BranchTrueFalseTotal
if $JSON::Schema::Validate::DEBUG 0 0 0
2889 if( $JSON::Schema::Validate::DEBUG );
2890 0 return;
2891 }
2892 0 $node = $node->[ $tok ];
2893 }
2894 else
2895 {
2896 0 ▶ warn( "_jsv_resolve_internal_ref: reached non-container node while resolving '$ptr'\n" )
Branch: 1 branch
BranchTrueFalseTotal
if $JSON::Schema::Validate::DEBUG 0 0 0
2897 if( $JSON::Schema::Validate::DEBUG );
2898 0 return;
2899 }
2900 }
2901  
2902 8 return( $node );
2903 }
2904  
2905 # Keyword groups
2906 # NOTE: instance pointer base
2907 # The pointer stack tracks the location of the failing value inside the *instance*,
2908 # which is what a user interface needs in order to highlight the offending field.
2909 # It must therefore be built from the current instance pointer, never from the
2910 # schema pointer, otherwise the reported path drifts into the schema as soon as
2911 # validation descends through a $ref or a combinator.
2912 sub _inst_ptr
2913 494 ▶{
Subroutine _inst_ptr: called CC=4 SCAR=15.6
2914 494 my( $ctx, $token ) = @_;
2915 494 ▶ my $base = ( $ctx->{ptr_stack} && @{$ctx->{ptr_stack}} )
Condition50%1/2
$ctx->{"ptr_stack"}[-1] // "#"
l!l
4940
MC/DC0%0/1
$ctx->{"ptr_stack"}[-1] // "#"
$ctx->{"ptr_stack"}[-1]
Truth table50%1/2
A
A= $ctx->{"ptr_stack"}[-1]
Aresult
11
00
2916 494 ▶ ? ( $ctx->{ptr_stack}->[-1] // '#' )
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'ptr_stack'} && @{$ctx->{'ptr_stack'};} ? : 494 0 494
Condition33%1/3
$ctx->{"ptr_stack"} and @{$ctx->{"ptr_stack"};}
!ll&&!rl&&r
00494
MC/DC0%0/2
$ctx->{"ptr_stack"} and @{$ctx->{"ptr_stack"};}
$ctx->{"ptr_stack"} @{$ctx->{"ptr_stack"};}
Truth table33%1/3
A and B
A= $ctx->{"ptr_stack"}B= @{$ctx->{"ptr_stack"};}
ABresult
0X0
100
111
2917 : '#';
2918 494 return( _join_ptr( $base, $token ) );
2919 }
2920  
2921 sub _k_array_all
2922 32 ▶{
Subroutine _k_array_all: called CC=34 SCAR=39.9
2923 32 my( $ctx, $sp, $S, $A ) = @_;
2924  
2925 32 ▶ if( exists( $S->{minItems} ) && @$A < $S->{minItems} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"minItems"} and @$A < $S->{"minItems"}) 0 32 32
Condition66%2/3
exists $S->{"minItems"} and @$A < $S->{"minItems"}
!ll&&!rl&&r
2750
MC/DC0%0/2
exists $S->{"minItems"} and @$A < $S->{"minItems"}
exists $S->{"minItems"} @$A < $S->{"minItems"}
Truth table66%2/3
A and B
A= exists $S->{"minItems"}B= @$A < $S->{"minItems"}
ABresult
0X0
100
111
2926 {
2927 0 return( _err_res( $ctx, $sp, "array has fewer than minItems $S->{minItems}", 'minItems' ) );
2928 }
2929 32 ▶ if( exists( $S->{maxItems} ) && @$A > $S->{maxItems} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"maxItems"} and @$A > $S->{"maxItems"}) 0 32 32
Condition33%1/3
exists $S->{"maxItems"} and @$A > $S->{"maxItems"}
!ll&&!rl&&r
3200
MC/DC0%0/2
exists $S->{"maxItems"} and @$A > $S->{"maxItems"}
exists $S->{"maxItems"} @$A > $S->{"maxItems"}
Truth table33%1/3
A and B
A= exists $S->{"maxItems"}B= @$A > $S->{"maxItems"}
ABresult
0X0
100
111
2930 {
2931 0 return( _err_res( $ctx, $sp, "array has more than maxItems $S->{maxItems}", 'maxItems' ) );
2932 }
2933  
2934 32 ▶ if( $S->{uniqueItems} )
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"uniqueItems"}) 0 32 32
2935 {
2936 0 my %seen;
2937 0 for my $i ( 0 .. $#$A )
2938 {
2939 0 my $k = _canon( $A->[$i] );
2940 0 ▶ if( $seen{ $k }++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$k}++) 0 0 0
2941 {
2942 0 return( _err_res( $ctx, _join_ptr( $sp, $i ), "array items not unique", 'uniqueItems' ) );
2943 }
2944 }
2945 }
2946  
2947 32 my %items_ann;
2948  
2949 32 ▶ if( ref( $S->{prefixItems} ) eq 'ARRAY' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $S->{'prefixItems'} eq 'ARRAY') { } 5 27 32
elsif (ref $S->{'items'} eq 'HASH') { } 14 13 27
2950 {
2951 5 my $tuple = $S->{prefixItems};
2952 5 for my $i ( 0 .. $#$A )
2953 {
2954 16 push( @{$ctx->{ptr_stack}}, _inst_ptr( $ctx, $i ) );
2955  
2956 16 ▶ if( $i <= $#$tuple )
Branch: 2 branches
BranchTrueFalseTotal
if ($i <= $tuple->$#*) { } 10 6 16
elsif (exists $S->{'items'} and ref $S->{'items'} eq 'HASH') { } 5 2 7
2957 {
2958 10 my $r = _v( $ctx, _join_ptr( $sp, "prefixItems/$i" ), $tuple->[$i], $A->[$i] );
2959 10 ▶ unless( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 10 10
2960 {
2961 0 pop( @{$ctx->{ptr_stack}} );
2962 0 return( $r );
2963 }
2964 10 $items_ann{ $i } = 1;
2965 }
2966 ▶ elsif( exists( $S->{items} ) && ref( $S->{items} ) eq 'HASH' )
Condition66%2/3
exists $S->{"items"} and ref $S->{"items"} eq "HASH"
!ll&&!rl&&r
105
MC/DC50%1/2
exists $S->{"items"} and ref $S->{"items"} eq "HASH"
exists $S->{"items"} ref $S->{"items"} eq "HASH"
Truth table66%2/3
A and B
A= exists $S->{"items"}B= ref $S->{"items"} eq "HASH"
ABresult
0X0
100
111
2967 {
2968 5 my $r = _v( $ctx, _join_ptr( $sp, "items" ), $S->{items}, $A->[$i] );
2969 5 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 1 4 5
2970 4 $items_ann{ $i } = 1;
2971 }
2972  
2973 15 pop( @{$ctx->{ptr_stack}} );
2974 }
2975 }
2976 elsif( ref( $S->{items} ) eq 'HASH' )
2977 {
2978 14 for my $i ( 0 .. $#$A )
2979 {
2980 27 push( @{$ctx->{ptr_stack}}, _inst_ptr( $ctx, $i ) );
2981 27 my $r = _v( $ctx, _join_ptr( $sp, "items" ), $S->{items}, $A->[$i] );
2982 # NOTE: the instance pointer must be popped on every exit path
2983 # Returning early without popping leaves the failing item's pointer on the
2984 # stack, and every later error in the same document inherits it as a prefix.
2985 27 ▶ unless( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 2 25 27
2986 {
2987 2 pop( @{$ctx->{ptr_stack}} );
2988 2 return( $r );
2989 }
2990 25 $items_ann{ $i } = 1;
2991 25 pop( @{$ctx->{ptr_stack}} );
2992 }
2993 }
2994  
2995 29 ▶ if( exists( $S->{contains} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contains"}) 10 19 29
2996 {
2997 10 my $matches = 0;
2998  
2999 # Quiet sub-context to avoid emitting errors for non-matching items
3000 10 for my $i ( 0 .. $#$A )
3001 {
3002 29 my %shadow = %$ctx;
3003 29 my @errs;
3004 29 $shadow{errors} = \@errs;
3005 29 $shadow{error_count} = 0;
3006  
3007 29 my $tmp = _v( \%shadow, _join_ptr( $sp, "contains" ), $S->{contains}, $A->[$i] );
3008 29 ▶ $matches++ if( $tmp->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->{"ok"} 21 8 29
3009 }
3010  
3011 10 ▶ my $minc = defined( $S->{minContains} ) ? $S->{minContains} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $S->{'minContains'} ? : 10 0 10
3012 10 ▶ my $maxc = defined( $S->{maxContains} ) ? $S->{maxContains} : ( 2**31 - 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $S->{'maxContains'} ? : 8 2 10
3013  
3014 10 ▶ return( _err_res( $ctx, $sp, "contains matched $matches < minContains $minc", 'minContains' ) ) if( $matches < $minc );
Branch: 1 branch
BranchTrueFalseTotal
if $matches < $minc 3 7 10
3015 7 ▶ return( _err_res( $ctx, $sp, "contains matched $matches > maxContains $maxc", 'maxContains' ) ) if( $matches > $maxc );
Branch: 1 branch
BranchTrueFalseTotal
if $matches > $maxc 2 5 7
3016 }
3017  
3018 24 ▶ if( exists( $S->{unevaluatedItems} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedItems"}) 3 21 24
3019 {
3020 3 my @unknown = ();
3021 3 for my $i ( 0 .. $#$A )
3022 {
3023 10 ▶ next if( $items_ann{ $i } );
Branch: 1 branch
BranchTrueFalseTotal
if $items_ann{$i} 9 1 10
3024 1 push( @unknown, $i );
3025 }
3026 3 my $UE = $S->{unevaluatedItems};
3027 3 ▶ if( !_is_true( $UE ) && !_is_hash( $UE ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not _is_true($UE) || _is_hash($UE)) { } 3 0 3
elsif (ref $UE eq 'HASH') { } 0 0 0
Condition33%1/3
_is_true($UE) || _is_hash($UE)
l!l&&r!l&&!r
003
MC/DC0%0/2
_is_true($UE) || _is_hash($UE)
_is_true($UE) _is_hash($UE)
Truth table33%1/3
A || B
A= _is_true($UE)B= _is_hash($UE)
ABresult
1X1
011
000
3028 {
3029 3 ▶ return( _err_res( $ctx, $sp, "unevaluatedItems not allowed at indices: " . join( ',', @unknown ), 'unevaluatedItems' ) ) if( @unknown );
Branch: 1 branch
BranchTrueFalseTotal
if @unknown 1 2 3
3030 }
3031 elsif( ref( $UE ) eq 'HASH' )
3032 {
3033 0 for my $i ( @unknown )
3034 {
3035 0 my $r = _v( $ctx, _join_ptr( $sp, "unevaluatedItems" ), $UE, $A->[$i] );
3036 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
3037 0 $items_ann{ $i } = 1;
3038 }
3039 }
3040 }
3041  
3042 23 return( { ok => 1, props => {}, items => \%items_ann } );
3043 }
3044  
3045 sub _k_combinator
3046 25 ▶{
Subroutine _k_combinator: called CC=17 SCAR=28.4
3047 25 my( $ctx, $sp, $S, $inst, $kw ) = @_;
3048  
3049  
3050 # allOf: all subschemas must pass, we merge their annotations
3051 25 ▶ if( $kw eq 'allOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "allOf") 10 15 25
3052 {
3053 10 my %props;
3054 my %items;
3055  
3056 10 for my $i ( 0 .. $#{$S->{allOf}} )
3057 {
3058 16 my $r = _v( $ctx, _join_ptr( $sp, "allOf/$i" ), $S->{allOf}->[ $i ], $inst );
3059 16 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 3 13 16
3060  
3061 13 %props = ( %props, %{$r->{props}} );
3062 13 %items = ( %items, %{$r->{items}} );
3063 }
3064  
3065 7 return( { ok => 1, props => \%props, items => \%items } );
3066 }
3067  
3068 # anyOf: at least one subschema must pass.
3069 # Errors from failing branches must NOT leak into the main context.
3070 15 ▶ if( $kw eq 'anyOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "anyOf") 2 13 15
3071 {
3072 2 my @branch_errs;
3073  
3074 2 for my $i ( 0 .. $#{$S->{anyOf}} )
3075 {
3076 # Shadow context: isolate errors for this branch
3077 3 my %shadow = %$ctx;
3078 3 my @errs;
3079 3 $shadow{errors} = \@errs;
3080 3 $shadow{error_count} = 0;
3081  
3082 3 my $r = _v( \%shadow, _join_ptr( $sp, "anyOf/$i" ), $S->{anyOf}->[ $i ], $inst );
3083  
3084 3 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"ok"}) 1 2 3
3085 {
3086 # One branch passed: combinator satisfied.
3087 # Ignore all other branch errors.
3088 1 return( { ok => 1, props => {}, items => {} } );
3089 }
3090  
3091 2 push( @branch_errs, \@errs );
3092 }
3093  
3094 # No branch matched: merge collected branch errors into main context
3095 1 for my $aref ( @branch_errs )
3096 {
3097 2 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 2 2
3098 2 push( @{$ctx->{errors}}, @$aref );
3099 2 $ctx->{error_count} += scalar( @$aref );
3100 }
3101  
3102 1 return( _err_res( $ctx, $sp, "instance does not satisfy anyOf", 'anyOf' ) );
3103 }
3104  
3105 # oneOf: exactly one subschema must pass.
3106 # Again, do not leak errors from non-selected branches.
3107 13 ▶ if( $kw eq 'oneOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "oneOf") 11 2 13
3108 {
3109 11 my @ok_results;
3110 my @branch_errs;
3111  
3112 11 for my $i ( 0 .. $#{$S->{oneOf}} )
3113 {
3114 22 my %shadow = %$ctx;
3115 22 my @errs;
3116 22 $shadow{errors} = \@errs;
3117 22 $shadow{error_count} = 0;
3118  
3119 22 my $r = _v( \%shadow, _join_ptr( $sp, "oneOf/$i" ), $S->{oneOf}->[$i], $inst );
3120  
3121 22 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'ok'}) { } 6 16 22
3122 {
3123 6 push( @ok_results, $r );
3124 }
3125 else
3126 {
3127 16 push( @branch_errs, \@errs );
3128 }
3129 }
3130  
3131 11 ▶ if( @ok_results == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ok_results == 1) 4 7 11
3132 {
3133 # Exactly one branch matched: combinator satisfied.
3134 # Do NOT bubble up branch props/items through oneOf.
3135 4 return( { ok => 1, props => {}, items => {} } );
3136 }
3137  
3138 # Zero or >1 matched -> failure; merge branch errors
3139 7 for my $aref ( @branch_errs )
3140 {
3141 12 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 12 12
3142 12 push( @{$ctx->{errors}}, @$aref );
3143 12 $ctx->{error_count} += scalar( @$aref );
3144 }
3145  
3146 return(
3147 7 _err_res(
3148 $ctx,
3149 $sp,
3150 "instance satisfies " . scalar( @ok_results ) . " schemas in oneOf (expected exactly 1)",
3151 'oneOf'
3152 )
3153 );
3154 }
3155  
3156 # not: subschema must NOT validate.
3157 # Any errors from validating the inner schema are irrelevant on success.
3158 2 ▶ if( $kw eq 'not' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "not") 2 0 2
3159 {
3160 2 my %shadow = %$ctx;
3161 2 my @errs;
3162 2 $shadow{errors} = \@errs;
3163 2 $shadow{error_count} = 0;
3164  
3165 2 my $r = _v( \%shadow, _join_ptr( $sp, "not" ), $S->{not}, $inst );
3166  
3167 # If inner schema passes, then "not" fails
3168 return( _err_res( $ctx, $sp, "instance matches forbidden not-schema", 'not' ) )
3169 2 ▶ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 1 1 2
3170  
3171 # Otherwise, "not" is satisfied; ignore inner errors entirely
3172 1 return( { ok => 1, props => {}, items => {} } );
3173 }
3174  
3175 # Unknown / unsupported combinator (defensive default)
3176 0 return( { ok => 1, props => {}, items => {} } );
3177 }
3178  
3179 sub _k_const
3180 6 ▶{
Subroutine _k_const: called CC=2 SCAR=8.1
3181 6 my( $ctx, $v, $const, $ptr ) = @_;
3182 6 ▶ return(1) if( _json_equal( $v, $const ) );
Branch: 1 branch
BranchTrueFalseTotal
if _json_equal($v, $const) 6 0 6
3183 0 return( _err( $ctx, $ptr, "const mismatch", 'const' ) );
3184 }
3185  
3186 sub _k_enum
3187 8 ▶{
Subroutine _k_enum: called CC=3 SCAR=11.0
3188 8 my( $ctx, $v, $arr, $ptr ) = @_;
3189 8 for my $e ( @$arr )
3190 {
3191 15 ▶ return(1) if( _json_equal( $v, $e ) );
Branch: 1 branch
BranchTrueFalseTotal
if _json_equal($v, $e) 4 11 15
3192 }
3193 4 return( _err( $ctx, $ptr, "value not in enum", 'enum' ) );
3194 }
3195  
3196 sub _k_format
3197 55 ▶{
Subroutine _k_format: called CC=4 SCAR=13.9
3198 55 my( $ctx, $s, $fmt, $ptr ) = @_;
3199 55 my $cb = $ctx->{formats}->{ $fmt };
3200 55 ▶ return(1) unless( $cb );
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 3 52 55
3201 52 local $@;
3202 52 ▶ my $ok = eval{ $cb->( $s ) ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
&$cb($s) ? : 34 18 52
3203 52 ▶ return( $ok ? 1 : _err( $ctx, $ptr, "string fails format '$fmt'", 'format' ) );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 34 18 52
3204 }
3205  
3206 sub _k_if_then_else
3207 16 ▶{
Subroutine _k_if_then_else: called CC=6 SCAR=18.5
3208 16 my( $ctx, $sp, $S, $inst ) = @_;
3209  
3210 # Evaluate "if" in a shadow context so its errors do NOT leak
3211 16 my %shadow = %$ctx;
3212 16 my @errs;
3213 16 $shadow{errors} = \@errs;
3214 16 $shadow{error_count} = 0;
3215  
3216 16 my $cond = _v( \%shadow, _join_ptr( $sp, 'if' ), $S->{if}, $inst );
3217  
3218 16 ▶ if( $cond->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cond->{'ok'}) { } 6 10 16
3219 {
3220 6 ▶ _t( $ctx, $sp, 'if', undef, 'pass', 'then' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 6 6
3221 return( { ok => 1, props => {}, items => {} } )
3222 6 ▶ unless( exists( $S->{then} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{"then"} 0 6 6
3223  
3224 # Apply "then" against the REAL context
3225 6 return( _v( $ctx, _join_ptr( $sp, 'then' ), $S->{then}, $inst ) );
3226 }
3227 else
3228 {
3229 10 ▶ _t( $ctx, $sp, 'if', undef, 'pass', 'else' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 10 10
3230 return( { ok => 1, props => {}, items => {} } )
3231 10 ▶ unless( exists( $S->{else} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{"else"} 10 0 10
3232  
3233 # Apply "else" against the REAL context
3234 0 return( _v( $ctx, _join_ptr( $sp, 'else' ), $S->{else}, $inst ) );
3235 }
3236 }
3237  
3238 sub _k_number
3239 88 ▶{
Subroutine _k_number: called CC=24 SCAR=35.5
3240 88 my( $ctx, $v, $kw, $arg, $ptr ) = @_;
3241 88 ▶ if( $kw eq 'multipleOf' )
Branch: 5 branches
BranchTrueFalseTotal
if ($kw eq 'multipleOf') { } 13 75 88
elsif ($kw eq 'minimum') { } 62 13 75
elsif ($kw eq 'maximum') { } 6 7 13
elsif ($kw eq 'exclusiveMinimum') { } 5 2 7
elsif ($kw eq 'exclusiveMaximum') { } 2 0 2
3242 {
3243 # Guard per spec: multipleOf must be > 0
3244 13 ▶ if( !defined( $arg ) || $arg <= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $arg or $arg <= 0) 1 12 13
Condition66%2/3
not defined $arg or $arg <= 0
l!l&&r!l&&!r
0112
MC/DC50%1/2
not defined $arg or $arg <= 0
not defined $arg $arg <= 0
Truth table66%2/3
not(A) or B
A= not defined $argB= $arg <= 0
ABresult
1X1
011
000
3245 {
3246 1 ▶ _t( $ctx, $ptr, 'multipleOf', undef, 'fail', 'arg<=0' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 1 1
3247 1 return( _err( $ctx, $ptr, "multipleOf must be > 0", 'multipleOf' ) );
3248 }
3249 # Float-tolerant multiple check
3250 # my $ok = abs( ( $v / $arg ) - int( $v / $arg + 1e-10 ) ) < 1e-9;
3251 12 my $ok = abs( ( $v / $arg ) - int( $v / $arg + 0.0000000001 ) ) < 1e-9;
3252 12 ▶ _t( $ctx, $ptr, 'multipleOf', undef, $ok ? 'pass' : 'fail', "$v mod $arg" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 12 12
$ok ? : 0 0 0
3253 12 ▶ return( $ok ? 1 : _err( $ctx, $ptr, "number not multipleOf $arg" ) );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 7 5 12
3254 }
3255 elsif( $kw eq 'minimum' )
3256 {
3257 62 ▶ _t( $ctx, $ptr, 'minimum', undef, $v >= $arg ? 'pass' : 'fail', "$v >= $arg" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 1 61 62
$v >= $arg ? : 0 1 1
3258 62 ▶ return( $v >= $arg ? 1 : _err( $ctx, $ptr, "number less than minimum $arg", 'minimum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v >= $arg ? : 49 13 62
3259 }
3260 elsif( $kw eq 'maximum' )
3261 {
3262 6 ▶ _t( $ctx, $ptr, 'maximum', undef, $v <= $arg ? 'pass' : 'fail', "$v <= $arg" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 6 6
$v <= $arg ? : 0 0 0
3263 6 ▶ return( $v <= $arg ? 1 : _err( $ctx, $ptr, "number greater than maximum $arg", 'maximum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v <= $arg ? : 5 1 6
3264 }
3265 elsif( $kw eq 'exclusiveMinimum' )
3266 {
3267 5 ▶ _t( $ctx, $ptr, 'exclusiveMinimum', undef, $v > $arg ? 'pass' : 'fail', "$v > $arg" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 5 5
$v > $arg ? : 0 0 0
3268 5 ▶ return( $v > $arg ? 1 : _err( $ctx, $ptr, "number not greater than exclusiveMinimum $arg", 'exclusiveMinimum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v > $arg ? : 3 2 5
3269 }
3270 elsif( $kw eq 'exclusiveMaximum' )
3271 {
3272 2 ▶ _t( $ctx, $ptr, 'exclusiveMaximum', undef, $v < $arg ? 'pass' : 'fail', "$v < $arg" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 2 2
$v < $arg ? : 0 0 0
3273 2 ▶ return( $v < $arg ? 1 : _err( $ctx, $ptr, "number not less than exclusiveMaximum $arg", 'exclusiveMaximum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v < $arg ? : 1 1 2
3274 }
3275 0 return(1);
3276 }
3277  
3278 sub _k_object_all
3279 287 ▶{
Subroutine _k_object_all: called CC=70 SCAR=48.5
3280 287 my( $ctx, $sp, $S, $H ) = @_;
3281  
3282 287 my $ok = 1;
3283  
3284 my $bail_if_max = sub
3285 136 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.1
3286 136 ▶ return( $ctx->{max_errors} && $ctx->{error_count} >= $ctx->{max_errors} ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'max_errors'} && $ctx->{'error_count'} >= $ctx->{'max_errors'} ? : 2 134 136
Condition66%2/3
$ctx->{"max_errors"} and $ctx->{"error_count"} >= $ctx->{"max_errors"}
!ll&&!rl&&r
01342
MC/DC50%1/2
$ctx->{"max_errors"} and $ctx->{"error_count"} >= $ctx->{"max_errors"}
$ctx->{"max_errors"} $ctx->{"error_count"} >= $ctx->{"max_errors"}
Truth table66%2/3
A and B
A= $ctx->{"max_errors"}B= $ctx->{"error_count"} >= $ctx->{"max_errors"}
ABresult
0X0
100
111
3287 287 };
3288  
3289 287 ▶ if( exists( $S->{minProperties} ) && ( scalar( keys( %$H ) ) ) < $S->{minProperties} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"minProperties"} and scalar keys %$H < $S->{"minProperties"}) 0 287 287
Condition33%1/3
exists $S->{"minProperties"} and scalar keys %$H < $S->{"minProperties"}
!ll&&!rl&&r
28700
MC/DC0%0/2
exists $S->{"minProperties"} and scalar keys %$H < $S->{"minProperties"}
exists $S->{"minProperties"} scalar keys %$H < $S->{"minProperties"}
Truth table33%1/3
A and B
A= exists $S->{"minProperties"}B= scalar keys %$H < $S->{"minProperties"}
ABresult
0X0
100
111
3290 {
3291 0 _err_res( $ctx, $sp, "object has fewer than minProperties $S->{minProperties}", 'minProperties' );
3292 0 $ok = 0;
3293 0 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3294 }
3295 287 ▶ if( exists( $S->{maxProperties} ) && ( scalar( keys( %$H ) ) ) > $S->{maxProperties} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"maxProperties"} and scalar keys %$H > $S->{"maxProperties"}) 0 287 287
Condition33%1/3
exists $S->{"maxProperties"} and scalar keys %$H > $S->{"maxProperties"}
!ll&&!rl&&r
28700
MC/DC0%0/2
exists $S->{"maxProperties"} and scalar keys %$H > $S->{"maxProperties"}
exists $S->{"maxProperties"} scalar keys %$H > $S->{"maxProperties"}
Truth table33%1/3
A and B
A= exists $S->{"maxProperties"}B= scalar keys %$H > $S->{"maxProperties"}
ABresult
0X0
100
111
3296 {
3297 0 _err_res( $ctx, $sp, "object has more than maxProperties $S->{maxProperties}", 'maxProperties' );
3298 0 $ok = 0;
3299 0 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3300 }
3301  
3302 # Merge required from:
3303 # - top-level "required" (array only)
3304 # - property-level { required => 1 } or { optional => 0 }
3305 287 my %required;
3306  
3307 287 ▶ if( exists( $S->{required} ) && ref( $S->{required} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"required"} and ref $S->{"required"} eq "ARRAY") 162 125 287
Condition100%3/3
exists $S->{"required"} and ref $S->{"required"} eq "ARRAY"
!ll&&!rl&&r
1223162
MC/DC100%2/2
exists $S->{"required"} and ref $S->{"required"} eq "ARRAY"
exists $S->{"required"} ref $S->{"required"} eq "ARRAY"
Truth table100%3/3
A and B
A= exists $S->{"required"}B= ref $S->{"required"} eq "ARRAY"
ABresult
0X0
100
111
3308 {
3309 162 $required{ $_ } = 1 for( @{ $S->{required} } );
3310 }
3311  
3312 287 ▶ if( my $P = $S->{properties} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $P = $S->{"properties"}) 251 36 287
3313 {
3314 251 for my $k ( keys( %$P ) )
3315 {
3316 393 my $pd = $P->{ $k };
3317 393 ▶ next unless( ref( $pd ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pd eq "HASH" 0 393 393
3318  
3319 393 ▶ if( exists( $pd->{required} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pd->{"required"}) 50 343 393
3320 {
3321 50 ▶ $required{ $k } = $pd->{required} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$pd->{'required'} ? : 48 2 50
3322 }
3323 393 ▶ if( exists( $pd->{optional} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pd->{"optional"}) 4 389 393
3324 {
3325 4 ▶ $required{ $k } = $pd->{optional} ? 0 : 1; # optional => 0 means required
Branch: 1 branch
BranchTrueFalseTotal
$pd->{'optional'} ? : 2 2 4
3326 }
3327 }
3328 }
3329  
3330 287 for my $rq ( grep{ $required{ $_ } } keys( %required ) )
3331 {
3332 257 ▶ next if( exists( $H->{ $rq } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $H->{$rq} 218 39 257
3333 39 ▶ _t( $ctx,$sp, 'required', undef, 'fail', $rq ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 1 38 39
3334  
3335 39 my @need = sort grep { $required{ $_ } } keys %required;
3336 39 my @have = sort keys %$H;
3337  
3338 39 ▶ my $need_str = @need ? join( ', ', @need ) : '(none)';
Branch: 1 branch
BranchTrueFalseTotal
@need ? : 39 0 39
3339 39 ▶ my $have_str = @have ? join( ', ', @have ) : '(none)';
Branch: 1 branch
BranchTrueFalseTotal
@have ? : 37 2 39
3340  
3341 39 my $msg = "required property '$rq' is missing "
3342 . "(required: $need_str; present: $have_str)";
3343  
3344 39 _err_res(
3345 $ctx,
3346 _join_ptr( $sp, $rq ),
3347 $msg,
3348 'required'
3349 );
3350  
3351 39 $ok = 0;
3352 39 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 1 38 39
3353 }
3354  
3355 286 ▶ if( exists( $S->{propertyNames} ) && ref( $S->{propertyNames} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH") 6 280 286
Condition66%2/3
exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH"
!ll&&!rl&&r
28006
MC/DC50%1/2
exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH"
exists $S->{"propertyNames"} ref $S->{"propertyNames"} eq "HASH"
Truth table66%2/3
A and B
A= exists $S->{"propertyNames"}B= ref $S->{"propertyNames"} eq "HASH"
ABresult
0X0
100
111
3356 {
3357 6 for my $k ( keys( %$H ) )
3358 {
3359 12 my $r = _v( $ctx, _join_ptr( $sp, "propertyNames" ), $S->{propertyNames}, $k );
3360 12 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 2 10 12
3361 {
3362 2 $ok = 0;
3363 2 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3364 }
3365 }
3366 }
3367  
3368 286 ▶ my $props = $S->{properties} || {};
Condition100%2/2
$S->{'properties'} || {}
l!l
25036
MC/DC100%1/1
$S->{'properties'} || {}
$S->{'properties'}
Truth table100%2/2
A
A= $S->{'properties'}
Aresult
11
00
3369 286 ▶ my $patprops = $S->{patternProperties} || {};
Condition100%2/2
$S->{'patternProperties'} || {}
l!l
6280
MC/DC100%1/1
$S->{'patternProperties'} || {}
$S->{'patternProperties'}
Truth table100%2/2
A
A= $S->{'patternProperties'}
Aresult
11
00
3370 286 my $addl_set = exists( $S->{additionalProperties} );
3371 286 ▶ my $addl = $addl_set ? $S->{additionalProperties} : JSON::true;
Branch: 1 branch
BranchTrueFalseTotal
$addl_set ? : 171 115 286
3372  
3373 286 my %ann;
3374  
3375 286 for my $k ( sort( keys( %$H ) ) )
3376 {
3377 443 my $v = $H->{ $k };
3378 443 my $matched = 0;
3379  
3380 443 my $child_path = _inst_ptr( $ctx, $k );
3381 443 push( @{$ctx->{ptr_stack}}, $child_path );
3382  
3383 443 ▶ if( exists( $props->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $props->{$k}) 288 155 443
3384 {
3385 288 my $r = _v( $ctx, _join_ptr( $sp, "properties/$k" ), $props->{ $k }, $v );
3386 288 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 74 214 288
3387 {
3388 74 $ok = 0;
3389 74 pop( @{$ctx->{ptr_stack}} );
3390 74 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 1 73 74
3391 73 next;
3392 }
3393 214 $ann{ $k } = 1;
3394 214 $matched = 1;
3395 }
3396  
3397 369 ▶ unless( $matched )
Branch: 1 branch
BranchTrueFalseTotal
unless ($matched) 155 214 369
3398 {
3399 155 local $@;
3400 155 for my $re ( keys( %$patprops ) )
3401 {
3402 4 my $re_ok = eval{ $k =~ /$re/ };
3403 4 ▶ next unless( $re_ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $re_ok 2 2 4
3404  
3405 2 my $r = _v( $ctx, _join_ptr( $sp, "patternProperties/$re" ), $patprops->{ $re }, $v );
3406 2 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 2 2
3407 {
3408 0 $ok = 0;
3409 0 pop( @{$ctx->{ptr_stack}} );
3410 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3411 0 next;
3412 }
3413 2 $ann{ $k } = 1;
3414 2 $matched = 1;
3415 }
3416 }
3417  
3418 369 ▶ unless( $matched )
Branch: 1 branch
BranchTrueFalseTotal
unless ($matched) 153 216 369
3419 {
3420 153 ▶ if( $addl_set && !_is_true( $addl ) && !_is_hash( $addl ) )
Branch: 2 branches
BranchTrueFalseTotal
if ($addl_set and not _is_true($addl) and not _is_hash($addl)) { } 16 137 153
elsif (ref $addl eq 'HASH') { } 5 132 137
Condition83%5/6
$addl_set and not _is_true($addl) and not _is_hash($addl)
!ll&&!rl&&r
132516
$addl_set and not _is_true($addl)
!ll&&!rl&&r
132021
MC/DC66%2/3
$addl_set and not _is_true($addl) and not _is_hash($addl)
$addl_set not _is_true($addl) not _is_hash($addl)
Truth table75%3/4
A and not(B) and not(C)
A= $addl_setB= not _is_true($addl)C= not _is_hash($addl)
ABCresult
0XX0
10X0
1100
1111
3421 {
3422 16 _err_res( $ctx, _join_ptr( $sp, $k ), "additionalProperties not allowed: '$k'", 'additionalProperties' );
3423 16 $ok = 0;
3424 16 pop( @{$ctx->{ptr_stack}} );
3425 16 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 16 16
3426 16 next;
3427 }
3428 elsif( ref( $addl ) eq 'HASH' )
3429 {
3430 5 my $r = _v( $ctx, _join_ptr( $sp, "additionalProperties" ), $addl, $v );
3431 5 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 5 5
3432 {
3433 0 $ok = 0;
3434 0 pop( @{$ctx->{ptr_stack}} );
3435 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3436 0 next;
3437 }
3438 5 $ann{ $k } = 1;
3439 }
3440 }
3441  
3442 353 pop( @{$ctx->{ptr_stack}} );
3443 }
3444  
3445 285 ▶ if( my $depR = $S->{dependentRequired} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $depR = $S->{"dependentRequired"}) 8 277 285
3446 {
3447 8 for my $k ( keys( %$depR ) )
3448 {
3449 8 ▶ next unless( exists( $H->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $H->{$k} 2 6 8
3450 6 ▶ for my $need ( @{$depR->{ $k } || []} )
Condition50%1/2
$depR->{$k} || []
l!l
60
MC/DC0%0/1
$depR->{$k} || []
$depR->{$k}
Truth table50%1/2
A
A= $depR->{$k}
Aresult
11
00
3451 {
3452 6 ▶ next if( exists( $H->{ $need } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $H->{$need} 4 2 6
3453 2 _err_res( $ctx, _join_ptr( $sp, $need ), "dependentRequired: '$need' required when '$k' is present", 'dependentRequired' );
3454 2 $ok = 0;
3455 2 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3456 }
3457 }
3458 }
3459  
3460 285 ▶ if( my $depS = $S->{dependentSchemas} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $depS = $S->{"dependentSchemas"}) 8 277 285
3461 {
3462 8 for my $k ( keys( %$depS ) )
3463 {
3464 8 ▶ next unless( exists( $H->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $H->{$k} 3 5 8
3465 5 my $r = _v( $ctx, _join_ptr( $sp, "dependentSchemas/$k" ), $depS->{ $k }, $H );
3466 5 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 2 3 5
3467 {
3468 2 $ok = 0;
3469 2 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3470 }
3471 }
3472 }
3473  
3474 285 ▶ if( exists( $S->{unevaluatedProperties} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedProperties"}) 4 281 285
3475 {
3476 4 my @unknown = grep { !$ann{ $_ } } keys( %$H );
3477 4 my $UE = $S->{unevaluatedProperties};
3478  
3479 4 ▶ if( !_is_true( $UE ) && !_is_hash( $UE ) )
Branch: 2 branches
BranchTrueFalseTotal
if (not _is_true($UE) || _is_hash($UE)) { } 4 0 4
elsif (ref $UE eq 'HASH') { } 0 0 0
Condition33%1/3
_is_true($UE) || _is_hash($UE)
l!l&&r!l&&!r
004
MC/DC0%0/2
_is_true($UE) || _is_hash($UE)
_is_true($UE) _is_hash($UE)
Truth table33%1/3
A || B
A= _is_true($UE)B= _is_hash($UE)
ABresult
1X1
011
000
3480 {
3481 4 ▶ if( @unknown )
Branch: 1 branch
BranchTrueFalseTotal
if (@unknown) 1 3 4
3482 {
3483 1 _err_res( $ctx, $sp, "unevaluatedProperties not allowed: " . join( ',', @unknown ), 'unevaluatedProperties' );
3484 1 $ok = 0;
3485 1 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 1 1
3486 }
3487 }
3488 elsif( ref( $UE ) eq 'HASH' )
3489 {
3490 0 for my $k ( @unknown )
3491 {
3492 0 my $r = _v( $ctx, _join_ptr( $sp, "unevaluatedProperties" ), $UE, $H->{ $k } );
3493 0 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 0 0
3494 {
3495 0 $ok = 0;
3496 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3497 0 next;
3498 }
3499 0 $ann{ $k } = 1;
3500 }
3501 }
3502 }
3503  
3504 285 ▶ return( { ok => ( $ok ? 1 : 0 ), props => \%ann, items => {} } );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 167 118 285
3505 }
3506  
3507 sub _k_string
3508 50 ▶{
Subroutine _k_string: called CC=15 SCAR=27.7
3509 50 my( $ctx, $s, $S, $ptr ) = @_;
3510 50 my $len = _strlen( $s );
3511  
3512 50 ▶ if( exists( $S->{minLength} ) && $len < $S->{minLength} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"minLength"} and $len < $S->{"minLength"}) 7 43 50
Condition100%3/3
exists $S->{"minLength"} and $len < $S->{"minLength"}
!ll&&!rl&&r
18257
MC/DC100%2/2
exists $S->{"minLength"} and $len < $S->{"minLength"}
exists $S->{"minLength"} $len < $S->{"minLength"}
Truth table100%3/3
A and B
A= exists $S->{"minLength"}B= $len < $S->{"minLength"}
ABresult
0X0
100
111
3513 {
3514 7 ▶ _t( $ctx, $ptr, 'minLength', undef, 'fail', "len=$len < $S->{minLength}" ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 1 6 7
3515 7 return( _err( $ctx, $ptr, "string shorter than minLength $S->{minLength}", 'minLength' ) );
3516 }
3517 43 ▶ _t( $ctx, $ptr, 'minLength', undef, 'pass', "len=$len >= $S->{minLength}" ) if( exists( $S->{minLength} ) && $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $S->{"minLength"} and $ctx->{"trace_on"} 0 43 43
Condition66%2/3
exists $S->{"minLength"} and $ctx->{"trace_on"}
!ll&&!rl&&r
18250
MC/DC0%0/2
exists $S->{"minLength"} and $ctx->{"trace_on"}
exists $S->{"minLength"} $ctx->{"trace_on"}
Truth table66%2/3
A and B
A= exists $S->{"minLength"}B= $ctx->{"trace_on"}
ABresult
0X0
100
111
3518  
3519 43 ▶ if( exists( $S->{maxLength} ) && $len > $S->{maxLength} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"maxLength"} and $len > $S->{"maxLength"}) 1 42 43
Condition100%3/3
exists $S->{"maxLength"} and $len > $S->{"maxLength"}
!ll&&!rl&&r
3841
MC/DC100%2/2
exists $S->{"maxLength"} and $len > $S->{"maxLength"}
exists $S->{"maxLength"} $len > $S->{"maxLength"}
Truth table100%3/3
A and B
A= exists $S->{"maxLength"}B= $len > $S->{"maxLength"}
ABresult
0X0
100
111
3520 {
3521 1 ▶ _t( $ctx, $ptr, 'maxLength', undef, 'fail', "len=$len > $S->{maxLength}" ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 1 1
3522 1 return( _err( $ctx, $ptr, "string longer than maxLength $S->{maxLength}", 'maxLength' ) );
3523 }
3524 42 ▶ _t( $ctx, $ptr, 'maxLength', undef, 'pass', "len=$len <= $S->{maxLength}" ) if( exists( $S->{maxLength} ) && $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if exists $S->{"maxLength"} and $ctx->{"trace_on"} 0 42 42
Condition66%2/3
exists $S->{"maxLength"} and $ctx->{"trace_on"}
!ll&&!rl&&r
3840
MC/DC0%0/2
exists $S->{"maxLength"} and $ctx->{"trace_on"}
exists $S->{"maxLength"} $ctx->{"trace_on"}
Truth table66%2/3
A and B
A= exists $S->{"maxLength"}B= $ctx->{"trace_on"}
ABresult
0X0
100
111
3525  
3526 42 ▶ if( exists( $S->{pattern} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"pattern"}) 18 24 42
3527 {
3528 18 my $re = $S->{pattern};
3529 18 local $@;
3530 18 my $ok = eval{ $s =~ /$re/ };
3531 18 ▶ _t( $ctx, $ptr, 'pattern', undef, $ok ? 'pass' : 'fail', "/$re/" ) if( $ctx->{trace_on} );
Branch: 2 branches
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 18 18
$ok ? : 0 0 0
3532 18 ▶ return( _err( $ctx, $ptr, "string does not match pattern /$re/", 'pattern' ) ) unless( $ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 16 18
3533 }
3534 40 return(1);
3535 }
3536  
3537 # Primitive keyword helpers
3538 sub _k_type
3539 582 ▶{
Subroutine _k_type: called CC=9 SCAR=22.0
3540 582 my( $ctx, $v, $type_kw, $ptr ) = @_;
3541  
3542 582 ▶ my @alts = ref( $type_kw ) eq 'ARRAY' ? @$type_kw : ( $type_kw );
Branch: 1 branch
BranchTrueFalseTotal
ref $type_kw eq 'ARRAY' ? : 26 556 582
3543  
3544 # First, allow inline schemas in the union
3545 582 my $i = 0;
3546 582 for my $alt ( @alts )
3547 {
3548 642 ▶ if( ref( $alt ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $alt eq "HASH") 20 622 642
3549 {
3550 20 my $r = _v( $ctx, _join_ptr( $ptr, "type/$i" ), $alt, $v );
3551 20 ▶ return(1) if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 3 17 20
3552 }
3553 639 $i++;
3554 }
3555  
3556 # Then, try string type names
3557 579 for my $t ( @alts )
3558 {
3559 610 ▶ next if( ref( $t ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $t 15 595 610
3560 595 ▶ return(1) if( _match_type( $v, $t ) );
Branch: 1 branch
BranchTrueFalseTotal
if _match_type($v, $t) 543 52 595
3561 }
3562  
3563 36 ▶ my $exp = join( '|', map{ ref( $_ ) ? 'schema' : $_ } @alts );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 15 34 49
3564 36 return( _err( $ctx, $ptr, "type mismatch: expected $exp", 'type' ) );
3565 }
3566  
3567 sub _k_unique_keys
3568 17 ▶{
Subroutine _k_unique_keys: called CC=12 SCAR=25.2
3569 17 my( $ctx, $sp, $uk_def, $array ) = @_;
3570 17 ▶ unless( ref( $uk_def ) eq 'ARRAY' && @$uk_def )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $uk_def eq "ARRAY" and @$uk_def) 0 17 17
Condition33%1/3
ref $uk_def eq "ARRAY" and @$uk_def
!ll&&!rl&&r
0017
MC/DC0%0/2
ref $uk_def eq "ARRAY" and @$uk_def
ref $uk_def eq "ARRAY" @$uk_def
Truth table33%1/3
A and B
A= ref $uk_def eq "ARRAY"B= @$uk_def
ABresult
0X0
100
111
3571 {
3572 0 return( { ok => 1, props => {}, items => {} } );
3573 }
3574  
3575 17 for my $key_set ( @$uk_def )
3576 {
3577 19 ▶ next unless( ref( $key_set ) eq 'ARRAY' && @$key_set );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $key_set eq "ARRAY" and @$key_set 0 19 19
Condition33%1/3
ref $key_set eq "ARRAY" and @$key_set
!ll&&!rl&&r
0019
MC/DC0%0/2
ref $key_set eq "ARRAY" and @$key_set
ref $key_set eq "ARRAY" @$key_set
Truth table33%1/3
A and B
A= ref $key_set eq "ARRAY"B= @$key_set
ABresult
0X0
100
111
3578  
3579 19 my %seen;
3580 19 for my $i ( 0 .. $#$array )
3581 {
3582 42 my $item = $array->[$i];
3583 42 ▶ next unless( ref( $item ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item eq "HASH" 2 40 42
3584  
3585 40 my @key_vals;
3586 40 my $all_present = 1;
3587 40 for my $key ( @$key_set )
3588 {
3589 47 ▶ if( exists( $item->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $item->{$key}) { } 44 3 47
3590 {
3591 44 push( @key_vals, _canon( $item->{ $key } ) );
3592 }
3593 else
3594 {
3595 3 $all_present = 0;
3596 3 last;
3597 }
3598 }
3599  
3600 # Skip items that do not have *all* keys in this key set
3601 40 ▶ next unless( $all_present );
Branch: 1 branch
BranchTrueFalseTotal
unless $all_present 3 37 40
3602  
3603 37 my $composite = join( "\0", @key_vals );
3604 37 ▶ if( exists( $seen{ $composite } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen{$composite}) 8 29 37
3605 {
3606 8 my $prev_i = $seen{ $composite };
3607 8 my $keys = join( ', ', map { "'$_'" } @$key_set );
3608 8 push( @{$ctx->{ptr_stack}}, _inst_ptr( $ctx, $i ) );
3609 8 my $res = _err_res(
3610 $ctx,
3611 $sp,
3612 "uniqueKeys violation: items[$prev_i] and items[$i] have identical values for key(s) [$keys]",
3613 'uniqueKeys',
3614 );
3615 8 pop( @{$ctx->{ptr_stack}} );
3616  
3617 8 return( $res );
3618 }
3619 29 $seen{ $composite } = $i;
3620 }
3621 }
3622  
3623 9 return( { ok => 1, props => {}, items => {} } );
3624 }
3625  
3626 sub _match_type
3627 595 ▶{
Subroutine _match_type: called CC=22 SCAR=31.0
3628 595 my( $v, $t ) = @_;
3629  
3630 595 ▶ return(1) if( $t eq 'null' && !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "null" and not defined $v 1 594 595
Condition66%2/3
$t eq "null" and not defined $v
!ll&&!rl&&r
59401
MC/DC50%1/2
$t eq "null" and not defined $v
$t eq "null" not defined $v
Truth table66%2/3
A and not(B)
A= $t eq "null"B= not defined $v
ABresult
0X0
100
111
3631  
3632 594 ▶ if( $t eq 'boolean' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "boolean") 16 578 594
3633 {
3634 16 ▶ return(0) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 2 14 16
3635 14 ▶ if( blessed( $v ) && ( ref( $v ) =~ /Boolean/ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($v) and ref($v) =~ /Boolean/u) 8 6 14
Condition66%2/3
builtin::blessed($v) and ref($v) =~ /Boolean/u
!ll&&!rl&&r
608
MC/DC50%1/2
builtin::blessed($v) and ref($v) =~ /Boolean/u
builtin::blessed($v) ref($v) =~ /Boolean/u
Truth table66%2/3
A and B
A= builtin::blessed($v)B= ref($v) =~ /Boolean/u
ABresult
0X0
100
111
3636 {
3637 8 my $s = "$v";
3638 8 ▶ return( ( $s eq '0' || $s eq '1' ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$s eq '0' || $s eq '1' ? : 8 0 8
Condition66%2/3
$s eq 0 or $s eq 1
l!l&&r!l&&!r
170
MC/DC0%0/2
$s eq 0 or $s eq 1
$s eq 0 $s eq 1
Truth table66%2/3
A or B
A= $s eq 0B= $s eq 1
ABresult
1X1
011
000
3639 }
3640 6 ▶ return( ( $v =~ /\A(?:0|1|true|false)\z/i ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A(?:0|1|true|false)\z/iu ? : 2 4 6
3641 }
3642  
3643 578 ▶ if( $t eq 'integer' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "integer") 113 465 578
3644 {
3645 113 ▶ return(0) unless( _is_number( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_number($v) 14 99 113
3646 99 ▶ return( ( $v =~ /\A-?(?:0|[1-9][0-9]*)\z/ ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$v =~ /\A-?(?:0|[1-9][0-9]*)\z/u ? : 98 1 99
3647 }
3648  
3649 465 ▶ if( $t eq 'number' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "number") 33 432 465
3650 {
3651 33 return( _is_number( $v ) );
3652 }
3653  
3654 432 ▶ if( $t eq 'string' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "string") 140 292 432
3655 {
3656 # Must be a scalar, defined, and NOT a numeric SV under strict typing.
3657 140 ▶ return( (!ref( $v ) && defined( $v ) && !_is_number( $v )) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
!ref($v) && defined $v && !_is_number($v) ? : 132 8 140
Condition83%5/6
not ref $v and defined $v and not _is_number($v)
!ll&&!rl&&r
35132
not ref $v and defined $v
!ll&&!rl&&r
03137
MC/DC66%2/3
not ref $v and defined $v and not _is_number($v)
not ref $v defined $v not _is_number($v)
Truth table75%3/4
not(A) and B and not(C)
A= not ref $vB= defined $vC= not _is_number($v)
ABCresult
0XX0
10X0
1100
1111
3658 }
3659  
3660 292 ▶ return(1) if( $t eq 'array' && ref( $v ) eq 'ARRAY' );
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "array" and ref $v eq "ARRAY" 37 255 292
Condition100%3/3
$t eq "array" and ref $v eq "ARRAY"
!ll&&!rl&&r
250537
MC/DC100%2/2
$t eq "array" and ref $v eq "ARRAY"
$t eq "array" ref $v eq "ARRAY"
Truth table100%3/3
A and B
A= $t eq "array"B= ref $v eq "ARRAY"
ABresult
0X0
100
111
3661 255 ▶ return(1) if( $t eq 'object' && ref( $v ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if $t eq "object" and ref $v eq "HASH" 236 19 255
Condition100%3/3
$t eq "object" and ref $v eq "HASH"
!ll&&!rl&&r
514236
MC/DC100%2/2
$t eq "object" and ref $v eq "HASH"
$t eq "object" ref $v eq "HASH"
Truth table100%3/3
A and B
A= $t eq "object"B= ref $v eq "HASH"
ABresult
0X0
100
111
3662  
3663 19 return(0);
3664 }
3665  
3666 sub _normalize_uri
3667 119 ▶{
Subroutine _normalize_uri: called CC=3 SCAR=12.5
3668 119 my( $u ) = @_;
3669 119 ▶ return( '#' ) unless( defined( $u ) && length( $u ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $u and length $u 0 119 119
Condition33%1/3
defined $u and length $u
!ll&&!rl&&r
00119
MC/DC0%0/2
defined $u and length $u
defined $u length $u
Truth table33%1/3
A and B
A= defined $uB= length $u
ABresult
0X0
100
111
3670 119 return( $u );
3671 }
3672  
3673 sub _parse_media_type
3674 7 ▶{
Subroutine _parse_media_type: called CC=5 SCAR=16.3
3675 7 my( $s ) = @_;
3676 7 my( $type, @rest ) = split( /;/, "$s" );
3677 7 ▶ $type ||= '';
Condition50%1/2
$type ||= ""
l!l
70
MC/DC0%0/1
$type ||= ""
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
3678 7 $type =~ s/\s+//g;
3679 7 my %p;
3680 7 for my $kv ( @rest )
3681 {
3682 7 my( $k, $v ) = split( /=/, $kv, 2 );
3683 7 ▶ next unless( defined( $k ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 7 7
3684 7 $k =~ s/\s+//g;
3685 7 ▶ $v = '' unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 7 7
3686 7 $v =~ s/^\s+|\s+$//g;
3687 # Allow single or double quote, but be consistent
3688 7 $v =~ s/^(?<quote>["'])(.*)\g{quote}$/$2/;
3689 7 $p{ lc( $k ) } = $v;
3690 }
3691 7 return( lc( $type ), \%p );
3692 }
3693  
3694 sub _prune_array_with_schema
3695 1 ▶{
Subroutine _prune_array_with_schema: called CC=6 SCAR=18.0
3696 1 my( $self, $schema, $data ) = @_;
3697  
3698 1 my @out;
3699  
3700 1 my $shape =
3701 {
3702 prefix_items => [], # index => subschema
3703 items => undef # subschema for additional items
3704 };
3705  
3706 1 $self->_extract_array_shape( $schema, $shape );
3707  
3708 1 for my $i ( 0 .. $#$data )
3709 {
3710 3 my $item = $data->[ $i ];
3711 3 my $item_schema;
3712  
3713 3 ▶ if( defined( $shape->{prefix_items}->[ $i ] ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $shape->{'prefix_items'}[$i]) { } 1 2 3
elsif ($shape->{'items'}) { } 2 0 2
3714 {
3715 1 $item_schema = $shape->{prefix_items}->[ $i ];
3716 }
3717 elsif( $shape->{items} )
3718 {
3719 2 $item_schema = $shape->{items};
3720 }
3721  
3722 3 ▶ if( $item_schema && ref( $item ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($item_schema and ref $item) { } 2 1 3
Condition66%2/3
$item_schema and ref $item
!ll&&!rl&&r
012
MC/DC50%1/2
$item_schema and ref $item
$item_schema ref $item
Truth table66%2/3
A and B
A= $item_schemaB= ref $item
ABresult
0X0
100
111
3723 {
3724 2 $out[ $i ] = $self->_prune_with_schema( $item_schema, $item );
3725 }
3726 else
3727 {
3728 # No structural knowledge or scalar item: keep as-is
3729 1 $out[ $i ] = $item;
3730 }
3731 }
3732  
3733 1 return( \@out );
3734 }
3735  
3736 sub _prune_object_with_schema
3737 6 ▶{
Subroutine _prune_object_with_schema: called CC=9 SCAR=22.9
3738 6 my( $self, $schema, $data ) = @_;
3739  
3740 # Collect effective object shape from this schema and any allOf mixins.
3741 6 my $shape =
3742 {
3743 props => {}, # property name => subschema
3744 patterns => [], # [ regex, subschema ] ...
3745 allow_ap => 1, # additionalProperties allowed?
3746 ap_schema => undef # subschema for additionalProperties, if any
3747 };
3748  
3749 6 $self->_extract_object_shape( $schema, $shape );
3750  
3751 6 my %clean;
3752  
3753 KEY:
3754 6 foreach my $key ( keys( %$data ) )
3755 {
3756 16 my $val = $data->{ $key };
3757  
3758 # 1) Direct properties
3759 16 ▶ if( exists( $shape->{props}->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $shape->{"props"}{$key}) 7 9 16
3760 {
3761 7 my $sub = $shape->{props}->{ $key };
3762 7 $clean{ $key } = $self->_prune_with_schema( $sub, $val );
3763 7 next KEY;
3764 }
3765  
3766 # 2) patternProperties
3767 9 foreach my $pair ( @{$shape->{patterns}} )
3768 {
3769 3 my( $re, $pschema ) = @$pair;
3770 3 my $ok;
3771  
3772 {
3773 3 local $@;
3774 3 ▶ $ok = eval{ $key =~ /$re/ ? 1 : 0; };
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /$re/u ? : 2 1 3
3775 }
3776  
3777 3 ▶ next unless( $ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
3778  
3779 2 $clean{ $key } = $self->_prune_with_schema( $pschema, $val );
3780 2 next KEY;
3781 }
3782  
3783 # 3) additionalProperties
3784 7 ▶ if( $shape->{allow_ap} )
Branch: 1 branch
BranchTrueFalseTotal
if ($shape->{'allow_ap'}) { } 0 7 7
3785 {
3786 0 ▶ if( $shape->{ap_schema} && ref( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($shape->{'ap_schema'} and ref $val) { } 0 0 0
Condition0%0/3
$shape->{"ap_schema"} and ref $val
!ll&&!rl&&r
000
MC/DC0%0/2
$shape->{"ap_schema"} and ref $val
$shape->{"ap_schema"} ref $val
Truth table0%0/3
A and B
A= $shape->{"ap_schema"}B= ref $val
ABresult
0X0
100
111
3787 {
3788 0 $clean{ $key } = $self->_prune_with_schema( $shape->{ap_schema}, $val );
3789 }
3790 else
3791 {
3792 # allowed, but no further structure known
3793 0 $clean{ $key } = $val;
3794 }
3795 }
3796 else
3797 {
3798 # additionalProperties is false (or equivalent) => drop unknown key
3799 7 next KEY;
3800 }
3801 }
3802  
3803 6 return( \%clean );
3804 }
3805  
3806 sub _prune_with_schema
3807 17 ▶{
Subroutine _prune_with_schema: called CC=4 SCAR=13.9
3808 17 my( $self, $schema, $data ) = @_;
3809  
3810 # Boolean schemas and non-hash schemas: do not attempt pruning.
3811 17 ▶ return( $data ) unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 17 17
3812  
3813 # Only prune structured values; scalars we leave untouched.
3814 17 ▶ if( ref( $data ) eq 'HASH' )
Branch: 2 branches
BranchTrueFalseTotal
if (ref $data eq 'HASH') { } 6 11 17
elsif (ref $data eq 'ARRAY') { } 1 10 11
3815 {
3816 6 return( $self->_prune_object_with_schema( $schema, $data ) );
3817 }
3818 elsif( ref( $data ) eq 'ARRAY' )
3819 {
3820 1 return( $self->_prune_array_with_schema( $schema, $data ) );
3821 }
3822  
3823 10 return( $data );
3824 }
3825  
3826 sub _ptr_of_node
3827 8 ▶{
Subroutine _ptr_of_node: called CC=3 SCAR=11.0
3828 8 my( $root, $target ) = @_;
3829 8 for my $p ( keys( %{$root->{anchors}} ) )
3830 {
3831 29 my $n = $root->{anchors}->{ $p };
3832 29 ▶ return( $p ) if( $n eq $target );
Branch: 1 branch
BranchTrueFalseTotal
if $n eq $target 8 21 29
3833 }
3834 0 return( '#' );
3835 }
3836  
3837 44 my %SCRIPT_LIKE = map{ $_ => 1 } qw(
3838 Hiragana Katakana Han Hangul Latin Cyrillic Greek
3839 Hebrew Thai Armenian Georgian
3840 Arabic Devanagari Bengali Gurmukhi Gujarati Oriya
3841 Tamil Telugu Kannada Malayalam Sinhala
3842 Lao Tibetan Myanmar Khmer
3843 );
3844 sub _re_to_js
3845 0 ▶{
Subroutine _re_to_js: not called CC=7 SCAR=40.3
3846 0 my $re = shift( @_ );
3847 0 my %opt = @_;
3848  
3849 # style: 'literal' => for use in /.../u
3850 # 'string' => for use in new RegExp("...", "u")
3851 0 ▶ my $style = $opt{style} || 'string';
Condition0%0/2
$opt{'style'} || 'string'
l!l
00
MC/DC0%0/1
$opt{'style'} || 'string'
$opt{'style'}
Truth table0%0/2
A
A= $opt{'style'}
Aresult
11
00
3852  
3853 0 ▶ return if( !defined( $re ) || !length( $re ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $re and length $re 0 0 0
Condition0%0/3
defined $re and length $re
!ll&&!rl&&r
000
MC/DC0%0/2
defined $re and length $re
defined $re length $re
Truth table0%0/3
A and B
A= defined $reB= length $re
ABresult
0X0
100
111
3854  
3855 #
3856 # 1) Convert \x{...} (Perl) to \u.... or \u{....} (JS)
3857 # - 1–4 hex digits -> \uHHHH
3858 # - 5–6 hex digits -> \u{HHHHH} (requires /u in JS)
3859 #
3860 0 $re =~ s{
3861 \\x\{([0-9A-Fa-f]{1,6})\}
3862 }{
3863 0 my $hex = uc( $1 );
3864 0 ▶ if( length( $hex ) <= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $hex <= 4) { } 0 0 0
3865 {
3866 0 "\\u$hex";
3867 }
3868 else
3869 {
3870 0 "\\u\{$hex\}";
3871 }
3872 }egx;
3873  
3874 # Script eXtended
3875 #
3876 # 2) Convert \p{Katakana} / \P{Katakana}
3877 # to \p{scx=Katakana} / \P{scx=Katakana}
3878 # (Script_Extensions so it covers half-width too)
3879 #
3880 0 $re =~ s[
3881 \\([pP])\{([^}]+)\}
3882 ][
3883 0 my( $p, $name ) = ( $1, $2 );
3884  
3885 0 my $norm = $name;
3886 0 $norm =~ s/^\s+|\s+$//g;
3887 0 $norm = ucfirst( lc( $norm ) );
3888  
3889 0 ▶ if( exists( $SCRIPT_LIKE{ $norm } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SCRIPT_LIKE{$norm}) { } 0 0 0
3890 {
3891 0 "\\$p\{scx=$norm\}";
3892 }
3893 else
3894 {
3895 # Pass other properties through unchanged:
3896 # \p{L}, \p{Letter}, \p{Nd}, etc.
3897 0 "\\$p\{$name\}";
3898 }
3899 ]egx;
3900  
3901 #
3902 # 3) Optionally escape backslashes for JS string literal
3903 #
3904 0 ▶ if( $style eq 'string' )
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq "string") 0 0 0
3905 {
3906 0 $re =~ s{\\}{\\\\}g; # existing
3907 0 $re =~ s{"}{\\"}g; # escape "
3908 0 $re =~ s{\n}{\\n}g;
3909 0 $re =~ s{\r}{\\r}g;
3910 0 $re =~ s{/}{\/}g;
3911 }
3912  
3913 # For 'literal', we leave backslashes as-is, for use in /.../u
3914  
3915 0 return( $re );
3916 }
3917  
3918 sub _register_builtin_media_validators
3919 4 ▶{
Subroutine _register_builtin_media_validators: called CC=1 SCAR=0.0
3920 4 my( $self ) = @_;
3921  
3922 # Example: application/json
3923 $self->register_media_validator( 'application/json' => sub
3924 2 ▶ {
Subroutine __ANON__: called CC=2 SCAR=7.0
3925 2 my( $bytes, $params ) = @_;
3926 2 local $@;
3927 2 my $v = eval{ JSON->new->allow_nonref(1)->decode( $bytes ) };
3928 2 ▶ return( 0, 'invalid JSON', undef ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
3929 # JSON value is valid even if it’s 0, "", or false
3930 2 return( 1, undef, $v );
3931 4 } );
3932  
3933 4 return( $self );
3934 }
3935  
3936 sub _resolve_uri
3937 37 ▶{
Subroutine _resolve_uri: called CC=6 SCAR=18.4
3938 37 my( $base, $ref ) = @_;
3939 37 ▶ return( $ref ) if( !defined( $base ) || $base eq '' || $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/ );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $base or $base eq "" or $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/u 19 18 37
Condition50%3/6
not defined $base or $base eq "" or $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/u
l!l&&r!l&&!r
01918
not defined $base or $base eq ""
l!l&&r!l&&!r
0037
MC/DC33%1/3
not defined $base or $base eq "" or $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/u
not defined $base $base eq "" $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/u
Truth table50%2/4
not(A) or B or C
A= not defined $baseB= $base eq ""C= $ref =~ /^[A-Za-z][A-Za-z0-9+\-.]*:/u
ABCresult
1XX1
01X1
0011
0000
3940 18 ▶ if( $ref =~ /^\#/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /^\#/u) 17 1 18
3941 {
3942 17 ( my $no_frag = $base ) =~ s/\#.*$//;
3943 17 return( $no_frag . $ref );
3944 }
3945 1 ▶ return( $base . $ref ) if( $base =~ /\/$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $base =~ m[/$]u 0 1 1
3946 1 ( my $dir = $base ) =~ s{[^/]*$}{};
3947 1 return( $dir . $ref );
3948 }
3949  
3950 sub _safe_invoke
3951 8 ▶{
Subroutine _safe_invoke: called CC=9 SCAR=32.3
3952 8 my( $cb, @args ) = @_;
3953 8 local $@;
3954 # Force list context to preserve (ok, msg, out) style returns
3955 8 my @ret = eval{ $cb->( @args ) };
3956 8 ▶ return( 0, ( $@ || 'callback failed' ), undef ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 8 8
Condition0%0/2
$@ || 'callback failed'
l!l
00
MC/DC0%0/1
$@ || 'callback failed'
$@
Truth table0%0/2
A
A= $@
Aresult
11
00
3957  
3958 # If callback returns (ok, msg, out) or (ok, msg)
3959 8 ▶ if( @ret >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ret >= 2) 8 0 8
3960 {
3961 8 ▶ my( $ok, $msg, $out ) = ( $ret[0] ? 1 : 0, $ret[1], $ret[2] );
Branch: 1 branch
BranchTrueFalseTotal
$ret[0] ? : 6 2 8
3962 8 return( $ok, $msg, $out );
3963 }
3964  
3965 # If callback returns a single value
3966 0 ▶ if( @ret == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ret == 1) 0 0 0
3967 {
3968 0 my $v = $ret[0];
3969 # Reference => treat as decoded structure (success)
3970 0 ▶ return( 1, undef, $v ) if( ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 0 0
3971 # Defined scalar => truthiness decides; scalar can be treated as decoded bytes
3972 0 ▶ return( $v ? 1 : 0, undef, ( defined( $v ) ? $v : undef ) );
Branch: 2 branches
BranchTrueFalseTotal
$v ? : 0 0 0
defined $v ? : 0 0 0
3973 }
3974  
3975 # Empty list => treat as failure (safer default)
3976 0 return( 0, 'callback returned no value', undef );
3977 }
3978  
3979 sub _strlen
3980 50 ▶{
Subroutine _strlen: called CC=2 SCAR=7.0
3981 50 my( $s ) = @_;
3982 50 ▶ $s = Encode::decode( 'UTF-8', "$s", Encode::FB_DEFAULT ) unless( Encode::is_utf8( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless &Encode::is_utf8($s) 50 0 50
3983 50 my @cp = unpack( 'U*', $s );
3984 50 return( scalar( @cp ) );
3985 }
3986  
3987 # Strict base64: validates alphabet, padding, length, and round-trips
3988 sub _strict_base64_decode
3989 6 ▶{
Subroutine _strict_base64_decode: called CC=6 SCAR=18.2
3990 6 my( $s ) = @_;
3991 6 ▶ return unless( defined( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 6 6
3992  
3993 # strip ASCII whitespace per RFC 4648 §3.3 (tests commonly include raw)
3994 6 ( my $norm = "$s" ) =~ s/\s+//g;
3995  
3996 # valid alphabet + padding only
3997 6 ▶ return unless( $norm =~ /\A[A-Za-z0-9+\/]*={0,2}\z/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $norm =~ m[\A[A-Za-z0-9+/]*={0,2}\z]u 3 3 6
3998  
3999 # length must be a multiple of 4
4000 3 ▶ return unless( ( length( $norm ) % 4 ) == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless length($norm) % 4 == 0 0 3 3
4001  
4002 3 local $@;
4003 3 ▶ return unless( eval{ require MIME::Base64; 1 } );
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require MIME::Base64; 1 } } 0 3 3
4004  
4005 3 my $out = MIME::Base64::decode_base64( $norm );
4006  
4007 # re-encode and compare to ensure no silent salvage
4008 3 my $re = MIME::Base64::encode_base64( $out, '' );
4009 # RFC allows omitting trailing '=' if not needed; normalize both
4010 3 $re =~ s/\s+//g;
4011 3 $norm =~ s/\s+//g;
4012 3 ▶ return unless( $re eq $norm );
Branch: 1 branch
BranchTrueFalseTotal
unless $re eq $norm 0 3 3
4013 3 return( $out );
4014 }
4015  
4016 sub _t
4017 44 ▶{
Subroutine _t: called CC=7 SCAR=21.5
4018 44 my( $ctx, $schema_ptr, $keyword, $inst_path, $outcome, $note ) = @_;
4019 44 ▶ return unless( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx->{"trace_on"} 0 44 44
4020  
4021 44 ▶ if( $ctx->{trace_limit} && @{$ctx->{trace}} >= $ctx->{trace_limit} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"trace_limit"} and @{$ctx->{"trace"};} >= $ctx->{"trace_limit"}) 0 44 44
Condition33%1/3
$ctx->{"trace_limit"} and @{$ctx->{"trace"};} >= $ctx->{"trace_limit"}
!ll&&!rl&&r
0440
MC/DC0%0/2
$ctx->{"trace_limit"} and @{$ctx->{"trace"};} >= $ctx->{"trace_limit"}
$ctx->{"trace_limit"} @{$ctx->{"trace"};} >= $ctx->{"trace_limit"}
Truth table33%1/3
A and B
A= $ctx->{"trace_limit"}B= @{$ctx->{"trace"};} >= $ctx->{"trace_limit"}
ABresult
0X0
100
111
4022 {
4023 0 return;
4024 }
4025 44 ▶ if( $ctx->{trace_sample} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"trace_sample"}) 8 36 44
4026 {
4027 8 ▶ return if( int( rand(100) ) >= $ctx->{trace_sample} );
Branch: 1 branch
BranchTrueFalseTotal
if int rand 100 >= $ctx->{"trace_sample"} 8 0 8
4028 }
4029  
4030 36 ▶ push( @{$ctx->{trace}},
Condition50%1/2
$ctx->{"ptr_stack"}[-1] // "#"
l!l
360
MC/DC0%0/1
$ctx->{"ptr_stack"}[-1] // "#"
$ctx->{"ptr_stack"}[-1]
Truth table50%1/2
A
A= $ctx->{"ptr_stack"}[-1]
Aresult
11
00
4031 {
4032 schema_ptr => $schema_ptr,
4033 keyword => $keyword,
4034 36 inst_path => ( $ctx->{ptr_stack}->[-1] // '#' ),
4035 outcome => $outcome, # 'pass' | 'fail'
4036 note => $note, # short string
4037 });
4038 }
4039  
4040 # Validation core with annotation + recursion
4041 # _v returns { ok => 0|1, props => {k=>1,...}, items => {i=>1,...} }
4042 sub _v
4043 715 ▶{
Subroutine _v: called CC=8 SCAR=20.9
4044 715 my( $ctx, $schema_ptr, $schema, $inst ) = @_;
4045  
4046 # Recursion guard only for reference types
4047 715 ▶ if( ref( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst) 364 351 715
4048 {
4049 364 my $inst_addr = _inst_addr( $inst, $ctx->{ptr_stack}->[-1] );
4050 364 my $vkey = "$schema_ptr|$inst_addr";
4051 364 ▶ return( { ok => 1, props => {}, items => {} } ) if( $ctx->{visited}->{ $vkey }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"visited"}{$vkey}++ 0 364 364
4052 }
4053  
4054 # Enter dynamicAnchor scope if present
4055 715 my $frame_added = 0;
4056 715 ▶ if( ref( $schema ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH" and exists $schema->{"\$dynamicAnchor"} and defined $schema->{"\$dynamicAnchor"} and $schema->{"\$dynamicAnchor"} ne "") 11 704 715
Condition66%6/9
ref $schema eq "HASH" and exists $schema->{"\$dynamicAnchor"} and defined $schema->{"\$dynamicAnchor"} and $schema->{"\$dynamicAnchor"} ne ""
!ll&&!rl&&r
704011
ref $schema eq "HASH" and exists $schema->{"\$dynamicAnchor"} and defined $schema->{"\$dynamicAnchor"}
!ll&&!rl&&r
704011
ref $schema eq "HASH" and exists $schema->{"\$dynamicAnchor"}
!ll&&!rl&&r
070411
MC/DC25%1/4
ref $schema eq "HASH" and exists $schema->{"\$dynamicAnchor"} and defined $schema->{"\$dynamicAnchor"} and $schema->{"\$dynamicAnchor"} ne ""
ref $schema eq "HASH" exists $schema->{"\$dynamicAnchor"} defined $schema->{"\$dynamicAnchor"} $schema->{"\$dynamicAnchor"} ne ""
Truth table40%2/5
A and B and C and D
A= ref $schema eq "HASH"B= exists $schema->{"\$dynamicAnchor"}C= defined $schema->{"\$dynamicAnchor"}D= $schema->{"\$dynamicAnchor"} ne ""
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4057 exists( $schema->{'$dynamicAnchor'} ) &&
4058 defined( $schema->{'$dynamicAnchor'} ) &&
4059 $schema->{'$dynamicAnchor'} ne '' )
4060 {
4061 11 my %frame = %{$ctx->{dyn_stack}->[-1]}; # inherit
4062 11 $frame{ $schema->{'$dynamicAnchor'} } = $schema;
4063 11 push( @{$ctx->{dyn_stack}}, \%frame );
4064 11 $frame_added = 1;
4065 }
4066  
4067 715 my $res = _v_node( $ctx, $schema_ptr, $schema, $inst );
4068  
4069 715 ▶ if( $frame_added )
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_added) 11 704 715
4070 {
4071 11 pop( @{$ctx->{dyn_stack}} );
4072 }
4073  
4074 715 return( $res );
4075 }
4076  
4077 sub _v_node
4078 715 ▶{
Subroutine _v_node: called CC=79 SCAR=46.2
4079 715 my( $ctx, $schema_ptr, $schema, $inst ) = @_;
4080  
4081 # $ref / $dynamicRef first
4082 715 ▶ if( ref( $schema ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH" and exists $schema->{"\$ref"}) 22 693 715
Condition66%2/3
ref $schema eq "HASH" and exists $schema->{"\$ref"}
!ll&&!rl&&r
069322
MC/DC50%1/2
ref $schema eq "HASH" and exists $schema->{"\$ref"}
ref $schema eq "HASH" exists $schema->{"\$ref"}
Truth table66%2/3
A and B
A= ref $schema eq "HASH"B= exists $schema->{"\$ref"}
ABresult
0X0
100
111
4083 exists( $schema->{'$ref'} ) )
4084 {
4085 22 return( _apply_ref( $ctx, $schema_ptr, $schema->{'$ref'}, $inst ) );
4086 }
4087 693 ▶ if( ref( $schema ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH" and exists $schema->{"\$dynamicRef"}) 5 688 693
Condition66%2/3
ref $schema eq "HASH" and exists $schema->{"\$dynamicRef"}
!ll&&!rl&&r
06885
MC/DC50%1/2
ref $schema eq "HASH" and exists $schema->{"\$dynamicRef"}
ref $schema eq "HASH" exists $schema->{"\$dynamicRef"}
Truth table66%2/3
A and B
A= ref $schema eq "HASH"B= exists $schema->{"\$dynamicRef"}
ABresult
0X0
100
111
4088 exists( $schema->{'$dynamicRef'} ) )
4089 {
4090 5 return( _apply_dynamic_ref( $ctx, $schema_ptr, $schema->{'$dynamicRef'}, $inst ) );
4091 }
4092 688 ▶ if( ref( $schema ) eq 'HASH' &&
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH" and exists $schema->{"\$comment"} and defined $schema->{"\$comment"}) 9 679 688
Condition66%4/6
ref $schema eq "HASH" and exists $schema->{"\$comment"} and defined $schema->{"\$comment"}
!ll&&!rl&&r
67909
ref $schema eq "HASH" and exists $schema->{"\$comment"}
!ll&&!rl&&r
06799
MC/DC33%1/3
ref $schema eq "HASH" and exists $schema->{"\$comment"} and defined $schema->{"\$comment"}
ref $schema eq "HASH" exists $schema->{"\$comment"} defined $schema->{"\$comment"}
Truth table50%2/4
A and B and C
A= ref $schema eq "HASH"B= exists $schema->{"\$comment"}C= defined $schema->{"\$comment"}
ABCresult
0XX0
10X0
1100
1111
4093 exists( $schema->{'$comment'} ) &&
4094 defined( $schema->{'$comment'} ) )
4095 {
4096 9 my $c = $schema->{'$comment'};
4097 9 ▶ if( my $cb = $ctx->{comment_handler} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{"comment_handler"}) 4 5 9
4098 {
4099 4 local $@;
4100 4 eval{ $cb->( $schema_ptr, "$c" ) };
4101 # ignore callback errors to keep validation resilient
4102 }
4103 9 ▶ _t( $ctx, $schema_ptr, '$comment', undef, 'visit', "$c" ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 9 0 9
4104 }
4105  
4106 688 ▶ _t( $ctx, $schema_ptr, 'node', undef, 'visit' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 12 676 688
4107  
4108 # Use compiled validator if enabled
4109 688 ▶ if( $ctx->{compile_on} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"compile_on"}) 35 653 688
4110 {
4111 35 my $fn = $ctx->{root}->{fn_index}->{ $schema_ptr };
4112 35 ▶ unless( $fn )
Branch: 1 branch
BranchTrueFalseTotal
unless ($fn) 23 12 35
4113 {
4114 23 $fn = _compile_node( $ctx->{root}, $schema_ptr, $schema );
4115 23 $ctx->{root}->{fn_index}->{ $schema_ptr } = $fn;
4116 }
4117 35 return( $fn->( $ctx, $inst ) );
4118 }
4119  
4120 653 ▶ return( { ok => 1, props => {}, items => {} } ) unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 653 653
4121  
4122 653 my $ptr = $schema_ptr;
4123  
4124 # Types / const / enum
4125 653 ▶ if( exists( $schema->{type} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"type"}) 547 106 653
4126 {
4127 547 ▶ _k_type( $ctx, $inst, $schema->{type}, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_type($ctx, $inst, $schema->{"type"}, $ptr) or return _fail() 511 36 547
4128 }
4129 617 ▶ if( exists( $schema->{const} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"const"}) 6 611 617
4130 {
4131 6 ▶ _k_const( $ctx, $inst, $schema->{const}, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_const($ctx, $inst, $schema->{"const"}, $ptr) or return _fail() 6 0 6
4132 }
4133 617 ▶ if( exists( $schema->{enum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"enum"}) 8 609 617
4134 {
4135 8 ▶ _k_enum( $ctx, $inst, $schema->{enum}, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_enum($ctx, $inst, $schema->{"enum"}, $ptr) or return _fail() 4 4 8
4136 }
4137 613 ▶ _t( $ctx, $schema_ptr, 'type/const/enum', undef, 'pass', '' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 613 613
4138  
4139 613 ▶ if( $ctx->{unique_keys} &&
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"unique_keys"} and exists $schema->{"uniqueKeys"} and ref $schema->{"uniqueKeys"} eq "ARRAY" and ref $inst eq "ARRAY") 17 596 613
Condition77%7/9
$ctx->{"unique_keys"} and exists $schema->{"uniqueKeys"} and ref $schema->{"uniqueKeys"} eq "ARRAY" and ref $inst eq "ARRAY"
!ll&&!rl&&r
596017
$ctx->{"unique_keys"} and exists $schema->{"uniqueKeys"} and ref $schema->{"uniqueKeys"} eq "ARRAY"
!ll&&!rl&&r
596017
$ctx->{"unique_keys"} and exists $schema->{"uniqueKeys"}
!ll&&!rl&&r
5375917
MC/DC50%2/4
$ctx->{"unique_keys"} and exists $schema->{"uniqueKeys"} and ref $schema->{"uniqueKeys"} eq "ARRAY" and ref $inst eq "ARRAY"
$ctx->{"unique_keys"} exists $schema->{"uniqueKeys"} ref $schema->{"uniqueKeys"} eq "ARRAY" ref $inst eq "ARRAY"
Truth table60%3/5
A and B and C and D
A= $ctx->{"unique_keys"}B= exists $schema->{"uniqueKeys"}C= ref $schema->{"uniqueKeys"} eq "ARRAY"D= ref $inst eq "ARRAY"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
4140 exists( $schema->{uniqueKeys} ) &&
4141 ref( $schema->{uniqueKeys} ) eq 'ARRAY' &&
4142 ref( $inst ) eq 'ARRAY' )
4143 {
4144 17 my $r = _k_unique_keys( $ctx, $ptr, $schema->{uniqueKeys}, $inst );
4145 17 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 8 9 17
4146 }
4147  
4148 # Numbers
4149 605 ▶ if( _is_number( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (_is_number($inst)) 139 466 605
4150 {
4151 139 for my $k ( qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum ) )
4152 {
4153 631 ▶ next unless( exists( $schema->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $schema->{$k} 545 86 631
4154 86 ▶ _k_number( $ctx, $inst, $k, $schema->{ $k }, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_number($ctx, $inst, $k, $schema->{$k}, $ptr) or return _fail() 64 22 86
4155 }
4156 }
4157  
4158 # Strings
4159 583 ▶ if( !ref( $inst ) && defined( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $inst and defined $inst) 265 318 583
Condition100%3/3
not ref $inst and defined $inst
!ll&&!rl&&r
3162265
MC/DC100%2/2
not ref $inst and defined $inst
not ref $inst defined $inst
Truth table100%3/3
not(A) and B
A= not ref $instB= defined $inst
ABresult
0X0
100
111
4160 {
4161 265 ▶ if( exists( $schema->{minLength} ) || exists( $schema->{maxLength} ) || exists( $schema->{pattern} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"minLength"} or exists $schema->{"maxLength"} or exists $schema->{"pattern"}) 48 217 265
Condition83%5/6
exists $schema->{"minLength"} or exists $schema->{"maxLength"} or exists $schema->{"pattern"}
l!l&&r!l&&!r
3018217
exists $schema->{"minLength"} or exists $schema->{"maxLength"}
l!l&&r!l&&!r
300235
MC/DC66%2/3
exists $schema->{"minLength"} or exists $schema->{"maxLength"} or exists $schema->{"pattern"}
exists $schema->{"minLength"} exists $schema->{"maxLength"} exists $schema->{"pattern"}
Truth table75%3/4
A or B or C
A= exists $schema->{"minLength"}B= exists $schema->{"maxLength"}C= exists $schema->{"pattern"}
ABCresult
1XX1
01X1
0011
0000
4162 {
4163 48 ▶ _k_string( $ctx, $inst, $schema, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_string($ctx, $inst, $schema, $ptr) or return _fail() 39 9 48
4164 }
4165 256 ▶ if( exists( $schema->{format} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"format"}) 53 203 256
4166 {
4167 53 ▶ _k_format( $ctx, $inst, $schema->{format}, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_format($ctx, $inst, $schema->{"format"}, $ptr) or return _fail() 36 17 53
4168 }
4169  
4170 # contentEncoding / contentMediaType / contentSchema
4171 239 ▶ if( exists( $schema->{contentEncoding} ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentEncoding"} or exists $schema->{"contentMediaType"} or exists $schema->{"contentSchema"}) 9 230 239
Condition66%4/6
exists $schema->{"contentEncoding"} or exists $schema->{"contentMediaType"} or exists $schema->{"contentSchema"}
l!l&&r!l&&!r
90230
exists $schema->{"contentEncoding"} or exists $schema->{"contentMediaType"}
l!l&&r!l&&!r
90230
MC/DC33%1/3
exists $schema->{"contentEncoding"} or exists $schema->{"contentMediaType"} or exists $schema->{"contentSchema"}
exists $schema->{"contentEncoding"} exists $schema->{"contentMediaType"} exists $schema->{"contentSchema"}
Truth table50%2/4
A or B or C
A= exists $schema->{"contentEncoding"}B= exists $schema->{"contentMediaType"}C= exists $schema->{"contentSchema"}
ABCresult
1XX1
01X1
0011
0000
4172 exists( $schema->{contentMediaType} ) ||
4173 exists( $schema->{contentSchema} ) )
4174 {
4175 9 ▶ my $assert = $ctx->{content_assert} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'content_assert'} ? : 6 3 9
4176 9 my $bytes = "$inst";
4177 9 my $decoded_ref;
4178  
4179 9 ▶ if( exists( $schema->{contentEncoding} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentEncoding"}) 9 0 9
4180 {
4181 9 my $dec = _content_decode( $ctx, $schema->{contentEncoding}, $bytes );
4182 9 ▶ if( !defined( $dec ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dec) { } 3 6 9
4183 {
4184 3 ▶ return( _err_res( $ctx, $ptr, "contentEncoding '$schema->{contentEncoding}' decode failed", 'contentEncoding' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 2 1 3
4185 }
4186 else
4187 {
4188 6 $bytes = $dec;
4189 }
4190 }
4191  
4192 7 ▶ if( exists( $schema->{contentMediaType} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentMediaType"}) 7 0 7
4193 {
4194 7 my( $mt, $params ) = _parse_media_type( $schema->{contentMediaType} );
4195 7 ▶ if( my $cb = $ctx->{media_validators}->{ $mt } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{'media_validators'}{$mt}) { } 5 2 7
4196 {
4197 5 my( $ok, $msg, $maybe_decoded ) = _safe_invoke( $cb, $bytes, $params );
4198 5 ▶ if( !$ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 3 5
4199 {
4200 2 ▶ return( _err_res( $ctx, $ptr, ( $msg || "contentMediaType '$mt' validation failed", 'contentMediaType' ) ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 1 1 2
Condition50%1/2
$msg || "contentMediaType '${mt}' validation failed"
l!l
10
MC/DC0%0/1
$msg || "contentMediaType '${mt}' validation failed"
$msg
Truth table50%1/2
A
A= $msg
Aresult
11
00
4201 }
4202 4 ▶ $decoded_ref = $maybe_decoded if( ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $maybe_decoded 2 2 4
4203 4 ▶ $bytes = $maybe_decoded if( defined( $maybe_decoded ) && !ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $maybe_decoded and not ref $maybe_decoded 1 3 4
Condition100%3/3
defined $maybe_decoded and not ref $maybe_decoded
!ll&&!rl&&r
121
MC/DC100%2/2
defined $maybe_decoded and not ref $maybe_decoded
defined $maybe_decoded not ref $maybe_decoded
Truth table100%3/3
A and not(B)
A= defined $maybe_decodedB= not ref $maybe_decoded
ABresult
0X0
100
111
4204 }
4205 else
4206 {
4207 2 ▶ if( $mt =~ m{\Atext/} && ( ( $params->{charset} || '' ) =~ /\Autf-?8\z/i ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu) 0 2 2
Condition20%1/5
$mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu
!ll&&!rl&&r
200
$params->{'charset'} || ''
l!l
00
MC/DC0%0/2
$mt =~ m[\Atext/]u and ($params->{"charset"} || "") =~ /\Autf-?8\z/iu
$mt =~ m[\Atext/]u $params->{'charset'}
Truth table33%1/3
A and B
A= $mt =~ m[\Atext/]uB= $params->{'charset'}
ABresult
0X0
100
111
4208 {
4209 0 local $@;
4210 my $ok = eval
4211 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; &Encode::decode('UTF-8', $bytes, 1); 1 } } ? : 0 0 0
4212 0 require Encode;
4213 0 Encode::decode( 'UTF-8', $bytes, Encode::FB_CROAK );
4214 0 1;
4215 } ? 1 : 0;
4216 0 ▶ if( !$ok && $assert )
Branch: 1 branch
BranchTrueFalseTotal
if (not $ok and $assert) 0 0 0
Condition0%0/3
not $ok and $assert
!ll&&!rl&&r
000
MC/DC0%0/2
not $ok and $assert
not $ok $assert
Truth table0%0/3
not(A) and B
A= not $okB= $assert
ABresult
0X0
100
111
4217 {
4218 0 return( _err_res( $ctx, $ptr, "contentMediaType '$mt' invalid UTF-8", 'contentMediaType' ) );
4219 }
4220 }
4221 }
4222 }
4223  
4224 6 ▶ if( exists( $schema->{contentSchema} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentSchema"}) 4 2 6
4225 {
4226 4 my $val;
4227 4 ▶ if( ref( $decoded_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decoded_ref) { } 2 2 4
4228 {
4229 2 $val = $decoded_ref; # already decoded by media validator
4230 }
4231 else
4232 {
4233 2 local $@;
4234 2 $val = eval{ JSON->new->allow_nonref(1)->utf8(1)->decode( $bytes ) };
4235 }
4236  
4237 4 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 1 3 4
4238 {
4239 1 ▶ return( _err_res( $ctx, $ptr, "contentSchema present but payload not JSON-decodable", 'contentSchema' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 0 1 1
4240 }
4241 else
4242 {
4243 3 my $r = _v( $ctx, _join_ptr( $ptr, 'contentSchema' ), $schema->{contentSchema}, $val );
4244 3 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 1 2 3
4245 }
4246 }
4247 }
4248 }
4249  
4250 553 my %ann_props;
4251 my %ann_items;
4252  
4253 # Arrays
4254 553 ▶ if( ref( $inst ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "ARRAY") 32 521 553
4255 {
4256 32 my $r = _k_array_all( $ctx, $schema_ptr, $schema, $inst );
4257 32 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 9 23 32
4258 23 %ann_items = ( %ann_items, %{ $r->{items} } );
4259 }
4260 544 ▶ _t( $ctx, $schema_ptr, 'array', undef, 'pass', '' ) if( ref( $inst ) eq 'ARRAY' && $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if ref $inst eq "ARRAY" and $ctx->{"trace_on"} 0 544 544
Condition66%2/3
ref $inst eq "ARRAY" and $ctx->{"trace_on"}
!ll&&!rl&&r
521230
MC/DC0%0/2
ref $inst eq "ARRAY" and $ctx->{"trace_on"}
ref $inst eq "ARRAY" $ctx->{"trace_on"}
Truth table66%2/3
A and B
A= ref $inst eq "ARRAY"B= $ctx->{"trace_on"}
ABresult
0X0
100
111
4261  
4262 # Objects
4263 544 ▶ if( ref( $inst ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "HASH") 270 274 544
4264 {
4265 270 my $r = _k_object_all( $ctx, $schema_ptr, $schema, $inst );
4266 270 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 113 157 270
4267 157 %ann_props = ( %ann_props, %{ $r->{props} } );
4268 }
4269 431 ▶ _t( $ctx, $schema_ptr, 'object', undef, 'pass', '' ) if( ref( $inst ) eq 'HASH' && $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if ref $inst eq "HASH" and $ctx->{"trace_on"} 0 431 431
Condition66%2/3
ref $inst eq "HASH" and $ctx->{"trace_on"}
!ll&&!rl&&r
2741570
MC/DC0%0/2
ref $inst eq "HASH" and $ctx->{"trace_on"}
ref $inst eq "HASH" $ctx->{"trace_on"}
Truth table66%2/3
A and B
A= ref $inst eq "HASH"B= $ctx->{"trace_on"}
ABresult
0X0
100
111
4270  
4271 # Combinators
4272 431 for my $comb ( qw( allOf anyOf oneOf not ) )
4273 {
4274 1706 ▶ next unless( exists( $schema->{ $comb } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $schema->{$comb} 1681 25 1706
4275 25 my $r = _k_combinator( $ctx, $schema_ptr, $schema, $inst, $comb );
4276 25 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 12 13 25
4277 13 %ann_props = ( %ann_props, %{ $r->{props} } );
4278 13 %ann_items = ( %ann_items, %{ $r->{items} } );
4279 13 ▶ _t( $ctx, $schema_ptr, $comb, undef, 'pass', '' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 13 13
4280 }
4281  
4282 # Conditionals
4283 419 ▶ if( exists( $schema->{if} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"if"}) 16 403 419
4284 {
4285 16 my $r = _k_if_then_else( $ctx, $schema_ptr, $schema, $inst );
4286 16 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 3 13 16
4287 13 %ann_props = ( %ann_props, %{ $r->{props} } );
4288 13 %ann_items = ( %ann_items, %{ $r->{items} } );
4289 }
4290  
4291 416 ▶ _t( $ctx, $schema_ptr, 'node', undef, 'pass' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 416 416
4292 416 return( { ok => 1, props => \%ann_props, items => \%ann_items } );
4293 }
4294  
4295 # NOTE: JSON::Schema::Validate::Error
4296 package JSON::Schema::Validate::Error;
4297 BEGIN
4298 44 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
4299 44 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4300 44 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4301 44 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
4302 44 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
4303 '""' => 'as_string',
4304 2 ▶ 'eq' => sub{ _obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4305 3 ▶ 'ne' => sub{ !_obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4306 1 ▶ '==' => sub{ _obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4307 0 ▶ '!=' => sub{ !_obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4308 5 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
4309 44 fallback => 1,
4310 44 );
4311 44 our $VERSION = 'v0.1.0';
4312 };
4313  
4314 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4315 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4316 44 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4317  
4318 sub new
4319 180 ▶{
Subroutine new: called CC=6 SCAR=18.6
4320 180 my $that = shift( @_ );
4321 180 my $ref = {};
4322 # Legacy instantiation
4323 # We make sure this is not one single option that was provided to us.
4324 180 ▶ if( @_ == 2 && $_[0] !~ /^(?:path|message|keyword|schema_pointer)$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_ == 2 and not $_[0] =~ /^(?:path|message|keyword|schema_pointer)$/u) { } 4 176 180
Condition66%2/3
@_ == 2 and not $_[0] =~ /^(?:path|message|keyword|schema_pointer)$/u
!ll&&!rl&&r
17604
MC/DC50%1/2
@_ == 2 and not $_[0] =~ /^(?:path|message|keyword|schema_pointer)$/u
@_ == 2 not $_[0] =~ /^(?:path|message|keyword|schema_pointer)$/u
Truth table66%2/3
A and not(B)
A= @_ == 2B= not $_[0] =~ /^(?:path|message|keyword|schema_pointer)$/u
ABresult
0X0
100
111
4325 {
4326 4 @$ref{qw( path message )} = @_;
4327 }
4328 else
4329 {
4330 176 my $args = { @_ };
4331 176 for( qw( path message keyword schema_pointer ) )
4332 {
4333 704 ▶ $ref->{ $_ } = $args->{ $_ } if( exists( $args->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$_} 704 0 704
4334 }
4335 }
4336 180 ▶ return( bless( $ref => ( ref( $that ) || $that ) ) );
Condition33%1/3
ref $that || $that
l!l&&r!l&&!r
01800
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table33%1/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
4337 }
4338  
4339 sub as_hash
4340 0 ▶{
Subroutine as_hash: not called CC=1 SCAR=6.9
4341 0 my $self = shift( @_ );
4342 0 my $ref = {};
4343 0 my @keys = qw( keyword message path schema_pointer );
4344 0 @$ref{ @keys } = @$self{ @keys };
4345 0 return( $ref );
4346 }
4347  
4348 sub as_string
4349 9 ▶{
Subroutine as_string: called CC=5 SCAR=16.3
4350 9 my $self = shift( @_ );
4351 9 ▶ my $sp = $self->schema_pointer // '';
Condition100%2/2
$self->schema_pointer // ""
l!l
81
MC/DC100%1/1
$self->schema_pointer // ""
$self->schema_pointer
Truth table100%2/2
A
A= $self->schema_pointer
Aresult
11
00
4352 9 ▶ my $path = $self->path // '';
Condition50%1/2
$self->path // ""
l!l
90
MC/DC0%0/1
$self->path // ""
$self->path
Truth table50%1/2
A
A= $self->path
Aresult
11
00
4353 9 ▶ my $msg = $self->message // '';
Condition50%1/2
$self->message // ""
l!l
90
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->message
Aresult
11
00
4354 # Dual-path if avail
4355 9 ▶ return( $sp ? "${sp} → ${path}: ${msg}" : "${path}: ${msg}" );
Branch: 1 branch
BranchTrueFalseTotal
$sp ? : 8 1 9
4356 }
4357  
4358 sub keyword
4359 8 ▶{
Subroutine keyword: called CC=2 SCAR=7.1
4360 8 my $self = shift( @_ );
4361 8 ▶ $self->{keyword} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
4362 8 return( $self->{keyword} );
4363 }
4364  
4365 sub message
4366 29 ▶{
Subroutine message: called CC=2 SCAR=7.1
4367 29 my $self = shift( @_ );
4368 29 ▶ $self->{message} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 29 29
4369 29 return( $self->{message} );
4370 }
4371  
4372 sub path
4373 17 ▶{
Subroutine path: called CC=2 SCAR=7.1
4374 17 my $self = shift( @_ );
4375 17 ▶ $self->{path} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 17 17
4376 17 return( $self->{path} );
4377 }
4378  
4379 sub schema_pointer
4380 10 ▶{
Subroutine schema_pointer: called CC=2 SCAR=7.1
4381 10 my $self = shift( @_ );
4382 10 ▶ $self->{schema_pointer} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 10 10
4383 10 return( $self->{schema_pointer} );
4384 }
4385  
4386 sub _obj_eq
4387 6 ▶{
Subroutine _obj_eq: called CC=12 SCAR=26.3
4388 44 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
4389 6 my $self = shift( @_ );
4390 6 my $other = shift( @_ );
4391 6 my $me;
4392 6 ▶ if( defined( $other ) &&
Branch: 2 branches
BranchTrueFalseTotal
if (defined $other and builtin::blessed($other) and $other->isa('JSON::Schema::Validate::Error')) { } 4 2 6
elsif (not ref $other) { } 2 0 2
Condition66%4/6
defined $other and builtin::blessed($other) and $other->isa("JSON::Schema::Validate::Error")
!ll&&!rl&&r
204
defined $other and builtin::blessed($other)
!ll&&!rl&&r
024
MC/DC33%1/3
defined $other and builtin::blessed($other) and $other->isa("JSON::Schema::Validate::Error")
defined $other builtin::blessed($other) $other->isa("JSON::Schema::Validate::Error")
Truth table50%2/4
A and B and C
A= defined $otherB= builtin::blessed($other)C= $other->isa("JSON::Schema::Validate::Error")
ABCresult
0XX0
10X0
1100
1111
4393 Scalar::Util::blessed( $other ) &&
4394 $other->isa( 'JSON::Schema::Validate::Error' ) )
4395 {
4396 4 ▶ if( ( $self->message // '' ) eq ( $other->message // '' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (($self->message // '') eq ($other->message // '') and ($self->path // '') eq ($other->path // '')) { } 2 2 4
Condition63%7/11
($self->message // "") eq ($other->message // "") and ($self->path // "") eq ($other->path // "")
!ll&&!rl&&r
112
$self->message // ""
l!l
40
$other->message // ""
l!l
40
$self->path // ""
l!l
30
$other->path // ""
l!l
30
MC/DC0%0/2
($self->message // "") eq ($other->message // "") and ($self->path // "") eq ($other->path // "")
$self->message $self->path
MC/DC0%0/1
$other->message // ""
$other->message
MC/DC0%0/1
$other->path // ""
$other->path
Truth table33%1/3
A and B
A= $self->messageB= $self->path
ABresult
0X0
100
111
Truth table50%1/2
A
A= $other->message
Aresult
11
00
Truth table50%1/2
A
A= $other->path
Aresult
11
00
4397 ( $self->path // '' ) eq ( $other->path // '' ) )
4398 {
4399 2 return(1);
4400 }
4401 else
4402 {
4403 2 return(0);
4404 }
4405 }
4406 # Compare error message
4407 elsif( !ref( $other ) )
4408 {
4409 2 ▶ my $me = $self->message // '';
Condition50%1/2
$self->message // ""
l!l
20
MC/DC0%0/1
$self->message // ""
$self->message
Truth table50%1/2
A
A= $self->message
Aresult
11
00
4410 2 return( $me eq $other );
4411 }
4412 # Otherwise some reference data to which we cannot compare
4413 0 return(0) ;
4414 }
4415  
4416 44 1;
4417 # NOTE: POD
4418 __END__
↑ Summary