| 1 | package JSON::Validator::Schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 82 | ▶ | use Mojo::Base 'JSON::Validator'; # TODO: Change this to "use Mojo::Base -base" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 82 | ▶ | use Carp qw(carp); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 82 | ▶ | use JSON::Validator::Formats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 82 | ▶ | use JSON::Validator::URI qw(uri); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 82 | ▶ | use JSON::Validator::Util qw(E data_checksum data_type is_bool is_num is_type prefix_errors schema_type str2data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 82 | ▶ | use List::Util qw(first uniq); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 82 | ▶ | use Mojo::JSON qw(false true); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 82 | ▶ | use Mojo::JSON::Pointer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 82 | ▶ | use Mojo::Util qw(deprecated); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 82 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 19 | ▶ | has errors => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 19 | ▶ | my $specification = $self->specification || 'http://json-schema.org/draft-04/schema#'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->specification || 'http://json-schema.org/draft-04/schema#'
MC/DC100%1/1
$self->specification || 'http://json-schema.org/draft-04/schema#'
$self->specification
Truth table100%2/2
A
A= $self->specification
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 19 | my $validator = $self->new(store => $self->store, _refs => {})->coerce('numbers,strings')->resolve($specification); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 19 | return [$self->_validate_id($self->id), $validator->validate($self->data)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 82 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 169 | ▶ | has formats => sub { shift->_build_formats }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1616 | ▶ | has id => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 1616 | my $data = shift->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 1616 | ▶ | return is_type($data, 'HASH') ? $data->{'$id'} || $data->{id} || '' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%5/5
$data->{"\$id"} or $data->{"id"} or ""
$data->{"\$id"} or $data->{"id"}
MC/DC100%2/2
$data->{"\$id"} or $data->{"id"} or ""
$data->{"\$id"}
$data->{"id"}
Truth table100%3/3
A or B
A= $data->{"\$id"}B= $data->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 82 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | has moniker => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | return "draft$1" if $self->specification =~ m!draft-(\d+)!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 0 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 82 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 82 | has recursive_data_protection => 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | has specification => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my $data = shift->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | ▶ | is_type($data, 'HASH') ? $data->{'$schema'} || $data->{schema} || '' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition40%2/5
$data->{"\$schema"} or $data->{"schema"} or ""
$data->{"\$schema"} or $data->{"schema"}
MC/DC0%0/2
$data->{"\$schema"} or $data->{"schema"} or ""
$data->{"\$schema"}
$data->{"schema"}
Truth table33%1/3
A or B
A= $data->{"\$schema"}B= $data->{"schema"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 82 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 18 | ▶ | has _ref_keys => sub { [qw($ref)] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | has _refs => sub { +{} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 24 | ▶ | sub bundle { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bundle: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 24 | my ($self, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 24 | ▶ | my $data = $args->{schema} // $self->data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$args->{"schema"} // $self->data
MC/DC0%0/2
$args->{"schema"} // $self->data
$args->{"schema"}
$self->data
Truth table66%2/3
A // B
A= $args->{"schema"}B= $self->data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # Avoid $ref on top level | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 24 | ▶ | while (ref $data eq 'HASH' and $data->{'$ref'} and !ref $data->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
ref $data eq "HASH" and $data->{"\$ref"} and not ref $data->{"\$ref"}
ref $data eq "HASH" and $data->{"\$ref"}
MC/DC33%1/3
ref $data eq "HASH" and $data->{"\$ref"} and not ref $data->{"\$ref"}
ref $data eq "HASH"
$data->{"\$ref"}
not ref $data->{"\$ref"}
Truth table50%2/4
A and B and not(C)
A= ref $data eq "HASH"B= $data->{"\$ref"}C= not ref $data->{"\$ref"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 5 | $data = $self->_refs->{$data}{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | # Check if we have a complex schema or not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 24 | ▶ | return $self->new(%$self) unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 24 | my $bundle = $self->new(%$self, data => {}, _refs => {}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 24 | local $bundle->{seen_bundle_ref} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 24 | local $bundle->{seen_schema} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 24 | $bundle->_bundle_from({base_url => $self->id, root => $self->data, schema => $data}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 24 | my $id = JSON::Validator::URI->new->from_data($bundle->data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 24 | ▶ | $bundle->id($bundle->store->exists($id) ? $id : $self->store->add($id, $bundle->data)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 24 | return $bundle; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub contains { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
contains: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | deprecated 'contains() is deprecated'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | state $p = Mojo::JSON::Pointer->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | return $p->data(shift->{data})->contains(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 9730 | ▶ | sub data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 9730 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 9730 | ▶ | return $self->{data} //= {} unless @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->{"data"} //= {}
MC/DC0%0/1
$self->{"data"} //= {}
$self->{"data"}
Truth table50%1/2
A
A= $self->{"data"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2335 | $self->{data} = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2335 | delete $self->{errors}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2335 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 383 | ▶ | sub get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 383 | my ($self, $pointer, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 383 | my %state = (path => [], root => $self->data, schema => $self->data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 383 | ▶ | return $self->_get([@$pointer], \%state, $cb) if is_type $pointer, 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 62 | ▶ | return $self->_get([split '/', $pointer], \%state, $cb) if $pointer =~ s!^/!!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | return length $pointer ? undef : $self->data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | sub is_invalid { !!@{shift->errors} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_invalid: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub load_and_validate_schema { Carp::confess('load_and_validate_schema(...) is unsupported.') } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load_and_validate_schema: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1720 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1720 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1720 | ▶ | return $class->SUPER::new(@_) unless @_ % 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1148 | my $data = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1148 | ▶ | $data = str2data $data if !ref $data and $data =~ m!^\{|^---|\n!s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $data and $data =~ /^\{|^---|\n/su
MC/DC100%2/2
not ref $data and $data =~ /^\{|^---|\n/su
not ref $data
$data =~ /^\{|^---|\n/su
Truth table100%3/3
not(A) and B
A= not ref $dataB= $data =~ /^\{|^---|\n/su
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1148 | return $class->SUPER::new(@_)->resolve($data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 2329 | ▶ | sub resolve { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resolve: called CC=19 SCAR=29.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 2329 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2329 | ▶ | my $data = shift // $self->data; # $self->data will get deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
shift() // $self->data
MC/DC0%0/2
shift() // $self->data
shift()
$self->data
Truth table66%2/3
A // B
A= shift()B= $self->data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 2329 | ▶ | my $state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
builtin::blessed($data) and $data->can("to_abs")
MC/DC100%2/2
builtin::blessed($data) and $data->can("to_abs")
builtin::blessed($data)
$data->can("to_abs")
Truth table100%3/3
A and B
A= builtin::blessed($data)B= $data->can("to_abs")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | = !ref $data ? $self->store->resolve($data) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | : (blessed $data && $data->can('to_abs')) ? $self->store->resolve($data->to_abs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | : {root => $data, schema => $data}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 2327 | $self->_refs({}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 2327 | $self->data($state->{schema}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2327 | ▶ | $self->id($state->{id} || JSON::Validator::URI->new->from_data($state->{schema})) unless $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$state->{'id'} || 'JSON::Validator::URI'->new->from_data($state->{'schema'})
MC/DC0%0/2
$state->{'id'} || 'JSON::Validator::URI'->new->from_data($state->{'schema'})
$state->{'id'}
'JSON::Validator::URI'->new->from_data($state->{'schema'})
Truth table66%2/3
A || B
A= $state->{'id'}B= 'JSON::Validator::URI'->new->from_data($state->{'schema'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2327 | ▶ | $state->{id} ||= $self->store->exists($self->id) || $self->store->add($self->id, $self->data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%4/6
$state->{"id"} ||= $self->store->exists($self->id) || $self->store->add($self->id, $self->data)
$self->store->exists($self->id) || $self->store->add($self->id, $self->data)
MC/DC0%0/3
$state->{"id"} ||= $self->store->exists($self->id) || $self->store->add($self->id, $self->data)
$state->{"id"}
$self->store->exists($self->id)
$self->store->add($self->id, $self->data)
Truth table0%0/4
A ||= B || C
A= $state->{"id"}B= $self->store->exists($self->id)C= $self->store->add($self->id, $self->data)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2327 | ▶ | $state->{base_url} ||= $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$state->{"base_url"} ||= $self->id
MC/DC0%0/2
$state->{"base_url"} ||= $self->id
$state->{"base_url"}
$self->id
Truth table66%2/3
A ||= B
A= $state->{"base_url"}B= $self->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 2327 | my (@topics, @refs, %seen) = ([$state, $state->{schema}]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Search the whole document for id/$id/$ref/$recursiveRef/... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | TOPIC: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 3970 | ▶ | while (@topics) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 386622 | my ($state, $schema) = @{shift @topics}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 386622 | ▶ | if (is_type $schema, 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 35713 | push @topics, map { [$state, $_] } @$schema; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif (is_type $schema, 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 278052 | ▶ | next TOPIC if $seen{$schema}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 215831 | $state = $self->_resolve_object($state, $schema, \@refs, \my %found); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 215831 | ▶ | ref $schema->{$_} and !$found{$_} and push @topics, [$state, $schema->{$_}] for keys %$schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $schema->{$_} and not $found{$_}
MC/DC50%1/2
ref $schema->{$_} and not $found{$_}
ref $schema->{$_}
not $found{$_}
Truth table66%2/3
A and not(B)
A= ref $schema->{$_}B= not $found{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # Need to resolve the $ref/$recursiveRef/... after id/$id/$anchor/... is found above | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3970 | @topics = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 3970 | ▶ | while (my $r = shift @refs) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 62385 | my ($schema, $state) = @$r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 62385 | my $resolved = $self->store->resolve($self->_extract_ref_from_schema($schema), $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 62383 | $self->_refs->{$schema} = $resolved; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 62383 | push @topics, [$resolved, $resolved->{schema}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # Traverse the newly discovered sub documents, if any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 3968 | ▶ | goto TOPIC if @topics; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 2325 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 1566 | ▶ | sub validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1566 | my ($self, $data, $schema) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1566 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1566 | my %state = (base_url => $self->id, path => [], root => $self->data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | my @errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 1566 | ▶ | = sort { $a->path cmp $b->path } $self->_validate($_[1], $self->_state(\%state, schema => $schema // $self->data)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$schema // $self->data
MC/DC0%0/2
$schema // $self->data
$schema
$self->data
Truth table66%2/3
A // B
A= $schemaB= $self->data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1566 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | sub schema { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | deprecated 'schema() is deprecated'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $_[0]->can('data') ? $_[0] : $_[0]->SUPER::schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 139 | ▶ | sub _build_formats { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_formats: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 'byte' => JSON::Validator::Formats->can('check_byte'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 'date' => JSON::Validator::Formats->can('check_date'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 'date-time' => JSON::Validator::Formats->can('check_date_time'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 'duration' => JSON::Validator::Formats->can('check_duration'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 'double' => JSON::Validator::Formats->can('check_double'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 'email' => JSON::Validator::Formats->can('check_email'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 'float' => JSON::Validator::Formats->can('check_float'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 'hostname' => JSON::Validator::Formats->can('check_hostname'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 'idn-email' => JSON::Validator::Formats->can('check_idn_email'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 'idn-hostname' => JSON::Validator::Formats->can('check_idn_hostname'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 'int32' => JSON::Validator::Formats->can('check_int32'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 'int64' => JSON::Validator::Formats->can('check_int64'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 'ipv4' => JSON::Validator::Formats->can('check_ipv4'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 'ipv6' => JSON::Validator::Formats->can('check_ipv6'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 'iri' => JSON::Validator::Formats->can('check_iri'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 'iri-reference' => JSON::Validator::Formats->can('check_iri_reference'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 'json-pointer' => JSON::Validator::Formats->can('check_json_pointer'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 'regex' => JSON::Validator::Formats->can('check_regex'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 'relative-json-pointer' => JSON::Validator::Formats->can('check_relative_json_pointer'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | 'string' => sub { undef }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 139 | 'time' => JSON::Validator::Formats->can('check_time'), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 'uri' => JSON::Validator::Formats->can('check_uri'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 'uri-reference' => JSON::Validator::Formats->can('check_uri_reference'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 'uri-reference' => JSON::Validator::Formats->can('check_uri_reference'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 'uri-template' => JSON::Validator::Formats->can('check_uri_template'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 'uuid' => JSON::Validator::Formats->can('check_uuid'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # $self inside _bundle() is the target bundle schema object and not the source | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 24 | ▶ | sub _bundle_from { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bundle_from: called CC=18 SCAR=30.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 24 | my ($self, $root_state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 24 | my @topics = ([$root_state, $root_state->{schema}, $self->data, []]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 24 | ▶ | while (my $topic = shift @topics) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 201 | my ($state, $source, $target, $path) = @$topic; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 201 | ▶ | next if $state->{seen_schema}{$target}++; # Avoid recursion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 190 | ▶ | if (ref $source eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 186 | for my $k (keys %$source) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 296 | ▶ | if ($k eq '$ref') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 48 | local @$state{qw(root_state schema_path)} = ($root_state, $path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 48 | push @topics, $self->_bundle_ref($state, $source, $target); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 248 | my $type = ref $source->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 248 | ▶ | $target->{$k} //= $type eq 'HASH' ? {} : $type eq 'ARRAY' ? [] : $source->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$target->{$k} //= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->{$k})
MC/DC0%0/2
$target->{$k} //= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->{$k})
$target->{$k}
$type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->{$k})
Truth table33%1/3
A //= B
A= $target->{$k}B= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->{$k})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 248 | ▶ | push @topics, [$state, $source->{$k}, $target->{$k}, [@$path, $k]] if $type eq 'HASH' or $type eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$type eq "HASH" or $type eq "ARRAY"
MC/DC100%2/2
$type eq "HASH" or $type eq "ARRAY"
$type eq "HASH"
$type eq "ARRAY"
Truth table100%3/3
A or B
A= $type eq "HASH"B= $type eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | elsif (ref $source eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | for my $i (0 .. @$source - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my $type = ref $source->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | $target->[$i] //= $type eq 'HASH' ? {} : $type eq 'ARRAY' ? [] : $source->[$i]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$target->[$i] //= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->[$i])
MC/DC0%0/2
$target->[$i] //= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->[$i])
$target->[$i]
$type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->[$i])
Truth table33%1/3
A //= B
A= $target->[$i]B= $type eq "HASH" ? {} : ($type eq "ARRAY" ? [] : $source->[$i])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | push @topics, [$state, $source->[$i], $target->[$i], [@$path, $i]] if $type eq 'HASH' or $type eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$type eq "HASH" or $type eq "ARRAY"
MC/DC0%0/2
$type eq "HASH" or $type eq "ARRAY"
$type eq "HASH"
$type eq "ARRAY"
Truth table33%1/3
A or B
A= $type eq "HASH"B= $type eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | warn "This should not happen! _bundle_from << $source => $target"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 47 | ▶ | sub _bundle_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bundle_ref: called CC=9 SCAR=22.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 47 | my ($self, $state, $source, $target) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | my $uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | = $state->{base_url} eq $state->{root_state}{base_url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | ? uri($source->{'$ref'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 47 | ▶ | : uri($source->{'$ref'}, $state->{base_url}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 47 | my $source_state = $self->store->resolve($source->{'$ref'}, $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 47 | my $prefix = join '-', map { s!^/+!!; $_ } grep { length $_ } pop @{$uri->path}, $uri->fragment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 47 | my ($i, $suffix, @path) = (-1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 47 | ▶ | while (++$i <= 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 47 | ▶ | $suffix ||= data_checksum $source_state->{schema} if $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$suffix ||= data_checksum($source_state->{"schema"})
MC/DC0%0/2
$suffix ||= data_checksum($source_state->{"schema"})
$suffix
data_checksum($source_state->{"schema"})
Truth table0%0/3
A ||= B
A= $suffixB= data_checksum($source_state->{"schema"})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 47 | ▶ | @path = $self->_bundle_ref_path_expand($source_state, $i ? join '-', $prefix, substr $suffix, 0, $i * 4 : $prefix); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 47 | $path[-1] =~ s!^\W+!!; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 47 | $path[-1] =~ s![^\w-]!_!g; # Make a pretty path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 47 | ▶ | last unless $self->{seen_bundle_ref}{@path}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 47 | my $def_target = $self->data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 47 | $target->{'$ref'} = join '/', '#', @path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 47 | ▶ | $def_target = $def_target->{$_} //= {} for @path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$def_target->{$_} //= {}
MC/DC100%1/1
$def_target->{$_} //= {}
$def_target->{$_}
Truth table100%2/2
A
A= $def_target->{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 47 | $self->_refs->{$target} = $source_state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 47 | return [$source_state, $source_state->{schema}, $def_target, $state->{schema_path}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 45 | ▶ | sub _bundle_ref_path_expand { local $_ = $_[2]; s!^definitions/!!; return 'definitions', $_; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_bundle_ref_path_expand: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 1401 | ▶ | sub _extract_ref_from_schema { $_[1]->{'$ref'} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_extract_ref_from_schema: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 530 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: called CC=11 SCAR=24.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 530 | my ($self, $pointer, $state, $cb) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 530 | my $path = $state->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 530 | my $schema = $state->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 1574 | ▶ | my $follow_ref = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 1574 | ▶ | return if $pointer->[0] and $pointer->[0] eq '$ref'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$pointer->[0] and $pointer->[0] eq "\$ref"
MC/DC100%2/2
$pointer->[0] and $pointer->[0] eq "\$ref"
$pointer->[0]
$pointer->[0] eq "\$ref"
Truth table100%3/3
A and B
A= $pointer->[0]B= $pointer->[0] eq "\$ref"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 1572 | my $ref_keys = $self->_ref_keys; # ($ref, $recursiveRef ...) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 1572 | my $schema_lookup = $schema; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 1572 | ▶ | while (ref $schema eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 1531 | ▶ | last unless my $ref_key = first { $schema->{$_} && !ref $schema->{$_} } @$ref_keys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 34 | ▶ | $state = $self->_refs->{$schema_lookup} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_refs->{$schema_lookup} // Carp::confess(qq[resolve() must be called before validate() to lookup "$schema_lookup->{$ref_key}".])
MC/DC0%0/1
$self->_refs->{$schema_lookup} // Carp::confess(qq[resolve() must be called before validate() to lookup "$schema_lookup->{$ref_key}".])
$self->_refs->{$schema_lookup}
Truth table50%1/2
A
A= $self->_refs->{$schema_lookup}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | // Carp::confess(qq(resolve() must be called before validate() to lookup "$schema_lookup->{$ref_key}".)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 34 | ▶ | if (is_type $state->{schema}, 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 34 | $schema_lookup = $state->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 34 | $schema = {%{$state->{schema}}, %$schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 34 | ▶ | $state->{schema}{'$ref'} ? ($schema->{'$ref'} = $state->{schema}{'$ref'}) : delete $schema->{'$ref'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | $state->{schema}{'$recursiveRef'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ? ($schema->{'$recursiveRef'} = $state->{schema}{'$recursiveRef'}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 34 | ▶ | : delete $schema->{'$recursiveRef'}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | $schema = $schema_lookup = $state->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 34 | $state = {%$state, path => $path, schema => $schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 530 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 530 | $follow_ref->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 530 | ▶ | while (@$pointer) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 1234 | my $p = shift @$pointer; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 1234 | ▶ | unless (defined $p) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 7 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | return Mojo::Collection->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 14 | ▶ | map { $self->_get([@$pointer], {%$state, path => [@$path, $_->[1]], schema => $_->[0]}, $cb) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | ▶ | ref $schema eq 'ARRAY' ? (map { [$_, $i++] } @$schema) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 7 | : ref $schema eq 'HASH' ? (map { [$schema->{$_}, $_] } sort keys %$schema) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | : ([$schema, ''])); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 1227 | $p =~ s!~1!/!g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 1227 | $p =~ s/~0/~/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 1227 | push @$path, $p; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 1227 | ▶ | if (ref $schema eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 1207 | ▶ | return undef unless exists $schema->{$p}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1024 | $schema = $schema->{$p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | elsif (ref $schema eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 20 | ▶ | return undef unless $p =~ /^\d+$/ and @$schema > $p; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$p =~ /^\d+$/u and @$schema > $p
MC/DC0%0/2
$p =~ /^\d+$/u and @$schema > $p
$p =~ /^\d+$/u
@$schema > $p
Truth table33%1/3
A and B
A= $p =~ /^\d+$/uB= @$schema > $p
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 20 | $schema = $schema->[$p]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 1044 | $follow_ref->(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 340 | ▶ | return $cb->($schema, E($path)->path) if $cb; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 337 | return $schema; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 3 | ▶ | sub _register_ref { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_register_ref: called CC=5 SCAR=19.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | my ($self, $ref, %state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | ▶ | $state{base_url} //= $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$state{"base_url"} //= $self->id
MC/DC0%0/2
$state{"base_url"} //= $self->id
$state{"base_url"}
$self->id
Truth table33%1/3
A //= B
A= $state{"base_url"}B= $self->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 3 | ▶ | $state{id} //= $self->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$state{"id"} //= $self->id
MC/DC0%0/2
$state{"id"} //= $self->id
$state{"id"}
$self->id
Truth table33%1/3
A //= B
A= $state{"id"}B= $self->id
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | ▶ | $state{root} //= $self->data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$state{"root"} //= $self->data
MC/DC0%0/2
$state{"root"} //= $self->data
$state{"root"}
$self->data
Truth table33%1/3
A //= B
A= $state{"root"}B= $self->data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | ▶ | $state{source} //= '_register_ref'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$state{"source"} //= "_register_ref"
MC/DC0%0/1
$state{"source"} //= "_register_ref"
$state{"source"}
Truth table50%1/2
A
A= $state{"source"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 3 | $self->_refs->{$ref} = \%state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 6569 | ▶ | sub _resolve_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_resolve_object: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 6569 | my ($self, $state, $schema, $refs, $found) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 6569 | ▶ | if ($schema->{id} and !ref $schema->{id}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$schema->{"id"} and not ref $schema->{"id"}
MC/DC100%2/2
$schema->{"id"} and not ref $schema->{"id"}
$schema->{"id"}
not ref $schema->{"id"}
Truth table100%3/3
A and not(B)
A= $schema->{"id"}B= not ref $schema->{"id"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 29 | my $id = uri $schema->{id}, $state->{base_url}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 29 | $self->store->add($id => $schema); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 29 | $state = {%$state, base_url => $id->fragment(undef), id => $id}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 6569 | ▶ | if ($found->{'$ref'} = $schema->{'$ref'} && !ref $schema->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$schema->{'$ref'} && !ref($schema->{'$ref'})
MC/DC100%2/2
$schema->{'$ref'} && !ref($schema->{'$ref'})
$schema->{'$ref'}
!ref($schema->{'$ref'})
Truth table100%3/3
A && not(B)
A= $schema->{'$ref'}B= !ref($schema->{'$ref'})
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2100 | push @$refs, [$schema, $state]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 6569 | return $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 3714 | ▶ | sub _state { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_state: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 3714 | my ($self, $curr, %override) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 3714 | my $schema = $override{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 3714 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 3714 | ▶ | while (ref $schema eq 'HASH' and $schema->{'$ref'} and !ref $schema->{'$ref'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
ref $schema eq "HASH" and $schema->{"\$ref"} and not ref $schema->{"\$ref"}
ref $schema eq "HASH" and $schema->{"\$ref"}
MC/DC66%2/3
ref $schema eq "HASH" and $schema->{"\$ref"} and not ref $schema->{"\$ref"}
ref $schema eq "HASH"
$schema->{"\$ref"}
not ref $schema->{"\$ref"}
Truth table75%3/4
A and B and not(C)
A= ref $schema eq "HASH"B= $schema->{"\$ref"}C= not ref $schema->{"\$ref"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 729 | ▶ | last if $seen{$schema}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | $schema = $self->_refs->{$schema}{schema} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 729 | ▶ | // Carp::confess(qq(resolve() must be called before validate() to lookup "$schema->{'$ref'}".)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->_refs->{$schema}{"schema"} // Carp::confess(qq[resolve() must be called before validate() to lookup "$schema->{"\$ref"}".])
MC/DC0%0/1
$self->_refs->{$schema}{"schema"} // Carp::confess(qq[resolve() must be called before validate() to lookup "$schema->{"\$ref"}".])
$self->_refs->{$schema}{"schema"}
Truth table50%1/2
A
A= $self->_refs->{$schema}{"schema"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 3714 | return {%$curr, %override, schema => $schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 51497 | ▶ | sub _validate { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate: called CC=24 SCAR=31.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 51497 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 51497 | my $schema = $state->{schema}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 51497 | ▶ | return $schema ? () : E $state->{path}, [not => 'not'] if is_bool $schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 51405 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 51405 | ▶ | if ($self->recursive_data_protection and 2 == grep { ref $_ && !is_bool($_) } $data, $schema) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$self->recursive_data_protection and 2 == grep({ref $_ and not is_bool($_);} $data, $schema)
ref $_ && !is_bool($_)
MC/DC100%2/2
$self->recursive_data_protection and 2 == grep({ref $_ and not is_bool($_);} $data, $schema)
$self->recursive_data_protection
2 == grep({ref $_ and not is_bool($_);} $data, $schema)
MC/DC100%2/2
ref $_ && !is_bool($_)
ref $_
!is_bool($_)
Truth table100%3/3
A and B
A= $self->recursive_data_protectionB= 2 == grep({ref $_ and not is_bool($_);} $data, $schema)
Truth table100%3/3
A && not(B)
A= ref $_B= !is_bool($_)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 26485 | my $seen_addr = "$schema:$data"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 26485 | my $seen = $self->{seen}{$seen_addr}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 26485 | ▶ | return @{$seen->[0]} if $seen; # Avoid recursion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Keep $schema and $data referenced for the rest of this validation run, so | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | # their memory addresses cannot be reused by transient (merged) schemas built | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | # later while following $ref/$dynamicRef. Otherwise this address-based cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # key collides with a freed entry and returns stale errors (GH #272). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 26483 | $self->{seen}{$seen_addr} = [\@errors, $schema, $data]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | 51403 | ▶ | local $_[1] = $data->TO_JSON if blessed $data and $data->can('TO_JSON'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($data) and $data->can("TO_JSON")
MC/DC100%2/2
builtin::blessed($data) and $data->can("TO_JSON")
builtin::blessed($data)
$data->can("TO_JSON")
Truth table100%3/3
A and B
A= builtin::blessed($data)B= $data->can("TO_JSON")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 51403 | ▶ | if ($schema->{not}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 133 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 133 | my @e = $self->_validate($_[1], $self->_state($state, schema => $schema->{not})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 133 | ▶ | push @errors, E $state->{path}, [not => 'not'] unless @e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 51403 | ▶ | if (my $rules = $schema->{allOf}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 628 | push @errors, $self->_validate_all_of($_[1], {%$state, schema => $rules}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 51403 | ▶ | if (my $rules = $schema->{anyOf}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 688 | push @errors, $self->_validate_any_of($_[1], {%$state, schema => $rules}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 51403 | ▶ | if (my $rules = $schema->{oneOf}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 755 | push @errors, $self->_validate_one_of($_[1], {%$state, schema => $rules}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 51403 | ▶ | if (exists $schema->{if}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 3007 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | my $rules = !$schema->{if} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 3007 | ▶ | || $self->_validate($_[1], $self->_state($state, schema => $schema->{if})) ? $schema->{else} : $schema->{then}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $schema->{"if"} or $self->_validate($_[1], $self->_state($state, "schema", $schema->{"if"}))
MC/DC50%1/2
not $schema->{"if"} or $self->_validate($_[1], $self->_state($state, "schema", $schema->{"if"}))
not $schema->{"if"}
$self->_validate($_[1], $self->_state($state, "schema", $schema->{"if"}))
Truth table66%2/3
not(A) or B
A= not $schema->{"if"}B= $self->_validate($_[1], $self->_state($state, "schema", $schema->{"if"}))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 3007 | ▶ | push @errors, $self->_validate($_[1], $self->_state($state, schema => $rules // {})); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rules // {}
MC/DC100%1/1
$rules // {}
$rules
Truth table100%2/2
A
A= $rules
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 51403 | ▶ | my $type = $schema->{type} || schema_type $schema, $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$schema->{'type'} || schema_type($schema, $_[1])
MC/DC100%2/2
$schema->{'type'} || schema_type($schema, $_[1])
$schema->{'type'}
schema_type($schema, $_[1])
Truth table100%3/3
A || B
A= $schema->{'type'}B= schema_type($schema, $_[1])
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 51403 | ▶ | if (ref $type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 265 | push @errors, $self->_validate_any_of_types($_[1], {%$state, schema => [map { +{%$schema, type => $_} } @$type]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | elsif ($type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 18761 | my $method = sprintf '_validate_type_%s', $type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 18761 | push @errors, $self->$method($_[1], $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 51403 | ▶ | return @errors if @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 45121 | ▶ | if (exists $schema->{const}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 1034 | push @errors, $self->_validate_type_const($_[1], $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 45121 | ▶ | if ($schema->{enum}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 825 | push @errors, $self->_validate_type_enum($_[1], $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 45121 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 628 | ▶ | sub _validate_all_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_all_of: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 628 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 628 | my (@errors, @errors_with_prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 628 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 628 | for my $rule (@{$state->{schema}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 3239 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | 3239 | ▶ | next unless my @e = $self->_validate($_[1], $self->_state($state, schema => $rule)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 29 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 29 | push @errors_with_prefix, [$i, @e]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3239 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 628 | ▶ | return if not @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 22 | my $e = E $state->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | return prefix_errors(allOf => @errors_with_prefix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | if @errors == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 22 | ▶ | or (grep { $_->details->[1] ne 'type' or $_->path ne $e->path } @errors); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
$_->details->[1] ne 'type' || $_->path ne $e->path
MC/DC100%2/2
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
@errors == 1
grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
MC/DC100%2/2
$_->details->[1] ne 'type' || $_->path ne $e->path
$_->details->[1] ne 'type'
$_->path ne $e->path
Truth table100%3/3
A or B
A= @errors == 1B= grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
Truth table100%3/3
A || B
A= $_->details->[1] ne 'type'B= $_->path ne $e->path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | # combine all 'type' errors at the base path together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 1 | my @details = map $_->details, @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | my $want_types = join '/', uniq map $_->[0], @details; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | return $e->details([allOf => type => $want_types, $details[-1][2]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 265 | ▶ | sub _validate_any_of_types { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_any_of_types: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 265 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 265 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 265 | for my $rule (@{$state->{schema}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 297 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 297 | ▶ | return unless my @e = $self->_validate($_[1], $self->_state($state, schema => $rule)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 50 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | # favor a non-type error from one of the rules | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 18 | my $e = E $state->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 18 | ▶ | if (my @e = grep { $_->details->[1] ne 'type' or $_->path ne $e->path } @errors) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$_->details->[1] ne 'type' || $_->path ne $e->path
MC/DC100%2/2
$_->details->[1] ne 'type' || $_->path ne $e->path
$_->details->[1] ne 'type'
$_->path ne $e->path
Truth table100%3/3
A || B
A= $_->details->[1] ne 'type'B= $_->path ne $e->path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 4 | return @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | # the type didn't match any of the rules: combine the errors together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 14 | my @details = map $_->details, @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 14 | my $want_types = join '/', uniq map $_->[0], @details; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 14 | return $e->details([$want_types => 'type', $details[-1][2]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 688 | ▶ | sub _validate_any_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_any_of: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 688 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 688 | my (@errors, @errors_with_prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 688 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 688 | for my $rule (@{$state->{schema}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 1219 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | 1219 | ▶ | return unless my @e = $self->_validate($_[1], $self->_state($state, schema => $rule)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | 545 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 545 | push @errors_with_prefix, [$i, @e]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 545 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | 14 | my $e = E $state->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | return prefix_errors(anyOf => @errors_with_prefix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | if @errors == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 14 | ▶ | or (grep { $_->details->[1] ne 'type' or $_->path ne $e->path } @errors); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
$_->details->[1] ne 'type' || $_->path ne $e->path
MC/DC100%2/2
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
@errors == 1
grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
MC/DC100%2/2
$_->details->[1] ne 'type' || $_->path ne $e->path
$_->details->[1] ne 'type'
$_->path ne $e->path
Truth table100%3/3
A or B
A= @errors == 1B= grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
Truth table100%3/3
A || B
A= $_->details->[1] ne 'type'B= $_->path ne $e->path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | # combine all 'type' errors at the base path together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 1 | my @details = map $_->details, @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 1 | my $want_types = join '/', uniq map $_->[0], @details; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 1 | return $e->details([anyOf => type => $want_types, $details[-1][2]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 19 | ▶ | sub _validate_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_id: called CC=6 SCAR=18.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 19 | my ($self, $id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 19 | ▶ | return unless length $id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 19 | ▶ | return E '/id', 'Fragment not allowed.' if $id =~ /\#./; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 18 | ▶ | return E '/id', 'Relative URL not allowed.' unless $id =~ /^\w+:/ or -e $id or $id =~ m!^/!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
$id =~ /^\w+:/u or -e $id or $id =~ m[^/]u
$id =~ /^\w+:/u or -e $id
MC/DC33%1/3
$id =~ /^\w+:/u or -e $id or $id =~ m[^/]u
$id =~ /^\w+:/u
-e $id
$id =~ m[^/]u
Truth table50%2/4
A or B or C
A= $id =~ /^\w+:/uB= -e $idC= $id =~ m[^/]u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 16 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 755 | ▶ | sub _validate_one_of { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_one_of: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 755 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 755 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 755 | my (@errors, @errors_with_prefix); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 755 | my ($i, @passed) = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | 755 | for my $rule (@{$state->{schema}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 1544 | local $self->{seen} = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 1544 | my @e = $self->_validate($_[1], $self->_state($state, schema => $rule)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1544 | ▶ | push @passed, $i and next unless @e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition60%3/5
@e || push(@passed, $i) && (next)
push @passed, $i and next
MC/DC0%0/2
@e || push(@passed, $i) && (next)
@e
push @passed, $i
Truth table66%2/3
A || B
A= @eB= push @passed, $i
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 802 | push @errors_with_prefix, [$i, @e]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 802 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | continue { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 1544 | $i++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 755 | ▶ | return if @passed == 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 23 | ▶ | return E $path, [oneOf => 'all_rules_match'] unless @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 20 | ▶ | return E $path, [oneOf => 'n_rules_match', join(', ', @passed)] if @passed; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 18 | my $e = E $state->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | return prefix_errors(oneOf => @errors_with_prefix) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | if @errors == 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 18 | ▶ | or (grep { $_->details->[1] ne 'type' or $_->path ne $e->path } @errors); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
$_->details->[1] ne 'type' || $_->path ne $e->path
MC/DC100%2/2
@errors == 1 or grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
@errors == 1
grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
MC/DC100%2/2
$_->details->[1] ne 'type' || $_->path ne $e->path
$_->details->[1] ne 'type'
$_->path ne $e->path
Truth table100%3/3
A or B
A= @errors == 1B= grep {$_->details->[1] ne "type" or $_->path ne $e->path;} @errors
Truth table100%3/3
A || B
A= $_->details->[1] ne 'type'B= $_->path ne $e->path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | # the type didn't match any of the rules: combine the errors together | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 1 | my @details = map $_->details, @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 1 | my $want_types = join '/', uniq map $_->[0], @details; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 1 | return $e->details([oneOf => type => $want_types, $details[-1][2]]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 152 | ▶ | sub _validate_number_max { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_number_max: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | 152 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 152 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 152 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 152 | ▶ | my $cmp_with = $schema->{exclusiveMaximum} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"exclusiveMaximum"} // ""
MC/DC100%1/1
$schema->{"exclusiveMaximum"} // ""
$schema->{"exclusiveMaximum"}
Truth table100%2/2
A
A= $schema->{"exclusiveMaximum"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 152 | ▶ | if (is_bool $cmp_with) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | ▶ | push @errors, E $path, [$expected => ex_maximum => $value, $schema->{maximum}] unless $value < $schema->{maximum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | elsif (is_num $cmp_with) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | ▶ | push @errors, E $path, [$expected => ex_maximum => $value, $cmp_with] unless $value < $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 152 | ▶ | if (exists $schema->{maximum}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 20 | my $cmp_with = $schema->{maximum}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 20 | ▶ | push @errors, E $path, [$expected => maximum => $value, $cmp_with] unless $value <= $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | 152 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 152 | ▶ | sub _validate_number_min { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_number_min: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 152 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 152 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 152 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 152 | ▶ | my $cmp_with = $schema->{exclusiveMinimum} // ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"exclusiveMinimum"} // ""
MC/DC100%1/1
$schema->{"exclusiveMinimum"} // ""
$schema->{"exclusiveMinimum"}
Truth table100%2/2
A
A= $schema->{"exclusiveMinimum"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 152 | ▶ | if (is_bool $cmp_with) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 2 | ▶ | push @errors, E $path, [$expected => ex_minimum => $value, $schema->{minimum}] unless $value > $schema->{minimum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | elsif (is_num $cmp_with) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 2 | ▶ | push @errors, E $path, [$expected => ex_minimum => $value, $cmp_with] unless $value > $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 152 | ▶ | if (exists $schema->{minimum}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 31 | my $cmp_with = $schema->{minimum}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 31 | ▶ | push @errors, E $path, [$expected => minimum => $value, $cmp_with] unless $value >= $cmp_with; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 152 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 1434 | ▶ | sub _validate_type_enum { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_enum: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 1434 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 1434 | my $enum = $state->{schema}{enum}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 1434 | my $m = data_checksum $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 1434 | for my $i (@$enum) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | 4274 | ▶ | return if $m eq data_checksum $i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 69 | ▶ | $enum = join ', ', map { (!defined or ref) ? Mojo::JSON::encode_json($_) : $_ } @$enum; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $_ or ref $_
MC/DC50%1/2
not defined $_ or ref $_
not defined $_
ref $_
Truth table66%2/3
not(A) or B
A= not defined $_B= ref $_
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 69 | return E $state->{path}, [enum => enum => $enum]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 4558 | ▶ | sub _validate_type_const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_const: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 4558 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 4558 | my $const = $state->{schema}{const}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | 4558 | ▶ | return if data_checksum($data) eq data_checksum($const); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 1523 | return E $state->{path}, [const => const => Mojo::JSON::encode_json($const)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 303 | ▶ | sub _validate_format { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_format: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 303 | my ($self, $value, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 303 | my $format = $state->{schema}{format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 303 | my $code = $self->formats->{$format}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 303 | ▶ | return do { warn "Format rule for '$format' is missing"; return } unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | 302 | ▶ | return unless my $err = $code->($value); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 67 | return E $state->{path}, [format => $format, $err]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 5 | ▶ | sub _validate_type_any { } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_any: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 163 | ▶ | sub _validate_type_array { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_array: called CC=23 SCAR=31.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 163 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 163 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 163 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 163 | ▶ | if (ref $data ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 71 | return E $path, [array => type => data_type $data]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 92 | ▶ | if (defined $schema->{minItems} and $schema->{minItems} > @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $schema->{"minItems"} and $schema->{"minItems"} > @$data
MC/DC100%2/2
defined $schema->{"minItems"} and $schema->{"minItems"} > @$data
defined $schema->{"minItems"}
$schema->{"minItems"} > @$data
Truth table100%3/3
A and B
A= defined $schema->{"minItems"}B= $schema->{"minItems"} > @$data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 1 | push @errors, E $path, [array => minItems => int(@$data), $schema->{minItems}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 92 | ▶ | if (defined $schema->{maxItems} and $schema->{maxItems} < @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $schema->{"maxItems"} and $schema->{"maxItems"} < @$data
MC/DC100%2/2
defined $schema->{"maxItems"} and $schema->{"maxItems"} < @$data
defined $schema->{"maxItems"}
$schema->{"maxItems"} < @$data
Truth table100%3/3
A and B
A= defined $schema->{"maxItems"}B= $schema->{"maxItems"} < @$data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | 2 | push @errors, E $path, [array => maxItems => int(@$data), $schema->{maxItems}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 92 | ▶ | if ($schema->{uniqueItems}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | 10 | my %uniq; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 10 | for (@$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 25 | ▶ | next if !$uniq{data_checksum($_)}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 5 | push @errors, E $path, [array => 'uniqueItems']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 5 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 92 | ▶ | if (exists $schema->{contains}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 8 | my ($contains, @e) = ($self->_state($state, schema => $schema->{contains})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 8 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | 13 | my @tmp = $self->_validate($data->[$i], {%$contains, path => [@$path, $i]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 13 | ▶ | push @e, \@tmp if @tmp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 8 | ▶ | push @errors, map {@$_} @e if @e >= @$data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 8 | ▶ | push @errors, E $path, [array => 'contains'] if not @$data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 92 | ▶ | if (ref $schema->{items} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 13 | ▶ | my $additional_items = $schema->{additionalItems} // {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{"additionalItems"} // {}
MC/DC100%1/1
$schema->{"additionalItems"} // {}
$schema->{"additionalItems"}
Truth table100%2/2
A
A= $schema->{"additionalItems"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 13 | my @rules = @{$schema->{items}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 13 | ▶ | if ($additional_items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 8 | ▶ | push @rules, $additional_items while @rules < @$data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 13 | ▶ | if (@rules >= @$data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 8 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 24 | push @errors, $self->_validate($data->[$i], $self->_state($state, path => [@$path, $i], schema => $rules[$i])); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | elsif (!$additional_items) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 5 | push @errors, E $path, [array => additionalItems => int(@$data), int(@rules)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | elsif (exists $schema->{items}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 62 | my $items = $self->_state($state, schema => $schema->{items}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 62 | for my $i (0 .. @$data - 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 130 | push @errors, $self->_validate($data->[$i], {%$items, path => [@$path, $i]}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 92 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | 623 | ▶ | sub _validate_type_boolean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_boolean: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | 623 | my ($self, $value, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | # String that looks like a boolean | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 623 | ▶ | if (defined $value and $self->{coerce}{booleans}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $value and $self->{"coerce"}{"booleans"}
MC/DC100%2/2
defined $value and $self->{"coerce"}{"booleans"}
defined $value
$self->{"coerce"}{"booleans"}
Truth table100%3/3
A and B
A= defined $valueB= $self->{"coerce"}{"booleans"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | 41 | ▶ | $_[1] = false if $value =~ m!^(0|false|)$!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 41 | ▶ | $_[1] = true if $value =~ m!^(1|true)$!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 623 | ▶ | return if is_bool $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 35 | return E $state->{path}, [boolean => type => data_type $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | 218 | ▶ | sub _validate_type_integer { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_integer: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 218 | my ($self, $value, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 218 | my @errors = $self->_validate_type_number($_[1], $state, 'integer'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | 218 | ▶ | return @errors if @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | 150 | ▶ | return if $value =~ /^-?\d+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | 1 | return E $state->{path}, [integer => type => data_type $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 6 | ▶ | sub _validate_type_null { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_null: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 6 | my ($self, $value, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | 6 | ▶ | return unless defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 3 | return E $state->{path}, [null => type => data_type $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | 393 | ▶ | sub _validate_type_number { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_number: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 393 | my ($self, $value, $state, $expected) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 393 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 393 | ▶ | $expected ||= 'number'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$expected ||= "number"
MC/DC100%1/1
$expected ||= "number"
$expected
Truth table100%2/2
A
A= $expected
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | 393 | ▶ | if (!defined $value or ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or ref $value
MC/DC100%2/2
not defined $value or ref $value
not defined $value
ref $value
Truth table100%3/3
not(A) or B
A= not defined $valueB= ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 3 | return E $state->{path}, [$expected => type => data_type $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | 390 | ▶ | unless (is_num $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | return E $state->{path}, [$expected => type => data_type $value] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | 186 | ▶ | if !$self->{coerce}{numbers} or $value !~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->{"coerce"}{"numbers"} and $value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u
MC/DC100%2/2
$self->{"coerce"}{"numbers"} and $value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u
$self->{"coerce"}{"numbers"}
$value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u
Truth table100%3/3
A and B
A= $self->{"coerce"}{"numbers"}B= $value =~ /^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 107 | $_[1] = 0 + $value; # coerce input value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 311 | ▶ | push @errors, $self->_validate_format($value, $state) if $state->{schema}{format}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | 311 | push @errors, $self->_validate_number_max($value, $state, $expected); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | 311 | push @errors, $self->_validate_number_min($value, $state, $expected); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | 311 | my $d = $state->{schema}{multipleOf}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 311 | ▶ | push @errors, E $state->{path}, [$expected => multipleOf => $d] if $d and ($value / $d) =~ /\.[^0]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$d and ($value / $d) =~ /\.[^0]+$/u
MC/DC100%2/2
$d and ($value / $d) =~ /\.[^0]+$/u
$d
($value / $d) =~ /\.[^0]+$/u
Truth table100%3/3
A and B
A= $dB= ($value / $d) =~ /\.[^0]+$/u
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | 311 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 486 | ▶ | sub _validate_type_object { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_object: called CC=39 SCAR=36.7
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | 486 | my ($self, $data, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 486 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | 486 | ▶ | return E $path, [object => type => data_type $data] unless ref $data eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 440 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 440 | my @dkeys = keys %$data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 440 | ▶ | if (defined $schema->{maxProperties} and $schema->{maxProperties} < @dkeys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $schema->{"maxProperties"} and $schema->{"maxProperties"} < @dkeys
MC/DC100%2/2
defined $schema->{"maxProperties"} and $schema->{"maxProperties"} < @dkeys
defined $schema->{"maxProperties"}
$schema->{"maxProperties"} < @dkeys
Truth table100%3/3
A and B
A= defined $schema->{"maxProperties"}B= $schema->{"maxProperties"} < @dkeys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 1 | push @errors, E $path, [object => maxProperties => int(@dkeys), $schema->{maxProperties}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 440 | ▶ | if (defined $schema->{minProperties} and $schema->{minProperties} > @dkeys) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $schema->{"minProperties"} and $schema->{"minProperties"} > @dkeys
MC/DC100%2/2
defined $schema->{"minProperties"} and $schema->{"minProperties"} > @dkeys
defined $schema->{"minProperties"}
$schema->{"minProperties"} > @dkeys
Truth table100%3/3
A and B
A= defined $schema->{"minProperties"}B= $schema->{"minProperties"} > @dkeys
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | 2 | push @errors, E $path, [object => minProperties => int(@dkeys), $schema->{minProperties}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 440 | ▶ | if (exists $schema->{propertyNames}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 3 | my $property_names = $self->_state($state, schema => $schema->{propertyNames}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | for my $name (keys %$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | 5 | ▶ | next unless my @e = $self->_validate($name, $property_names); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 2 | push @errors, prefix_errors propertyName => map [$name, $_], @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 440 | my %rules; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 440 | ▶ | for my $k (keys %{$schema->{properties} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'properties'} || {}
MC/DC100%1/1
$schema->{'properties'} || {}
$schema->{'properties'}
Truth table100%2/2
A
A= $schema->{'properties'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | 640 | my $r = $schema->{properties}{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | 640 | push @{$rules{$k}}, $r; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 640 | ▶ | if ($self->{coerce}{defaults} and ref $r eq 'HASH' and exists $r->{default} and !exists $data->{$k}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
$self->{"coerce"}{"defaults"} and ref $r eq "HASH" and exists $r->{"default"} and not exists $data->{$k}
$self->{"coerce"}{"defaults"} and ref $r eq "HASH" and exists $r->{"default"}
$self->{"coerce"}{"defaults"} and ref $r eq "HASH"
MC/DC25%1/4
$self->{"coerce"}{"defaults"} and ref $r eq "HASH" and exists $r->{"default"} and not exists $data->{$k}
$self->{"coerce"}{"defaults"}
ref $r eq "HASH"
exists $r->{"default"}
not exists $data->{$k}
Truth table40%2/5
A and B and C and not(D)
A= $self->{"coerce"}{"defaults"}B= ref $r eq "HASH"C= exists $r->{"default"}D= not exists $data->{$k}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | 1 | $data->{$k} = $r->{default}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 440 | ▶ | for my $p (keys %{$schema->{patternProperties} || {}}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'patternProperties'} || {}
MC/DC100%1/1
$schema->{'patternProperties'} || {}
$schema->{'patternProperties'}
Truth table100%2/2
A
A= $schema->{'patternProperties'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | 18 | my $r = $schema->{patternProperties}{$p}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | 18 | push @{$rules{$_}}, $r for grep { $_ =~ /$p/ } @dkeys; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 440 | ▶ | my $additional = exists $schema->{additionalProperties} ? $schema->{additionalProperties} : {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 440 | ▶ | if ($additional) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 437 | ▶ | $additional = {} unless is_type $additional, 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 437 | ▶ | $rules{$_} ||= [$additional] for @dkeys; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$rules{$_} ||= [$additional]
MC/DC100%1/1
$rules{$_} ||= [$additional]
$rules{$_}
Truth table100%2/2
A
A= $rules{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | 9 | elsif (my @k = grep { !$rules{$_} } @dkeys) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | 3 | local $" = ', '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 3 | return E $path, [object => additionalProperties => join ', ', sort @k]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 437 | ▶ | for my $k (uniq @{$schema->{required} || []}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'required'} || []
MC/DC100%1/1
$schema->{'required'} || []
$schema->{'required'}
Truth table100%2/2
A
A= $schema->{'required'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 108 | ▶ | next if exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 31 | push @errors, E [@$path, $k], [object => 'required']; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 31 | delete $rules{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 437 | ▶ | my $dependencies = $schema->{dependencies} || {}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$schema->{'dependencies'} || {}
MC/DC100%1/1
$schema->{'dependencies'} || {}
$schema->{'dependencies'}
Truth table100%2/2
A
A= $schema->{'dependencies'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 437 | for my $k (keys %$dependencies) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 11 | ▶ | next if not exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 3 | ▶ | if (ref $dependencies->{$k} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | push @errors, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | 2 | map { E [@$path, $_], [object => dependencies => $k] } grep { !exists $data->{$_} } @{$dependencies->{$k}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | elsif (ref $dependencies->{$k} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | 1 | push @errors, $self->_validate_type_object($data, $self->_state($state, schema => $schema->{dependencies}{$k})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 437 | for my $k (keys %rules) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 780 | for my $r (@{$rules{$k}}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 780 | ▶ | next unless exists $data->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | 683 | my $s2 = $self->_state($state, path => [@$path, $k], schema => $r); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | 683 | my @e = $self->_validate($data->{$k}, $s2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 683 | push @errors, @e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | 683 | ▶ | next if @e or !is_type $r, 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@e or not is_type($r, "HASH")
MC/DC100%2/2
@e or not is_type($r, "HASH")
@e
not is_type($r, "HASH")
Truth table100%3/3
A or not(B)
A= @eB= not is_type($r, "HASH")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | 387 | ▶ | push @errors, $self->_validate_type_enum($data->{$k}, $s2) if $r->{enum}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 387 | ▶ | push @errors, $self->_validate_type_const($data->{$k}, $s2) if $r->{const}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 437 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 3017 | ▶ | sub _validate_type_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_validate_type_string: called CC=16 SCAR=27.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 3017 | my ($self, $value, $state) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 3017 | my ($path, $schema) = @$state{qw(path schema)}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 3017 | my @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 3017 | ▶ | if (!$schema->{type} and !defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$schema->{"type"} or defined $value
MC/DC0%0/2
$schema->{"type"} or defined $value
$schema->{"type"}
defined $value
Truth table66%2/3
A or B
A= $schema->{"type"}B= defined $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 3017 | ▶ | if (!defined $value or ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $value or ref $value
MC/DC100%2/2
not defined $value or ref $value
not defined $value
ref $value
Truth table100%3/3
not(A) or B
A= not defined $valueB= ref $value
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 46 | return E $path, [string => type => data_type $value]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 2971 | ▶ | if (B::svref_2object(\$value)->FLAGS & (B::SVp_IOK | B::SVp_NOK) and 0 + $value eq $value and $value * 0 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
B::svref_2object(\$value)->FLAGS & 12288 and 0 + $value eq $value and $value * 0 == 0
B::svref_2object(\$value)->FLAGS & 12288 and 0 + $value eq $value
MC/DC33%1/3
B::svref_2object(\$value)->FLAGS & 12288 and 0 + $value eq $value and $value * 0 == 0
B::svref_2object(\$value)->FLAGS & 12288
0 + $value eq $value
$value * 0 == 0
Truth table50%2/4
A and B and C
A= B::svref_2object(\$value)->FLAGS & 12288B= 0 + $value eq $valueC= $value * 0 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | 28 | ▶ | return E $path, [string => type => data_type $value] unless $self->{coerce}{strings}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 4 | $_[1] = "$value"; # coerce input value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 2947 | ▶ | if ($schema->{format}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 287 | push @errors, $self->_validate_format($value, $state); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 2947 | ▶ | if (defined $schema->{maxLength}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | 45 | ▶ | if (length($value) > $schema->{maxLength}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 16 | push @errors, E $path, [string => maxLength => length($value), $schema->{maxLength}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | 2947 | ▶ | if (defined $schema->{minLength}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 37 | ▶ | if (length($value) < $schema->{minLength}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 3 | push @errors, E $path, [string => minLength => length($value), $schema->{minLength}]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 2947 | ▶ | if (defined $schema->{pattern}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 544 | my $p = $schema->{pattern}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | 544 | ▶ | push @errors, E $path, [string => pattern => $p] unless $value =~ /$p/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 2947 | return @errors; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | 82 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | =encoding utf8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | JSON::Validator::Schema - Base class for JSON::Validator schemas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | =head2 Basics | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | # Create a new schema from a file on disk | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | # It is also possible to create the object from JSON::Validator::Schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # but you most likely want to use one of the subclasses. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | my $schema = JSON::Validator::Schema::Draft7->new('file:///cool/beans.yaml'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # Validate the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | die $schema->errors->[0] if $schema->is_invalid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | # Validate data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | my @errors = $schema->validate({some => 'data'}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | die $errors[0] if @errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | =head2 Shared store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | my $store = JSON::Validator::Store->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | my $schema = JSON::Validator::Schema::Draft7->new(store => $store); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | # Will not fetch the file from web, if the $store has already retrieved | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | # the schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | $schema->resolve('https://api.example.com/cool/beans.json'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | =head2 Make a new validation class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | package JSON::Validator::Schema::SomeSchema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | use Mojo::Base 'JSON::Validator::Schema'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | has specification => 'https://api.example.com/my/spec.json#'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | L<JSON::Validator::Schema> is the base class for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | L<JSON::Validator::Schema::Draft4>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | L<JSON::Validator::Schema::Draft6>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | L<JSON::Validator::Schema::Draft7>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | L<JSON::Validator::Schema::Draft201909>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | L<JSON::Validator::Schema::OpenAPIv2> and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | L<JSON::Validator::Schema::OpenAPIv3>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | Any of the classes above can be used instead of L<JSON::Validator> if you know | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | which draft/version you are working with up front. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | =head2 Validation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | L<JSON::Validator::Schema> can both validate user input and the schema itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | A L<JSON::Validator::Schema> represents a set of validation rules stored in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | L</data>. The rules stored in the L</data> attribute will be used when calling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | the L</validate> method. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | The input to C<validate()> could be some data from a web request or some other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | user input. C<validate()> returns a list of L<JSON::Validator::Error> objects, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | if the user input (input to C<validate()>) contains invalid data. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | =item * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | The L</errors> and L</is_invalid> attributes has nothing to do with user input, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | meaning it is I<not> relevant for L</validate>. These two accessors are used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | check if the rules/schema stored in L</data> is correct. The validation is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | performed against the L</specification>. This is pretty much the same as: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | my $jv = JSON::Validator->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | my $draft7 = $jv->schema('http://json-schema.org/draft-07/schema#')->schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | my $schema = $jv->schema({name => {type => 'string'}})->schema; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | my @errors = $draft7->validate($schema->data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | =head2 errors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | $array_ref = $schema->errors; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | Holds the errors after checking L</data> against L</specification>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | C<$array_ref> containing no elements means L</data> is valid. Each element in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | the array-ref is a L<JSON::Validator::Error> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | This attribute is I<not> changed by L</validate>. It only reflects if the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | C<$schema> is valid. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | =head2 formats | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | $hash_ref = $schema->formats; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | $schema = $schema->formats(\%hash); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | Holds a hash-ref, where the keys are supported JSON type "formats", and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | the associated values hold code blocks which can validate the given format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | A code block should return C<undef> on success and an error string on error: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | sub { return defined $_[0] && $_[0] eq "42" ? undef : "Not the answer." }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | See L<JSON::Validator::Formats> for a list of supported formats. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | =head2 recursive_data_protection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | The value of this attribute will be copied into the created L</schema>. See | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | L<JSON::Validator::Schema/recursive_data_protection> for more details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | =head2 id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | $str = $schema->id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | $schema = $schema->id($str); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | Holds the ID for this schema. Usually extracted from C<"$id"> or C<"id"> in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | =head2 moniker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | $str = $schema->moniker; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | $schema = $schema->moniker("some_name"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | Used to get/set the moniker for the given schema. Will be "draft04" if | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | L</specification> points to a JSON Schema draft URL, and fallback to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | empty string if unable to guess a moniker name. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | This attribute will (probably) detect more monikers from a given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | L</specification> or C</id> in the future. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | =head2 recursive_data_protection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | $schema = $schema->recursive_data_protection($bool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | $bool = $schema->recursive_data_protection; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | Recursive data protection is active by default, however it can be deactivated | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | by assigning a false value to the L</recursive_data_protection> attribute. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | Recursive data protection can have a noticeable impact on memory usage when | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | validating large data structures. If you are encountering issues with memory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | and you can guarantee that you do not have any loops in your data structure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | then deactivating the recursive data protection may help. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | This attribute is EXPERIMENTAL and may change in a future release. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | B<Disclaimer: Use at your own risk, if you have any doubt then don't use it> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | =head2 specification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | $str = $schema->specification; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | $schema = $schema->specification($str); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | The URL to the specification used when checking for L</errors>. Usually | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | extracted from C<"$schema"> or C<"schema"> in L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | =head2 store | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | $store = $schema->store; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | Holds a L<JSON::Validator::Store> object that caches the retrieved schemas. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | This object can be shared amongst different schema objects to prevent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | a schema from having to be downloaded again. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | =head2 bundle | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | $bundled = $schema->bundle; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | C<$bundled> is a new L<JSON::Validator::Schema> object where none of the "$ref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | will point to external resources. This can be useful, if you want to have a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | bunch of files locally, but hand over a single file to a client. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | Mojo::File->new("client.json") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | ->spurt(Mojo::JSON::to_json($schema->bundle->data)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | =head2 coerce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | $schema = $schema->coerce('bool,def,num,str'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | $schema = $schema->coerce('booleans,defaults,numbers,strings'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | $hash_ref = $schema->coerce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | Set the given type to coerce. Before enabling coercion this module is very | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | strict when it comes to validating types. Example: The string C<"1"> is not the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | same as the number C<1>, unless you have "numbers" coercion enabled. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | =over 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | =item * booleans | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | Will convert what could be interpreted as a boolean (that is, an actual | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | numeric C<1> or C<0>, and the strings "true" and "false") to a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | L<JSON::PP::Boolean> object. Note that "foo" is not considered a true value and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | will fail the validation. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | =item * defaults | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | Will copy the default value defined in the schema, into the input structure, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | if the input value is non-existing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | Note that support for "default" is currently EXPERIMENTAL, and enabling this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | might be changed in future versions. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | =item * numbers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | Will convert strings that look like numbers, into true numbers. This works for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | both the "integer" and "number" types. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | =item * strings | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | Will convert a number into a string. This works for the "string" type. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | =head2 contains | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | This method will be removed in a future release. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | =head2 data | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | my $hash_ref = $schema->data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | my $schema = $schema->data($bool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | my $schema = $schema->data($hash_ref); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | Will set a structure representing the schema. In most cases you want to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | use L</resolve> instead of L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | =head2 get | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | my $data = $schema->get([@json_pointer]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | my $data = $schema->get($json_pointer); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | my $data = $schema->get($json_pointer, sub { my ($data, $json_pointer) = @_; }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | This method will extract data from L</data>, using a C<$json_pointer> - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | L<RFC 6901|http://tools.ietf.org/html/rfc6901>. It can however be used in a more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | complex way by passing in an array-ref: The array-ref can contain C<undef()> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | values, will result in extracting any element on that point, regardless of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | value. In that case a L<Mojo::Collection> will be returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | A callback can also be given. This callback will be called each time the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | C<$json_pointer> matches some data, and will pass in the C<$json_pointer> at | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | that place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | In addition if this method "sees" a JSON-Schema C<$ref> on the way, the "$ref" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | will be followed into any given sub-schema. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | =head2 is_invalid | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | my $bool = $schema->is_invalid; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | Returns true if the schema in L</data> is invalid. Internally this method calls | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | L</errors> which will validate L</data> against L</specification>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | =head2 load_and_validate_schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | This method is unsupported. Use L</is_invalid> or L</errors> instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | my $schema = JSON::Validator::Schema->new($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | my $schema = JSON::Validator::Schema->new($data, %attributes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | my $schema = JSON::Validator::Schema->new(%attributes); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | Construct a new L<JSON::Validator::Schema> object. Passing C<$data> as the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | first argument will cause L</resolve> to be called, meaning the constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | might throw an exception if the schema could not be successfully resolved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | =head2 resolve | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | $schema = $schema->resolve($uri); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | $schema = $schema->resolve($data); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | Used to resolve L<$uri> or L<$data> and store the resolved schema in L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | If C<$data> or C<$uri> contain any "$ref", then these schemas will be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | downloaded and resolved as well. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | If L</data> does not contain an "id" or "$id", then L</id> will be assigned a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | autogenerated "urn". This "urn" might be changed in future releases, but should | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | always be the same for the same L</data>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | =head2 schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | This method will be removed in a future release. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | =head2 validate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | @errors = $schema->validate($any); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | Will validate C<$any> against the schema defined in L</data>. Each element in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | C<@errors> is an L<JSON::Validator::Error> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | L<JSON::Validator>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||