Branch Coverage

blib/lib/JSON/Validator.pm
Criterion Covered Total %
branch 339 370 91.6


line true false branch
60 4 11 $args->{'schema'} ? :
63 3 12 if ($args->{'replace'}) { }
67 3 12 if $from_type eq 'HASH' and $tied = tied %$from
68 9 6 $from_type eq 'HASH' ? :
0 15 $from_type eq 'ARRAY' ? :
69 9 6 if $from_type
79 143 35 unless ($tied)
80 52 91 $from_type eq 'HASH' ? :
0 143 $from_type eq 'ARRAY' ? :
81 52 91 if $from_type
87 8 27 if not $args->{'schema'} and $tied->fqn =~ /^\Q$self->{'root_schema_url'}\E\#/
90 27 0 unless ($self->{'bundled_refs'}{$tied->fqn}++)
103 0 15 if $args->{'ref_key'}
109 0 130 if (ref $from eq 'ARRAY') { }
130 0 elsif (ref $from eq 'HASH') { }
126 5 14 unless defined(my $what = shift())
128 1 13 if ($what eq '1')
136 10 4 unless ref $what
146 50 2 unless @_
154 267 3 if not $self->{'version'} and $schema =~ /draft-0+(\w+)/
157 1 264 if @errors
165 3 577 if defined $self->{'coerce'}
171 906 624 unless @_
181 0 917 unless defined $schema
225 4 23 if ($ref->fqn =~ m[#/$prefix/([^/]+)$])
228 1 0 if ($self->{'bundled_refs'}{$ref->fqn} or not $node or not $node->{$key} or data_checksum($ref->schema) eq data_checksum($node->{$key}))
240 23 0 if (-e $spec_path)
253 7801 64 $_[0]->version < 7 ? :
258 289 39 if ($url =~ m[^https?://])
264 18 21 if ($url =~ m[^data://([^/]*)/(.*)])
270 0 21 if ($url =~ /^\s*[\[\{]/)
279 20 1 if (-e $file) { }
0 1 elsif ($url =~ m[^/] and $self->ua->server->app) { }
299 327 0 if $$text =~ /^\s*\{/s
302 0 0 unless &YAML_SUPPORT()
319 13 275 unless -r $path
326 2 15 if $err
328 0 11 if ($cache_path and $cache_path ne $BUNDLED_CACHE_DIR || $ENV{'JSON_VALIDATOR_CACHE_ANYWAYS'} and -w $cache_path)
335 0 0 unless $ENV{'HARNESS_ACTIVE'}
347 85 54 if $create
348 20 119 unless $node = $$node{$path->[$n]}
349 88 31 if ++$n + $offset >= @$path
361 0 1456 if @guard > 100
364 15 1441 if is_type($schema, 'BOOL')
384 898 6965 unless $self->{'level'}
386 574 7289 if (ref $schema eq 'HASH') { }
6953 336 elsif ($resolved = $self->{'schemas'}{$schema // ''}) { }
8 328 elsif (is_type($schema, 'BOOL')) { }
388 0 574 if $resolved = $self->{'schemas'}{$id}
399 277 47 if $schema->{$id_key}
402 875 23 unless ($self->{'level'})
404 303 572 if ($rid)
405 1 302 if $rid =~ /\#./
407 2 11 unless $rid =~ /^\w+:/ or -e $rid or $rid =~ m[^/]
421 20 875 is_type($id, 'Mojo::File') ? :
425 2750 36920 if (is_type($topic, 'ARRAY')) { }
20506 16414 elsif (is_type($topic, 'HASH')) { }
430 0 20506 if $seen{$seen_addr}++
433 6882 13624 if $topic->{'$ref'} and not ref $topic->{'$ref'}
435 288 13336 if ($topic->{$id_key} and not ref $topic->{$id_key})
437 11 277 unless $fqn->is_abs
454 129 6836 if $location_as_url->is_abs
457 22 6814 if (is_type($base, 'Mojo::File'))
458 7 15 unless length $location
467 1 6881 if tied %$topic
473 11 13831 if is_type($other, 'BOOL')
476 0 13831 if @guard > 100
478 6866 6965 if not $ref or ref $ref
479 0 6965 $ref =~ m[^/] ? :
482 2472 4493 if length $location and not length $pointer
483 4493 2472 if defined $pointer
487 4472 21 if (defined $pointer and length $pointer and $pointer =~ m[^/])
489 1 4471 unless defined $other
503 819 4014 if ref $schema eq 'HASH' and $schema->{'$ref'}
504 54 20 $schema ? :
74 4824 if is_type($schema, 'BOOL')
507 2356 2468 ref $data ? :
510 293 4531 if ($self->{'seen'}{$seen_addr})
515 4 4527 &blessed($data) && $data->can('TO_JSON') ? :
517 4 4527 if $to_json
521 97 4434 if (ref $type eq 'ARRAY') { }
2771 1663 elsif ($type) { }
525 0 97 $to_json ? :
529 4 2767 $to_json ? :
530 523 2248 if @errors
533 32 3976 if (exists $schema->{'const'})
534 0 32 $to_json ? :
536 12 20 if @errors
539 505 3491 if ($schema->{'enum'})
540 0 505 $to_json ? :
542 22 483 if @errors
545 11 3963 if (my $rules = $schema->{'not'})
546 0 11 $to_json ? :
547 5 6 @errors ? :
550 107 3856 if (my $rules = $schema->{'allOf'}) { }
565 3291 elsif ($rules = $schema->{'anyOf'}) { }
28 3263 elsif ($rules = $schema->{'oneOf'}) { }
551 0 107 $to_json ? :
555 0 565 $to_json ? :
559 0 28 $to_json ? :
573 189 18 unless my(@e) = $self->_validate($_[1], $path, $rule)
575 17 1 if $schema_type
576 16 2 if not $schema_type or $schema_type eq $type
582 1 106 if not @errors and @expected
584 13 93 if @errors
596 647 127 unless @e
598 24 103 if not $schema_type or $schema_type eq $type
606 7 8 unless @errors
617 28 31 unless my(@e) = $self->_validate($_[1], $path, $rule)
619 12 19 if not $schema_type or $schema_type eq $type
626 18 10 if @passed == 1
627 3 7 unless @errors + @expected
628 2 5 if @passed
629 4 1 if @errors
638 4 375 if (is_type($cmp_with, 'BOOL')) { }
2 373 elsif (is_type($cmp_with, 'NUM')) { }
641 2 2 unless $value < $schema->{'maximum'}
644 1 1 unless $value < $cmp_with
648 32 347 if (exists $schema->{'maximum'})
650 6 26 unless $value <= $cmp_with
662 12 367 if (is_type($cmp_with, 'BOOL')) { }
2 365 elsif (is_type($cmp_with, 'NUM')) { }
665 2 10 unless $value > $schema->{'minimum'}
668 1 1 unless $value > $cmp_with
672 158 221 if (exists $schema->{'minimum'})
674 13 145 unless $value >= $cmp_with
687 502 1477 if $m eq data_checksum($i)
691 12 100 !defined($_) || ref $_ ? :
699 31 20 if data_checksum($data) eq data_checksum($const)
706 1 232 unless $code
708 195 37 unless my $err = &$code($value)
718 34 228 if (ref $data ne 'ARRAY')
721 4 224 if (defined $schema->{'minItems'} and $schema->{'minItems'} > @$data)
725 3 225 if (defined $schema->{'maxItems'} and $schema->{'maxItems'} < @$data)
729 93 135 if ($schema->{'uniqueItems'})
732 170 7 unless $uniq{data_checksum($_)}++
738 2 226 if ($schema->{'contains'}) { }
17 209 elsif (ref $schema->{'items'} eq 'ARRAY') { }
156 53 elsif (exists $schema->{'items'}) { }
742 3 1 if @tmp
744 1 1 if @e >= @$data
750 14 3 if ($additional_items)
754 13 4 if (@rules == @$data) { }
2 2 elsif (not $additional_items) { }
775 65 81 if is_type($value, 'BOOL')
778 27 3 if (defined $value and $self->{'coerce'}{'booleans'} and B::svref_2object(\$value)->FLAGS & 12288 || $value =~ /^(true|false)$/)
785 24 3 $value ? :
796 45 209 if @errors
797 203 6 if $value =~ /^-?\d+$/
804 6 8 unless defined $value
814 17 414 if (not defined $value or ref $value)
817 85 329 unless (is_type($value, 'NUM'))
820 35 50 unless $self->{'coerce'}{'numbers'} and $value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/
825 0 379 if $schema->{'format'}
830 10 369 if $d and ($value / $d) =~ /\.[^0]+$/
839 44 1353 if (ref $data ne 'HASH')
845 2 1351 if (defined $schema->{'maxProperties'} and $schema->{'maxProperties'} < @dkeys)
849 3 1350 if (defined $schema->{'minProperties'} and $schema->{'minProperties'} > @dkeys)
853 3 1350 if (my $n_schema = $schema->{'propertyNames'})
855 3 1 unless my(@e) = $self->_validate($name, $path, $n_schema)
859 4 1349 if ($schema->{'if'})
863 2 2 $self->_validate($data, $path, $schema->{'if'}) ? :
870 18 30 if ($self->{'coerce'}{'defaults'} and ref $r eq 'HASH' and exists $r->{'default'} and not exists $data->{$k})
879 1316 37 unless $schema->{'patternProperties'}
887 179 1174 exists $schema->{'additionalProperties'} ? :
888 1341 12 if ($additional) { }
6 6 elsif (my(@k) = grep({not $rules{$_};} @dkeys)) { }
889 1 1340 unless is_type($additional, 'HASH')
897 1261 86 unless $schema->{'required'}
898 72 24 if exists $data->{$k}
905 26155 2608 unless exists $data->{$k}
906 637 1942 if ref $r eq 'HASH' and $r->{'$ref'}
909 160 2448 if @e or not is_type($r, 'HASH')
912 19 2429 if $r->{'enum'}
915 3 2445 if $r->{'const'}
926 16 481 if (not defined $value or ref $value)
929 22 0 if (B::svref_2object(\$value)->FLAGS & 12288 and 0 + $value eq $value and $value * 0 == 0)
934 21 1 unless $self->{'coerce'}{'strings'}
937 233 227 if ($schema->{'format'})
940 30 430 if (defined $schema->{'maxLength'})
941 11 19 if (length $value > $schema->{'maxLength'})
946 24 436 if (defined $schema->{'minLength'})
947 4 20 if (length $value < $schema->{'minLength'})
952 9 451 if (defined $schema->{'pattern'})
954 2 7 unless $value =~ /$p/