Corvus/Loader.pm

filter: Statementstmt 82.2% 176 / 214 Branchbran 60.5% 69 / 114 Conditioncond 38.3% 23 / 60 MC/DCmcdc 13.1% 5 / 38 Subroutinesub 100% 35 / 35 Podpod 0.0% 0 / 11 totaltotal 65.2% 308 / 472 CC 84 SCAR 44.7
CC
84
Cov
69%
_walk
201.2
get_dialect_info
97.3
try_resolve_fragment
8.5
CRAP 87.6
« Corvus/Regex/Charset.pm ↑ Summary Corvus/Dialect.pm »
1 package JSON::Schema::Corvus::Loader;
2  
3 # Loads schema documents, identifies resources and anchors, and resolves references. A port of the Python package's
4 # loader.py (Corvus.Text.Json.RuntimeEvaluator.Compilation.SchemaLoader): elements are identified by (document, JSON
5 # pointer) rather than by a parsed document's row index.
6  
7 4 ▶use 5.026;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use JSON::Schema::Corvus::Dialect qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use JSON::Schema::Corvus::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use JSON::Schema::Corvus::Json;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use JSON::Schema::Corvus::Metaschemas;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use JSON::Schema::Corvus::Uri;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 4 ▶use constant DEFAULT_ROOT_URI => 'https://corvus-oss.org/runtime-evaluator/root.json';
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 4 my $Json = 'JSON::Schema::Corvus::Json';
20  
21 991 ▶sub _is_container { my $r = ref $_[0]; $r eq 'HASH' || $r eq 'ARRAY' }
Subroutine _is_container: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$r eq "HASH" or $r eq "ARRAY" 961 30 991
22 93 ▶sub _is_schema_value { my $r = ref $_[0]; $r eq 'HASH' || $r eq 'JSON::PP::Boolean' }
Subroutine _is_schema_value: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$r eq "HASH" or $r eq "JSON::PP::Boolean" 89 4 93
23 612 ▶sub _is_string { JSON::Schema::Corvus::Json::is_string($_[0]) }
Subroutine _is_string: called CC=1 SCAR=0.0
24  
25 # --- Values by schema location ---
26 #
27 # Schema objects (hashes and arrays) are keyed by identity, which avoids hashing long pointers; the pointer decides
28 # for scalars and for objects in the document's shared set, which appear at more than one location (possible in a
29 # schema built in Perl, never in parsed JSON). The walk records those as it meets them.
30  
31 512 ▶sub _map_get {
Subroutine _map_get: called CC=3 SCAR=11.0
32 512 my ($doc, $map, $schema, $pointer) = @_;
33 512 ▶ if (_is_container($schema)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_container($schema)) 500 12 512
34 500 my $addr = Scalar::Util::refaddr($schema);
35 500 ▶ return $doc->{$map}{object}{$addr} unless $doc->{shared}{$addr};
Branch: 1 branch
BranchTrueFalseTotal
unless $doc->{"shared"}{$addr} 500 0 500
36 }
37 12 return $doc->{$map}{pointer}{$pointer};
38 }
39  
40 319 ▶sub _map_set {
Subroutine _map_set: called CC=3 SCAR=11.0
41 319 my ($doc, $map, $schema, $pointer, $value) = @_;
42 319 ▶ if (_is_container($schema)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_container($schema)) 307 12 319
43 307 my $addr = Scalar::Util::refaddr($schema);
44 307 ▶ if (!$doc->{shared}{$addr}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc->{"shared"}{$addr}) 307 0 307
45 307 $doc->{$map}{object}{$addr} = $value;
46 307 return;
47 }
48 }
49 12 $doc->{$map}{pointer}{$pointer} = $value;
50 }
51  
52 # The resource that owns a schema location, and the compiled node of one (which the compiler records).
53 93 ▶sub resource_of { my ($self, $doc, $value, $pointer) = @_; _map_get($doc, 'resources', $value, $pointer) }
Subroutine resource_of: called CC=1 SCAR=0.0
Pod undocumented
54 359 ▶sub node_of { my ($self, $doc, $value, $pointer) = @_; _map_get($doc, 'nodes', $value, $pointer) }
Subroutine node_of: called CC=1 SCAR=0.0
Pod undocumented
55 159 ▶sub set_node_of { my ($self, $doc, $value, $pointer, $id) = @_; _map_set($doc, 'nodes', $value, $pointer, $id) }
Subroutine set_node_of: called CC=1 SCAR=0.0
Pod undocumented
56  
57 367 ▶sub escape_pointer_token { JSON::Schema::Corvus::Uri::escape_pointer_token($_[0]) }
Subroutine escape_pointer_token: called CC=1 SCAR=0.0
Pod undocumented
58  
59 176 ▶sub _value_at {
Subroutine _value_at: called CC=1 SCAR=0.0
60 176 my ($doc, $pointer) = @_;
61 176 return (JSON::Schema::Corvus::Uri::resolve_pointer($doc->{root}, $pointer))[1];
62 }
63  
64 # The root value of a resource.
65 171 ▶sub resource_root {
Subroutine resource_root: called CC=1 SCAR=0.0
Pod undocumented
66 171 my ($resource) = @_;
67 171 return _value_at($resource->{document}, $resource->{root_pointer});
68 }
69  
70 # A reference's target: { document, pointer, value, resource }.
71 173 ▶sub _target {
Subroutine _target: called CC=1 SCAR=0.0
72 173 my ($document, $pointer, $value, $resource) = @_;
73 173 return { document => $document, pointer => $pointer, value => $value, resource => $resource };
74 }
75  
76 46 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
77 46 my ($class, $options) = @_;
78 46 return bless {
79 options => $options,
80 documents => [],
81 resources => [],
82 resources_by_uri => {},
83 documents_by_uri => {},
84 metaschema_info => {},
85 metaschema_loading => {},
86 }, $class;
87 }
88  
89 44 ▶sub load_root {
Subroutine load_root: called CC=2 SCAR=6.9
Pod undocumented
90 44 my ($self, $schema, $base_uri) = @_;
91 44 ▶ my $uri = defined $base_uri ? JSON::Schema::Corvus::Uri::normalize($base_uri) : DEFAULT_ROOT_URI;
Branch: 1 branch
BranchTrueFalseTotal
defined $base_uri ? : 1 43 44
92 44 my $doc = $self->_add_document($uri, $schema);
93 44 return _map_get($doc, 'resources', $doc->{root}, '');
94 }
95  
96 2 ▶sub load_root_from_uri {
Subroutine load_root_from_uri: called CC=2 SCAR=7.0
Pod undocumented
97 2 my ($self, $uri) = @_;
98 2 my $normalized = JSON::Schema::Corvus::Uri::normalize($uri);
99 2 ▶ die JSON::Schema::Corvus::Error::Compilation->_new("Unable to resolve the schema document '$uri'.")
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_try_load_document($normalized) 0 2 2
100 unless $self->_try_load_document($normalized);
101 2 my $doc = $self->{documents_by_uri}{$normalized};
102 2 return _map_get($doc, 'resources', $doc->{root}, '');
103 }
104  
105 63 ▶sub try_resolve_reference {
Subroutine try_resolve_reference: called CC=2 SCAR=6.9
Pod undocumented
106 63 my ($self, $source, $reference) = @_;
107 63 my $cache = $source->{document}{reference_cache};
108 63 my $key = "$source->{id} $reference";
109 63 ▶ return $cache->{$key} if exists $cache->{$key};
Branch: 1 branch
BranchTrueFalseTotal
if exists $cache->{$key} 30 33 63
110 33 return $cache->{$key} = $self->_resolve_reference($source, $reference);
111 }
112  
113 33 ▶sub _resolve_reference {
Subroutine _resolve_reference: called CC=4 SCAR=13.9
114 33 my ($self, $source, $reference) = @_;
115 33 my ($uri_part, $fragment) = JSON::Schema::Corvus::Uri::split_fragment($reference);
116 33 my $absolute = JSON::Schema::Corvus::Uri::resolve($source->{uri}, $uri_part);
117 33 my $resource = $self->{resources_by_uri}{$absolute};
118 33 ▶ if (!$resource) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($resource) 13 20 33
119 13 ▶ return undef unless $self->_try_load_document($absolute);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_try_load_document($absolute) 1 10 11
120 10 ▶ $resource = $self->{resources_by_uri}{$absolute} or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$resource = $self->{"resources_by_uri"}{$absolute} or return undef 10 0 10
121 }
122 30 return $self->try_resolve_fragment($resource, JSON::Schema::Corvus::Uri::decode_fragment($fragment));
123 }
124  
125 174 ▶sub try_resolve_fragment {
Subroutine try_resolve_fragment: called CC=8 SCAR=21.3
Pod undocumented
126 174 my ($self, $resource, $fragment) = @_;
127 174 ▶ if ($fragment eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($fragment eq "") 154 20 174
128 154 return _target($resource->{document}, $resource->{root_pointer}, resource_root($resource), $resource);
129 }
130 20 ▶ if (substr($fragment, 0, 1) eq '/') {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($fragment, 0, 1) eq "/") 15 5 20
131 15 my ($found, $value, $path) = JSON::Schema::Corvus::Uri::resolve_pointer(resource_root($resource), $fragment);
132 15 ▶ return undef unless $found;
Branch: 1 branch
BranchTrueFalseTotal
unless $found 1 14 15
133 14 my $pointer = $resource->{root_pointer};
134 14 $pointer .= '/' . escape_pointer_token("$_") for @$path;
135 14 ▶ my $owner = _map_get($resource->{document}, 'resources', $value, $pointer) || $resource;
Condition33%1/3
_map_get($resource->{'document'}, 'resources', $value, $pointer) || $resource
l!l&&r!l&&!r
1400
MC/DC0%0/2
_map_get($resource->{'document'}, 'resources', $value, $pointer) || $resource
_map_get($resource->{'document'}, 'resources', $value, $pointer) $resource
Truth table33%1/3
A || B
A= _map_get($resource->{'document'}, 'resources', $value, $pointer)B= $resource
ABresult
1X1
011
000
136 14 return _target($resource->{document}, $pointer, $value, $owner);
137 }
138 5 ▶ my $anchor = $resource->{anchors} ? $resource->{anchors}{$fragment} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$resource->{'anchors'} ? : 5 0 5
139 5 ▶ return _target($resource->{document}, $anchor, _value_at($resource->{document}, $anchor), $resource)
Branch: 1 branch
BranchTrueFalseTotal
if defined $anchor 5 0 5
140 if defined $anchor;
141 0 return undef;
142 }
143  
144 # The dialect and vocabularies of a metaschema URI.
145 9 ▶sub get_dialect_info {
Subroutine get_dialect_info: called CC=11 SCAR=45.8
Pod undocumented
146 9 my ($self, $schema_uri) = @_;
147 # The standard metaschema URIs, as usually written, need no normalisation.
148 9 (my $plain_uri = $schema_uri) =~ s/#\z//;
149 9 my $plain = known_dialect($plain_uri);
150 9 ▶ return ($plain, V_ALL_ANNOTATING_FORMAT) if defined $plain;
Branch: 1 branch
BranchTrueFalseTotal
if defined $plain 9 0 9
151 0 my $normalized = JSON::Schema::Corvus::Uri::normalize($schema_uri);
152 0 my $known = known_dialect($normalized);
153 0 ▶ return ($known, V_ALL_ANNOTATING_FORMAT) if defined $known;
Branch: 1 branch
BranchTrueFalseTotal
if defined $known 0 0 0
154 0 ▶ if (my $cached = $self->{metaschema_info}{$normalized}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $cached = $self->{"metaschema_info"}{$normalized}) 0 0 0
155 0 return @$cached;
156 }
157 0 ▶ return ($self->{options}{default_dialect}, V_ALL_ANNOTATING_FORMAT) if $self->{metaschema_loading}{$normalized};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"metaschema_loading"}{$normalized} 0 0 0
158 0 local $self->{metaschema_loading}{$normalized} = 1;
159 0 my $fallback = [ $self->{options}{default_dialect}, V_ALL_ANNOTATING_FORMAT ];
160 0 my $meta_resource = $self->{resources_by_uri}{$normalized};
161 0 ▶ if (!$meta_resource) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta_resource) 0 0 0
162 0 ▶ if (!$self->_try_load_document($normalized) || !($meta_resource = $self->{resources_by_uri}{$normalized})) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_try_load_document($normalized) and $meta_resource = $self->{"resources_by_uri"}{$normalized}) 0 0 0
Condition0%0/3
$self->_try_load_document($normalized) and $meta_resource = $self->{"resources_by_uri"}{$normalized}
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_try_load_document($normalized) and $meta_resource = $self->{"resources_by_uri"}{$normalized}
$self->_try_load_document($normalized) $meta_resource = $self->{"resources_by_uri"}{$normalized}
Truth table0%0/3
A and B
A= $self->_try_load_document($normalized)B= $meta_resource = $self->{"resources_by_uri"}{$normalized}
ABresult
0X0
100
111
163 0 $self->{metaschema_info}{$normalized} = $fallback;
164 0 return @$fallback;
165 }
166 }
167 0 my $meta = resource_root($meta_resource);
168 0 my $vocabularies = V_ALL_ANNOTATING_FORMAT;
169 0 ▶ if (ref $meta eq 'HASH' && ref $meta->{'$vocabulary'} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $meta eq "HASH" and ref $meta->{"\$vocabulary"} eq "HASH") 0 0 0
Condition0%0/3
ref $meta eq "HASH" and ref $meta->{"\$vocabulary"} eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $meta eq "HASH" and ref $meta->{"\$vocabulary"} eq "HASH"
ref $meta eq "HASH" ref $meta->{"\$vocabulary"} eq "HASH"
Truth table0%0/3
A and B
A= ref $meta eq "HASH"B= ref $meta->{"\$vocabulary"} eq "HASH"
ABresult
0X0
100
111
170 0 $vocabularies = V_NONE;
171 0 $vocabularies |= vocabulary_flag($_) for keys %{ $meta->{'$vocabulary'} };
172 0 $vocabularies |= V_CORE;
173 }
174 0 my $info = [ $meta_resource->{dialect}, $vocabularies ];
175 0 $self->{metaschema_info}{$normalized} = $info;
176 0 return @$info;
177 }
178  
179 15 ▶sub _try_load_document {
Subroutine _try_load_document: called CC=7 SCAR=19.5
180 15 my ($self, $absolute_uri) = @_;
181 15 ▶ return 1 if $self->{documents_by_uri}{$absolute_uri};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"documents_by_uri"}{$absolute_uri} 0 15 15
182 15 my $resolver = $self->{options}{resolve_document};
183 15 ▶ my $resolved = $resolver ? $resolver->($absolute_uri) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$resolver ? : 7 8 15
184 14 ▶ if (defined $resolved) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $resolved) 5 9 14
185 5 ▶ $self->_add_document($absolute_uri, ref $resolved || JSON::Schema::Corvus::Json::is_bool($resolved)
Branch: 1 branch
BranchTrueFalseTotal
ref $resolved || JSON::Schema::Corvus::Json::is_bool($resolved) ? : 2 3 5
Condition66%2/3
ref $resolved or JSON::Schema::Corvus::Json::is_bool($resolved)
l!l&&r!l&&!r
203
MC/DC50%1/2
ref $resolved or JSON::Schema::Corvus::Json::is_bool($resolved)
ref $resolved JSON::Schema::Corvus::Json::is_bool($resolved)
Truth table66%2/3
A or B
A= ref $resolvedB= JSON::Schema::Corvus::Json::is_bool($resolved)
ABresult
1X1
011
000
186 ? JSON::Schema::Corvus::Json::from_data($resolved) : JSON::Schema::Corvus::Json::decode($resolved, 1));
187 4 return 1;
188 }
189 9 my $meta = $JSON::Schema::Corvus::Metaschemas::METASCHEMAS{$absolute_uri};
190 9 ▶ if (defined $meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta) 8 1 9
191 8 $self->_add_document($absolute_uri, JSON::Schema::Corvus::Json::decode($meta, 1));
192 8 return 1;
193 }
194 1 return 0;
195 }
196  
197 56 ▶sub _add_document {
Subroutine _add_document: called CC=1 SCAR=0.0
198 56 my ($self, $uri, $root) = @_;
199 my $doc = {
200 56 id => scalar @{ $self->{documents} },
201 root => $root,
202 retrieval_uri => $uri,
203 shared => {},
204 first_location => {},
205 resources => { object => {}, pointer => {} },
206 nodes => { object => {}, pointer => {} },
207 reference_cache => {},
208 };
209 56 push @{ $self->{documents} }, $doc;
210 56 $self->{documents_by_uri}{$uri} = $doc;
211 56 my ($dialect, $vocabularies) = $self->_get_root_dialect($root);
212 56 my $resource = $self->_create_resource($doc, '', $uri, $dialect, $vocabularies);
213 56 $self->_walk($doc, $root, '', $resource, 1);
214 56 return $doc;
215 }
216  
217 56 ▶sub _get_root_dialect {
Subroutine _get_root_dialect: called CC=3 SCAR=11.0
218 56 my ($self, $root) = @_;
219 56 ▶ return $self->get_dialect_info($root->{'$schema'}) if ref $root eq 'HASH' && _is_string($root->{'$schema'});
Branch: 1 branch
BranchTrueFalseTotal
if ref $root eq "HASH" and _is_string($root->{"\$schema"}) 9 47 56
Condition100%3/3
ref $root eq "HASH" and _is_string($root->{"\$schema"})
!ll&&!rl&&r
2459
MC/DC100%2/2
ref $root eq "HASH" and _is_string($root->{"\$schema"})
ref $root eq "HASH" _is_string($root->{"\$schema"})
Truth table100%3/3
A and B
A= ref $root eq "HASH"B= _is_string($root->{"\$schema"})
ABresult
0X0
100
111
220 47 return ($self->{options}{default_dialect}, V_ALL_ANNOTATING_FORMAT);
221 }
222  
223 56 ▶sub _create_resource {
Subroutine _create_resource: called CC=2 SCAR=7.1
224 56 my ($self, $doc, $pointer, $uri, $dialect, $vocabularies) = @_;
225 my $resource = {
226 56 id => scalar @{ $self->{resources} },
227 document => $doc,
228 root_pointer => $pointer,
229 uri => $uri,
230 dialect => $dialect,
231 vocabularies => $vocabularies,
232 recursive_anchor => 0,
233 anchors => undef,
234 dynamic_anchors => undef,
235 };
236 56 push @{ $self->{resources} }, $resource;
237 56 ▶ $self->{resources_by_uri}{$uri} //= $resource;
Condition33%1/3
$self->{"resources_by_uri"}{$uri} //= $resource
l!l&&r!l&&!r
0560
MC/DC0%0/2
$self->{"resources_by_uri"}{$uri} //= $resource
$self->{"resources_by_uri"}{$uri} $resource
Truth table33%1/3
A //= B
A= $self->{"resources_by_uri"}{$uri}B= $resource
ABresult
1X1
011
000
238 56 return $resource;
239 }
240  
241 8 ▶sub _add_anchor {
Subroutine _add_anchor: called CC=2 SCAR=8.1
242 8 my ($resource, $name, $pointer) = @_;
243 8 ▶ $resource->{anchors}{$name} //= $pointer;
Condition33%1/3
$resource->{"anchors"}{$name} //= $pointer
l!l&&r!l&&!r
080
MC/DC0%0/2
$resource->{"anchors"}{$name} //= $pointer
$resource->{"anchors"}{$name} $pointer
Truth table33%1/3
A //= B
A= $resource->{"anchors"}{$name}B= $pointer
ABresult
1X1
011
000
244 }
245  
246 160 ▶sub _walk {
Subroutine _walk: called CC=45 SCAR=53.0
247 160 my ($self, $doc, $element, $pointer, $resource, $is_resource_root) = @_;
248 160 ▶ if (_is_container($element)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_container($element)) 154 6 160
249 154 my $key = Scalar::Util::refaddr($element);
250 154 my $first = $doc->{first_location}{$key};
251 154 ▶ if (!defined $first) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $first) { } 154 0 154
elsif ($first ne $pointer and not $doc->{'shared'}{$key}) { } 0 0 0
252 154 $doc->{first_location}{$key} = $pointer;
253 }
254 ▶ elsif ($first ne $pointer && !$doc->{shared}{$key}) {
Condition0%0/3
$first ne $pointer and not $doc->{"shared"}{$key}
!ll&&!rl&&r
000
MC/DC0%0/2
$first ne $pointer and not $doc->{"shared"}{$key}
$first ne $pointer not $doc->{"shared"}{$key}
Truth table0%0/3
A and not(B)
A= $first ne $pointerB= not $doc->{"shared"}{$key}
ABresult
0X0
100
111
255 # Re-key what was recorded for the first location by its pointer.
256 0 my $owner = _map_get($doc, 'resources', $element, $first);
257 0 $doc->{shared}{$key} = 1;
258 0 ▶ _map_set($doc, 'resources', $element, $first, $owner) if $owner;
Branch: 1 branch
BranchTrueFalseTotal
if $owner 0 0 0
259 }
260 }
261 160 ▶ if (ref $element ne 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $element ne "HASH") 6 154 160
262 6 _map_set($doc, 'resources', $element, $pointer, $resource);
263 6 return;
264 }
265  
266 154 my $dialect = $resource->{dialect};
267 154 my $vocabularies = $resource->{vocabularies};
268 154 ▶ if (!$is_resource_root && _is_string($element->{'$schema'})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_resource_root and _is_string($element->{"\$schema"})) 0 154 154
Condition66%2/3
not $is_resource_root and _is_string($element->{"\$schema"})
!ll&&!rl&&r
541000
MC/DC0%0/2
not $is_resource_root and _is_string($element->{"\$schema"})
not $is_resource_root _is_string($element->{"\$schema"})
Truth table66%2/3
not(A) and B
A= not $is_resource_rootB= _is_string($element->{"\$schema"})
ABresult
0X0
100
111
269 0 ($dialect, $vocabularies) = $self->get_dialect_info($element->{'$schema'});
270 }
271  
272 154 ▶ my $legacy_ref_overrides_siblings = $dialect <= DRAFT7 && _is_string($element->{'$ref'});
Condition66%2/3
$dialect <= 2 && _is_string($element->{'$ref'})
!ll&&!rl&&r
15040
MC/DC0%0/2
$dialect <= 2 && _is_string($element->{'$ref'})
$dialect <= 2 _is_string($element->{'$ref'})
Truth table66%2/3
A && B
A= $dialect <= 2B= _is_string($element->{'$ref'})
ABresult
0X0
100
111
273 154 ▶ if (!$legacy_ref_overrides_siblings) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($legacy_ref_overrides_siblings) 154 0 154
274 154 ▶ my $id_value = $dialect == DRAFT4 ? $element->{id} : $element->{'$id'};
Branch: 1 branch
BranchTrueFalseTotal
$dialect == 0 ? : 1 153 154
275 154 ▶ if (_is_string($id_value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (_is_string($id_value)) 8 146 154
276 8 my ($uri_part, $fragment) = JSON::Schema::Corvus::Uri::split_fragment($id_value);
277 8 ▶ if ($uri_part eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($uri_part eq '') { } 0 8 8
278 0 ▶ _add_anchor($resource, $fragment, $pointer) if length $fragment && $dialect <= DRAFT7;
Branch: 1 branch
BranchTrueFalseTotal
if length $fragment and $dialect <= 2 0 0 0
Condition0%0/3
length $fragment and $dialect <= 2
!ll&&!rl&&r
000
MC/DC0%0/2
length $fragment and $dialect <= 2
length $fragment $dialect <= 2
Truth table0%0/3
A and B
A= length $fragmentB= $dialect <= 2
ABresult
0X0
100
111
279 }
280 else {
281 8 my $absolute = JSON::Schema::Corvus::Uri::resolve($resource->{uri}, $uri_part);
282 8 ▶ if (!$is_resource_root || $absolute ne $resource->{uri}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $is_resource_root or $absolute ne $resource->{"uri"}) 0 8 8
Condition33%1/3
not $is_resource_root or $absolute ne $resource->{"uri"}
l!l&&r!l&&!r
008
MC/DC0%0/2
not $is_resource_root or $absolute ne $resource->{"uri"}
not $is_resource_root $absolute ne $resource->{"uri"}
Truth table33%1/3
not(A) or B
A= not $is_resource_rootB= $absolute ne $resource->{"uri"}
ABresult
1X1
011
000
283 0 ▶ if ($is_resource_root) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_resource_root) { } 0 0 0
284 0 ▶ $self->{resources_by_uri}{$absolute} //= $resource;
Condition0%0/3
$self->{"resources_by_uri"}{$absolute} //= $resource
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{"resources_by_uri"}{$absolute} //= $resource
$self->{"resources_by_uri"}{$absolute} $resource
Truth table0%0/3
A //= B
A= $self->{"resources_by_uri"}{$absolute}B= $resource
ABresult
1X1
011
000
285 0 $resource->{uri} = $absolute;
286 }
287 else {
288 0 $resource = $self->_create_resource($doc, $pointer, $absolute, $dialect, $vocabularies);
289 0 $is_resource_root = 1;
290 }
291 }
292 8 ▶ _add_anchor($resource, $fragment, $pointer) if length $fragment && $dialect <= DRAFT7;
Branch: 1 branch
BranchTrueFalseTotal
if length $fragment and $dialect <= 2 0 8 8
Condition33%1/3
length $fragment and $dialect <= 2
!ll&&!rl&&r
800
MC/DC0%0/2
length $fragment and $dialect <= 2
length $fragment $dialect <= 2
Truth table33%1/3
A and B
A= length $fragmentB= $dialect <= 2
ABresult
0X0
100
111
293 }
294 }
295 154 my $anchor = $element->{'$anchor'};
296 154 ▶ _add_anchor($resource, $anchor, $pointer) if $dialect >= DRAFT201909 && _is_string($anchor);
Branch: 1 branch
BranchTrueFalseTotal
if $dialect >= 3 and _is_string($anchor) 0 154 154
Condition66%2/3
$dialect >= 3 and _is_string($anchor)
!ll&&!rl&&r
41500
MC/DC0%0/2
$dialect >= 3 and _is_string($anchor)
$dialect >= 3 _is_string($anchor)
Truth table66%2/3
A and B
A= $dialect >= 3B= _is_string($anchor)
ABresult
0X0
100
111
297 154 my $dynamic_anchor = $element->{'$dynamicAnchor'};
298 154 ▶ if ($dialect >= DRAFT202012 && _is_string($dynamic_anchor)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect >= 4 and _is_string($dynamic_anchor)) 8 146 154
Condition100%3/3
$dialect >= 4 and _is_string($dynamic_anchor)
!ll&&!rl&&r
41428
MC/DC100%2/2
$dialect >= 4 and _is_string($dynamic_anchor)
$dialect >= 4 _is_string($dynamic_anchor)
Truth table100%3/3
A and B
A= $dialect >= 4B= _is_string($dynamic_anchor)
ABresult
0X0
100
111
299 8 ▶ $resource->{dynamic_anchors}{$dynamic_anchor} //= $pointer;
Condition33%1/3
$resource->{"dynamic_anchors"}{$dynamic_anchor} //= $pointer
l!l&&r!l&&!r
080
MC/DC0%0/2
$resource->{"dynamic_anchors"}{$dynamic_anchor} //= $pointer
$resource->{"dynamic_anchors"}{$dynamic_anchor} $pointer
Truth table33%1/3
A //= B
A= $resource->{"dynamic_anchors"}{$dynamic_anchor}B= $pointer
ABresult
1X1
011
000
300 8 _add_anchor($resource, $dynamic_anchor, $pointer);
301 }
302 154 ▶ if ($dialect == DRAFT201909 && $is_resource_root && JSON::Schema::Corvus::Json::is_bool($element->{'$recursiveAnchor'})
Branch: 1 branch
BranchTrueFalseTotal
if ($dialect == 3 and $is_resource_root and JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"}) and $element->{"\$recursiveAnchor"}) 0 154 154
Condition33%3/9
$dialect == 3 and $is_resource_root and JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"}) and $element->{"\$recursiveAnchor"}
!ll&&!rl&&r
15400
$dialect == 3 and $is_resource_root and JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"})
!ll&&!rl&&r
15400
$dialect == 3 and $is_resource_root
!ll&&!rl&&r
15400
MC/DC0%0/4
$dialect == 3 and $is_resource_root and JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"}) and $element->{"\$recursiveAnchor"}
$dialect == 3 $is_resource_root JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"}) $element->{"\$recursiveAnchor"}
Truth table20%1/5
A and B and C and D
A= $dialect == 3B= $is_resource_rootC= JSON::Schema::Corvus::Json::is_bool($element->{"\$recursiveAnchor"})D= $element->{"\$recursiveAnchor"}
ABCDresult
0XXX0
10XX0
110X0
11100
11111
303 && $element->{'$recursiveAnchor'}) {
304 0 $resource->{recursive_anchor} = 1;
305 }
306 }
307  
308 154 _map_set($doc, 'resources', $element, $pointer, $resource);
309  
310 154 for my $name ($Json->can('names')->($element)) {
311 262 my $value = $element->{$name};
312 262 my $base = $pointer . '/' . escape_pointer_token($name);
313 262 my $kind = subschema_kind($name, $dialect, $legacy_ref_overrides_siblings);
314 262 ▶ if ($kind == K_SINGLE) {
Branch: 4 branches
BranchTrueFalseTotal
if ($kind == 1) { } 16 246 262
elsif ($kind == 2) { } 0 246 246
elsif ($kind == 3) { } 3 243 246
elsif ($kind == 4) { } 17 226 243
315 16 ▶ $self->_walk($doc, $value, $base, $resource, 0) if _is_schema_value($value);
Branch: 1 branch
BranchTrueFalseTotal
if _is_schema_value($value) 16 0 16
316 }
317 elsif ($kind == K_SINGLE_OR_ARRAY) {
318 0 ▶ if (ref $value eq 'ARRAY') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value eq 'ARRAY') { } 0 0 0
elsif (_is_schema_value($value)) { } 0 0 0
319 0 $self->_walk($doc, $value->[$_], "$base/$_", $resource, 0) for 0 .. $#$value;
320 }
321 elsif (_is_schema_value($value)) {
322 0 $self->_walk($doc, $value, $base, $resource, 0);
323 }
324 }
325 elsif ($kind == K_ARRAY) {
326 3 ▶ if (ref $value eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "ARRAY") 3 0 3
327 3 $self->_walk($doc, $value->[$_], "$base/$_", $resource, 0) for 0 .. $#$value;
328 }
329 }
330 elsif ($kind == K_MAP) {
331 17 ▶ if (ref $value eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $value eq "HASH") 17 0 17
332 17 for my $entry (JSON::Schema::Corvus::Json::names($value)) {
333 77 my $v = $value->{$entry};
334 77 ▶ $self->_walk($doc, $v, $base . '/' . escape_pointer_token($entry), $resource, 0) if _is_schema_value($v);
Branch: 1 branch
BranchTrueFalseTotal
if _is_schema_value($v) 77 0 77
335 }
336 }
337 }
338 }
339 }
340  
341 4 1;
« Corvus/Regex/Charset.pm ↑ Summary Corvus/Dialect.pm »