| 1 | 46 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 46 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package JSON::Schema::Modern::Document; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: One JSON Schema document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 46 | our $VERSION = '0.654'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 46 | ▶ | use 5.020; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 46 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 46 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 46 | ▶ | use stable 0.031 'postderef'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 46 | ▶ | use experimental 'signatures'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 46 | ▶ | no autovivification warn => qw(fetch store exists delete); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 46 | ▶ | use if "$]" >= 5.022, experimental => 're_strict'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 46 | ▶ | no if "$]" >= 5.031009, feature => 'indirect'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 46 | ▶ | no if "$]" >= 5.033001, feature => 'multidimensional'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 46 | ▶ | no if "$]" >= 5.033006, feature => 'bareword_filehandles'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 46 | ▶ | no if "$]" >= 5.041009, feature => 'smartmatch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 46 | ▶ | no feature 'switch'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 46 | ▶ | use Mojo::URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 46 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 46 | ▶ | use List::Util 1.29 'pairs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 46 | ▶ | use builtin::compat qw(refaddr blessed); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 46 | ▶ | use MooX::TypeTiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 46 | ▶ | use Types::Standard 1.016003 qw(InstanceOf HashRef Str Map Dict Tuple ArrayRef Enum ClassName Undef Slurpy Optional Bool); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 46 | ▶ | use Types::Common::Numeric 'PositiveOrZeroInt'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 46 | ▶ | use Syntax::Operator::Equ 'is_strequ'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 46 | ▶ | use JSON::Schema::Modern::Utilities qw(json_pointer_type canonical_uri_type E); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 46 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 46 | extends 'Mojo::JSON::Pointer'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 46 | has schema => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | has canonical_uri => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | isa => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | default => sub { Mojo::URL->new }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 17932 | ▶ | coerce => sub { blessed($_[0]) && $_[0]->isa('Mojo::URL') ? $_[0] : Mojo::URL->new($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
Condition66%2/3
builtin::blessed($_[0]) and $_[0]->isa("Mojo::URL")
MC/DC50%1/2
builtin::blessed($_[0]) and $_[0]->isa("Mojo::URL")
builtin::blessed($_[0])
$_[0]->isa("Mojo::URL")
Truth table66%2/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Mojo::URL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 46 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # this is also known as the retrieval uri in the OpenAPI specification | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | # it may be undefined, in which case users may wish to fall back to canonical_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 46 | has original_uri => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | isa => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | init_arg => undef, # not allowed as a constructor argument, but rather populated in BUILD | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 46 | *retrieval_uri = \&original_uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | has metaschema_uri => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | isa => InstanceOf['Mojo::URL'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 17902 | ▶ | coerce => sub { blessed($_[0]) && $_[0]->isa('Mojo::URL') ? $_[0] : Mojo::URL->new($_[0]) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
Condition33%1/3
builtin::blessed($_[0]) and $_[0]->isa("Mojo::URL")
MC/DC0%0/2
builtin::blessed($_[0]) and $_[0]->isa("Mojo::URL")
builtin::blessed($_[0])
$_[0]->isa("Mojo::URL")
Truth table33%1/3
A and B
A= builtin::blessed($_[0])B= $_[0]->isa("Mojo::URL")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 46 | predicate => '_has_metaschema_uri', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # default not defined here, but might be defined in a subclass | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # "A JSON Schema resource is a schema which is canonically identified by an absolute URI." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # https://json-schema.org/draft/2020-12/json-schema-core.html#rfc.section.4.3.5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | has resource_index => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | is => 'bare', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | isa => Map[my $resource_key_type = Str->where('!/#/') => my $resource_type = Dict[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | canonical_uri => (InstanceOf['Mojo::URL'])->where(q{not defined $_->fragment}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | path => json_pointer_type, # JSON pointer relative to the document root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | specification_version => Enum[qw(draft4 draft6 draft7 draft2019-09 draft2020-12)], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # the vocabularies used when evaluating instance data against schema | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | vocabularies => ArrayRef[ClassName->where(q{$_->DOES('JSON::Schema::Modern::Vocabulary')})], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | anchors => Optional[HashRef[Dict[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | canonical_uri => canonical_uri_type, # equivalent uri with json pointer fragment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | path => json_pointer_type, # JSON pointer relative to the document root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | dynamic => Optional[Bool], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | ]]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | Slurpy[HashRef[Undef]], # no other fields allowed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ]], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 17902 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 46 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 52 | ▶ | sub resource_index { $_[0]->{resource_index}->%* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource_index: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 18155 | ▶ | sub resource_pairs { pairs $_[0]->{resource_index}->%* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
resource_pairs: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 3083 | ▶ | sub _get_resource { $_[0]->{resource_index}{$_[1]} } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_resource: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | sub _canonical_resources { values $_[0]->{resource_index}->%* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_canonical_resources: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 18644 | ▶ | sub _add_resource { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_resource: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 18644 | ▶ | croak 'uri "'.$_[1].'" conflicts with an existing schema resource' if $_[0]->{resource_index}{$_[1]}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 18643 | $_[0]->{resource_index}{$resource_key_type->($_[1])} = $resource_type->($_[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # for internal use only | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 46 | has _checksum => ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | isa => Str, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | has errors => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | is => 'bare', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | writer => '_set_errors', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | isa => ArrayRef[InstanceOf['JSON::Schema::Modern::Error']], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 46 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 163 | ▶ | sub errors { ($_[0]->{errors}//[])->@* } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errors: called CC=2 SCAR=7.6
Pod
documented
Condition50%1/2
$_[0]{"errors"} // []
MC/DC0%0/1
$_[0]{"errors"} // []
$_[0]{"errors"}
Truth table50%1/2
A
A= $_[0]{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 18261 | ▶ | sub has_errors { scalar(($_[0]->{errors}//[])->@*) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_errors: called CC=2 SCAR=7.6
Pod
undocumented
Condition50%1/2
$_[0]{"errors"} // []
MC/DC0%0/1
$_[0]{"errors"} // []
$_[0]{"errors"}
Truth table50%1/2
A
A= $_[0]{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 17752 | ▶ | sub _push_errors { push((shift->{errors}//=[])->@*, @_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_push_errors: called CC=2 SCAR=6.9
Condition100%2/2
(shift())->{"errors"} //= []
MC/DC100%1/1
(shift())->{"errors"} //= []
(shift())->{"errors"}
Truth table100%2/2
A
A= (shift())->{"errors"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # an entity is defined as a type of location that can be addressed by a $ref in a document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # json pointer => entity name (indexed by integer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | has _entities => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | isa => Map[json_pointer_type() => PositiveOrZeroInt], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 17902 | ▶ | default => sub { {} }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 46 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # in this class, the only entity type is 'schema', but subclasses add more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 111940 | ▶ | sub __entities ($) { qw(schema) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__entities: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 45286 | ▶ | sub __entity_type { Enum[$_[0]->__entities] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__entity_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 42204 | ▶ | sub __entity_index ($self, $entity) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__entity_index: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 42204 | my @e = $self->__entities; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 42204 | ▶ | foreach my $i (0..$#e) { return $i if $e[$i] eq $entity; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 42203 | ▶ | sub _add_entity_location ($self, $location, $entity) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_entity_location: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 42203 | $self->__entity_type->($entity); # verify string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 42203 | $self->_entities->{$location} = $self->__entity_index($entity); # store integer-mapped value | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 24464 | ▶ | sub get_entity_at_location ($self, $location) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_entity_at_location: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 24464 | ▶ | return '' if not exists $self->_entities->{$location}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 24450 | ▶ | ($self->__entities)[ $self->_entities->{$location} ] // croak "missing mapping for ", $self->_entities->{$location}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
($self->__entities)[$self->_entities->{$location}] // croak("missing mapping for ", $self->_entities->{$location})
MC/DC0%0/1
($self->__entities)[$self->_entities->{$location}] // croak("missing mapping for ", $self->_entities->{$location})
($self->__entities)[$self->_entities->{$location}]
Truth table50%1/2
A
A= ($self->__entities)[$self->_entities->{$location}]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # note: not sorted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | ▶ | sub get_entity_locations ($self, $entity) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_entity_locations: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 1 | $self->__entity_type->($entity); # verify string | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | my $index = $self->__entity_index($entity); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | grep $self->{_entities}{$_} == $index, keys $self->{_entities}->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # references to a location in an unknown document are not considered to be errors at document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # loading time, but might be checked later on by some other mechanism | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | has _deferred_references => ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | is => 'rwp', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | isa => ArrayRef[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | my $reference_type = Tuple[ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | Str|Undef, # keyword | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | json_pointer_type, # path location | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | InstanceOf['Mojo::URL'], # absolute target | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | Str, # expected entity (should actually be __entity_type) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | init_arg => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 70 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 46 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | # shims for Mojo::JSON::Pointer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 25943 | ▶ | sub data { shift->schema(@_) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 17903 | ▶ | sub FOREIGNBUILDARGS { () } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FOREIGNBUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # for JSON serializers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub TO_JSON { shift->schema } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TO_JSON: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # note that this is always called, even in subclasses | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 17902 | ▶ | sub BUILD ($self, $args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=12 SCAR=24.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 17902 | ▶ | croak 'cannot provide "retrieval_uri"' if exists $args->{retrieval_uri}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # note! not a clone! Please don't change canonical_uri in-place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 17902 | ▶ | $self->_set_original_uri($self->canonical_uri) if defined $args->{canonical_uri}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # this should extract all identifiers, references, and entities, and set canonical_uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # metaschema_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | my $state = $self->traverse( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | $args->{evaluator} // JSON::Schema::Modern->new, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | $args->{specification_version} ? $args->%{specification_version} : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 17902 | ▶ | $args->{skip_ref_checks} ? $args->%{skip_ref_checks} : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$$args{"evaluator"} // "JSON::Schema::Modern"->new
MC/DC0%0/2
$$args{"evaluator"} // "JSON::Schema::Modern"->new
$$args{"evaluator"}
"JSON::Schema::Modern"->new
Truth table66%2/3
A // B
A= $$args{"evaluator"}B= "JSON::Schema::Modern"->new
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 17902 | ▶ | if ($state->{errors}->@*) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 150 | $self->_set_errors($state->{errors}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 150 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 17752 | my $seen_root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 17752 | foreach my $key (keys $state->{identifiers}->%*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 2071 | my $value = $state->{identifiers}{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 2071 | $self->_add_resource($key => $value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # we're adding a non-anchor entry for the document root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 2071 | ▶ | ++$seen_root if $value->{path} eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | # we only index the original uri if nothing in the schema itself identified a root resource: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # otherwise the top of the document would be unreferenceable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $self->_add_resource(($self->original_uri//'').'' => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | path => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | canonical_uri => $self->canonical_uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 17752 | ▶ | $state->%{qw(specification_version vocabularies)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$self->original_uri // ""
MC/DC100%1/1
$self->original_uri // ""
$self->original_uri
Truth table100%2/2
A
A= $self->original_uri
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | if not $seen_root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 17751 | ▶ | $self->_set_errors($state->{errors}) if $state->{errors}->@*; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # set aside unverified references, perhaps to be checked later when new documents are added to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # resource index; updates 'errors' and '_deferred_references' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 17751 | $self->verify_references($args->{evaluator}, $state, $state->{references}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | # checks a list of references for validity, returning those to unknown documents that cannot be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # verified yet; will update errors automatically | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 17752 | ▶ | sub verify_references ($self, $evaluator, $state = undef, $references = undef) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
verify_references: called CC=16 SCAR=27.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 17752 | ▶ | $state //= { # minimum needed for E() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$state //= {"initial_schema_uri", $self->canonical_uri, "traversed_keyword_path", "", "traverse", 1}
MC/DC100%1/1
$state //= {"initial_schema_uri", $self->canonical_uri, "traversed_keyword_path", "", "traverse", 1}
$state
Truth table100%2/2
A
A= $state
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | initial_schema_uri => $self->canonical_uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | traversed_keyword_path => '', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | traverse => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 17752 | ▶ | $references //= $self->_deferred_references; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$references //= $self->_deferred_references
MC/DC0%0/2
$references //= $self->_deferred_references
$references
$self->_deferred_references
Truth table66%2/3
A //= B
A= $referencesB= $self->_deferred_references
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 17752 | $state->{errors} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 17752 | my @deferred_references; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 17752 | foreach my $ref ($references->@*) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 3082 | $reference_type->($ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 3082 | $self->__entity_type->($ref->[3]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 3082 | my ($keyword, $path_location, $abs_target, $expected_entity) = @$ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # look for resource locally; fall back to the evaluator's index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 3082 | my $resource = $self->_get_resource(my $base_uri = $abs_target->clone->fragment(undef)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 3082 | my $document = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 3082 | ▶ | if (not $resource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 531 | ▶ | $resource = $evaluator->_get_resource($base_uri) if $evaluator; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 531 | ▶ | if (not $resource) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 173 | push @deferred_references, [ $keyword, $path_location, $abs_target, $expected_entity ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 173 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 358 | $document = $resource->{document}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 2909 | my $fragment = $abs_target->fragment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 2909 | my $target_path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2909 | ▶ | if (not length $fragment) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 874 | $target_path = $resource->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | elsif ($fragment =~ m{^/}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | # json pointer fragment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | '%s target "%s" is a non-existent location', $expected_entity, $abs_target), next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1718 | ▶ | if not $document->contains($target_path = $resource->{path}.$fragment); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | ▶ | elsif (my $subresource = ($resource->{anchors}//{})->{$fragment}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$$resource{"anchors"} // {}
MC/DC0%0/1
$$resource{"anchors"} // {}
$$resource{"anchors"}
Truth table50%1/2
A
A= $$resource{"anchors"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | # valid anchor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 312 | $target_path = $subresource->{path}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # invalid anchor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 5 | ()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | '%s target "%s" is a non-existent location', $expected_entity, $abs_target); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 5 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 2899 | my $entity = $document->get_entity_at_location($target_path); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 2899 | ▶ | ()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | '%s target "%s" is not a referenceable location', $expected_entity, $abs_target), next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | if not $entity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2893 | ▶ | ()= E({ %$state, keyword_path => $path_location, keyword => $keyword }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | '%s target "%s" is the wrong object type (got %s)', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | $expected_entity, $abs_target, $entity), next | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | if $entity ne $expected_entity; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 17752 | $self->_push_errors($state->{errors}->@*); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 17752 | $self->_set__deferred_references(\@deferred_references); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # a subclass's method will override this one | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 17901 | ▶ | sub traverse ($self, $evaluator, $config_override = {}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
traverse: called CC=10 SCAR=24.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | die 'wrong class - use JSON::Schema::Modern::Document::OpenAPI instead' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 17901 | ▶ | if ref $self->schema eq 'HASH' and exists $self->schema->{openapi}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self->schema eq "HASH" and exists $self->schema->{"openapi"}
MC/DC0%0/2
ref $self->schema eq "HASH" and exists $self->schema->{"openapi"}
ref $self->schema eq "HASH"
exists $self->schema->{"openapi"}
Truth table66%2/3
A and B
A= ref $self->schema eq "HASH"B= exists $self->schema->{"openapi"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 17901 | my $original_uri = $self->original_uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 17901 | ▶ | my $state = $evaluator->traverse($self->schema, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | initial_schema_uri => $original_uri, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | $self->_has_metaschema_uri ? (metaschema_uri => $self->metaschema_uri) : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | %$config_override, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 17901 | ▶ | die 'original_uri has changed' if not is_strequ($self->original_uri, $original_uri) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition55%5/9
not is_strequ(scalar $self->original_uri, $original_uri) or defined $self->original_uri and defined $original_uri and builtin::refaddr($self->original_uri) != builtin::refaddr($original_uri)
defined $self->original_uri and defined $original_uri and builtin::refaddr($self->original_uri) != builtin::refaddr($original_uri)
defined $self->original_uri and defined $original_uri
MC/DC0%0/4
not is_strequ(scalar $self->original_uri, $original_uri) or defined $self->original_uri and defined $original_uri and builtin::refaddr($self->original_uri) != builtin::refaddr($original_uri)
not is_strequ(scalar $self->original_uri, $original_uri)
defined $self->original_uri
defined $original_uri
builtin::refaddr($self->original_uri) != builtin::refaddr($original_uri)
Truth table40%2/5
not(A) or B and C and D
A= not is_strequ(scalar $self->original_uri, $original_uri)B= defined $self->original_uriC= defined $original_uriD= builtin::refaddr($self->original_uri) != builtin::refaddr($original_uri)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | or (defined $self->original_uri and defined $original_uri and refaddr($self->original_uri) != refaddr($original_uri)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | # if the document identified a canonical uri for itself via '$id', or metaschema uri via '$schema', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | # they overrides the initial values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # Note that subclasses of this class may choose to identify these values in a different way | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # (e.g. "$self" in OpenAPI) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 17901 | $self->_set_canonical_uri($state->{initial_schema_uri}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 17901 | $self->_set_metaschema_uri($state->{metaschema_uri}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 17901 | $self->_add_entity_location($_, 'schema') foreach $state->{subschemas}->@*; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 17901 | return $state; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 3 | ▶ | sub validate ($class, @args) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 3 | ▶ | croak 'bad argument list' if blessed($args[0]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 3 | my $args = $class->Moo::Object::BUILDARGS(@args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 3 | ▶ | my $document = blessed($class) ? $class : $class->new($args); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 3 | my $doc_result = JSON::Schema::Modern::Result->new(errors => [ $document->errors ]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | # ideally, the traverse phase run during document construction should have found all errors that a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # simple metaschema evaluation would reveal, but we'll do both just to make sure. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | my $evaluator = $args->{evaluator} // JSON::Schema::Modern->new(validate_formats => 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$$args{"evaluator"} // "JSON::Schema::Modern"->new("validate_formats", 1)
MC/DC0%0/2
$$args{"evaluator"} // "JSON::Schema::Modern"->new("validate_formats", 1)
$$args{"evaluator"}
"JSON::Schema::Modern"->new("validate_formats", 1)
Truth table66%2/3
A // B
A= $$args{"evaluator"}B= "JSON::Schema::Modern"->new("validate_formats", 1)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 3 | my $eval_result = $evaluator->evaluate($document->schema, $document->metaschema_uri); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 3 | ▶ | if (my ($missing_resource) = grep $_->error =~ /EXCEPTION: unable to find resource/, $eval_result->errors) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | $missing_resource->{error} .= ' (did you forget to provide "evaluator" to ->validate?)'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 3 | return $doc_result & $eval_result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # callback hook for Sereal::Encoder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | ▶ | sub FREEZE ($self, $serializer) { +{ %$self } } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
FREEZE: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | # callback hook for Sereal::Decoder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 10 | ▶ | sub THAW ($class, $serializer, $data) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
THAW: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 10 | delete $data->{evaluator}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 10 | my $self = bless($data, $class); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 10 | foreach my $attr (qw(schema _entities)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | croak "serialization missing attribute '$attr' on document for identifier '$self->{canonical_uri}': perhaps your serialized data was produced for an older version of $class?" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 20 | ▶ | if not exists $self->{$attr}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 10 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 46 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||