lib/JSON/Schema/Validate.pm

filter: Statementstmt 64.2% 1169 / 1821 Branchbran 54.4% 691 / 1270 Conditioncond 36.8% 237 / 643 MC/DCmcdc 15.4% 57 / 369 Subroutinesub 85.6% 119 / 139 Podpod 100% 30 / 30 totaltotal 53.9% 2303 / 4272 CC 933 SCAR 77.2
CC
933
Cov
56%
_compile_js_node
16770.0
__ANON__
2563.1
_compile_node
482.3
CRAP 2255.9
↑ Summary blib/lib/JSON/Schema/Validate.pm »
1 ##----------------------------------------------------------------------------
2 ## JSON Schema Validator - ~/lib/JSON/Schema/Validate.pm
3 ## Version v0.9.0
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2025/11/07
7 ## Modified 2026/03/01
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 {
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.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
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 {
35 121 ▶ my $class = shift( @_ );
Subroutine new: called CC=26 SCAR=34.1
Pod documented
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 {
150 1 ▶ my( $self, $bool ) = @_;
Subroutine compile: called CC=4 SCAR=15.0
Pod documented
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 {
163 0 ▶ my $self = shift( @_ );
Subroutine compile_js: not called CC=7 SCAR=40.3
Pod documented
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 {
270 3 ▶ my( $self, $bool ) = @_;
Subroutine content_checks: called CC=4 SCAR=14.6
Pod documented
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 {
290 1 ▶ my( $self, $bool ) = @_;
Subroutine extensions: called CC=2 SCAR=7.0
Pod documented
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 {
299 3 ▶ my( $self ) = @_;
Subroutine get_trace: called CC=2 SCAR=7.1
Pod documented
300 3 ▶ return( [@{ $self->{last_trace} || [] }] );
Branch: 1 branch
BranchTrueFalseTotal
$self->{"last_trace"} or [] 0 3 3
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 {
311 0 ▶ my( $self, $bool ) = @_;
Subroutine ignore_unknown_required_vocab: not called CC=2 SCAR=17.9
Pod documented
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 {
330 2 ▶ my $self = shift( @_ );
Subroutine is_valid: called CC=3 SCAR=11.0
Pod documented
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 {
346 5 ▶ my( $self, $data ) = @_;
Subroutine prune_instance: called CC=2 SCAR=7.0
Pod documented
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 {
360 0 ▶ my( $self, $bool ) = @_;
Subroutine prune_unknown: not called CC=3 SCAR=24.8
Pod documented
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 {
368 47 ▶ my( $self ) = @_;
Subroutine register_builtin_formats: called CC=7 SCAR=23.4
Pod documented
369  
370 47 local $@;
371 47 ▶ 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 47 ▶ my $has_dt = eval{ require DateTime; 1 } ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require DateTime; 1 } } ? : 0 47 47
374 47 ▶ 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 {
383 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=11 SCAR=34.5
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 {
435 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=8 SCAR=27.7
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 {
458 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=7 SCAR=26.5
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 {
480 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=11 SCAR=32.1
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 {
507 13 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.9
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 {
515 1 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=10 SCAR=34.5
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 {
544 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=8 SCAR=23.4
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 {
557 1 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=12 SCAR=37.0
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 {
580 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.9
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 {
592 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.9
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 {
617 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.9
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 {
624 1 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=16.1
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 {
631 1 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=16.1
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 {
642 3 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.9
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 {
650 3 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.7
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 {
658 3 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=5 SCAR=16.7
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 {
667 2 ▶ my( $s ) = @_;
Subroutine __ANON__: called CC=4 SCAR=14.3
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 {
683 1 ▶ my( $self, $name, $cb ) = @_;
Subroutine register_content_decoder: called CC=2 SCAR=7.4
Pod documented
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 {
697 0 ▶ my( $self, $name, $code ) = @_;
Subroutine register_format: not called CC=4 SCAR=30.0
Pod documented
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 {
706 5 ▶ my( $self, $type, $cb ) = @_;
Subroutine register_media_validator: called CC=2 SCAR=7.4
Pod documented
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 {
720 4 ▶ my( $self, $code ) = @_;
Subroutine set_comment_handler: called CC=5 SCAR=16.2
Pod documented
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 {
735 2 ▶ my( $self, $code ) = @_;
Subroutine set_resolver: called CC=5 SCAR=20.9
Pod documented
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 {
750 0 ▶ my( $self, $h ) = @_;
Subroutine set_vocabulary_support: not called CC=2 SCAR=17.9
Pod documented
751 0 ▶ $self->{vocab_support} = { %{ $h || {} } };
Branch: 1 branch
BranchTrueFalseTotal
$h or {} 0 0 0
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 {
764 1 ▶ my( $self, $bool ) = @_;
Subroutine trace: called CC=2 SCAR=7.0
Pod documented
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 {
772 0 ▶ my( $self, $n ) = @_;
Subroutine trace_limit: not called CC=2 SCAR=17.9
Pod documented
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 {
779 0 ▶ my( $self, $pct ) = @_;
Subroutine trace_sample: not called CC=2 SCAR=17.9
Pod documented
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 {
786 9 ▶ my( $self, $bool ) = @_;
Subroutine unique_keys: called CC=2 SCAR=7.0
Pod documented
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 {
794 218 ▶ my $self = shift( @_ );
Subroutine validate: called CC=30 SCAR=46.1
Pod documented
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 {
905 5 ▶ my( $ctx, $schema_ptr, $ref, $inst ) = @_;
Subroutine _apply_dynamic_ref: called CC=4 SCAR=14.5
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 {
927 22 ▶ my( $ctx, $schema_ptr, $ref, $inst ) = @_;
Subroutine _apply_ref: called CC=21 SCAR=40.4
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") 0 9 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 {
1035 86 ▶ my( $v ) = @_;
Subroutine _canon: called CC=1 SCAR=0.0
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 {
1042 120 ▶ my( $self ) = @_;
Subroutine _check_vocabulary_required: called CC=8 SCAR=21.2
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 {
1064 344 ▶ my( $v ) = @_;
Subroutine _clone: called CC=1 SCAR=0.0
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 {
1071 0 ▶ my $self = shift( @_ );
Subroutine _compile_js_node: not called CC=129 SCAR=97.3
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 + '/allOf/$i', 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 + '/anyOf/$i', 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 + '/oneOf/$i', 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 + '/not', 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 + '/if', 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 + '/then', 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 + '/else', 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 {
2085 38 ▶ my( $root, $ptr, $S ) = @_;
Subroutine _compile_node: called CC=38 SCAR=61.8
2086  
2087 # Non-hash schemas (incl. booleans) => trivial pass
2088 return sub
2089 {
2090 0 ▶ my( $ctx, $inst ) = @_;
Subroutine __ANON__: not called CC=1 SCAR=6.9
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 # Capture presence and values so runtime avoids hash lookups
2095 38 my $has_type = exists( $S->{type} );
2096 38 my $type_spec = $S->{type};
2097  
2098 38 my $has_const = exists( $S->{const} );
2099 38 my $const_val = $S->{const};
2100  
2101 38 my $has_enum = exists( $S->{enum} );
2102 38 my $enum_vals = $S->{enum};
2103  
2104 38 my %numk = map{ $_ => $S->{ $_ } } grep{ exists( $S->{ $_ } ) }
2105 qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum );
2106  
2107 38 ▶ 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 36 38
Condition66%4/6
exists $S->{"minLength"} or exists $S->{"maxLength"} or exists $S->{"pattern"}
l!l&&r!l&&!r
2036
exists $S->{"minLength"} or exists $S->{"maxLength"}
l!l&&r!l&&!r
2036
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
2108 38 my $has_format = exists( $S->{format} );
2109 38 my $format_name = $S->{format};
2110  
2111 my $has_unique_keys =
2112 exists( $S->{uniqueKeys} ) &&
2113 38 ▶ ref( $S->{uniqueKeys} ) eq 'ARRAY';
Condition33%1/3
exists $S->{'uniqueKeys'} && ref $S->{'uniqueKeys'} eq 'ARRAY'
!ll&&!rl&&r
3800
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
2114  
2115 # Precompile child closures (same structure our interpreter walks)
2116 38 my %child;
2117  
2118 # Arrays
2119 38 ▶ if( ref( $S->{prefixItems} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"prefixItems"} eq "ARRAY") 0 38 38
2120 {
2121 0 for my $i ( 0 .. $#{ $S->{prefixItems} } )
2122 {
2123 0 my $cp = _join_ptr( $ptr, "prefixItems/$i" );
2124 0 $child{ "prefix:$i" } = _compile_node( $root, $cp, $S->{prefixItems}->[$i] );
2125 }
2126 }
2127 38 ▶ if( ref( $S->{items} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"items"} eq "HASH") 0 38 38
2128 {
2129 0 $child{ "items" } = _compile_node( $root, _join_ptr( $ptr, "items" ), $S->{items} );
2130 }
2131 38 ▶ if( exists( $S->{contains} ) && ref( $S->{contains} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contains"} and ref $S->{"contains"}) 0 38 38
Condition33%1/3
exists $S->{"contains"} and ref $S->{"contains"}
!ll&&!rl&&r
3800
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
2132 {
2133 0 $child{ "contains" } = _compile_node( $root, _join_ptr( $ptr, "contains" ), $S->{contains} );
2134 }
2135 38 ▶ if( exists( $S->{unevaluatedItems} ) && ref( $S->{unevaluatedItems} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedItems"} and ref $S->{"unevaluatedItems"} eq "HASH") 0 38 38
Condition33%1/3
exists $S->{"unevaluatedItems"} and ref $S->{"unevaluatedItems"} eq "HASH"
!ll&&!rl&&r
3800
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
2136 {
2137 0 $child{ "unevaluatedItems" } = _compile_node( $root, _join_ptr( $ptr, "unevaluatedItems" ), $S->{unevaluatedItems} );
2138 }
2139  
2140 # Objects
2141 38 ▶ if( ref( $S->{properties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"properties"} eq "HASH") 11 27 38
2142 {
2143 11 for my $k ( keys( %{$S->{properties}} ) )
2144 {
2145 15 my $cp = _join_ptr( $ptr, "properties/$k" );
2146 15 $child{ "prop:$k" } = _compile_node( $root, $cp, $S->{properties}->{ $k } );
2147 }
2148 }
2149 38 ▶ if( ref( $S->{patternProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{"patternProperties"} eq "HASH") 0 38 38
2150 {
2151 0 for my $re ( keys( %{ $S->{patternProperties} } ) )
2152 {
2153 0 my $cp = _join_ptr( $ptr, "patternProperties/$re" );
2154 0 $child{ "pat:$re" } = _compile_node( $root, $cp, $S->{patternProperties}->{ $re } );
2155 }
2156 }
2157 38 ▶ if( exists( $S->{additionalProperties} ) && ref( $S->{additionalProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"additionalProperties"} and ref $S->{"additionalProperties"} eq "HASH") 0 38 38
Condition66%2/3
exists $S->{"additionalProperties"} and ref $S->{"additionalProperties"} eq "HASH"
!ll&&!rl&&r
28100
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
2158 {
2159 0 $child{ "additional" } = _compile_node( $root, _join_ptr( $ptr, "additionalProperties" ), $S->{additionalProperties} );
2160 }
2161 38 ▶ if( exists( $S->{propertyNames} ) && ref( $S->{propertyNames} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH") 0 38 38
Condition33%1/3
exists $S->{"propertyNames"} and ref $S->{"propertyNames"} eq "HASH"
!ll&&!rl&&r
3800
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
2162 {
2163 0 $child{ "propnames" } = _compile_node( $root, _join_ptr( $ptr, "propertyNames" ), $S->{propertyNames} );
2164 }
2165 38 ▶ if( exists( $S->{dependentSchemas} ) && ref( $S->{dependentSchemas} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"dependentSchemas"} and ref $S->{"dependentSchemas"} eq "HASH") 0 38 38
Condition33%1/3
exists $S->{"dependentSchemas"} and ref $S->{"dependentSchemas"} eq "HASH"
!ll&&!rl&&r
3800
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
2166 {
2167 0 for my $k ( keys( %{$S->{dependentSchemas}} ) )
2168 {
2169 0 my $cp = _join_ptr( $ptr, "dependentSchemas/$k" );
2170 0 $child{ "deps:$k" } = _compile_node( $root, $cp, $S->{dependentSchemas}->{ $k } );
2171 }
2172 }
2173 38 ▶ if( exists( $S->{unevaluatedProperties} ) && ref( $S->{unevaluatedProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedProperties"} and ref $S->{"unevaluatedProperties"} eq "HASH") 0 38 38
Condition33%1/3
exists $S->{"unevaluatedProperties"} and ref $S->{"unevaluatedProperties"} eq "HASH"
!ll&&!rl&&r
3800
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
2174 {
2175 0 $child{ "ueprops" } = _compile_node( $root, _join_ptr( $ptr, "unevaluatedProperties" ), $S->{unevaluatedProperties} );
2176 }
2177  
2178 # Combinators
2179 38 for my $kw ( qw( allOf anyOf oneOf not ) )
2180 {
2181 152 ▶ next unless( exists( $S->{ $kw } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{$kw} 152 0 152
2182 0 ▶ if( $kw eq 'not' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "not") 0 0 0
2183 {
2184 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
2185 0 next;
2186 }
2187 0 ▶ if( ref( $S->{ $kw } ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $S->{$kw} eq "ARRAY") 0 0 0
2188 {
2189 0 for my $i ( 0 .. $#{$S->{ $kw }} )
2190 {
2191 0 my $cp = _join_ptr( $ptr, "$kw/$i" );
2192 0 $child{ "$kw:$i" } = _compile_node( $root, $cp, $S->{ $kw }->[$i] );
2193 }
2194 }
2195 }
2196  
2197 # Conditionals
2198 38 ▶ if( exists( $S->{if} ) && ref( $S->{if} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"if"} and ref $S->{"if"} eq "HASH") 0 38 38
Condition33%1/3
exists $S->{"if"} and ref $S->{"if"} eq "HASH"
!ll&&!rl&&r
3800
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
2199 {
2200 0 $child{ "if" } = _compile_node( $root, _join_ptr( $ptr, 'if' ), $S->{if} );
2201 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
2202 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
2203 }
2204  
2205 # Return specialized validator
2206 return sub
2207 {
2208 35 ▶ my( $ctx, $inst ) = @_;
Subroutine __ANON__: called CC=79 SCAR=78.5
2209  
2210 # Parity with interpreter: trace node visit
2211 35 ▶ _t( $ctx, $ptr, 'node', undef, 'visit' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 12 23 35
2212  
2213 # Type / const / enum
2214 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() 0 35 35
2215 35 ▶ 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
2216 35 ▶ 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
2217  
2218 # uniqueKeys extension (compiled path)
2219 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
2220 {
2221 0 my $r = _k_unique_keys( $ctx, $ptr, $S->{uniqueKeys}, $inst );
2222 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2223 }
2224  
2225 # Numbers
2226 35 ▶ if( _is_number( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (_is_number($inst)) 6 29 35
2227 {
2228 6 for my $k ( qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum ) )
2229 {
2230 27 ▶ next unless( exists( $numk{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $numk{$k} 25 2 27
2231 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
2232 }
2233 }
2234  
2235 # Strings
2236 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
2237 {
2238 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
2239 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
2240  
2241 # contentEncoding / contentMediaType / contentSchema (compiled path)
2242 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
2243 exists( $S->{contentMediaType} ) ||
2244 exists( $S->{contentSchema} ) )
2245 {
2246 0 ▶ my $assert = $ctx->{content_assert} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'content_assert'} ? : 0 0 0
2247 0 my $bytes = "$inst";
2248 0 my $decoded_ref;
2249  
2250 0 ▶ if( exists( $S->{contentEncoding} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentEncoding"}) 0 0 0
2251 {
2252 0 my $dec = _content_decode( $ctx, $S->{contentEncoding}, $bytes );
2253 0 ▶ if( !defined( $dec ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dec) { } 0 0 0
2254 {
2255 0 ▶ return( _err_res( $ctx, $ptr, "contentEncoding '$S->{contentEncoding}' decode failed", 'contentEncoding' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 0 0 0
2256 }
2257 else
2258 {
2259 0 $bytes = $dec;
2260 }
2261 }
2262  
2263 0 ▶ if( exists( $S->{contentMediaType} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentMediaType"}) 0 0 0
2264 {
2265 0 my( $mt, $params ) = _parse_media_type( $S->{contentMediaType} );
2266 0 ▶ if( my $cb = $ctx->{media_validators}->{ $mt } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{'media_validators'}{$mt}) { } 0 0 0
2267 {
2268 0 my( $ok, $msg, $maybe_decoded ) = _safe_invoke( $cb, $bytes, $params );
2269 0 ▶ if( !$ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2270 {
2271 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
2272 }
2273 # If the media validator decoded into a Perl structure, keep it
2274 0 ▶ $decoded_ref = $maybe_decoded if( ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $maybe_decoded 0 0 0
2275 # If it produced new octets/text, keep that too
2276 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
2277 }
2278 else
2279 {
2280 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
2281 {
2282 0 local $@;
2283 my $ok = eval
2284 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; &Encode::decode('UTF-8', $bytes, 1); 1 } } ? : 0 0 0
2285 0 require Encode;
2286 0 Encode::decode( 'UTF-8', $bytes, Encode::FB_CROAK );
2287 0 1;
2288 } ? 1 : 0;
2289 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
2290 {
2291 0 return( _err_res( $ctx, $ptr, "contentMediaType '$mt' invalid UTF-8", 'contentMediaType' ) );
2292 }
2293 }
2294 }
2295 }
2296  
2297 0 ▶ if( exists( $S->{contentSchema} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contentSchema"}) 0 0 0
2298 {
2299 0 my $val;
2300  
2301 0 ▶ if( ref( $decoded_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decoded_ref) { } 0 0 0
2302 {
2303 # already decoded by media validator (e.g. application/json)
2304 0 $val = $decoded_ref;
2305 }
2306 else
2307 {
2308 0 local $@;
2309 # still a string of bytes; try JSON decode now
2310 0 $val = eval{ JSON->new->allow_nonref(1)->utf8(1)->decode( $bytes ) };
2311 }
2312  
2313 0 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 0 0 0
2314 {
2315 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
2316 }
2317 else
2318 {
2319 0 my $r = _v( $ctx, _join_ptr( $ptr, 'contentSchema' ), $S->{contentSchema}, $val );
2320 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2321 }
2322 }
2323 }
2324 }
2325  
2326 32 my %ann_props;
2327 my %ann_items;
2328  
2329 # Arrays
2330 32 ▶ if( ref( $inst ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "ARRAY") 0 32 32
2331 {
2332 0 my $r = _k_array_all( $ctx, $ptr, $S, $inst );
2333 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2334 0 %ann_items = ( %ann_items, %{$r->{items}} );
2335 }
2336  
2337 # Objects
2338 32 ▶ if( ref( $inst ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "HASH") 17 15 32
2339 {
2340 17 my $r = _k_object_all( $ctx, $ptr, $S, $inst );
2341 17 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 7 10 17
2342 10 %ann_props = ( %ann_props, %{$r->{props}} );
2343 }
2344  
2345 # Combinators
2346 # allOf: all subschemas must pass, and we merge their annotations.
2347 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
2348 {
2349 0 my( %p, %it );
2350 0 for my $i ( 0 .. $#{ $S->{allOf} } )
2351 {
2352 0 my $r = $child{ "allOf:$i" }->( $ctx, $inst );
2353 0 ▶ return $r unless $r->{ok};
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2354 0 %p = ( %p, %{$r->{props}} );
2355 0 %it = ( %it, %{$r->{items}} );
2356 }
2357 0 %ann_props = ( %ann_props, %p );
2358 0 %ann_items = ( %ann_items, %it );
2359 }
2360  
2361 # anyOf: at least one subschema must pass; do NOT leak errors from
2362 # non-selected branches into the main context.
2363 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
2364 {
2365 0 my $ok = 0;
2366 0 my( %p, %it );
2367 0 my @branch_errs;
2368  
2369 0 for my $i ( 0 .. $#{ $S->{anyOf} } )
2370 {
2371 # Shadow context for this branch
2372 0 my %shadow = %$ctx;
2373 0 my @errs;
2374 0 $shadow{errors} = \@errs;
2375 0 $shadow{error_count} = 0;
2376  
2377 0 my $r = $child{ "anyOf:$i" }->( \%shadow, $inst );
2378  
2379 0 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"ok"}) 0 0 0
2380 {
2381 0 $ok = 1;
2382 0 %p = ( %p, %{$r->{props}} );
2383 0 %it = ( %it, %{$r->{items}} );
2384 0 last;
2385 }
2386  
2387 0 push( @branch_errs, \@errs );
2388 }
2389  
2390 0 ▶ unless( $ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 0 0 0
2391 {
2392 # No branch matched: merge collected branch errors into main context
2393 0 for my $aref ( @branch_errs )
2394 {
2395 0 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 0 0
2396 0 push( @{$ctx->{errors}}, @$aref );
2397 0 $ctx->{error_count} += scalar( @$aref );
2398 }
2399  
2400 0 return( _err_res( $ctx, $ptr, "instance does not satisfy anyOf", 'anyOf' ) );
2401 }
2402  
2403 0 %ann_props = ( %ann_props, %p );
2404 0 %ann_items = ( %ann_items, %it );
2405 }
2406  
2407 # oneOf: exactly one subschema must pass; again, isolate branch errors.
2408 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
2409 {
2410 0 my $hits = 0;
2411  
2412 0 for my $i ( 0 .. $#{ $S->{oneOf} } )
2413 {
2414 0 my %shadow = %$ctx;
2415 0 my @errs;
2416 0 $shadow{errors} = \@errs;
2417 0 $shadow{error_count} = 0;
2418  
2419 0 my $r = $child{ "oneOf:$i" }->( \%shadow, $inst );
2420 0 ▶ $hits++ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 0 0 0
2421 }
2422  
2423 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
2424 unless( $hits == 1 );
2425 }
2426  
2427 # not: the inner schema must **fail**; its own errors are irrelevant
2428 # on success, so we run it entirely in a shadow context.
2429 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
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{ "not" }->( \%shadow, $inst );
2437  
2438 # If inner schema passes, then "not" fails
2439 return( _err_res( $ctx, $ptr, "instance matches forbidden not-schema", 'not' ) )
2440 0 ▶ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 0 0 0
2441  
2442 # Otherwise, "not" is satisfied; ignore inner errors entirely
2443 }
2444  
2445 # Conditionals
2446 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
2447 {
2448 0 my $cond = $child{ "if" }->( $ctx, $inst );
2449 0 ▶ if( $cond->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cond->{'ok'}) { } 0 0 0
2450 {
2451 0 ▶ if( exists( $child{ "then" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $child{"then"}) 0 0 0
2452 {
2453 0 my $r = $child{ "then" }->( $ctx, $inst );
2454 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2455 }
2456 }
2457 else
2458 {
2459 0 ▶ if( exists( $child{ "else" } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $child{"else"}) 0 0 0
2460 {
2461 0 my $r = $child{ "else" }->( $ctx, $inst );
2462 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2463 }
2464 }
2465 }
2466  
2467 25 ▶ _t( $ctx, $ptr, 'node', undef, 'pass' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 8 17 25
2468 25 return( { ok => 1, props => \%ann_props, items => \%ann_items } );
2469 38 };
2470 }
2471  
2472 # Compilation / Indexing
2473 sub _compile_root
2474 {
2475 114 ▶ my( $schema ) = @_;
Subroutine _compile_root: called CC=6 SCAR=18.4
2476  
2477 114 ▶ if( ref( $schema ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema eq "HASH") 114 0 114
2478 {
2479 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
2480 }
2481  
2482 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
2483  
2484 114 my $anchors = {};
2485 114 my $id_index = {};
2486  
2487 114 _index_schema_202012( $schema, $base, '#', $anchors, $id_index );
2488  
2489 return({
2490 114 schema => $schema,
2491 anchors => $anchors, # "#/a/b/0"
2492 id_index => $id_index, # absolute IDs and #anchors
2493 base => $base,
2494 fn_index => {}, # cache of ptr => compiled closure
2495 });
2496 }
2497  
2498 sub _content_decode
2499 {
2500 9 ▶ my( $ctx, $enc, $s ) = @_;
Subroutine _content_decode: called CC=5 SCAR=16.7
2501 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
2502  
2503 9 ▶ if( my $cb = $ctx->{content_decoders}->{ $enc } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{"content_decoders"}{$enc}) 3 6 9
2504 {
2505 3 my( $ok, $msg, $out ) = _safe_invoke( $cb, $s );
2506 3 ▶ return( $ok ? $out : undef );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 3 0 3
2507 }
2508  
2509 6 ▶ if( $enc eq 'base64' )
Branch: 1 branch
BranchTrueFalseTotal
if ($enc eq "base64") 6 0 6
2510 {
2511 6 my $out = _strict_base64_decode( $s );
2512 # undef on failure is exactly what we want
2513 6 return( $out );
2514 }
2515  
2516 # Unknown encoding (annotation only unless assert)
2517 0 return;
2518 }
2519  
2520 # Errors, utils, pointers, URIs
2521 sub _err
2522 {
2523 176 ▶ my( $ctx, $schema_ptr, $msg, $keyword ) = @_;
Subroutine _err: called CC=5 SCAR=17.3
2524 176 ▶ return(0) if( $ctx->{error_count} >= $ctx->{max_errors} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"error_count"} >= $ctx->{"max_errors"} 0 176 176
2525  
2526 # Instance path: use current ptr_stack top if available, else '#'
2527 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
2528 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
2529 : '#';
2530  
2531 176 push( @{$ctx->{errors}}, JSON::Schema::Validate::Error->new(
2532 path => $inst_path,
2533 message => $msg,
2534 keyword => $keyword, # may be undef (back-compat)
2535 schema_pointer => $schema_ptr, # where in the schema this came from
2536 ));
2537 176 $ctx->{error_count}++;
2538 176 return(0);
2539 }
2540  
2541 sub _err_res
2542 {
2543 85 ▶ my( $ctx, $schema_ptr, $msg, $keyword ) = @_;
Subroutine _err_res: called CC=1 SCAR=0.0
2544 85 _err( $ctx, $schema_ptr, $msg, $keyword );
2545 85 return( { ok => 0, props => {}, items => {} } );
2546 }
2547  
2548 # Used by _prune* methods
2549 sub _extract_array_shape
2550 {
2551 1 ▶ my( $self, $schema, $out ) = @_;
Subroutine _extract_array_shape: called CC=10 SCAR=28.2
2552  
2553 1 ▶ return unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 1 1
2554  
2555 1 ▶ if( ref( $schema->{prefixItems} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"prefixItems"} eq "ARRAY") 1 0 1
2556 {
2557 1 my $src = $schema->{prefixItems};
2558 1 for my $i ( 0 .. $#$src )
2559 {
2560 # First win: do not override an existing prefix schema at this index
2561 $out->{prefix_items}->[ $i ] = $src->[ $i ]
2562 1 ▶ unless( defined( $out->{prefix_items}->[ $i ] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $out->{"prefix_items"}[$i] 1 0 1
2563 }
2564 }
2565  
2566 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
2567 {
2568 # Again, first win: if we already have items from another branch, keep it.
2569 1 ▶ $out->{items} = $schema->{items} unless( $out->{items} );
Branch: 1 branch
BranchTrueFalseTotal
unless $out->{"items"} 1 0 1
2570 }
2571  
2572 # allOf mixins for arrays as well
2573 1 ▶ if( ref( $schema->{allOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"allOf"} eq "ARRAY") 0 1 1
2574 {
2575 0 foreach my $sub ( @{$schema->{allOf}} )
2576 {
2577 0 $self->_extract_array_shape( $sub, $out );
2578 }
2579 }
2580  
2581 # anyOf / oneOf / not ignored for same reason as objects.
2582 }
2583  
2584 # Used by _prune* methods
2585 sub _extract_object_shape
2586 {
2587 8 ▶ my( $self, $schema, $out ) = @_;
Subroutine _extract_object_shape: called CC=17 SCAR=31.1
2588  
2589 8 ▶ return unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 8 8
2590  
2591 # Direct properties
2592 8 ▶ if( ref( $schema->{properties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"properties"} eq "HASH") 6 2 8
2593 {
2594 6 foreach my $k ( keys( %{$schema->{properties}} ) )
2595 {
2596 # First win: do not override an already-collected subschema
2597 $out->{props}->{ $k } = $schema->{properties}->{ $k }
2598 7 ▶ unless( exists( $out->{props}->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $out->{"props"}{$k} 7 0 7
2599 }
2600 }
2601  
2602 # patternProperties
2603 8 ▶ if( ref( $schema->{patternProperties} ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"patternProperties"} eq "HASH") 1 7 8
2604 {
2605 1 foreach my $re ( keys( %{$schema->{patternProperties}} ) )
2606 {
2607 1 push( @{$out->{patterns}}, [ $re, $schema->{patternProperties}->{ $re } ] );
2608 }
2609 }
2610  
2611 # additionalProperties
2612 8 ▶ if( exists( $schema->{additionalProperties} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"additionalProperties"}) 7 1 8
2613 {
2614 7 my $ap = $schema->{additionalProperties};
2615  
2616 # JSON booleans or plain scalars
2617 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
2618 {
2619 7 ▶ if( $ap )
Branch: 1 branch
BranchTrueFalseTotal
if ($ap) { } 1 6 7
2620 {
2621 # true: additionalProperties allowed; keep any stricter setting we might already have
2622 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
2623 # do not touch ap_schema here
2624 }
2625 else
2626 {
2627 # false: forbidden regardless of earlier "true"
2628 6 $out->{allow_ap} = 0;
2629 6 $out->{ap_schema} = undef;
2630 }
2631 }
2632 elsif( ref( $ap ) eq 'HASH' )
2633 {
2634 # Schema for additionals
2635 0 $out->{allow_ap} = 1;
2636 0 $out->{ap_schema} = $ap;
2637 }
2638 }
2639  
2640 # allOf mixins: merge their object keywords as well.
2641 8 ▶ if( ref( $schema->{allOf} ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $schema->{"allOf"} eq "ARRAY") 1 7 8
2642 {
2643 1 foreach my $sub ( @{$schema->{allOf}} )
2644 {
2645 2 $self->_extract_object_shape( $sub, $out );
2646 }
2647 }
2648  
2649 # NOTE:
2650 # We intentionally ignore anyOf / oneOf / not for pruning.
2651 # Without performing full validation against each branch, we cannot
2652 # safely decide which properties are truly forbidden, so we err on
2653 # the side of *keeping* more rather than over-pruning.
2654 }
2655  
2656 91 ▶sub _fail { return( { ok => 0, props => {}, items => {} } ); }
Subroutine _fail: called CC=1 SCAR=0.0
2657  
2658 sub _first_error_text
2659 {
2660 0 ▶ my( $errs ) = @_;
Subroutine _first_error_text: not called CC=2 SCAR=17.9
2661 0 ▶ return( '' ) unless( @$errs );
Branch: 1 branch
BranchTrueFalseTotal
unless @$errs 0 0 0
2662 0 my $e = $errs->[0];
2663 0 return( "$e" );
2664 }
2665  
2666 sub _get_args_as_hash
2667 {
2668 341 ▶ my $self = shift( @_ );
Subroutine _get_args_as_hash: called CC=7 SCAR=20.2
2669 341 ▶ return( {} ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 320 21 341
2670 21 my $ref = {};
2671 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
2672 defined( $_[0] ) &&
2673 ( ref( $_[0] ) || '' ) eq 'HASH' )
2674 {
2675 2 $ref = shift( @_ );
2676 }
2677 elsif( !( scalar( @_ ) % 2 ) )
2678 {
2679 19 $ref = { @_ };
2680 }
2681 else
2682 {
2683 0 die( "Uneven number of parameters provided: '", join( "', '", map( overload::StrVal( $_ ), @_ ) ), "'" );
2684 }
2685 21 return( $ref );
2686 }
2687  
2688 sub _index_schema_202012
2689 {
2690 1999 ▶ my( $node, $base_uri, $ptr, $anchors, $id_index ) = @_;
Subroutine _index_schema_202012: called CC=14 SCAR=26.6
2691  
2692 1999 $anchors->{ $ptr } = $node;
2693  
2694 1999 my $here_base = $base_uri;
2695  
2696 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
2697 {
2698 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
2699 {
2700 15 $here_base = _resolve_uri( $base_uri, $node->{'$id'} );
2701 15 $id_index->{ $here_base } = $node;
2702 }
2703  
2704 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
2705 {
2706 1 my $abs = $here_base . '#' . $node->{'$anchor'};
2707 1 $id_index->{ $abs } = $node;
2708 }
2709  
2710 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
2711 {
2712 2 my $abs = $here_base . '#dyn:' . $node->{'$dynamicAnchor'};
2713 2 $id_index->{ $abs } = $node;
2714 }
2715  
2716 790 for my $k ( sort( keys( %$node ) ) )
2717 {
2718 1569 my $child = $node->{ $k };
2719 1569 my $child_ptr = _join_ptr( $ptr, $k );
2720 1569 _index_schema_202012( $child, $here_base, $child_ptr, $anchors, $id_index );
2721 }
2722 }
2723 elsif( ref( $node ) eq 'ARRAY' )
2724 {
2725 233 for my $i ( 0 .. $#$node )
2726 {
2727 311 my $child = $node->[$i];
2728 311 my $child_ptr = _join_ptr( $ptr, $i );
2729 311 _index_schema_202012( $child, $here_base, $child_ptr, $anchors, $id_index );
2730 }
2731 }
2732 }
2733  
2734 sub _inst_addr
2735 {
2736 364 ▶ my( $inst, $ptr ) = @_;
Subroutine _inst_addr: called CC=2 SCAR=7.1
2737 364 ▶ return( "SCALAR:$ptr" ) unless( ref( $inst ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $inst 0 364 364
2738 364 return( ref( $inst ) . ':' . refaddr( $inst ) );
2739 }
2740  
2741 # truthy helpers
2742 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
2743  
2744 sub _is_number
2745 {
2746 923 ▶ my( $v ) = @_;
Subroutine _is_number: called CC=6 SCAR=18.0
2747  
2748 923 ▶ return(0) if( ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 335 588 923
2749 588 ▶ return(0) unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 6 582 588
2750  
2751 # Strict JSON typing: accept only scalars that actually carry numeric flags.
2752 # JSON marks numbers with IOK/NOK; plain strings (even "12") will not have them.
2753 582 my $sv = B::svref_2object( \$v );
2754 582 my $flags = $sv->FLAGS;
2755  
2756 582 local $@;
2757 # SVf_IOK = 0x02000000, SVf_NOK = 0x04000000 on most builds;
2758 # we do not hardcode constants—B::SV’s FLAGS is stable to test with these bitmasks.
2759 # Use string eval to avoid importing platform-specific constants.
2760 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
2761 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
2762  
2763 582 ▶ return( ( $flags & ( $SVf_IOK | $SVf_NOK ) ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$flags & ($SVf_IOK | $SVf_NOK) ? : 278 304 582
2764 }
2765  
2766 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
2767  
2768 sub _join_ptr
2769 {
2770 2917 ▶ my( $base, @tokens ) = @_;
Subroutine _join_ptr: called CC=6 SCAR=18.4
2771  
2772 # Default base to '#' if not provided
2773 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
2774  
2775 2917 my $ptr = $base;
2776  
2777 2917 for my $token ( @tokens )
2778 {
2779 2917 ▶ next unless( defined( $token ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $token 0 2917 2917
2780  
2781 # Proper rfc6901 JSON Pointer escaping
2782 2917 $token =~ s/~/~0/g;
2783 2917 $token =~ s/\//~1/g;
2784  
2785 2917 ▶ if( $ptr eq '#' )
Branch: 1 branch
BranchTrueFalseTotal
if ($ptr eq '#') { } 1015 1902 2917
2786 {
2787 1015 $ptr = "#/$token";
2788 }
2789 else
2790 {
2791 1902 $ptr .= "/$token";
2792 }
2793 }
2794  
2795 2917 return( $ptr );
2796 }
2797  
2798 sub _js_quote
2799 {
2800 0 ▶ my $s = shift( @_ );
Subroutine _js_quote: not called CC=2 SCAR=17.9
2801 0 ▶ $s = '' unless( defined( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 0 0
2802 0 $s =~ s/\\/\\\\/g;
2803 0 $s =~ s/'/\\'/g;
2804 0 $s =~ s/\r\n/\n/g;
2805 0 $s =~ s/\r/\n/g;
2806 0 $s =~ s/\n/\\n/g;
2807 0 return( "'$s'" );
2808 }
2809  
2810 sub _json_equal
2811 {
2812 21 ▶ my( $a, $b ) = @_;
Subroutine _json_equal: called CC=1 SCAR=0.0
2813 21 return( _canon( $a ) eq _canon( $b ) );
2814 }
2815  
2816 # Very small JSON Pointer resolver for internal refs ("#/...") for JS compile
2817 sub _jsv_resolve_internal_ref
2818 {
2819 9 ▶ my( $root, $ptr ) = @_;
Subroutine _jsv_resolve_internal_ref: called CC=18 SCAR=39.0
2820  
2821 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
2822  
2823 # Expect something like "#/definitions/address"
2824 9 $ptr =~ s/^#//;
2825  
2826 9 my @tokens = split( /\//, $ptr );
2827 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
2828  
2829 9 my $node = $root;
2830  
2831 TOKEN:
2832 9 for my $tok ( @tokens )
2833 {
2834 # rfc6901 JSON Pointer unescaping
2835 17 $tok =~ s/~1/\//g;
2836 17 $tok =~ s/~0/~/g;
2837  
2838 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
2839 {
2840 # Draft 2020-12 alias: allow "definitions" to hit "$defs" if needed
2841 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
2842 !exists( $node->{definitions} ) &&
2843 exists( $node->{'$defs'} ) )
2844 {
2845 8 $tok = '$defs';
2846 }
2847  
2848 17 ▶ unless( exists( $node->{ $tok } ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $node->{$tok}) 1 16 17
2849 {
2850 # Optional: help debug resolution problems
2851 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
2852 if( $JSON::Schema::Validate::DEBUG );
2853 1 return;
2854 }
2855 16 $node = $node->{ $tok };
2856 }
2857 elsif( ref( $node ) eq 'ARRAY' )
2858 {
2859 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
2860 {
2861 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
2862 if( $JSON::Schema::Validate::DEBUG );
2863 0 return;
2864 }
2865 0 $node = $node->[ $tok ];
2866 }
2867 else
2868 {
2869 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
2870 if( $JSON::Schema::Validate::DEBUG );
2871 0 return;
2872 }
2873 }
2874  
2875 8 return( $node );
2876 }
2877  
2878 # Keyword groups
2879 sub _k_array_all
2880 {
2881 32 ▶ my( $ctx, $sp, $S, $A ) = @_;
Subroutine _k_array_all: called CC=34 SCAR=39.3
2882  
2883 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
2884 {
2885 0 return( _err_res( $ctx, $sp, "array has fewer than minItems $S->{minItems}", 'minItems' ) );
2886 }
2887 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
2888 {
2889 0 return( _err_res( $ctx, $sp, "array has more than maxItems $S->{maxItems}", 'maxItems' ) );
2890 }
2891  
2892 32 ▶ if( $S->{uniqueItems} )
Branch: 1 branch
BranchTrueFalseTotal
if ($S->{"uniqueItems"}) 0 32 32
2893 {
2894 0 my %seen;
2895 0 for my $i ( 0 .. $#$A )
2896 {
2897 0 my $k = _canon( $A->[$i] );
2898 0 ▶ if( $seen{ $k }++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($seen{$k}++) 0 0 0
2899 {
2900 0 return( _err_res( $ctx, _join_ptr( $sp, $i ), "array items not unique", 'uniqueItems' ) );
2901 }
2902 }
2903 }
2904  
2905 32 my %items_ann;
2906  
2907 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
2908 {
2909 5 my $tuple = $S->{prefixItems};
2910 5 for my $i ( 0 .. $#$A )
2911 {
2912 16 push( @{$ctx->{ptr_stack}}, _join_ptr( $sp, $i ) );
2913  
2914 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
2915 {
2916 10 my $r = _v( $ctx, _join_ptr( $sp, "prefixItems/$i" ), $tuple->[$i], $A->[$i] );
2917 10 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 10 10
2918 10 $items_ann{ $i } = 1;
2919 }
2920 ▶ 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
2921 {
2922 5 my $r = _v( $ctx, _join_ptr( $sp, "items" ), $S->{items}, $A->[$i] );
2923 5 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 1 4 5
2924 4 $items_ann{ $i } = 1;
2925 }
2926  
2927 15 pop( @{$ctx->{ptr_stack}} );
2928 }
2929 }
2930 elsif( ref( $S->{items} ) eq 'HASH' )
2931 {
2932 14 for my $i ( 0 .. $#$A )
2933 {
2934 27 push( @{$ctx->{ptr_stack}}, _join_ptr( $sp, $i ) );
2935 27 my $r = _v( $ctx, _join_ptr( $sp, "items" ), $S->{items}, $A->[$i] );
2936 27 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 2 25 27
2937 25 $items_ann{ $i } = 1;
2938 25 pop( @{$ctx->{ptr_stack}} );
2939 }
2940 }
2941  
2942 29 ▶ if( exists( $S->{contains} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"contains"}) 10 19 29
2943 {
2944 10 my $matches = 0;
2945  
2946 # Quiet sub-context to avoid emitting errors for non-matching items
2947 10 for my $i ( 0 .. $#$A )
2948 {
2949 29 my %shadow = %$ctx;
2950 29 my @errs;
2951 29 $shadow{errors} = \@errs;
2952 29 $shadow{error_count} = 0;
2953  
2954 29 my $tmp = _v( \%shadow, _join_ptr( $sp, "contains" ), $S->{contains}, $A->[$i] );
2955 29 ▶ $matches++ if( $tmp->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->{"ok"} 21 8 29
2956 }
2957  
2958 10 ▶ my $minc = defined( $S->{minContains} ) ? $S->{minContains} : 1;
Branch: 1 branch
BranchTrueFalseTotal
defined $S->{'minContains'} ? : 10 0 10
2959 10 ▶ my $maxc = defined( $S->{maxContains} ) ? $S->{maxContains} : ( 2**31 - 1 );
Branch: 1 branch
BranchTrueFalseTotal
defined $S->{'maxContains'} ? : 8 2 10
2960  
2961 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
2962 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
2963 }
2964  
2965 24 ▶ if( exists( $S->{unevaluatedItems} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedItems"}) 3 21 24
2966 {
2967 3 my @unknown = ();
2968 3 for my $i ( 0 .. $#$A )
2969 {
2970 10 ▶ next if( $items_ann{ $i } );
Branch: 1 branch
BranchTrueFalseTotal
if $items_ann{$i} 9 1 10
2971 1 push( @unknown, $i );
2972 }
2973 3 my $UE = $S->{unevaluatedItems};
2974 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
2975 {
2976 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
2977 }
2978 elsif( ref( $UE ) eq 'HASH' )
2979 {
2980 0 for my $i ( @unknown )
2981 {
2982 0 my $r = _v( $ctx, _join_ptr( $sp, "unevaluatedItems" ), $UE, $A->[$i] );
2983 0 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 0 0 0
2984 0 $items_ann{ $i } = 1;
2985 }
2986 }
2987 }
2988  
2989 23 return( { ok => 1, props => {}, items => \%items_ann } );
2990 }
2991  
2992 sub _k_combinator
2993 {
2994 25 ▶ my( $ctx, $sp, $S, $inst, $kw ) = @_;
Subroutine _k_combinator: called CC=17 SCAR=28.4
2995  
2996  
2997 # allOf: all subschemas must pass, we merge their annotations
2998 25 ▶ if( $kw eq 'allOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "allOf") 10 15 25
2999 {
3000 10 my %props;
3001 my %items;
3002  
3003 10 for my $i ( 0 .. $#{$S->{allOf}} )
3004 {
3005 16 my $r = _v( $ctx, _join_ptr( $sp, "allOf/$i" ), $S->{allOf}->[ $i ], $inst );
3006 16 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 3 13 16
3007  
3008 13 %props = ( %props, %{$r->{props}} );
3009 13 %items = ( %items, %{$r->{items}} );
3010 }
3011  
3012 7 return( { ok => 1, props => \%props, items => \%items } );
3013 }
3014  
3015 # anyOf: at least one subschema must pass.
3016 # Errors from failing branches must NOT leak into the main context.
3017 15 ▶ if( $kw eq 'anyOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "anyOf") 2 13 15
3018 {
3019 2 my @branch_errs;
3020  
3021 2 for my $i ( 0 .. $#{$S->{anyOf}} )
3022 {
3023 # Shadow context: isolate errors for this branch
3024 3 my %shadow = %$ctx;
3025 3 my @errs;
3026 3 $shadow{errors} = \@errs;
3027 3 $shadow{error_count} = 0;
3028  
3029 3 my $r = _v( \%shadow, _join_ptr( $sp, "anyOf/$i" ), $S->{anyOf}->[ $i ], $inst );
3030  
3031 3 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{"ok"}) 1 2 3
3032 {
3033 # One branch passed: combinator satisfied.
3034 # Ignore all other branch errors.
3035 1 return( { ok => 1, props => {}, items => {} } );
3036 }
3037  
3038 2 push( @branch_errs, \@errs );
3039 }
3040  
3041 # No branch matched: merge collected branch errors into main context
3042 1 for my $aref ( @branch_errs )
3043 {
3044 2 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 2 2
3045 2 push( @{$ctx->{errors}}, @$aref );
3046 2 $ctx->{error_count} += scalar( @$aref );
3047 }
3048  
3049 1 return( _err_res( $ctx, $sp, "instance does not satisfy anyOf", 'anyOf' ) );
3050 }
3051  
3052 # oneOf: exactly one subschema must pass.
3053 # Again, do not leak errors from non-selected branches.
3054 13 ▶ if( $kw eq 'oneOf' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "oneOf") 11 2 13
3055 {
3056 11 my @ok_results;
3057 my @branch_errs;
3058  
3059 11 for my $i ( 0 .. $#{$S->{oneOf}} )
3060 {
3061 22 my %shadow = %$ctx;
3062 22 my @errs;
3063 22 $shadow{errors} = \@errs;
3064 22 $shadow{error_count} = 0;
3065  
3066 22 my $r = _v( \%shadow, _join_ptr( $sp, "oneOf/$i" ), $S->{oneOf}->[$i], $inst );
3067  
3068 22 ▶ if( $r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->{'ok'}) { } 6 16 22
3069 {
3070 6 push( @ok_results, $r );
3071 }
3072 else
3073 {
3074 16 push( @branch_errs, \@errs );
3075 }
3076 }
3077  
3078 11 ▶ if( @ok_results == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ok_results == 1) 4 7 11
3079 {
3080 # Exactly one branch matched: combinator satisfied.
3081 # Do NOT bubble up branch props/items through oneOf.
3082 4 return( { ok => 1, props => {}, items => {} } );
3083 }
3084  
3085 # Zero or >1 matched -> failure; merge branch errors
3086 7 for my $aref ( @branch_errs )
3087 {
3088 12 ▶ next unless( @$aref );
Branch: 1 branch
BranchTrueFalseTotal
unless @$aref 0 12 12
3089 12 push( @{$ctx->{errors}}, @$aref );
3090 12 $ctx->{error_count} += scalar( @$aref );
3091 }
3092  
3093 return(
3094 7 _err_res(
3095 $ctx,
3096 $sp,
3097 "instance satisfies " . scalar( @ok_results ) . " schemas in oneOf (expected exactly 1)",
3098 'oneOf'
3099 )
3100 );
3101 }
3102  
3103 # not: subschema must NOT validate.
3104 # Any errors from validating the inner schema are irrelevant on success.
3105 2 ▶ if( $kw eq 'not' )
Branch: 1 branch
BranchTrueFalseTotal
if ($kw eq "not") 2 0 2
3106 {
3107 2 my %shadow = %$ctx;
3108 2 my @errs;
3109 2 $shadow{errors} = \@errs;
3110 2 $shadow{error_count} = 0;
3111  
3112 2 my $r = _v( \%shadow, _join_ptr( $sp, "not" ), $S->{not}, $inst );
3113  
3114 # If inner schema passes, then "not" fails
3115 return( _err_res( $ctx, $sp, "instance matches forbidden not-schema", 'not' ) )
3116 2 ▶ if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 1 1 2
3117  
3118 # Otherwise, "not" is satisfied; ignore inner errors entirely
3119 1 return( { ok => 1, props => {}, items => {} } );
3120 }
3121  
3122 # Unknown / unsupported combinator (defensive default)
3123 0 return( { ok => 1, props => {}, items => {} } );
3124 }
3125  
3126 sub _k_const
3127 {
3128 6 ▶ my( $ctx, $v, $const, $ptr ) = @_;
Subroutine _k_const: called CC=2 SCAR=8.1
3129 6 ▶ return(1) if( _json_equal( $v, $const ) );
Branch: 1 branch
BranchTrueFalseTotal
if _json_equal($v, $const) 6 0 6
3130 0 return( _err( $ctx, $ptr, "const mismatch", 'const' ) );
3131 }
3132  
3133 sub _k_enum
3134 {
3135 8 ▶ my( $ctx, $v, $arr, $ptr ) = @_;
Subroutine _k_enum: called CC=3 SCAR=11.0
3136 8 for my $e ( @$arr )
3137 {
3138 15 ▶ return(1) if( _json_equal( $v, $e ) );
Branch: 1 branch
BranchTrueFalseTotal
if _json_equal($v, $e) 4 11 15
3139 }
3140 4 return( _err( $ctx, $ptr, "value not in enum", 'enum' ) );
3141 }
3142  
3143 sub _k_format
3144 {
3145 55 ▶ my( $ctx, $s, $fmt, $ptr ) = @_;
Subroutine _k_format: called CC=4 SCAR=13.9
3146 55 my $cb = $ctx->{formats}->{ $fmt };
3147 55 ▶ return(1) unless( $cb );
Branch: 1 branch
BranchTrueFalseTotal
unless $cb 3 52 55
3148 52 local $@;
3149 52 ▶ my $ok = eval{ $cb->( $s ) ? 1 : 0 };
Branch: 1 branch
BranchTrueFalseTotal
&$cb($s) ? : 34 18 52
3150 52 ▶ return( $ok ? 1 : _err( $ctx, $ptr, "string fails format '$fmt'", 'format' ) );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 34 18 52
3151 }
3152  
3153 sub _k_if_then_else
3154 {
3155 16 ▶ my( $ctx, $sp, $S, $inst ) = @_;
Subroutine _k_if_then_else: called CC=6 SCAR=18.5
3156  
3157 # Evaluate "if" in a shadow context so its errors do NOT leak
3158 16 my %shadow = %$ctx;
3159 16 my @errs;
3160 16 $shadow{errors} = \@errs;
3161 16 $shadow{error_count} = 0;
3162  
3163 16 my $cond = _v( \%shadow, _join_ptr( $sp, 'if' ), $S->{if}, $inst );
3164  
3165 16 ▶ if( $cond->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
if ($cond->{'ok'}) { } 6 10 16
3166 {
3167 6 ▶ _t( $ctx, $sp, 'if', undef, 'pass', 'then' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 6 6
3168 return( { ok => 1, props => {}, items => {} } )
3169 6 ▶ unless( exists( $S->{then} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{"then"} 0 6 6
3170  
3171 # Apply "then" against the REAL context
3172 6 return( _v( $ctx, _join_ptr( $sp, 'then' ), $S->{then}, $inst ) );
3173 }
3174 else
3175 {
3176 10 ▶ _t( $ctx, $sp, 'if', undef, 'pass', 'else' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 10 10
3177 return( { ok => 1, props => {}, items => {} } )
3178 10 ▶ unless( exists( $S->{else} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $S->{"else"} 10 0 10
3179  
3180 # Apply "else" against the REAL context
3181 0 return( _v( $ctx, _join_ptr( $sp, 'else' ), $S->{else}, $inst ) );
3182 }
3183 }
3184  
3185 sub _k_number
3186 {
3187 88 ▶ my( $ctx, $v, $kw, $arg, $ptr ) = @_;
Subroutine _k_number: called CC=24 SCAR=35.5
3188 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
3189 {
3190 # Guard per spec: multipleOf must be > 0
3191 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
3192 {
3193 1 ▶ _t( $ctx, $ptr, 'multipleOf', undef, 'fail', 'arg<=0' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 1 1
3194 1 return( _err( $ctx, $ptr, "multipleOf must be > 0", 'multipleOf' ) );
3195 }
3196 # Float-tolerant multiple check
3197 # my $ok = abs( ( $v / $arg ) - int( $v / $arg + 1e-10 ) ) < 1e-9;
3198 12 my $ok = abs( ( $v / $arg ) - int( $v / $arg + 0.0000000001 ) ) < 1e-9;
3199 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
3200 12 ▶ return( $ok ? 1 : _err( $ctx, $ptr, "number not multipleOf $arg" ) );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 7 5 12
3201 }
3202 elsif( $kw eq 'minimum' )
3203 {
3204 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
3205 62 ▶ return( $v >= $arg ? 1 : _err( $ctx, $ptr, "number less than minimum $arg", 'minimum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v >= $arg ? : 49 13 62
3206 }
3207 elsif( $kw eq 'maximum' )
3208 {
3209 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
3210 6 ▶ return( $v <= $arg ? 1 : _err( $ctx, $ptr, "number greater than maximum $arg", 'maximum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v <= $arg ? : 5 1 6
3211 }
3212 elsif( $kw eq 'exclusiveMinimum' )
3213 {
3214 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
3215 5 ▶ return( $v > $arg ? 1 : _err( $ctx, $ptr, "number not greater than exclusiveMinimum $arg", 'exclusiveMinimum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v > $arg ? : 3 2 5
3216 }
3217 elsif( $kw eq 'exclusiveMaximum' )
3218 {
3219 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
3220 2 ▶ return( $v < $arg ? 1 : _err( $ctx, $ptr, "number not less than exclusiveMaximum $arg", 'exclusiveMaximum' ) );
Branch: 1 branch
BranchTrueFalseTotal
$v < $arg ? : 1 1 2
3221 }
3222 0 return(1);
3223 }
3224  
3225 sub _k_object_all
3226 {
3227 287 ▶ my( $ctx, $sp, $S, $H ) = @_;
Subroutine _k_object_all: called CC=70 SCAR=48.5
3228  
3229 287 my $ok = 1;
3230  
3231 my $bail_if_max = sub
3232 {
3233 136 ▶ return( $ctx->{max_errors} && $ctx->{error_count} >= $ctx->{max_errors} ) ? 1 : 0;
Subroutine __ANON__: called CC=3 SCAR=11.1
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
3234 287 };
3235  
3236 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
3237 {
3238 0 _err_res( $ctx, $sp, "object has fewer than minProperties $S->{minProperties}", 'minProperties' );
3239 0 $ok = 0;
3240 0 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3241 }
3242 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
3243 {
3244 0 _err_res( $ctx, $sp, "object has more than maxProperties $S->{maxProperties}", 'maxProperties' );
3245 0 $ok = 0;
3246 0 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3247 }
3248  
3249 # Merge required from:
3250 # - top-level "required" (array only)
3251 # - property-level { required => 1 } or { optional => 0 }
3252 287 my %required;
3253  
3254 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
3255 {
3256 162 $required{ $_ } = 1 for( @{ $S->{required} } );
3257 }
3258  
3259 287 ▶ if( my $P = $S->{properties} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $P = $S->{"properties"}) 251 36 287
3260 {
3261 251 for my $k ( keys( %$P ) )
3262 {
3263 393 my $pd = $P->{ $k };
3264 393 ▶ next unless( ref( $pd ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $pd eq "HASH" 0 393 393
3265  
3266 393 ▶ if( exists( $pd->{required} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pd->{"required"}) 50 343 393
3267 {
3268 50 ▶ $required{ $k } = $pd->{required} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$pd->{'required'} ? : 48 2 50
3269 }
3270 393 ▶ if( exists( $pd->{optional} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $pd->{"optional"}) 4 389 393
3271 {
3272 4 ▶ $required{ $k } = $pd->{optional} ? 0 : 1; # optional => 0 means required
Branch: 1 branch
BranchTrueFalseTotal
$pd->{'optional'} ? : 2 2 4
3273 }
3274 }
3275 }
3276  
3277 287 for my $rq ( grep{ $required{ $_ } } keys( %required ) )
3278 {
3279 257 ▶ next if( exists( $H->{ $rq } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $H->{$rq} 218 39 257
3280 39 ▶ _t( $ctx,$sp, 'required', undef, 'fail', $rq ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 1 38 39
3281  
3282 39 my @need = sort grep { $required{ $_ } } keys %required;
3283 39 my @have = sort keys %$H;
3284  
3285 39 ▶ my $need_str = @need ? join( ', ', @need ) : '(none)';
Branch: 1 branch
BranchTrueFalseTotal
@need ? : 39 0 39
3286 39 ▶ my $have_str = @have ? join( ', ', @have ) : '(none)';
Branch: 1 branch
BranchTrueFalseTotal
@have ? : 37 2 39
3287  
3288 39 my $msg = "required property '$rq' is missing "
3289 . "(required: $need_str; present: $have_str)";
3290  
3291 39 _err_res(
3292 $ctx,
3293 _join_ptr( $sp, $rq ),
3294 $msg,
3295 'required'
3296 );
3297  
3298 39 $ok = 0;
3299 39 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 1 38 39
3300 }
3301  
3302 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
3303 {
3304 6 for my $k ( keys( %$H ) )
3305 {
3306 12 my $r = _v( $ctx, _join_ptr( $sp, "propertyNames" ), $S->{propertyNames}, $k );
3307 12 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 2 10 12
3308 {
3309 2 $ok = 0;
3310 2 ▶ return( { ok => 0, props => {}, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3311 }
3312 }
3313 }
3314  
3315 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
3316 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
3317 286 my $addl_set = exists( $S->{additionalProperties} );
3318 286 ▶ my $addl = $addl_set ? $S->{additionalProperties} : JSON::true;
Branch: 1 branch
BranchTrueFalseTotal
$addl_set ? : 171 115 286
3319  
3320 286 my %ann;
3321  
3322 286 for my $k ( sort( keys( %$H ) ) )
3323 {
3324 443 my $v = $H->{ $k };
3325 443 my $matched = 0;
3326  
3327 443 my $child_path = _join_ptr( $sp, $k );
3328 443 push( @{$ctx->{ptr_stack}}, $child_path );
3329  
3330 443 ▶ if( exists( $props->{ $k } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $props->{$k}) 288 155 443
3331 {
3332 288 my $r = _v( $ctx, _join_ptr( $sp, "properties/$k" ), $props->{ $k }, $v );
3333 288 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 74 214 288
3334 {
3335 74 $ok = 0;
3336 74 pop( @{$ctx->{ptr_stack}} );
3337 74 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 1 73 74
3338 73 next;
3339 }
3340 214 $ann{ $k } = 1;
3341 214 $matched = 1;
3342 }
3343  
3344 369 ▶ unless( $matched )
Branch: 1 branch
BranchTrueFalseTotal
unless ($matched) 155 214 369
3345 {
3346 155 local $@;
3347 155 for my $re ( keys( %$patprops ) )
3348 {
3349 4 my $re_ok = eval{ $k =~ /$re/ };
3350 4 ▶ next unless( $re_ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $re_ok 2 2 4
3351  
3352 2 my $r = _v( $ctx, _join_ptr( $sp, "patternProperties/$re" ), $patprops->{ $re }, $v );
3353 2 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 2 2
3354 {
3355 0 $ok = 0;
3356 0 pop( @{$ctx->{ptr_stack}} );
3357 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3358 0 next;
3359 }
3360 2 $ann{ $k } = 1;
3361 2 $matched = 1;
3362 }
3363 }
3364  
3365 369 ▶ unless( $matched )
Branch: 1 branch
BranchTrueFalseTotal
unless ($matched) 153 216 369
3366 {
3367 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
3368 {
3369 16 _err_res( $ctx, _join_ptr( $sp, $k ), "additionalProperties not allowed: '$k'", 'additionalProperties' );
3370 16 $ok = 0;
3371 16 pop( @{$ctx->{ptr_stack}} );
3372 16 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 16 16
3373 16 next;
3374 }
3375 elsif( ref( $addl ) eq 'HASH' )
3376 {
3377 5 my $r = _v( $ctx, _join_ptr( $sp, "additionalProperties" ), $addl, $v );
3378 5 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 5 5
3379 {
3380 0 $ok = 0;
3381 0 pop( @{$ctx->{ptr_stack}} );
3382 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3383 0 next;
3384 }
3385 5 $ann{ $k } = 1;
3386 }
3387 }
3388  
3389 353 pop( @{$ctx->{ptr_stack}} );
3390 }
3391  
3392 285 ▶ if( my $depR = $S->{dependentRequired} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $depR = $S->{"dependentRequired"}) 8 277 285
3393 {
3394 8 for my $k ( keys( %$depR ) )
3395 {
3396 8 ▶ next unless( exists( $H->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $H->{$k} 2 6 8
3397 6 ▶ for my $need ( @{$depR->{ $k } || []} )
Branch: 1 branch
BranchTrueFalseTotal
$depR->{$k} or [] 0 6 6
3398 {
3399 6 ▶ next if( exists( $H->{ $need } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $H->{$need} 4 2 6
3400 2 _err_res( $ctx, _join_ptr( $sp, $need ), "dependentRequired: '$need' required when '$k' is present", 'dependentRequired' );
3401 2 $ok = 0;
3402 2 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3403 }
3404 }
3405 }
3406  
3407 285 ▶ if( my $depS = $S->{dependentSchemas} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $depS = $S->{"dependentSchemas"}) 8 277 285
3408 {
3409 8 for my $k ( keys( %$depS ) )
3410 {
3411 8 ▶ next unless( exists( $H->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $H->{$k} 3 5 8
3412 5 my $r = _v( $ctx, _join_ptr( $sp, "dependentSchemas/$k" ), $depS->{ $k }, $H );
3413 5 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 2 3 5
3414 {
3415 2 $ok = 0;
3416 2 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 2 2
3417 }
3418 }
3419 }
3420  
3421 285 ▶ if( exists( $S->{unevaluatedProperties} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"unevaluatedProperties"}) 4 281 285
3422 {
3423 4 my @unknown = grep { !$ann{ $_ } } keys( %$H );
3424 4 my $UE = $S->{unevaluatedProperties};
3425  
3426 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
3427 {
3428 4 ▶ if( @unknown )
Branch: 1 branch
BranchTrueFalseTotal
if (@unknown) 1 3 4
3429 {
3430 1 _err_res( $ctx, $sp, "unevaluatedProperties not allowed: " . join( ',', @unknown ), 'unevaluatedProperties' );
3431 1 $ok = 0;
3432 1 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 1 1
3433 }
3434 }
3435 elsif( ref( $UE ) eq 'HASH' )
3436 {
3437 0 for my $k ( @unknown )
3438 {
3439 0 my $r = _v( $ctx, _join_ptr( $sp, "unevaluatedProperties" ), $UE, $H->{ $k } );
3440 0 ▶ if( !$r->{ok} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->{"ok"}) 0 0 0
3441 {
3442 0 $ok = 0;
3443 0 ▶ return( { ok => 0, props => \%ann, items => {} } ) if( $bail_if_max->() );
Branch: 1 branch
BranchTrueFalseTotal
if &$bail_if_max() 0 0 0
3444 0 next;
3445 }
3446 0 $ann{ $k } = 1;
3447 }
3448 }
3449 }
3450  
3451 285 ▶ return( { ok => ( $ok ? 1 : 0 ), props => \%ann, items => {} } );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 167 118 285
3452 }
3453  
3454 sub _k_string
3455 {
3456 50 ▶ my( $ctx, $s, $S, $ptr ) = @_;
Subroutine _k_string: called CC=15 SCAR=27.7
3457 50 my $len = _strlen( $s );
3458  
3459 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
3460 {
3461 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
3462 7 return( _err( $ctx, $ptr, "string shorter than minLength $S->{minLength}", 'minLength' ) );
3463 }
3464 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
3465  
3466 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
3467 {
3468 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
3469 1 return( _err( $ctx, $ptr, "string longer than maxLength $S->{maxLength}", 'maxLength' ) );
3470 }
3471 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
3472  
3473 42 ▶ if( exists( $S->{pattern} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $S->{"pattern"}) 18 24 42
3474 {
3475 18 my $re = $S->{pattern};
3476 18 local $@;
3477 18 my $ok = eval{ $s =~ /$re/ };
3478 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
3479 18 ▶ return( _err( $ctx, $ptr, "string does not match pattern /$re/", 'pattern' ) ) unless( $ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 2 16 18
3480 }
3481 40 return(1);
3482 }
3483  
3484 # Primitive keyword helpers
3485 sub _k_type
3486 {
3487 582 ▶ my( $ctx, $v, $type_kw, $ptr ) = @_;
Subroutine _k_type: called CC=9 SCAR=22.0
3488  
3489 582 ▶ my @alts = ref( $type_kw ) eq 'ARRAY' ? @$type_kw : ( $type_kw );
Branch: 1 branch
BranchTrueFalseTotal
ref $type_kw eq 'ARRAY' ? : 26 556 582
3490  
3491 # First, allow inline schemas in the union
3492 582 my $i = 0;
3493 582 for my $alt ( @alts )
3494 {
3495 642 ▶ if( ref( $alt ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $alt eq "HASH") 20 622 642
3496 {
3497 20 my $r = _v( $ctx, _join_ptr( $ptr, "type/$i" ), $alt, $v );
3498 20 ▶ return(1) if( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
if $r->{"ok"} 3 17 20
3499 }
3500 639 $i++;
3501 }
3502  
3503 # Then, try string type names
3504 579 for my $t ( @alts )
3505 {
3506 610 ▶ next if( ref( $t ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $t 15 595 610
3507 595 ▶ return(1) if( _match_type( $v, $t ) );
Branch: 1 branch
BranchTrueFalseTotal
if _match_type($v, $t) 543 52 595
3508 }
3509  
3510 36 ▶ my $exp = join( '|', map{ ref( $_ ) ? 'schema' : $_ } @alts );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 15 34 49
3511 36 return( _err( $ctx, $ptr, "type mismatch: expected $exp", 'type' ) );
3512 }
3513  
3514 sub _k_unique_keys
3515 {
3516 17 ▶ my( $ctx, $sp, $uk_def, $array ) = @_;
Subroutine _k_unique_keys: called CC=12 SCAR=25.2
3517 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
3518 {
3519 0 return( { ok => 1, props => {}, items => {} } );
3520 }
3521  
3522 17 for my $key_set ( @$uk_def )
3523 {
3524 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
3525  
3526 19 my %seen;
3527 19 for my $i ( 0 .. $#$array )
3528 {
3529 42 my $item = $array->[$i];
3530 42 ▶ next unless( ref( $item ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $item eq "HASH" 2 40 42
3531  
3532 40 my @key_vals;
3533 40 my $all_present = 1;
3534 40 for my $key ( @$key_set )
3535 {
3536 47 ▶ if( exists( $item->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $item->{$key}) { } 44 3 47
3537 {
3538 44 push( @key_vals, _canon( $item->{ $key } ) );
3539 }
3540 else
3541 {
3542 3 $all_present = 0;
3543 3 last;
3544 }
3545 }
3546  
3547 # Skip items that do not have *all* keys in this key set
3548 40 ▶ next unless( $all_present );
Branch: 1 branch
BranchTrueFalseTotal
unless $all_present 3 37 40
3549  
3550 37 my $composite = join( "\0", @key_vals );
3551 37 ▶ if( exists( $seen{ $composite } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $seen{$composite}) 8 29 37
3552 {
3553 8 my $prev_i = $seen{ $composite };
3554 8 my $keys = join( ', ', map { "'$_'" } @$key_set );
3555 8 push( @{$ctx->{ptr_stack}}, _join_ptr( $sp, $i ) );
3556 8 my $res = _err_res(
3557 $ctx,
3558 $sp,
3559 "uniqueKeys violation: items[$prev_i] and items[$i] have identical values for key(s) [$keys]",
3560 'uniqueKeys',
3561 );
3562 8 pop( @{$ctx->{ptr_stack}} );
3563  
3564 8 return( $res );
3565 }
3566 29 $seen{ $composite } = $i;
3567 }
3568 }
3569  
3570 9 return( { ok => 1, props => {}, items => {} } );
3571 }
3572  
3573 sub _match_type
3574 {
3575 595 ▶ my( $v, $t ) = @_;
Subroutine _match_type: called CC=22 SCAR=31.0
3576  
3577 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
3578  
3579 594 ▶ if( $t eq 'boolean' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "boolean") 16 578 594
3580 {
3581 16 ▶ return(0) if( !defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 2 14 16
3582 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
3583 {
3584 8 my $s = "$v";
3585 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
3586 }
3587 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
3588 }
3589  
3590 578 ▶ if( $t eq 'integer' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "integer") 113 465 578
3591 {
3592 113 ▶ return(0) unless( _is_number( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless _is_number($v) 14 99 113
3593 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
3594 }
3595  
3596 465 ▶ if( $t eq 'number' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "number") 33 432 465
3597 {
3598 33 return( _is_number( $v ) );
3599 }
3600  
3601 432 ▶ if( $t eq 'string' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t eq "string") 140 292 432
3602 {
3603 # Must be a scalar, defined, and NOT a numeric SV under strict typing.
3604 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
3605 }
3606  
3607 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
3608 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
3609  
3610 19 return(0);
3611 }
3612  
3613 sub _normalize_uri
3614 {
3615 119 ▶ my( $u ) = @_;
Subroutine _normalize_uri: called CC=3 SCAR=12.5
3616 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
3617 119 return( $u );
3618 }
3619  
3620 sub _parse_media_type
3621 {
3622 7 ▶ my( $s ) = @_;
Subroutine _parse_media_type: called CC=5 SCAR=16.3
3623 7 my( $type, @rest ) = split( /;/, "$s" );
3624 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
3625 7 $type =~ s/\s+//g;
3626 7 my %p;
3627 7 for my $kv ( @rest )
3628 {
3629 7 my( $k, $v ) = split( /=/, $kv, 2 );
3630 7 ▶ next unless( defined( $k ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $k 0 7 7
3631 7 $k =~ s/\s+//g;
3632 7 ▶ $v = '' unless( defined( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 0 7 7
3633 7 $v =~ s/^\s+|\s+$//g;
3634 # Allow single or double quote, but be consistent
3635 7 $v =~ s/^(?<quote>["'])(.*)\g{quote}$/$2/;
3636 7 $p{ lc( $k ) } = $v;
3637 }
3638 7 return( lc( $type ), \%p );
3639 }
3640  
3641 sub _prune_array_with_schema
3642 {
3643 1 ▶ my( $self, $schema, $data ) = @_;
Subroutine _prune_array_with_schema: called CC=6 SCAR=18.0
3644  
3645 1 my @out;
3646  
3647 1 my $shape =
3648 {
3649 prefix_items => [], # index => subschema
3650 items => undef # subschema for additional items
3651 };
3652  
3653 1 $self->_extract_array_shape( $schema, $shape );
3654  
3655 1 for my $i ( 0 .. $#$data )
3656 {
3657 3 my $item = $data->[ $i ];
3658 3 my $item_schema;
3659  
3660 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
3661 {
3662 1 $item_schema = $shape->{prefix_items}->[ $i ];
3663 }
3664 elsif( $shape->{items} )
3665 {
3666 2 $item_schema = $shape->{items};
3667 }
3668  
3669 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
3670 {
3671 2 $out[ $i ] = $self->_prune_with_schema( $item_schema, $item );
3672 }
3673 else
3674 {
3675 # No structural knowledge or scalar item: keep as-is
3676 1 $out[ $i ] = $item;
3677 }
3678 }
3679  
3680 1 return( \@out );
3681 }
3682  
3683 sub _prune_object_with_schema
3684 {
3685 6 ▶ my( $self, $schema, $data ) = @_;
Subroutine _prune_object_with_schema: called CC=9 SCAR=22.9
3686  
3687 # Collect effective object shape from this schema and any allOf mixins.
3688 6 my $shape =
3689 {
3690 props => {}, # property name => subschema
3691 patterns => [], # [ regex, subschema ] ...
3692 allow_ap => 1, # additionalProperties allowed?
3693 ap_schema => undef # subschema for additionalProperties, if any
3694 };
3695  
3696 6 $self->_extract_object_shape( $schema, $shape );
3697  
3698 6 my %clean;
3699  
3700 KEY:
3701 6 foreach my $key ( keys( %$data ) )
3702 {
3703 16 my $val = $data->{ $key };
3704  
3705 # 1) Direct properties
3706 16 ▶ if( exists( $shape->{props}->{ $key } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $shape->{"props"}{$key}) 7 9 16
3707 {
3708 7 my $sub = $shape->{props}->{ $key };
3709 7 $clean{ $key } = $self->_prune_with_schema( $sub, $val );
3710 7 next KEY;
3711 }
3712  
3713 # 2) patternProperties
3714 9 foreach my $pair ( @{$shape->{patterns}} )
3715 {
3716 3 my( $re, $pschema ) = @$pair;
3717 3 my $ok;
3718  
3719 {
3720 3 local $@;
3721 3 ▶ $ok = eval{ $key =~ /$re/ ? 1 : 0; };
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /$re/u ? : 2 1 3
3722 }
3723  
3724 3 ▶ next unless( $ok );
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 1 2 3
3725  
3726 2 $clean{ $key } = $self->_prune_with_schema( $pschema, $val );
3727 2 next KEY;
3728 }
3729  
3730 # 3) additionalProperties
3731 7 ▶ if( $shape->{allow_ap} )
Branch: 1 branch
BranchTrueFalseTotal
if ($shape->{'allow_ap'}) { } 0 7 7
3732 {
3733 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
3734 {
3735 0 $clean{ $key } = $self->_prune_with_schema( $shape->{ap_schema}, $val );
3736 }
3737 else
3738 {
3739 # allowed, but no further structure known
3740 0 $clean{ $key } = $val;
3741 }
3742 }
3743 else
3744 {
3745 # additionalProperties is false (or equivalent) => drop unknown key
3746 7 next KEY;
3747 }
3748 }
3749  
3750 6 return( \%clean );
3751 }
3752  
3753 sub _prune_with_schema
3754 {
3755 17 ▶ my( $self, $schema, $data ) = @_;
Subroutine _prune_with_schema: called CC=4 SCAR=13.9
3756  
3757 # Boolean schemas and non-hash schemas: do not attempt pruning.
3758 17 ▶ return( $data ) unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 17 17
3759  
3760 # Only prune structured values; scalars we leave untouched.
3761 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
3762 {
3763 6 return( $self->_prune_object_with_schema( $schema, $data ) );
3764 }
3765 elsif( ref( $data ) eq 'ARRAY' )
3766 {
3767 1 return( $self->_prune_array_with_schema( $schema, $data ) );
3768 }
3769  
3770 10 return( $data );
3771 }
3772  
3773 sub _ptr_of_node
3774 {
3775 8 ▶ my( $root, $target ) = @_;
Subroutine _ptr_of_node: called CC=3 SCAR=11.0
3776 8 for my $p ( keys( %{$root->{anchors}} ) )
3777 {
3778 89 my $n = $root->{anchors}->{ $p };
3779 89 ▶ return( $p ) if( $n eq $target );
Branch: 1 branch
BranchTrueFalseTotal
if $n eq $target 8 81 89
3780 }
3781 0 return( '#' );
3782 }
3783  
3784 44 my %SCRIPT_LIKE = map{ $_ => 1 } qw(
3785 Hiragana Katakana Han Hangul Latin Cyrillic Greek
3786 Hebrew Thai Armenian Georgian
3787 Arabic Devanagari Bengali Gurmukhi Gujarati Oriya
3788 Tamil Telugu Kannada Malayalam Sinhala
3789 Lao Tibetan Myanmar Khmer
3790 );
3791 sub _re_to_js
3792 {
3793 0 ▶ my $re = shift( @_ );
Subroutine _re_to_js: not called CC=7 SCAR=40.3
3794 0 my %opt = @_;
3795  
3796 # style: 'literal' => for use in /.../u
3797 # 'string' => for use in new RegExp("...", "u")
3798 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
3799  
3800 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
3801  
3802 #
3803 # 1) Convert \x{...} (Perl) to \u.... or \u{....} (JS)
3804 # - 1–4 hex digits -> \uHHHH
3805 # - 5–6 hex digits -> \u{HHHHH} (requires /u in JS)
3806 #
3807 0 $re =~ s{
3808 \\x\{([0-9A-Fa-f]{1,6})\}
3809 }{
3810 0 my $hex = uc( $1 );
3811 0 ▶ if( length( $hex ) <= 4 )
Branch: 1 branch
BranchTrueFalseTotal
if (length $hex <= 4) { } 0 0 0
3812 {
3813 0 "\\u$hex";
3814 }
3815 else
3816 {
3817 0 "\\u\{$hex\}";
3818 }
3819 }egx;
3820  
3821 # Script eXtended
3822 #
3823 # 2) Convert \p{Katakana} / \P{Katakana}
3824 # to \p{scx=Katakana} / \P{scx=Katakana}
3825 # (Script_Extensions so it covers half-width too)
3826 #
3827 0 $re =~ s[
3828 \\([pP])\{([^}]+)\}
3829 ][
3830 0 my( $p, $name ) = ( $1, $2 );
3831  
3832 0 my $norm = $name;
3833 0 $norm =~ s/^\s+|\s+$//g;
3834 0 $norm = ucfirst( lc( $norm ) );
3835  
3836 0 ▶ if( exists( $SCRIPT_LIKE{ $norm } ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SCRIPT_LIKE{$norm}) { } 0 0 0
3837 {
3838 0 "\\$p\{scx=$norm\}";
3839 }
3840 else
3841 {
3842 # Pass other properties through unchanged:
3843 # \p{L}, \p{Letter}, \p{Nd}, etc.
3844 0 "\\$p\{$name\}";
3845 }
3846 ]egx;
3847  
3848 #
3849 # 3) Optionally escape backslashes for JS string literal
3850 #
3851 0 ▶ if( $style eq 'string' )
Branch: 1 branch
BranchTrueFalseTotal
if ($style eq "string") 0 0 0
3852 {
3853 0 $re =~ s{\\}{\\\\}g; # existing
3854 0 $re =~ s{"}{\\"}g; # escape "
3855 0 $re =~ s{\n}{\\n}g;
3856 0 $re =~ s{\r}{\\r}g;
3857 0 $re =~ s{/}{\/}g;
3858 }
3859  
3860 # For 'literal', we leave backslashes as-is, for use in /.../u
3861  
3862 0 return( $re );
3863 }
3864  
3865 sub _register_builtin_media_validators
3866 {
3867 4 ▶ my( $self ) = @_;
Subroutine _register_builtin_media_validators: called CC=1 SCAR=0.0
3868  
3869 # Example: application/json
3870 $self->register_media_validator( 'application/json' => sub
3871 {
3872 2 ▶ my( $bytes, $params ) = @_;
Subroutine __ANON__: called CC=2 SCAR=7.0
3873 2 local $@;
3874 2 my $v = eval{ JSON->new->allow_nonref(1)->decode( $bytes ) };
3875 2 ▶ return( 0, 'invalid JSON', undef ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
3876 # JSON value is valid even if it’s 0, "", or false
3877 2 return( 1, undef, $v );
3878 4 } );
3879  
3880 4 return( $self );
3881 }
3882  
3883 sub _resolve_uri
3884 {
3885 37 ▶ my( $base, $ref ) = @_;
Subroutine _resolve_uri: called CC=6 SCAR=18.4
3886 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
3887 18 ▶ if( $ref =~ /^\#/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /^\#/u) 17 1 18
3888 {
3889 17 ( my $no_frag = $base ) =~ s/\#.*$//;
3890 17 return( $no_frag . $ref );
3891 }
3892 1 ▶ return( $base . $ref ) if( $base =~ /\/$/ );
Branch: 1 branch
BranchTrueFalseTotal
if $base =~ m[/$]u 0 1 1
3893 1 ( my $dir = $base ) =~ s{[^/]*$}{};
3894 1 return( $dir . $ref );
3895 }
3896  
3897 sub _safe_invoke
3898 {
3899 8 ▶ my( $cb, @args ) = @_;
Subroutine _safe_invoke: called CC=9 SCAR=32.3
3900 8 local $@;
3901 # Force list context to preserve (ok, msg, out) style returns
3902 8 my @ret = eval{ $cb->( @args ) };
3903 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
3904  
3905 # If callback returns (ok, msg, out) or (ok, msg)
3906 8 ▶ if( @ret >= 2 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ret >= 2) 8 0 8
3907 {
3908 8 ▶ my( $ok, $msg, $out ) = ( $ret[0] ? 1 : 0, $ret[1], $ret[2] );
Branch: 1 branch
BranchTrueFalseTotal
$ret[0] ? : 6 2 8
3909 8 return( $ok, $msg, $out );
3910 }
3911  
3912 # If callback returns a single value
3913 0 ▶ if( @ret == 1 )
Branch: 1 branch
BranchTrueFalseTotal
if (@ret == 1) 0 0 0
3914 {
3915 0 my $v = $ret[0];
3916 # Reference => treat as decoded structure (success)
3917 0 ▶ return( 1, undef, $v ) if( ref( $v ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $v 0 0 0
3918 # Defined scalar => truthiness decides; scalar can be treated as decoded bytes
3919 0 ▶ return( $v ? 1 : 0, undef, ( defined( $v ) ? $v : undef ) );
Branch: 2 branches
BranchTrueFalseTotal
$v ? : 0 0 0
defined $v ? : 0 0 0
3920 }
3921  
3922 # Empty list => treat as failure (safer default)
3923 0 return( 0, 'callback returned no value', undef );
3924 }
3925  
3926 sub _strlen
3927 {
3928 50 ▶ my( $s ) = @_;
Subroutine _strlen: called CC=2 SCAR=7.0
3929 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
3930 50 my @cp = unpack( 'U*', $s );
3931 50 return( scalar( @cp ) );
3932 }
3933  
3934 # Strict base64: validates alphabet, padding, length, and round-trips
3935 sub _strict_base64_decode
3936 {
3937 6 ▶ my( $s ) = @_;
Subroutine _strict_base64_decode: called CC=6 SCAR=18.2
3938 6 ▶ return unless( defined( $s ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $s 0 6 6
3939  
3940 # strip ASCII whitespace per RFC 4648 §3.3 (tests commonly include raw)
3941 6 ( my $norm = "$s" ) =~ s/\s+//g;
3942  
3943 # valid alphabet + padding only
3944 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
3945  
3946 # length must be a multiple of 4
3947 3 ▶ return unless( ( length( $norm ) % 4 ) == 0 );
Branch: 1 branch
BranchTrueFalseTotal
unless length($norm) % 4 == 0 0 3 3
3948  
3949 3 local $@;
3950 3 ▶ return unless( eval{ require MIME::Base64; 1 } );
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require MIME::Base64; 1 } } 0 3 3
3951  
3952 3 my $out = MIME::Base64::decode_base64( $norm );
3953  
3954 # re-encode and compare to ensure no silent salvage
3955 3 my $re = MIME::Base64::encode_base64( $out, '' );
3956 # RFC allows omitting trailing '=' if not needed; normalize both
3957 3 $re =~ s/\s+//g;
3958 3 $norm =~ s/\s+//g;
3959 3 ▶ return unless( $re eq $norm );
Branch: 1 branch
BranchTrueFalseTotal
unless $re eq $norm 0 3 3
3960 3 return( $out );
3961 }
3962  
3963 sub _t
3964 {
3965 44 ▶ my( $ctx, $schema_ptr, $keyword, $inst_path, $outcome, $note ) = @_;
Subroutine _t: called CC=7 SCAR=21.5
3966 44 ▶ return unless( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
unless $ctx->{"trace_on"} 0 44 44
3967  
3968 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
3969 {
3970 0 return;
3971 }
3972 44 ▶ if( $ctx->{trace_sample} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"trace_sample"}) 8 36 44
3973 {
3974 8 ▶ return if( int( rand(100) ) >= $ctx->{trace_sample} );
Branch: 1 branch
BranchTrueFalseTotal
if int rand 100 >= $ctx->{"trace_sample"} 8 0 8
3975 }
3976  
3977 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
3978 {
3979 schema_ptr => $schema_ptr,
3980 keyword => $keyword,
3981 36 inst_path => ( $ctx->{ptr_stack}->[-1] // '#' ),
3982 outcome => $outcome, # 'pass' | 'fail'
3983 note => $note, # short string
3984 });
3985 }
3986  
3987 # Validation core with annotation + recursion
3988 # _v returns { ok => 0|1, props => {k=>1,...}, items => {i=>1,...} }
3989 sub _v
3990 {
3991 715 ▶ my( $ctx, $schema_ptr, $schema, $inst ) = @_;
Subroutine _v: called CC=8 SCAR=20.9
3992  
3993 # Recursion guard only for reference types
3994 715 ▶ if( ref( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst) 364 351 715
3995 {
3996 364 my $inst_addr = _inst_addr( $inst, $ctx->{ptr_stack}->[-1] );
3997 364 my $vkey = "$schema_ptr|$inst_addr";
3998 364 ▶ return( { ok => 1, props => {}, items => {} } ) if( $ctx->{visited}->{ $vkey }++ );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"visited"}{$vkey}++ 0 364 364
3999 }
4000  
4001 # Enter dynamicAnchor scope if present
4002 715 my $frame_added = 0;
4003 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
4004 exists( $schema->{'$dynamicAnchor'} ) &&
4005 defined( $schema->{'$dynamicAnchor'} ) &&
4006 $schema->{'$dynamicAnchor'} ne '' )
4007 {
4008 11 my %frame = %{$ctx->{dyn_stack}->[-1]}; # inherit
4009 11 $frame{ $schema->{'$dynamicAnchor'} } = $schema;
4010 11 push( @{$ctx->{dyn_stack}}, \%frame );
4011 11 $frame_added = 1;
4012 }
4013  
4014 715 my $res = _v_node( $ctx, $schema_ptr, $schema, $inst );
4015  
4016 715 ▶ if( $frame_added )
Branch: 1 branch
BranchTrueFalseTotal
if ($frame_added) 11 704 715
4017 {
4018 11 pop( @{$ctx->{dyn_stack}} );
4019 }
4020  
4021 715 return( $res );
4022 }
4023  
4024 sub _v_node
4025 {
4026 715 ▶ my( $ctx, $schema_ptr, $schema, $inst ) = @_;
Subroutine _v_node: called CC=79 SCAR=46.3
4027  
4028 # $ref / $dynamicRef first
4029 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
4030 exists( $schema->{'$ref'} ) )
4031 {
4032 22 return( _apply_ref( $ctx, $schema_ptr, $schema->{'$ref'}, $inst ) );
4033 }
4034 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
4035 exists( $schema->{'$dynamicRef'} ) )
4036 {
4037 5 return( _apply_dynamic_ref( $ctx, $schema_ptr, $schema->{'$dynamicRef'}, $inst ) );
4038 }
4039 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
4040 exists( $schema->{'$comment'} ) &&
4041 defined( $schema->{'$comment'} ) )
4042 {
4043 9 my $c = $schema->{'$comment'};
4044 9 ▶ if( my $cb = $ctx->{comment_handler} )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{"comment_handler"}) 4 5 9
4045 {
4046 4 local $@;
4047 4 eval{ $cb->( $schema_ptr, "$c" ) };
4048 # ignore callback errors to keep validation resilient
4049 }
4050 9 ▶ _t( $ctx, $schema_ptr, '$comment', undef, 'visit', "$c" ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 9 0 9
4051 }
4052  
4053 688 ▶ _t( $ctx, $schema_ptr, 'node', undef, 'visit' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 12 676 688
4054  
4055 # Use compiled validator if enabled
4056 688 ▶ if( $ctx->{compile_on} )
Branch: 1 branch
BranchTrueFalseTotal
if ($ctx->{"compile_on"}) 35 653 688
4057 {
4058 35 my $fn = $ctx->{root}->{fn_index}->{ $schema_ptr };
4059 35 ▶ unless( $fn )
Branch: 1 branch
BranchTrueFalseTotal
unless ($fn) 23 12 35
4060 {
4061 23 $fn = _compile_node( $ctx->{root}, $schema_ptr, $schema );
4062 23 $ctx->{root}->{fn_index}->{ $schema_ptr } = $fn;
4063 }
4064 35 return( $fn->( $ctx, $inst ) );
4065 }
4066  
4067 653 ▶ return( { ok => 1, props => {}, items => {} } ) unless( ref( $schema ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $schema eq "HASH" 0 653 653
4068  
4069 653 my $ptr = $schema_ptr;
4070  
4071 # Types / const / enum
4072 653 ▶ if( exists( $schema->{type} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"type"}) 547 106 653
4073 {
4074 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() 36 511 547
4075 }
4076 617 ▶ if( exists( $schema->{const} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"const"}) 6 611 617
4077 {
4078 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() 0 6 6
4079 }
4080 617 ▶ if( exists( $schema->{enum} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"enum"}) 8 609 617
4081 {
4082 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
4083 }
4084 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
4085  
4086 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
4087 exists( $schema->{uniqueKeys} ) &&
4088 ref( $schema->{uniqueKeys} ) eq 'ARRAY' &&
4089 ref( $inst ) eq 'ARRAY' )
4090 {
4091 17 my $r = _k_unique_keys( $ctx, $ptr, $schema->{uniqueKeys}, $inst );
4092 17 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 8 9 17
4093 }
4094  
4095 # Numbers
4096 605 ▶ if( _is_number( $inst ) )
Branch: 1 branch
BranchTrueFalseTotal
if (_is_number($inst)) 139 466 605
4097 {
4098 139 for my $k ( qw( multipleOf minimum maximum exclusiveMinimum exclusiveMaximum ) )
4099 {
4100 631 ▶ next unless( exists( $schema->{ $k } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $schema->{$k} 545 86 631
4101 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() 22 64 86
4102 }
4103 }
4104  
4105 # Strings
4106 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
4107 {
4108 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"}) 18 217 235
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
4109 {
4110 48 ▶ _k_string( $ctx, $inst, $schema, $ptr ) or return( _fail() );
Branch: 1 branch
BranchTrueFalseTotal
_k_string($ctx, $inst, $schema, $ptr) or return _fail() 9 39 48
4111 }
4112 256 ▶ if( exists( $schema->{format} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"format"}) 53 203 256
4113 {
4114 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() 17 36 53
4115 }
4116  
4117 # contentEncoding / contentMediaType / contentSchema
4118 239 ▶ if( exists( $schema->{contentEncoding} ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentEncoding"} or exists $schema->{"contentMediaType"} or exists $schema->{"contentSchema"}) 0 230 230
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
4119 exists( $schema->{contentMediaType} ) ||
4120 exists( $schema->{contentSchema} ) )
4121 {
4122 9 ▶ my $assert = $ctx->{content_assert} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$ctx->{'content_assert'} ? : 6 3 9
4123 9 my $bytes = "$inst";
4124 9 my $decoded_ref;
4125  
4126 9 ▶ if( exists( $schema->{contentEncoding} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentEncoding"}) 9 0 9
4127 {
4128 9 my $dec = _content_decode( $ctx, $schema->{contentEncoding}, $bytes );
4129 9 ▶ if( !defined( $dec ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $dec) { } 3 6 9
4130 {
4131 3 ▶ return( _err_res( $ctx, $ptr, "contentEncoding '$schema->{contentEncoding}' decode failed", 'contentEncoding' ) ) if( $assert );
Branch: 1 branch
BranchTrueFalseTotal
if $assert 2 1 3
4132 }
4133 else
4134 {
4135 6 $bytes = $dec;
4136 }
4137 }
4138  
4139 7 ▶ if( exists( $schema->{contentMediaType} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentMediaType"}) 7 0 7
4140 {
4141 7 my( $mt, $params ) = _parse_media_type( $schema->{contentMediaType} );
4142 7 ▶ if( my $cb = $ctx->{media_validators}->{ $mt } )
Branch: 1 branch
BranchTrueFalseTotal
if (my $cb = $ctx->{'media_validators'}{$mt}) { } 5 2 7
4143 {
4144 5 my( $ok, $msg, $maybe_decoded ) = _safe_invoke( $cb, $bytes, $params );
4145 5 ▶ if( !$ok )
Branch: 1 branch
BranchTrueFalseTotal
unless ($ok) 2 3 5
4146 {
4147 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
4148 }
4149 4 ▶ $decoded_ref = $maybe_decoded if( ref( $maybe_decoded ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $maybe_decoded 2 2 4
4150 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
4151 }
4152 else
4153 {
4154 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
4155 {
4156 0 local $@;
4157 my $ok = eval
4158 0 ▶ {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Encode; &Encode::decode('UTF-8', $bytes, 1); 1 } } ? : 0 0 0
4159 0 require Encode;
4160 0 Encode::decode( 'UTF-8', $bytes, Encode::FB_CROAK );
4161 0 1;
4162 } ? 1 : 0;
4163 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
4164 {
4165 0 return( _err_res( $ctx, $ptr, "contentMediaType '$mt' invalid UTF-8", 'contentMediaType' ) );
4166 }
4167 }
4168 }
4169 }
4170  
4171 6 ▶ if( exists( $schema->{contentSchema} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"contentSchema"}) 4 2 6
4172 {
4173 4 my $val;
4174 4 ▶ if( ref( $decoded_ref ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $decoded_ref) { } 2 2 4
4175 {
4176 2 $val = $decoded_ref; # already decoded by media validator
4177 }
4178 else
4179 {
4180 2 local $@;
4181 2 $val = eval{ JSON->new->allow_nonref(1)->utf8(1)->decode( $bytes ) };
4182 }
4183  
4184 4 ▶ if( !defined( $val ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $val) { } 1 3 4
4185 {
4186 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
4187 }
4188 else
4189 {
4190 3 my $r = _v( $ctx, _join_ptr( $ptr, 'contentSchema' ), $schema->{contentSchema}, $val );
4191 3 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 1 2 3
4192 }
4193 }
4194 }
4195 }
4196  
4197 553 my %ann_props;
4198 my %ann_items;
4199  
4200 # Arrays
4201 553 ▶ if( ref( $inst ) eq 'ARRAY' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "ARRAY") 32 521 553
4202 {
4203 32 my $r = _k_array_all( $ctx, $schema_ptr, $schema, $inst );
4204 32 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 9 23 32
4205 23 %ann_items = ( %ann_items, %{ $r->{items} } );
4206 }
4207 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
4208  
4209 # Objects
4210 544 ▶ if( ref( $inst ) eq 'HASH' )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $inst eq "HASH") 270 274 544
4211 {
4212 270 my $r = _k_object_all( $ctx, $schema_ptr, $schema, $inst );
4213 270 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 113 157 270
4214 157 %ann_props = ( %ann_props, %{ $r->{props} } );
4215 }
4216 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
4217  
4218 # Combinators
4219 431 for my $comb ( qw( allOf anyOf oneOf not ) )
4220 {
4221 1706 ▶ next unless( exists( $schema->{ $comb } ) );
Branch: 1 branch
BranchTrueFalseTotal
unless exists $schema->{$comb} 1681 25 1706
4222 25 my $r = _k_combinator( $ctx, $schema_ptr, $schema, $inst, $comb );
4223 25 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 12 13 25
4224 13 %ann_props = ( %ann_props, %{ $r->{props} } );
4225 13 %ann_items = ( %ann_items, %{ $r->{items} } );
4226 13 ▶ _t( $ctx, $schema_ptr, $comb, undef, 'pass', '' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 13 13
4227 }
4228  
4229 # Conditionals
4230 419 ▶ if( exists( $schema->{if} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $schema->{"if"}) 16 403 419
4231 {
4232 16 my $r = _k_if_then_else( $ctx, $schema_ptr, $schema, $inst );
4233 16 ▶ return( $r ) unless( $r->{ok} );
Branch: 1 branch
BranchTrueFalseTotal
unless $r->{"ok"} 3 13 16
4234 13 %ann_props = ( %ann_props, %{ $r->{props} } );
4235 13 %ann_items = ( %ann_items, %{ $r->{items} } );
4236 }
4237  
4238 416 ▶ _t( $ctx, $schema_ptr, 'node', undef, 'pass' ) if( $ctx->{trace_on} );
Branch: 1 branch
BranchTrueFalseTotal
if $ctx->{"trace_on"} 0 416 416
4239 416 return( { ok => 1, props => \%ann_props, items => \%ann_items } );
4240 }
4241  
4242 # NOTE: JSON::Schema::Validate::Error
4243 package JSON::Schema::Validate::Error;
4244 BEGIN
4245 {
4246 44 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4247 44 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4248 44 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
4249 use overload (
4250 '""' => 'as_string',
4251 2 ▶ 'eq' => sub{ _obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4252 3 ▶ 'ne' => sub{ !_obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4253 1 ▶ '==' => sub{ _obj_eq(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
4254 0 ▶ '!=' => sub{ !_obj_eq(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
4255 5 ▶ bool => sub{1},
Subroutine __ANON__: called CC=1 SCAR=0.0
4256 44 fallback => 1,
4257 44 ▶ );
Subroutine BEGIN: called CC=1 SCAR=0.0
4258 44 ▶ our $VERSION = 'v0.1.0';
Subroutine BEGIN: called CC=1 SCAR=0.0
4259 };
4260  
4261 44 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4262 44 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4263 44 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
4264  
4265 sub new
4266 {
4267 180 ▶ my $that = shift( @_ );
Subroutine new: called CC=6 SCAR=18.6
4268 180 my $ref = {};
4269 # Legacy instantiation
4270 # We make sure this is not one single option that was provided to us.
4271 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
4272 {
4273 4 @$ref{qw( path message )} = @_;
4274 }
4275 else
4276 {
4277 176 my $args = { @_ };
4278 176 for( qw( path message keyword schema_pointer ) )
4279 {
4280 704 ▶ $ref->{ $_ } = $args->{ $_ } if( exists( $args->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $args->{$_} 704 0 704
4281 }
4282 }
4283 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
4284 }
4285  
4286 sub as_hash
4287 {
4288 0 ▶ my $self = shift( @_ );
Subroutine as_hash: not called CC=1 SCAR=6.9
4289 0 my $ref = {};
4290 0 my @keys = qw( keyword message path schema_pointer );
4291 0 @$ref{ @keys } = @$self{ @keys };
4292 0 return( $ref );
4293 }
4294  
4295 sub as_string
4296 {
4297 9 ▶ my $self = shift( @_ );
Subroutine as_string: called CC=5 SCAR=16.3
4298 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
4299 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
4300 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
4301 # Dual-path if avail
4302 9 ▶ return( $sp ? "${sp} → ${path}: ${msg}" : "${path}: ${msg}" );
Branch: 1 branch
BranchTrueFalseTotal
$sp ? : 8 1 9
4303 }
4304  
4305 sub keyword
4306 {
4307 8 ▶ my $self = shift( @_ );
Subroutine keyword: called CC=2 SCAR=7.1
4308 8 ▶ $self->{keyword} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 8 8
4309 8 return( $self->{keyword} );
4310 }
4311  
4312 sub message
4313 {
4314 29 ▶ my $self = shift( @_ );
Subroutine message: called CC=2 SCAR=7.1
4315 29 ▶ $self->{message} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 29 29
4316 29 return( $self->{message} );
4317 }
4318  
4319 sub path
4320 {
4321 17 ▶ my $self = shift( @_ );
Subroutine path: called CC=2 SCAR=7.1
4322 17 ▶ $self->{path} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 17 17
4323 17 return( $self->{path} );
4324 }
4325  
4326 sub schema_pointer
4327 {
4328 10 ▶ my $self = shift( @_ );
Subroutine schema_pointer: called CC=2 SCAR=7.1
4329 10 ▶ $self->{schema_pointer} = shift( @_ ) if( @_ );
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 10 10
4330 10 return( $self->{schema_pointer} );
4331 }
4332  
4333 sub _obj_eq
4334 {
4335 44 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
4336 6 ▶ my $self = shift( @_ );
Subroutine _obj_eq: called CC=12 SCAR=26.7
4337 6 my $other = shift( @_ );
4338 6 my $me;
4339 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
4340 Scalar::Util::blessed( $other ) &&
4341 $other->isa( 'JSON::Schema::Validate::Error' ) )
4342 {
4343 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
4344 ( $self->path // '' ) eq ( $other->path // '' ) )
4345 {
4346 2 return(1);
4347 }
4348 else
4349 {
4350 2 return(0);
4351 }
4352 }
4353 # Compare error message
4354 elsif( !ref( $other ) )
4355 {
4356 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
4357 2 return( $me eq $other );
4358 }
4359 # Otherwise some reference data to which we cannot compare
4360 0 return(0) ;
4361 }
4362  
4363 44 1;
4364 # NOTE: POD
4365 __END__
↑ Summary blib/lib/JSON/Schema/Validate.pm »