Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/Core.pm |
Statements | Executed 1111246 statements in 1.47s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
39121 | 1 | 1 | 705ms | 97.2s | _eval_keyword_ref (recurses: max depth 31, inclusive time 939s) | JSON::Schema::Modern::Vocabulary::Core::
94075 | 2 | 1 | 331ms | 331ms | keywords | JSON::Schema::Modern::Vocabulary::Core::
25862 | 1 | 1 | 328ms | 1.87s | _eval_keyword_id | JSON::Schema::Modern::Vocabulary::Core::
2586 | 1 | 1 | 143ms | 68.0s | _eval_keyword_dynamicRef (recurses: max depth 6, inclusive time 72.9s) | JSON::Schema::Modern::Vocabulary::Core::
725 | 2 | 2 | 4.20ms | 171ms | _traverse_keyword_ref | JSON::Schema::Modern::Vocabulary::Core::
11 | 1 | 1 | 543µs | 5.94ms | _traverse_keyword_vocabulary | JSON::Schema::Modern::Vocabulary::Core::
118 | 1 | 1 | 522µs | 2.33ms | _traverse_keyword_comment | JSON::Schema::Modern::Vocabulary::Core::
14 | 1 | 1 | 455µs | 5.94ms | _traverse_keyword_id | JSON::Schema::Modern::Vocabulary::Core::
15 | 2 | 2 | 336µs | 4.42ms | _traverse_keyword_anchor | JSON::Schema::Modern::Vocabulary::Core::
15 | 1 | 1 | 285µs | 4.58ms | _traverse_keyword_schema | JSON::Schema::Modern::Vocabulary::Core::
30 | 1 | 1 | 111µs | 111µs | CORE:match (opcode) | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 102µs | 664µs | __fetch_vocabulary_data | JSON::Schema::Modern::Vocabulary::Core::
13 | 3 | 1 | 94µs | 115µs | CORE:sort (opcode) | JSON::Schema::Modern::Vocabulary::Core::
22 | 1 | 1 | 68µs | 5.63ms | _traverse_keyword_dynamicRef | JSON::Schema::Modern::Vocabulary::Core::
12 | 1 | 1 | 46µs | 80.9ms | _traverse_keyword_defs (recurses: max depth 1, inclusive time 13.6ms) | JSON::Schema::Modern::Vocabulary::Core::
14 | 1 | 1 | 45µs | 4.10ms | _traverse_keyword_dynamicAnchor | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 32µs | 35µs | BEGIN@1 | Module::Runtime::
1 | 1 | 1 | 25µs | 991µs | BEGIN@11 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 18µs | 38µs | BEGIN@14 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 17µs | 50µs | BEGIN@13 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 16µs | 16µs | BEGIN@9 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 15µs | 28µs | BEGIN@16 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 12µs | 27µs | BEGIN@15 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 11µs | 281µs | BEGIN@10 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 10µs | 264µs | BEGIN@18 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 9µs | 138µs | BEGIN@12 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 9µs | 73µs | BEGIN@17 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 7µs | 36µs | BEGIN@2 | Module::Runtime::
3 | 1 | 1 | 2µs | 2µs | evaluation_order | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 1µs | 1µs | vocabulary | JSON::Schema::Modern::Vocabulary::Core::
0 | 0 | 0 | 0s | 0s | _eval_keyword_recursiveAnchor | JSON::Schema::Modern::Vocabulary::Core::
0 | 0 | 0 | 0s | 0s | _eval_keyword_recursiveRef | JSON::Schema::Modern::Vocabulary::Core::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_definitions | JSON::Schema::Modern::Vocabulary::Core::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_recursiveAnchor | JSON::Schema::Modern::Vocabulary::Core::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_recursiveRef | JSON::Schema::Modern::Vocabulary::Core::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 33µs | 2 | 38µs | # spent 35µs (32+3) within Module::Runtime::BEGIN@1 which was called:
# once (32µs+3µs) by Module::Runtime::require_module at line 1 # spent 35µs making 1 call to Module::Runtime::BEGIN@1
# spent 3µs making 1 call to strict::import |
2 | 2 | 48µs | 2 | 65µs | # spent 36µs (7+29) within Module::Runtime::BEGIN@2 which was called:
# once (7µs+29µs) by Module::Runtime::require_module at line 2 # spent 36µs making 1 call to Module::Runtime::BEGIN@2
# spent 29µs making 1 call to warnings::import |
3 | package JSON::Schema::Modern::Vocabulary::Core; | ||||
4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||
5 | # ABSTRACT: Implementation of the JSON Schema Core vocabulary | ||||
6 | |||||
7 | 1 | 0s | our $VERSION = '0.552'; | ||
8 | |||||
9 | 2 | 38µs | 1 | 16µs | # spent 16µs within JSON::Schema::Modern::Vocabulary::Core::BEGIN@9 which was called:
# once (16µs+0s) by Module::Runtime::require_module at line 9 # spent 16µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@9 |
10 | 2 | 33µs | 2 | 551µs | # spent 281µs (11+270) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@10 which was called:
# once (11µs+270µs) by Module::Runtime::require_module at line 10 # spent 281µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@10
# spent 270µs making 1 call to Moo::import |
11 | 3 | 46µs | 3 | 1.96ms | # spent 991µs (25+966) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@11 which was called:
# once (25µs+966µs) by Module::Runtime::require_module at line 11 # spent 991µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@11
# spent 945µs making 1 call to strictures::import
# spent 20µs making 1 call to strictures::VERSION |
12 | 2 | 60µs | 2 | 267µs | # spent 138µs (9+129) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@12 which was called:
# once (9µs+129µs) by Module::Runtime::require_module at line 12 # spent 138µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@12
# spent 129µs making 1 call to experimental::import |
13 | 2 | 41µs | 2 | 53µs | # spent 50µs (17+33) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@13 which was called:
# once (17µs+33µs) by Module::Runtime::require_module at line 13 # spent 50µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@13
# spent 3µs making 1 call to if::import |
14 | 2 | 30µs | 2 | 40µs | # spent 38µs (18+20) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@14 which was called:
# once (18µs+20µs) by Module::Runtime::require_module at line 14 # spent 38µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@14
# spent 2µs making 1 call to if::unimport |
15 | 2 | 32µs | 2 | 29µs | # spent 27µs (12+15) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@15 which was called:
# once (12µs+15µs) by Module::Runtime::require_module at line 15 # spent 27µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@15
# spent 2µs making 1 call to if::unimport |
16 | 2 | 27µs | 2 | 29µs | # spent 28µs (15+13) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@16 which was called:
# once (15µs+13µs) by Module::Runtime::require_module at line 16 # spent 28µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@16
# spent 1µs making 1 call to if::unimport |
17 | 2 | 170µs | 2 | 137µs | # spent 73µs (9+64) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@17 which was called:
# once (9µs+64µs) by Module::Runtime::require_module at line 17 # spent 73µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@17
# spent 64µs making 1 call to Exporter::import |
18 | 2 | 2.76ms | 2 | 518µs | # spent 264µs (10+254) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@18 which was called:
# once (10µs+254µs) by Module::Runtime::require_module at line 18 # spent 264µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@18
# spent 254µs making 1 call to namespace::clean::import |
19 | |||||
20 | 1 | 3µs | 1 | 4.18ms | with 'JSON::Schema::Modern::Vocabulary'; # spent 4.18ms making 1 call to Moo::with |
21 | |||||
22 | # spent 1µs within JSON::Schema::Modern::Vocabulary::Core::vocabulary which was called:
# once (1µs+0s) by JSON::Schema::Modern::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern.pm:670] at line 666 of JSON/Schema/Modern.pm | ||||
23 | 1 | 3µs | 'https://json-schema.org/draft/2019-09/vocab/core' => 'draft2019-09', | ||
24 | 'https://json-schema.org/draft/2020-12/vocab/core' => 'draft2020-12'; | ||||
25 | } | ||||
26 | |||||
27 | 3 | 6µs | # spent 2µs within JSON::Schema::Modern::Vocabulary::Core::evaluation_order which was called 3 times, avg 667ns/call:
# 3 times (2µs+0s) by JSON::Schema::Modern::Vocabulary::Core::CORE:sort at line 322, avg 667ns/call | ||
28 | |||||
29 | 282225 | 53.9ms | # spent 331ms within JSON::Schema::Modern::Vocabulary::Core::keywords which was called 94075 times, avg 4µs/call:
# 91595 times (324ms+0s) by JSON::Schema::Modern::_eval_subschema at line 535 of JSON/Schema/Modern.pm, avg 4µs/call
# 2480 times (7.26ms+0s) by JSON::Schema::Modern::_traverse_subschema at line 447 of JSON/Schema/Modern.pm, avg 3µs/call | ||
30 | return ( | ||||
31 | 94075 | 357ms | qw($id $schema), | ||
32 | $spec_version ne 'draft7' ? '$anchor' : (), | ||||
33 | $spec_version eq 'draft2019-09' ? '$recursiveAnchor' : (), | ||||
34 | $spec_version eq 'draft2020-12' ? '$dynamicAnchor' : (), | ||||
35 | '$ref', | ||||
36 | $spec_version eq 'draft2019-09' ? '$recursiveRef' : (), | ||||
37 | $spec_version eq 'draft2020-12' ? '$dynamicRef' : (), | ||||
38 | $spec_version eq 'draft7' ? 'definitions' : qw($vocabulary $comment $defs), | ||||
39 | ); | ||||
40 | } | ||||
41 | |||||
42 | # adds the following keys to $state during traversal: | ||||
43 | # - identifiers: an arrayref of tuples: | ||||
44 | # $uri => { path => $path_to_identifier, canonical_uri => Mojo::URL (absolute when possible) } | ||||
45 | # this is used by the Document constructor to build its resource_index. | ||||
46 | |||||
47 | 56 | 8µs | # spent 5.94ms (455µs+5.48) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id which was called 14 times, avg 424µs/call:
# 14 times (455µs+5.48ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 424µs/call | ||
48 | 14 | 57µs | 28 | 3.08ms | return if not assert_keyword_type($state, $schema, 'string') # spent 2.27ms making 14 calls to JSON::Schema::Modern::Utilities::assert_uri_reference, avg 162µs/call
# spent 809µs making 14 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 58µs/call |
49 | or not assert_uri_reference($state, $schema); | ||||
50 | |||||
51 | 14 | 30µs | 14 | 566µs | my $uri = Mojo::URL->new($schema->{'$id'}); # spent 566µs making 14 calls to Mojo::URL::new, avg 40µs/call |
52 | |||||
53 | 14 | 18µs | if ($state->{spec_version} eq 'draft7') { | ||
54 | if (length($uri->fragment)) { | ||||
55 | return E($state, '$id cannot change the base uri at the same time as declaring an anchor') | ||||
56 | if length($uri->clone->fragment(undef)); | ||||
57 | |||||
58 | return $self->_traverse_keyword_anchor({ %$schema, $state->{keyword} => $uri->fragment }, $state); | ||||
59 | } | ||||
60 | } | ||||
61 | else { | ||||
62 | 14 | 13µs | 14 | 8µs | return E($state, '$id value "%s" cannot have a non-empty fragment', $schema->{'$id'}) # spent 8µs making 14 calls to Mojo::URL::fragment, avg 571ns/call |
63 | if length $uri->fragment; | ||||
64 | } | ||||
65 | |||||
66 | 14 | 13µs | 14 | 16µs | $uri->fragment(undef); # spent 16µs making 14 calls to Mojo::URL::fragment, avg 1µs/call |
67 | 14 | 30µs | 14 | 1.18ms | return E($state, '$id cannot be empty') if not length $uri; # spent 1.18ms making 14 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 84µs/call |
68 | |||||
69 | 14 | 24µs | 14 | 45µs | $state->{initial_schema_uri} = $uri->is_abs ? $uri : $uri->to_abs($state->{initial_schema_uri}); # spent 45µs making 14 calls to Mojo::URL::is_abs, avg 3µs/call |
70 | 14 | 17µs | $state->{traversed_schema_path} = $state->{traversed_schema_path}.$state->{schema_path}; | ||
71 | # we don't set or update document_path because it is identical to traversed_schema_path | ||||
72 | 14 | 10µs | $state->{schema_path} = ''; | ||
73 | |||||
74 | push $state->{identifiers}->@*, | ||||
75 | $state->{initial_schema_uri} => { | ||||
76 | path => $state->{traversed_schema_path}, | ||||
77 | canonical_uri => $state->{initial_schema_uri}->clone, | ||||
78 | specification_version => $state->{spec_version}, # note! $schema keyword can change this | ||||
79 | vocabularies => $state->{vocabularies}, # reference, not copy | ||||
80 | configs => $state->{configs}, | ||||
81 | 14 | 127µs | 14 | 589µs | }; # spent 589µs making 14 calls to Mojo::URL::clone, avg 42µs/call |
82 | 14 | 33µs | return 1; | ||
83 | } | ||||
84 | |||||
85 | 129310 | 29.4ms | # spent 1.87s (328ms+1.54) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_id which was called 25862 times, avg 72µs/call:
# 25862 times (328ms+1.54s) by JSON::Schema::Modern::_eval_subschema at line 548 of JSON/Schema/Modern.pm, avg 72µs/call | ||
86 | 25862 | 80.2ms | 25862 | 687ms | my $schema_info = $state->{document}->path_to_resource($state->{document_path}.$state->{schema_path}); # spent 687ms making 25862 calls to JSON::Schema::Modern::Document::path_to_resource, avg 27µs/call |
87 | # this should never happen, if the pre-evaluation traversal was performed correctly | ||||
88 | 25862 | 6.61ms | abort($state, 'failed to resolve %s to canonical uri', $state->{keyword}) if not $schema_info; | ||
89 | |||||
90 | 25862 | 42.2ms | 25862 | 851ms | $state->{initial_schema_uri} = $schema_info->{canonical_uri}->clone; # spent 851ms making 25862 calls to Mojo::URL::clone, avg 33µs/call |
91 | 25862 | 26.7ms | $state->{traversed_schema_path} = $state->{traversed_schema_path}.$state->{schema_path}; | ||
92 | 25862 | 10.7ms | $state->{document_path} = $state->{document_path}.$state->{schema_path}; | ||
93 | 25862 | 7.35ms | $state->{schema_path} = ''; | ||
94 | 25862 | 9.24ms | $state->{spec_version} = $schema_info->{specification_version}; | ||
95 | 25862 | 8.06ms | $state->{vocabularies} = $schema_info->{vocabularies}; | ||
96 | 25862 | 24.6ms | $state->@{keys $state->{configs}->%*} = values $state->{configs}->%*; | ||
97 | 25862 | 27.1ms | push $state->{dynamic_scope}->@*, $state->{initial_schema_uri}; | ||
98 | |||||
99 | 25862 | 47.0ms | return 1; | ||
100 | } | ||||
101 | |||||
102 | 60 | 19µs | # spent 4.58ms (285µs+4.29) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema which was called 15 times, avg 305µs/call:
# 15 times (285µs+4.29ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 305µs/call | ||
103 | 15 | 45µs | 30 | 2.58ms | return if not assert_keyword_type($state, $schema, 'string') or not assert_uri($state, $schema); # spent 2.31ms making 15 calls to JSON::Schema::Modern::Utilities::assert_uri, avg 154µs/call
# spent 275µs making 15 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 18µs/call |
104 | |||||
105 | # "A JSON Schema resource is a schema which is canonically identified by an absolute URI." | ||||
106 | # "A resource's root schema is its top-level schema object." | ||||
107 | # note: we need not be at the document root, but simply adjacent to an $id (or be the at the | ||||
108 | # document root) | ||||
109 | return E($state, '$schema can only appear at the schema resource root') | ||||
110 | 15 | 9µs | if length($state->{schema_path}); | ||
111 | |||||
112 | 15 | 4µs | my ($spec_version, $vocabularies); | ||
113 | |||||
114 | 15 | 47µs | 15 | 443µs | if (my $metaschema_info = $state->{evaluator}->_get_metaschema_vocabulary_classes($schema->{'$schema'})) { # spent 443µs making 15 calls to JSON::Schema::Modern::_get_metaschema_vocabulary_classes, avg 30µs/call |
115 | ($spec_version, $vocabularies) = @$metaschema_info; | ||||
116 | } | ||||
117 | else { | ||||
118 | 1 | 3µs | 1 | 551µs | my $schema_info = $state->{evaluator}->_fetch_from_uri($schema->{'$schema'}); # spent 551µs making 1 call to JSON::Schema::Modern::_fetch_from_uri |
119 | 1 | 0s | return E($state, 'EXCEPTION: unable to find resource %s', $schema->{'$schema'}) if not $schema_info; | ||
120 | |||||
121 | ($spec_version, $vocabularies) = $self->__fetch_vocabulary_data({ %$state, | ||||
122 | keyword => '$vocabulary', initial_schema_uri => Mojo::URL->new($schema->{'$schema'}), | ||||
123 | 1 | 15µs | 3 | 715µs | traversed_schema_path => jsonp($state->{schema_path}, '$schema'), # spent 664µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data
# spent 40µs making 1 call to Mojo::URL::new
# spent 11µs making 1 call to JSON::Schema::Modern::Utilities::jsonp |
124 | }, $schema_info); | ||||
125 | } | ||||
126 | |||||
127 | 15 | 6µs | return E($state, '"%s" is not a valid metaschema', $schema->{'$schema'}) if not @$vocabularies; | ||
128 | |||||
129 | # we special-case this because the check in _eval_subschema for older drafts + $ref has already happened | ||||
130 | return E($state, '$schema and $ref cannot be used together in older drafts') | ||||
131 | 15 | 41µs | if exists $schema->{'$ref'} and $spec_version eq 'draft7'; | ||
132 | |||||
133 | 15 | 20µs | $state->@{qw(spec_version vocabularies)} = ($spec_version, $vocabularies); | ||
134 | |||||
135 | # remember, if we don't have a sibling $id, we must be at the document root with no identifiers | ||||
136 | 15 | 21µs | if ($state->{identifiers}->@*) { | ||
137 | $state->{identifiers}[-1]->@{qw(specification_version vocabularies)} = $state->@{qw(spec_version vocabularies)}; | ||||
138 | } | ||||
139 | |||||
140 | 15 | 32µs | return 1; | ||
141 | } | ||||
142 | |||||
143 | 60 | 30µs | # spent 4.42ms (336µs+4.08) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor which was called 15 times, avg 294µs/call:
# 14 times (276µs+3.78ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicAnchor at line 188, avg 290µs/call
# once (60µs+302µs) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm | ||
144 | 15 | 17µs | 15 | 200µs | return if not assert_keyword_type($state, $schema, 'string'); # spent 200µs making 15 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 13µs/call |
145 | |||||
146 | return E($state, '%s value "%s" does not match required syntax', | ||||
147 | $state->{keyword}, ($state->{keyword} eq '$id' ? '#' : '').$schema->{$state->{keyword}}) | ||||
148 | if $state->{spec_version} =~ /^draft(?:7|2019-09)$/ | ||||
149 | and $schema->{$state->{keyword}} !~ /^[A-Za-z][A-Za-z0-9_:.-]*$/ | ||||
150 | or $state->{spec_version} eq 'draft2020-12' | ||||
151 | 15 | 175µs | 30 | 111µs | and $schema->{$state->{keyword}} !~ /^[A-Za-z_][A-Za-z0-9._-]*$/; # spent 111µs making 30 calls to JSON::Schema::Modern::Vocabulary::Core::CORE:match, avg 4µs/call |
152 | |||||
153 | 15 | 28µs | 15 | 820µs | my $canonical_uri = canonical_uri($state); # spent 820µs making 15 calls to JSON::Schema::Modern::Utilities::canonical_uri, avg 55µs/call |
154 | |||||
155 | push $state->{identifiers}->@*, | ||||
156 | Mojo::URL->new->to_abs($canonical_uri)->fragment($schema->{$state->{keyword}}) => { | ||||
157 | path => $state->{traversed_schema_path}.$state->{schema_path}, | ||||
158 | canonical_uri => $canonical_uri, | ||||
159 | specification_version => $state->{spec_version}, | ||||
160 | vocabularies => $state->{vocabularies}, # reference, not copy | ||||
161 | configs => $state->{configs}, | ||||
162 | 15 | 115µs | 45 | 2.95ms | }; # spent 2.90ms making 15 calls to Mojo::URL::to_abs, avg 193µs/call
# spent 35µs making 15 calls to Mojo::URL::new, avg 2µs/call
# spent 20µs making 15 calls to Mojo::URL::fragment, avg 1µs/call |
163 | 15 | 32µs | return 1; | ||
164 | } | ||||
165 | |||||
166 | # we already indexed the $anchor uri, so there is nothing more to do at evaluation time. | ||||
167 | # we explicitly do NOT set $state->{initial_schema_uri}. | ||||
168 | |||||
169 | sub _traverse_keyword_recursiveAnchor ($self, $schema, $state) { | ||||
170 | return if not assert_keyword_type($state, $schema, 'boolean'); | ||||
171 | |||||
172 | # this is required because the location is used as the base URI for future resolution | ||||
173 | # of $recursiveRef, and the fragment would be disregarded in the base | ||||
174 | return E($state, '"$recursiveAnchor" keyword used without "$id"') | ||||
175 | if length($state->{schema_path}); | ||||
176 | return 1; | ||||
177 | } | ||||
178 | |||||
179 | sub _eval_keyword_recursiveAnchor ($self, $data, $schema, $state) { | ||||
180 | return 1 if not $schema->{'$recursiveAnchor'} or exists $state->{recursive_anchor_uri}; | ||||
181 | |||||
182 | # record the canonical location of the current position, to be used against future resolution | ||||
183 | # of a $recursiveRef uri -- as if it was the current location when we encounter a $ref. | ||||
184 | $state->{recursive_anchor_uri} = canonical_uri($state); | ||||
185 | return 1; | ||||
186 | } | ||||
187 | |||||
188 | 14 | 41µs | 14 | 4.05ms | # spent 4.10ms (45µs+4.06) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicAnchor which was called 14 times, avg 293µs/call:
# 14 times (45µs+4.06ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 293µs/call # spent 4.05ms making 14 calls to JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor, avg 290µs/call |
189 | |||||
190 | # we already indexed the $dynamicAnchor uri, so there is nothing more to do at evaluation time. | ||||
191 | # we explicitly do NOT set $state->{initial_schema_uri}. | ||||
192 | |||||
193 | 2900 | 520µs | # spent 171ms (4.20+167) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_ref which was called 725 times, avg 236µs/call:
# 703 times (4.05ms+161ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 235µs/call
# 22 times (153µs+5.41ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicRef at line 219, avg 253µs/call | ||
194 | 725 | 1.47ms | 1450 | 167ms | return if not assert_keyword_type($state, $schema, 'string') # spent 156ms making 725 calls to JSON::Schema::Modern::Utilities::assert_uri_reference, avg 215µs/call
# spent 10.8ms making 725 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 15µs/call |
195 | or not assert_uri_reference($state, $schema); | ||||
196 | 725 | 1.53ms | return 1; | ||
197 | } | ||||
198 | |||||
199 | 195605 | 38.0ms | # spent 97.2s (705ms+96.5) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref which was called 39121 times, avg 2.49ms/call:
# 39121 times (705ms+96.5s) by JSON::Schema::Modern::_eval_subschema at line 548 of JSON/Schema/Modern.pm, avg 2.49ms/call | ||
200 | 39121 | 154ms | 78242 | 12.0s | my $uri = Mojo::URL->new($schema->{'$ref'})->to_abs($state->{initial_schema_uri}); # spent 7.92s making 39121 calls to Mojo::URL::to_abs, avg 202µs/call
# spent 4.04s making 39121 calls to Mojo::URL::new, avg 103µs/call |
201 | 39121 | 437ms | 39121 | 97.2s | $self->eval_subschema_at_uri($data, $schema, $state, $uri); # spent 1023s making 39121 calls to JSON::Schema::Modern::Vocabulary::eval_subschema_at_uri, avg 26.2ms/call, recursion: max depth 38, sum of overlapping time 926s |
202 | } | ||||
203 | |||||
204 | sub _traverse_keyword_recursiveRef { shift->_traverse_keyword_ref(@_) } | ||||
205 | |||||
206 | sub _eval_keyword_recursiveRef ($self, $data, $schema, $state) { | ||||
207 | my $uri = Mojo::URL->new($schema->{'$recursiveRef'})->to_abs($state->{initial_schema_uri}); | ||||
208 | my $schema_info = $state->{evaluator}->_fetch_from_uri($uri); | ||||
209 | abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not $schema_info; | ||||
210 | |||||
211 | if (is_type('boolean', $schema_info->{schema}{'$recursiveAnchor'}) and $schema_info->{schema}{'$recursiveAnchor'}) { | ||||
212 | $uri = Mojo::URL->new($schema->{'$recursiveRef'}) | ||||
213 | ->to_abs($state->{recursive_anchor_uri} // $state->{initial_schema_uri}); | ||||
214 | } | ||||
215 | |||||
216 | return $self->eval_subschema_at_uri($data, $schema, $state, $uri); | ||||
217 | } | ||||
218 | |||||
219 | 22 | 69µs | 22 | 5.57ms | # spent 5.63ms (68µs+5.57) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicRef which was called 22 times, avg 256µs/call:
# 22 times (68µs+5.57ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 256µs/call # spent 5.57ms making 22 calls to JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_ref, avg 253µs/call |
220 | |||||
221 | 12930 | 3.08ms | # spent 68.0s (143ms+67.8) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef which was called 2586 times, avg 26.3ms/call:
# 2586 times (143ms+67.8s) by JSON::Schema::Modern::_eval_subschema at line 548 of JSON/Schema/Modern.pm, avg 26.3ms/call | ||
222 | 2586 | 10.2ms | 5172 | 746ms | my $uri = Mojo::URL->new($schema->{'$dynamicRef'})->to_abs($state->{initial_schema_uri}); # spent 411ms making 2586 calls to Mojo::URL::to_abs, avg 159µs/call
# spent 334ms making 2586 calls to Mojo::URL::new, avg 129µs/call |
223 | 2586 | 7.02ms | 2586 | 662ms | my $schema_info = $state->{evaluator}->_fetch_from_uri($uri); # spent 662ms making 2586 calls to JSON::Schema::Modern::_fetch_from_uri, avg 256µs/call |
224 | 2586 | 1.06ms | abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not $schema_info; | ||
225 | |||||
226 | # If the initially resolved starting point URI includes a fragment that was created by the | ||||
227 | # "$dynamicAnchor" keyword, ... | ||||
228 | 2586 | 11.0ms | 5172 | 3.57ms | if (length $uri->fragment and exists $schema_info->{schema}{'$dynamicAnchor'} # spent 3.57ms making 5172 calls to Mojo::URL::fragment, avg 690ns/call |
229 | and $uri->fragment eq (my $anchor = $schema_info->{schema}{'$dynamicAnchor'})) { | ||||
230 | # ...the initial URI MUST be replaced by the URI (including the fragment) for the outermost | ||||
231 | # schema resource in the dynamic scope that defines an identically named fragment with | ||||
232 | # "$dynamicAnchor". | ||||
233 | 2586 | 1.89ms | foreach my $base_scope ($state->{dynamic_scope}->@*) { | ||
234 | 2586 | 4.48ms | 5172 | 318ms | my $test_uri = Mojo::URL->new($base_scope)->fragment($anchor); # spent 315ms making 2586 calls to Mojo::URL::new, avg 122µs/call
# spent 2.62ms making 2586 calls to Mojo::URL::fragment, avg 1µs/call |
235 | 2586 | 4.48ms | 2586 | 483ms | my $dynamic_anchor_subschema_info = $state->{evaluator}->_fetch_from_uri($test_uri); # spent 483ms making 2586 calls to JSON::Schema::Modern::_fetch_from_uri, avg 187µs/call |
236 | 2586 | 2.05ms | if (($dynamic_anchor_subschema_info->{schema}->{'$dynamicAnchor'}//'') eq $anchor) { | ||
237 | 2586 | 9.00ms | $uri = $test_uri; | ||
238 | 2586 | 6.37ms | last; | ||
239 | } | ||||
240 | } | ||||
241 | } | ||||
242 | |||||
243 | 2586 | 42.6ms | 2586 | 0s | return $self->eval_subschema_at_uri($data, $schema, $state, $uri); # spent 139s making 2586 calls to JSON::Schema::Modern::Vocabulary::eval_subschema_at_uri, avg 53.6ms/call, recursion: max depth 34, sum of overlapping time 139s |
244 | } | ||||
245 | |||||
246 | 44 | 12µs | # spent 5.94ms (543µs+5.40) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_vocabulary which was called 11 times, avg 540µs/call:
# 11 times (543µs+5.40ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 540µs/call | ||
247 | 11 | 17µs | 11 | 74µs | return if not assert_keyword_type($state, $schema, 'object'); # spent 74µs making 11 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 7µs/call |
248 | |||||
249 | return E($state, '$vocabulary can only appear at the schema resource root') | ||||
250 | 11 | 5µs | if length($state->{schema_path}); | ||
251 | |||||
252 | 11 | 8µs | my $valid = 1; | ||
253 | |||||
254 | 11 | 1µs | my @vocabulary_classes; | ||
255 | 11 | 66µs | 11 | 15µs | foreach my $uri (sort keys $schema->{'$vocabulary'}->%*) { # spent 15µs making 11 calls to JSON::Schema::Modern::Vocabulary::Core::CORE:sort, avg 1µs/call |
256 | 31 | 207µs | 31 | 563µs | $valid = 0, next if not assert_keyword_type({ %$state, _schema_path_suffix => $uri }, $schema, 'boolean'); # spent 563µs making 31 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 18µs/call |
257 | 31 | 159µs | 31 | 4.75ms | $valid = 0, next if not assert_uri({ %$state, _schema_path_suffix => $uri }, undef, $uri); # spent 4.75ms making 31 calls to JSON::Schema::Modern::Utilities::assert_uri, avg 153µs/call |
258 | } | ||||
259 | |||||
260 | # we cannot return an error here for invalid or incomplete vocabulary lists, because | ||||
261 | # - the specification vocabulary schemas themselves don't list Core, | ||||
262 | # - it is possible for a metaschema to $ref to another metaschema that uses an unrecognized | ||||
263 | # vocabulary uri while still validating those vocabulary keywords (e.g. | ||||
264 | # https://spec.openapis.org/oas/3.1/schema-base/2021-05-20) | ||||
265 | # Instead, we will verify these constraints when we actually use the metaschema, in | ||||
266 | # _traverse_keyword_schema -> __fetch_vocabulary_data | ||||
267 | |||||
268 | 11 | 26µs | return $valid; | ||
269 | } | ||||
270 | |||||
271 | # we do nothing with $vocabulary yet at evaluation time. When we know we are in a metaschema, | ||||
272 | # we can scan the URIs included here and either abort if a vocabulary is enabled that we do not | ||||
273 | # understand, or turn on and off certain keyword behaviours based on the boolean values seen. | ||||
274 | |||||
275 | 472 | 94µs | # spent 2.33ms (522µs+1.81) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_comment which was called 118 times, avg 20µs/call:
# 118 times (522µs+1.81ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 20µs/call | ||
276 | 118 | 115µs | 118 | 1.81ms | return if not assert_keyword_type($state, $schema, 'string'); # spent 1.81ms making 118 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 15µs/call |
277 | 118 | 191µs | return 1; | ||
278 | } | ||||
279 | |||||
280 | # we do nothing with $comment at evaluation time, including not collecting its value for annotations. | ||||
281 | |||||
282 | sub _traverse_keyword_definitions { shift->traverse_object_schemas(@_) } | ||||
283 | 12 | 50µs | 12 | 80.9ms | # spent 80.9ms (46µs+80.9) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_defs which was called 12 times, avg 6.74ms/call:
# 12 times (46µs+80.9ms) by JSON::Schema::Modern::_traverse_subschema at line 457 of JSON/Schema/Modern.pm, avg 6.74ms/call # spent 94.4ms making 12 calls to JSON::Schema::Modern::Vocabulary::traverse_object_schemas, avg 7.87ms/call, recursion: max depth 2, sum of overlapping time 13.6ms |
284 | |||||
285 | # we do nothing directly with $defs at evaluation time, including not collecting its value for | ||||
286 | # annotations. | ||||
287 | |||||
288 | |||||
289 | # translate vocabulary URIs into classes, caching the results (if any) | ||||
290 | 4 | 0s | # spent 664µs (102+562) within JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data which was called:
# once (102µs+562µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema at line 123 | ||
291 | 1 | 1µs | if (not exists $schema_info->{schema}{'$vocabulary'}) { | ||
292 | # "If "$vocabulary" is absent, an implementation MAY determine behavior based on the meta-schema | ||||
293 | # if it is recognized from the URI value of the referring schema's "$schema" keyword." | ||||
294 | my $metaschema_uri = $state->{evaluator}->METASCHEMA_URIS->{$schema_info->{specification_version}}; | ||||
295 | return $state->{evaluator}->_get_metaschema_vocabulary_classes($metaschema_uri)->@*; | ||||
296 | } | ||||
297 | |||||
298 | 1 | 0s | my $valid = 1; | ||
299 | 1 | 1µs | $valid = E($state, '$vocabulary can only appear at the document root') if length $schema_info->{document_path}; | ||
300 | 1 | 1µs | $valid = E($state, 'metaschemas must have an $id') if not exists $schema_info->{schema}{'$id'}; | ||
301 | |||||
302 | 1 | 0s | return (undef, []) if not $valid; | ||
303 | |||||
304 | 1 | 0s | my @vocabulary_classes; | ||
305 | |||||
306 | 1 | 12µs | 1 | 3µs | foreach my $uri (sort keys $schema_info->{schema}{'$vocabulary'}->%*) { # spent 3µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::CORE:sort |
307 | 8 | 12µs | 8 | 164µs | my $class_info = $state->{evaluator}->_get_vocabulary_class($uri); # spent 164µs making 8 calls to JSON::Schema::Modern::_get_vocabulary_class, avg 20µs/call |
308 | $valid = E({ %$state, _schema_path_suffix => $uri }, '"%s" is not a known vocabulary', $uri), next | ||||
309 | 8 | 33µs | 8 | 8µs | if $schema_info->{schema}{'$vocabulary'}{$uri} and not $class_info; # spent 8µs making 8 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:7], avg 1µs/call |
310 | |||||
311 | 8 | 0s | next if not $class_info; # vocabulary is not known, but marked as false in the metaschema | ||
312 | |||||
313 | 8 | 8µs | my ($spec_version, $class) = @$class_info; | ||
314 | $valid = E({ %$state, _schema_path_suffix => $uri }, '"%s" uses %s, but the metaschema itself uses %s', | ||||
315 | $uri, $spec_version, $schema_info->{specification_version}), next | ||||
316 | 8 | 2µs | if $spec_version ne $schema_info->{specification_version}; | ||
317 | |||||
318 | 8 | 7µs | push @vocabulary_classes, $class; | ||
319 | } | ||||
320 | |||||
321 | @vocabulary_classes = sort { | ||||
322 | 16 | 47µs | 31 | 118µs | $a->evaluation_order <=> $b->evaluation_order # spent 97µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::CORE:sort
# spent 4µs making 5 calls to JSON::Schema::Modern::Vocabulary::MetaData::evaluation_order, avg 800ns/call
# spent 3µs making 4 calls to JSON::Schema::Modern::Vocabulary::Applicator::evaluation_order, avg 750ns/call
# spent 3µs making 5 calls to JSON::Schema::Modern::Vocabulary::FormatAnnotation::evaluation_order, avg 600ns/call
# spent 3µs making 5 calls to JSON::Schema::Modern::Vocabulary::Validation::evaluation_order, avg 600ns/call
# spent 2µs making 3 calls to JSON::Schema::Modern::Vocabulary::Content::evaluation_order, avg 667ns/call
# spent 2µs making 3 calls to JSON::Schema::Modern::Vocabulary::Core::evaluation_order, avg 667ns/call
# spent 2µs making 2 calls to JSON::Schema::Modern::Vocabulary::Unevaluated::evaluation_order, avg 1µs/call
# spent 2µs making 3 calls to JSON::Schema::Modern::Vocabulary::evaluation_order, avg 667ns/call |
323 | || ($a->evaluation_order == 999 ? 0 | ||||
324 | : ($valid = E($state, '%s and %s have a conflicting evaluation_order', sort $a, $b))) | ||||
325 | } @vocabulary_classes; | ||||
326 | |||||
327 | 1 | 1µs | $valid = E($state, 'the first vocabulary (by evaluation_order) must be Core') | ||
328 | if ($vocabulary_classes[0]//'') ne 'JSON::Schema::Modern::Vocabulary::Core'; | ||||
329 | |||||
330 | $state->{evaluator}->_set_metaschema_vocabulary_classes($schema_info->{canonical_uri}, | ||||
331 | 1 | 4µs | 1 | 290µs | [ $schema_info->{specification_version}, \@vocabulary_classes ]) if $valid; # spent 290µs making 1 call to JSON::Schema::Modern::_set_metaschema_vocabulary_classes |
332 | |||||
333 | 1 | 5µs | return ($schema_info->{specification_version}, $valid ? \@vocabulary_classes : []); | ||
334 | } | ||||
335 | |||||
336 | 1 | 8µs | 1; | ||
337 | |||||
338 | 1 | 47µs | 1 | 595µs | __END__ # spent 595µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[B/Hooks/EndOfScope/XS.pm:26] |
# spent 111µs within JSON::Schema::Modern::Vocabulary::Core::CORE:match which was called 30 times, avg 4µs/call:
# 30 times (111µs+0s) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor at line 151, avg 4µs/call | |||||
# spent 115µs (94+21) within JSON::Schema::Modern::Vocabulary::Core::CORE:sort which was called 13 times, avg 9µs/call:
# 11 times (15µs+0s) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_vocabulary at line 255, avg 1µs/call
# once (76µs+21µs) by JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data at line 322
# once (3µs+0s) by JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data at line 306 |