Branch Coverage

blib/lib/JSON/Validator.pm
Criterion Covered Total %
branch 344 376 91.4


line true false branch
60 4 11 $args->{'schema'} ? :
63 3 12 if ($args->{'replace'}) { }
68 3 12 if $from_type eq 'HASH' and $tied = tied %$from
69 9 6 $from_type eq 'HASH' ? :
0 15 $from_type eq 'ARRAY' ? :
70 9 6 if $from_type
80 143 35 unless ($tied)
81 52 91 $from_type eq 'HASH' ? :
0 143 $from_type eq 'ARRAY' ? :
82 52 91 if $from_type
88 8 27 if not $args->{'schema'} and $tied->fqn =~ /^\Q$self->{'root_schema_url'}\E\#/
91 27 0 unless ($self->{'bundled_refs'}{$tied->fqn}++)
104 0 15 if $args->{'ref_key'}
110 0 130 if (ref $from eq 'ARRAY') { }
130 0 elsif (ref $from eq 'HASH') { }
127 5 14 unless defined(my $what = shift())
129 1 13 if ($what eq '1')
137 10 4 unless ref $what
147 50 2 unless @_
155 267 3 if not $self->{'version'} and $schema =~ /draft-0+(\w+)/
158 1 264 if @errors
166 3 578 if defined $self->{'coerce'}
172 918 636 unless @_
182 0 929 unless defined $schema
226 4 23 if ($ref->fqn =~ m[#/$prefix/([^/]+)$])
229 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}))
241 23 0 if (-e $spec_path)
254 7813 64 $_[0]->version < 7 ? :
259 289 39 if ($url =~ m[^https?://])
265 18 21 if ($url =~ m[^data://([^/]*)/(.*)])
271 0 21 if ($url =~ /^\s*[\[\{]/)
280 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()
318 13 275 unless -r $path
325 2 15 if $err
327 0 11 if ($cache_path and $cache_path ne $BUNDLED_CACHE_DIR || $ENV{'JSON_VALIDATOR_CACHE_ANYWAYS'} and -w $cache_path)
334 0 0 unless $ENV{'HARNESS_ACTIVE'}
346 85 54 if $create
347 20 119 unless $node = $$node{$path->[$n]}
348 88 31 if ++$n + $offset >= @$path
360 0 1456 if @guard > 100
363 15 1441 if is_type($schema, 'BOOL')
383 910 6965 unless $self->{'level'}
385 586 7289 if (ref $schema eq 'HASH') { }
6953 336 elsif ($resolved = $self->{'schemas'}{$schema // ''}) { }
8 328 elsif (is_type($schema, 'BOOL')) { }
387 0 586 if $resolved = $self->{'schemas'}{$id}
398 277 47 if $schema->{$id_key}
401 887 23 unless ($self->{'level'})
403 303 584 if ($rid)
404 1 302 if $rid =~ /\#./
406 2 11 unless $rid =~ /^\w+:/ or -e $rid or $rid =~ m[^/]
420 20 887 is_type($id, 'Mojo::File') ? :
424 2772 37077 if (is_type($topic, 'ARRAY')) { }
20585 16492 elsif (is_type($topic, 'HASH')) { }
429 0 20585 if $seen{$seen_addr}++
432 6882 13703 if $topic->{'$ref'} and not ref $topic->{'$ref'}
434 288 13415 if ($topic->{$id_key} and not ref $topic->{$id_key})
436 11 277 unless $fqn->is_abs
453 129 6836 if $location_as_url->is_abs
456 22 6814 if (is_type($base, 'Mojo::File'))
457 7 15 unless length $location
466 1 6881 if tied %$topic
472 11 13831 if is_type($other, 'BOOL')
475 0 13831 if @guard > 100
477 6866 6965 if not $ref or ref $ref
478 0 6965 $ref =~ m[^/] ? :
481 2472 4493 if length $location and not length $pointer
482 4493 2472 if defined $pointer
486 4472 21 if (defined $pointer and length $pointer and $pointer =~ m[^/])
488 1 4471 unless defined $other
501 819 4072 if ref $schema eq 'HASH' and $schema->{'$ref'}
502 54 20 $schema ? :
74 4882 if is_type($schema, 'BOOL')
505 2369 2513 ref $data ? :
508 293 4589 if ($self->{'seen'}{$seen_addr})
513 4 4585 &blessed($data) && $data->can('TO_JSON') ? :
515 4 4585 if $to_json
519 97 4492 if (ref $type eq 'ARRAY') { }
2822 1670 elsif ($type) { }
523 0 97 $to_json ? :
527 4 2818 $to_json ? :
528 540 2282 if @errors
531 32 4017 if (exists $schema->{'const'})
532 0 32 $to_json ? :
534 12 20 if @errors
537 505 3532 if ($schema->{'enum'})
538 0 505 $to_json ? :
540 22 483 if @errors
543 11 4004 if (my $rules = $schema->{'not'})
544 0 11 $to_json ? :
545 5 6 @errors ? :
548 111 3893 if (my $rules = $schema->{'allOf'})
549 0 111 $to_json ? :
553 569 3435 if (my $rules = $schema->{'anyOf'})
554 0 569 $to_json ? :
558 32 3972 if (my $rules = $schema->{'oneOf'})
559 0 32 $to_json ? :
563 7 3997 if ($schema->{'if'})
567 3 4 $self->_validate($data, $path, $schema->{'if'}) ? :
581 196 19 unless my(@e) = $self->_validate($_[1], $path, $rule)
583 18 1 if $schema_type
584 17 2 if not $schema_type or $schema_type eq $type
590 1 110 if not @errors and @expected
592 14 96 if @errors
604 650 131 unless @e
606 28 103 if not $schema_type or $schema_type eq $type
614 7 9 unless @errors
625 30 37 unless my(@e) = $self->_validate($_[1], $path, $rule)
627 18 19 if not $schema_type or $schema_type eq $type
634 20 12 if @passed == 1
635 3 9 unless @errors + @expected
636 2 7 if @passed
637 6 1 if @errors
646 4 376 if (is_type($cmp_with, 'BOOL')) { }
2 374 elsif (is_type($cmp_with, 'NUM')) { }
649 2 2 unless $value < $schema->{'maximum'}
652 1 1 unless $value < $cmp_with
656 32 348 if (exists $schema->{'maximum'})
658 6 26 unless $value <= $cmp_with
670 12 368 if (is_type($cmp_with, 'BOOL')) { }
2 366 elsif (is_type($cmp_with, 'NUM')) { }
673 2 10 unless $value > $schema->{'minimum'}
676 1 1 unless $value > $cmp_with
680 158 222 if (exists $schema->{'minimum'})
682 13 145 unless $value >= $cmp_with
695 502 1477 if $m eq data_checksum($i)
699 12 100 !defined($_) || ref $_ ? :
707 31 20 if data_checksum($data) eq data_checksum($const)
714 1 232 unless $code
716 195 37 unless my $err = &$code($value)
726 34 237 if (ref $data ne 'ARRAY')
729 4 233 if (defined $schema->{'minItems'} and $schema->{'minItems'} > @$data)
733 4 233 if (defined $schema->{'maxItems'} and $schema->{'maxItems'} < @$data)
737 93 144 if ($schema->{'uniqueItems'})
740 170 7 unless $uniq{data_checksum($_)}++
746 2 235 if ($schema->{'contains'}) { }
17 218 elsif (ref $schema->{'items'} eq 'ARRAY') { }
159 59 elsif (exists $schema->{'items'}) { }
750 3 1 if @tmp
752 1 1 if @e >= @$data
758 14 3 if ($additional_items)
762 13 4 if (@rules == @$data) { }
2 2 elsif (not $additional_items) { }
783 65 81 if is_type($value, 'BOOL')
786 27 3 if (defined $value and $self->{'coerce'}{'booleans'} and B::svref_2object(\$value)->FLAGS & 12288 || $value =~ /^(true|false)$/)
793 24 3 $value ? :
804 45 209 if @errors
805 203 6 if $value =~ /^-?\d+$/
812 6 8 unless defined $value
822 17 415 if (not defined $value or ref $value)
825 85 330 unless (is_type($value, 'NUM'))
828 35 50 unless $self->{'coerce'}{'numbers'} and $value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/
833 0 380 if $schema->{'format'}
838 10 370 if $d and ($value / $d) =~ /\.[^0]+$/
847 44 1355 if (ref $data ne 'HASH')
853 2 1353 if (defined $schema->{'maxProperties'} and $schema->{'maxProperties'} < @dkeys)
857 3 1352 if (defined $schema->{'minProperties'} and $schema->{'minProperties'} > @dkeys)
861 3 1352 if (my $n_schema = $schema->{'propertyNames'})
863 3 1 unless my(@e) = $self->_validate($name, $path, $n_schema)
872 18 30 if ($self->{'coerce'}{'defaults'} and ref $r eq 'HASH' and exists $r->{'default'} and not exists $data->{$k})
881 1318 37 unless $schema->{'patternProperties'}
889 179 1176 exists $schema->{'additionalProperties'} ? :
890 1343 12 if ($additional) { }
6 6 elsif (my(@k) = grep({not $rules{$_};} @dkeys)) { }
891 1 1342 unless is_type($additional, 'HASH')
899 1257 92 unless $schema->{'required'}
900 77 25 if exists $data->{$k}
907 1530 10 unless exists $data->{$k}
908 9 1 if (ref $dependencies->{$k} eq 'ARRAY') { }
1 0 elsif (ref $dependencies->{$k} eq 'HASH') { }
921 26160 2614 unless exists $data->{$k}
922 637 1948 if ref $r eq 'HASH' and $r->{'$ref'}
925 160 2454 if @e or not is_type($r, 'HASH')
928 19 2435 if $r->{'enum'}
931 3 2451 if $r->{'const'}
942 16 521 if (not defined $value or ref $value)
945 22 0 if (B::svref_2object(\$value)->FLAGS & 12288 and 0 + $value eq $value and $value * 0 == 0)
950 21 1 unless $self->{'coerce'}{'strings'}
953 233 267 if ($schema->{'format'})
956 38 462 if (defined $schema->{'maxLength'})
957 14 24 if (length $value > $schema->{'maxLength'})
962 28 472 if (defined $schema->{'minLength'})
963 4 24 if (length $value < $schema->{'minLength'})
968 35 465 if (defined $schema->{'pattern'})
970 14 21 unless $value =~ /$p/