Filename | /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm |
Statements | Executed 803950 statements in 1.24s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
38781 | 1 | 1 | 651ms | 64.4s | _eval_keyword_ref (recurses: max depth 31, inclusive time 621s) | JSON::Schema::Modern::Vocabulary::Core::
25562 | 1 | 1 | 535ms | 1.97s | _eval_keyword_id | JSON::Schema::Modern::Vocabulary::Core::
2556 | 1 | 1 | 109ms | 44.0s | _eval_keyword_dynamicRef (recurses: max depth 6, inclusive time 48.1s) | JSON::Schema::Modern::Vocabulary::Core::
726 | 2 | 2 | 3.87ms | 172ms | _traverse_keyword_ref | JSON::Schema::Modern::Vocabulary::Core::
112 | 1 | 1 | 530µs | 1.85ms | _traverse_keyword_comment | JSON::Schema::Modern::Vocabulary::Core::
14 | 1 | 1 | 478µs | 24.8ms | _traverse_keyword_id | JSON::Schema::Modern::Vocabulary::Core::
11 | 1 | 1 | 425µs | 4.37ms | _traverse_keyword_vocabulary | JSON::Schema::Modern::Vocabulary::Core::
15 | 2 | 2 | 362µs | 4.01ms | _traverse_keyword_anchor | JSON::Schema::Modern::Vocabulary::Core::
15 | 1 | 1 | 261µs | 3.75ms | _traverse_keyword_schema | JSON::Schema::Modern::Vocabulary::Core::
14 | 1 | 1 | 75µs | 3.54ms | _traverse_keyword_dynamicAnchor | JSON::Schema::Modern::Vocabulary::Core::
12 | 1 | 1 | 60µs | 89.3ms | _traverse_keyword_defs (recurses: max depth 1, inclusive time 9.91ms) | JSON::Schema::Modern::Vocabulary::Core::
22 | 1 | 1 | 58µs | 4.45ms | _traverse_keyword_dynamicRef | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 56µs | 485µs | __fetch_vocabulary_data | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 26µs | 29µs | BEGIN@1 | Module::Runtime::
1 | 1 | 1 | 15µs | 778µs | BEGIN@11 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 13µs | 13µs | BEGIN@9 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 12µs | 32µs | BEGIN@13 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 11µs | 28µs | BEGIN@14 | JSON::Schema::Modern::Vocabulary::Core::
2 | 2 | 1 | 9µs | 9µs | keywords | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 8µs | 96µs | BEGIN@12 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 7µs | 17µs | BEGIN@15 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 7µs | 17µs | BEGIN@16 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 7µs | 174µs | BEGIN@18 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 6µs | 223µs | BEGIN@10 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 6µs | 48µs | BEGIN@17 | JSON::Schema::Modern::Vocabulary::Core::
1 | 1 | 1 | 5µs | 33µ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 | 31µs | 2 | 32µs | # spent 29µs (26+3) within Module::Runtime::BEGIN@1 which was called:
# once (26µs+3µs) by Module::Runtime::require_module at line 1 # spent 29µs making 1 call to Module::Runtime::BEGIN@1
# spent 3µs making 1 call to strict::import |
2 | 2 | 70µs | 2 | 61µs | # spent 33µs (5+28) within Module::Runtime::BEGIN@2 which was called:
# once (5µs+28µs) by Module::Runtime::require_module at line 2 # spent 33µs making 1 call to Module::Runtime::BEGIN@2
# spent 28µ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.559'; | ||
8 | |||||
9 | 2 | 28µs | 1 | 13µs | # spent 13µs within JSON::Schema::Modern::Vocabulary::Core::BEGIN@9 which was called:
# once (13µs+0s) by Module::Runtime::require_module at line 9 # spent 13µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@9 |
10 | 2 | 24µs | 2 | 440µs | # spent 223µs (6+217) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@10 which was called:
# once (6µs+217µs) by Module::Runtime::require_module at line 10 # spent 223µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@10
# spent 217µs making 1 call to Moo::import |
11 | 3 | 159µs | 3 | 1.54ms | # spent 778µs (15+763) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@11 which was called:
# once (15µs+763µs) by Module::Runtime::require_module at line 11 # spent 778µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@11
# spent 747µs making 1 call to strictures::import
# spent 16µs making 1 call to strictures::VERSION |
12 | 2 | 30µs | 2 | 184µs | # spent 96µs (8+88) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@12 which was called:
# once (8µs+88µs) by Module::Runtime::require_module at line 12 # spent 96µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@12
# spent 88µs making 1 call to experimental::import |
13 | 2 | 23µs | 2 | 35µs | # spent 32µs (12+20) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@13 which was called:
# once (12µs+20µs) by Module::Runtime::require_module at line 13 # spent 32µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@13
# spent 3µs making 1 call to if::import |
14 | 2 | 22µs | 2 | 29µs | # spent 28µs (11+17) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@14 which was called:
# once (11µs+17µs) by Module::Runtime::require_module at line 14 # spent 28µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@14
# spent 1µs making 1 call to if::unimport |
15 | 2 | 16µs | 2 | 18µs | # spent 17µs (7+10) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@15 which was called:
# once (7µs+10µs) by Module::Runtime::require_module at line 15 # spent 17µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@15
# spent 1µs making 1 call to if::unimport |
16 | 2 | 20µs | 2 | 18µs | # spent 17µs (7+10) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@16 which was called:
# once (7µs+10µs) by Module::Runtime::require_module at line 16 # spent 17µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@16
# spent 1µs making 1 call to if::unimport |
17 | 2 | 17µs | 2 | 90µs | # spent 48µs (6+42) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@17 which was called:
# once (6µs+42µs) by Module::Runtime::require_module at line 17 # spent 48µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@17
# spent 42µs making 1 call to Exporter::import |
18 | 2 | 2.12ms | 2 | 341µs | # spent 174µs (7+167) within JSON::Schema::Modern::Vocabulary::Core::BEGIN@18 which was called:
# once (7µs+167µs) by Module::Runtime::require_module at line 18 # spent 174µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::BEGIN@18
# spent 167µs making 1 call to namespace::clean::import |
19 | |||||
20 | 1 | 1µs | 1 | 3.67ms | with 'JSON::Schema::Modern::Vocabulary'; # spent 3.67ms 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/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm:709] at line 705 of /Users/ether/git/JSON-Schema-Modern/lib/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 | 4µ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 337, avg 667ns/call | ||
28 | |||||
29 | 6 | 2µs | # spent 9µs within JSON::Schema::Modern::Vocabulary::Core::keywords which was called 2 times, avg 4µs/call:
# once (5µs+0s) by JSON::Schema::Modern::_eval_subschema at line 572 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
# once (4µs+0s) by JSON::Schema::Modern::_traverse_subschema at line 480 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||
30 | return ( | ||||
31 | 2 | 13µs | 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 | 9µs | # spent 24.8ms (478µs+24.3) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_id which was called 14 times, avg 1.77ms/call:
# 14 times (478µs+24.3ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 1.77ms/call | ||
48 | 14 | 77µs | 28 | 21.9ms | return if not assert_keyword_type($state, $schema, 'string') # spent 21.5ms making 14 calls to JSON::Schema::Modern::Utilities::assert_uri_reference, avg 1.54ms/call
# spent 335µs making 14 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 24µs/call |
49 | or not assert_uri_reference($state, $schema); | ||||
50 | |||||
51 | 14 | 17µs | 14 | 582µs | my $uri = Mojo::URL->new($schema->{'$id'}); # spent 582µs making 14 calls to Mojo::URL::new, avg 42µs/call |
52 | |||||
53 | 14 | 53µ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 | 17µs | 14 | 7µs | return E($state, '$id value "%s" cannot have a non-empty fragment', $schema->{'$id'}) # spent 7µs making 14 calls to Mojo::URL::fragment, avg 500ns/call |
63 | if length $uri->fragment; | ||||
64 | } | ||||
65 | |||||
66 | 14 | 15µs | 14 | 19µs | $uri->fragment(undef); # spent 19µs making 14 calls to Mojo::URL::fragment, avg 1µs/call |
67 | 14 | 26µs | 14 | 1.17ms | return E($state, '$id cannot be empty') if not length $uri; # spent 1.17ms making 14 calls to Mojo::URL::__ANON__[Mojo/URL.pm:3], avg 83µs/call |
68 | |||||
69 | 14 | 23µs | 14 | 55µs | $state->{initial_schema_uri} = $uri->is_abs ? $uri : $uri->to_abs($state->{initial_schema_uri}); # spent 55µs making 14 calls to Mojo::URL::is_abs, avg 4µs/call |
70 | 14 | 11µ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 | 6µ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 | 94µs | 14 | 608µs | }; # spent 608µs making 14 calls to Mojo::URL::clone, avg 43µs/call |
82 | 14 | 30µs | return 1; | ||
83 | } | ||||
84 | |||||
85 | 127810 | 19.9ms | # spent 1.97s (535ms+1.44) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_id which was called 25562 times, avg 77µs/call:
# 25562 times (535ms+1.44s) by JSON::Schema::Modern::_eval_subschema at line 587 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 77µs/call | ||
86 | 25562 | 62.0ms | 25562 | 574ms | my $schema_info = $state->{document}->path_to_resource($state->{document_path}.$state->{schema_path}); # spent 574ms making 25562 calls to JSON::Schema::Modern::Document::path_to_resource, avg 22µs/call |
87 | # this should never happen, if the pre-evaluation traversal was performed correctly | ||||
88 | 25562 | 6.34ms | abort($state, 'failed to resolve %s to canonical uri', $state->{keyword}) if not $schema_info; | ||
89 | |||||
90 | 25562 | 36.3ms | 25562 | 791ms | $state->{initial_schema_uri} = $schema_info->{canonical_uri}->clone; # spent 791ms making 25562 calls to Mojo::URL::clone, avg 31µs/call |
91 | 25562 | 23.3ms | $state->{traversed_schema_path} = $state->{traversed_schema_path}.$state->{schema_path}; | ||
92 | 25562 | 9.66ms | $state->{document_path} = $state->{document_path}.$state->{schema_path}; | ||
93 | 25562 | 8.21ms | $state->{schema_path} = ''; | ||
94 | 25562 | 9.41ms | $state->{spec_version} = $schema_info->{specification_version}; | ||
95 | 25562 | 7.94ms | $state->{vocabularies} = $schema_info->{vocabularies}; | ||
96 | |||||
97 | # XXX this code doesn't belong here - but rather in eval_subschema_at_uri | ||||
98 | # it's possible that a different schema resource has its own set of configs, different from the | ||||
99 | # JSM attribute value | ||||
100 | |||||
101 | # XXX come up with a test! | ||||
102 | # it involves processing a 'format' after going through a $ref. | ||||
103 | |||||
104 | 25562 | 10.2ms | if ($state->{validate_formats}) { | ||
105 | $state->{vocabularies} = [ | ||||
106 | map s/^JSON::Schema::Modern::Vocabulary::Format\KAnnotation$/Assertion/r, $state->{vocabularies}->@* | ||||
107 | 25562 | 298ms | 178934 | 70.9ms | ]; # spent 70.9ms making 178934 calls to JSON::Schema::Modern::Vocabulary::Core::CORE:subst, avg 396ns/call |
108 | 25562 | 10.6ms | require JSON::Schema::Modern::Vocabulary::FormatAssertion; | ||
109 | } | ||||
110 | |||||
111 | 25562 | 19.1ms | $state->@{keys $state->{configs}->%*} = values $state->{configs}->%*; | ||
112 | 25562 | 22.9ms | push $state->{dynamic_scope}->@*, $state->{initial_schema_uri}; | ||
113 | |||||
114 | 25562 | 45.9ms | return 1; | ||
115 | } | ||||
116 | |||||
117 | 60 | 13µs | # spent 3.75ms (261µs+3.49) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema which was called 15 times, avg 250µs/call:
# 15 times (261µs+3.49ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 250µs/call | ||
118 | 15 | 76µs | 30 | 2.09ms | return if not assert_keyword_type($state, $schema, 'string') or not assert_uri($state, $schema); # spent 1.90ms making 15 calls to JSON::Schema::Modern::Utilities::assert_uri, avg 127µs/call
# spent 189µs making 15 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 13µs/call |
119 | |||||
120 | # "A JSON Schema resource is a schema which is canonically identified by an absolute URI." | ||||
121 | # "A resource's root schema is its top-level schema object." | ||||
122 | # note: we need not be at the document root, but simply adjacent to an $id (or be the at the | ||||
123 | # document root) | ||||
124 | return E($state, '$schema can only appear at the schema resource root') | ||||
125 | 15 | 7µs | if length($state->{schema_path}); | ||
126 | |||||
127 | 15 | 5µs | my ($spec_version, $vocabularies); | ||
128 | |||||
129 | 15 | 37µs | 15 | 416µs | if (my $metaschema_info = $state->{evaluator}->_get_metaschema_vocabulary_classes($schema->{'$schema'})) { # spent 416µs making 15 calls to JSON::Schema::Modern::_get_metaschema_vocabulary_classes, avg 28µs/call |
130 | ($spec_version, $vocabularies) = @$metaschema_info; | ||||
131 | } | ||||
132 | else { | ||||
133 | 1 | 3µs | 1 | 458µs | my $schema_info = $state->{evaluator}->_fetch_from_uri($schema->{'$schema'}); # spent 458µs making 1 call to JSON::Schema::Modern::_fetch_from_uri |
134 | 1 | 0s | return E($state, 'EXCEPTION: unable to find resource %s', $schema->{'$schema'}) if not $schema_info; | ||
135 | |||||
136 | ($spec_version, $vocabularies) = $self->__fetch_vocabulary_data({ %$state, | ||||
137 | keyword => '$vocabulary', initial_schema_uri => Mojo::URL->new($schema->{'$schema'}), | ||||
138 | 1 | 12µs | 3 | 526µs | traversed_schema_path => jsonp($state->{schema_path}, '$schema'), # spent 485µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data
# spent 33µs making 1 call to Mojo::URL::new
# spent 8µs making 1 call to JSON::Schema::Modern::Utilities::jsonp |
139 | }, $schema_info); | ||||
140 | } | ||||
141 | |||||
142 | 15 | 7µs | return E($state, '"%s" is not a valid metaschema', $schema->{'$schema'}) if not @$vocabularies; | ||
143 | |||||
144 | # we special-case this because the check in _eval_subschema for older drafts + $ref has already happened | ||||
145 | return E($state, '$schema and $ref cannot be used together in older drafts') | ||||
146 | 15 | 7µs | if exists $schema->{'$ref'} and $spec_version eq 'draft7'; | ||
147 | |||||
148 | 15 | 14µs | $state->@{qw(spec_version vocabularies)} = ($spec_version, $vocabularies); | ||
149 | |||||
150 | # remember, if we don't have a sibling $id, we must be at the document root with no identifiers | ||||
151 | 15 | 20µs | if ($state->{identifiers}->@*) { | ||
152 | $state->{identifiers}[-1]->@{qw(specification_version vocabularies)} = $state->@{qw(spec_version vocabularies)}; | ||||
153 | } | ||||
154 | |||||
155 | 15 | 29µs | return 1; | ||
156 | } | ||||
157 | |||||
158 | 60 | 28µs | # spent 4.01ms (362µs+3.65) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor which was called 15 times, avg 268µs/call:
# 14 times (302µs+3.17ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicAnchor at line 203, avg 248µs/call
# once (60µs+484µs) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||
159 | 15 | 17µs | 15 | 167µs | return if not assert_keyword_type($state, $schema, 'string'); # spent 167µs making 15 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 11µs/call |
160 | |||||
161 | return E($state, '%s value "%s" does not match required syntax', | ||||
162 | $state->{keyword}, ($state->{keyword} eq '$id' ? '#' : '').$schema->{$state->{keyword}}) | ||||
163 | if $state->{spec_version} =~ /^draft(?:7|2019-09)$/ | ||||
164 | and $schema->{$state->{keyword}} !~ /^[A-Za-z][A-Za-z0-9_:.-]*$/ | ||||
165 | or $state->{spec_version} eq 'draft2020-12' | ||||
166 | 15 | 106µs | 30 | 51µs | and $schema->{$state->{keyword}} !~ /^[A-Za-z_][A-Za-z0-9._-]*$/; # spent 51µs making 30 calls to JSON::Schema::Modern::Vocabulary::Core::CORE:match, avg 2µs/call |
167 | |||||
168 | 15 | 35µs | 15 | 324µs | my $canonical_uri = canonical_uri($state); # spent 324µs making 15 calls to JSON::Schema::Modern::Utilities::canonical_uri, avg 22µs/call |
169 | |||||
170 | push $state->{identifiers}->@*, | ||||
171 | Mojo::URL->new->to_abs($canonical_uri)->fragment($schema->{$state->{keyword}}) => { | ||||
172 | path => $state->{traversed_schema_path}.$state->{schema_path}, | ||||
173 | canonical_uri => $canonical_uri, | ||||
174 | specification_version => $state->{spec_version}, | ||||
175 | vocabularies => $state->{vocabularies}, # reference, not copy | ||||
176 | configs => $state->{configs}, | ||||
177 | 15 | 156µs | 45 | 3.11ms | }; # spent 3.05ms making 15 calls to Mojo::URL::to_abs, avg 203µs/call
# spent 48µs making 15 calls to Mojo::URL::new, avg 3µs/call
# spent 13µs making 15 calls to Mojo::URL::fragment, avg 867ns/call |
178 | 15 | 30µs | return 1; | ||
179 | } | ||||
180 | |||||
181 | # we already indexed the $anchor uri, so there is nothing more to do at evaluation time. | ||||
182 | # we explicitly do NOT set $state->{initial_schema_uri}. | ||||
183 | |||||
184 | sub _traverse_keyword_recursiveAnchor ($self, $schema, $state) { | ||||
185 | return if not assert_keyword_type($state, $schema, 'boolean'); | ||||
186 | |||||
187 | # this is required because the location is used as the base URI for future resolution | ||||
188 | # of $recursiveRef, and the fragment would be disregarded in the base | ||||
189 | return E($state, '"$recursiveAnchor" keyword used without "$id"') | ||||
190 | if length($state->{schema_path}); | ||||
191 | return 1; | ||||
192 | } | ||||
193 | |||||
194 | sub _eval_keyword_recursiveAnchor ($self, $data, $schema, $state) { | ||||
195 | return 1 if not $schema->{'$recursiveAnchor'} or exists $state->{recursive_anchor_uri}; | ||||
196 | |||||
197 | # record the canonical location of the current position, to be used against future resolution | ||||
198 | # of a $recursiveRef uri -- as if it was the current location when we encounter a $ref. | ||||
199 | $state->{recursive_anchor_uri} = canonical_uri($state); | ||||
200 | return 1; | ||||
201 | } | ||||
202 | |||||
203 | 14 | 66µs | 14 | 3.47ms | # spent 3.54ms (75µs+3.47) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicAnchor which was called 14 times, avg 253µs/call:
# 14 times (75µs+3.47ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 253µs/call # spent 3.47ms making 14 calls to JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_anchor, avg 248µs/call |
204 | |||||
205 | # we already indexed the $dynamicAnchor uri, so there is nothing more to do at evaluation time. | ||||
206 | # we explicitly do NOT set $state->{initial_schema_uri}. | ||||
207 | |||||
208 | 2904 | 352µs | # spent 172ms (3.87+168) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_ref which was called 726 times, avg 236µs/call:
# 704 times (3.76ms+163ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 237µs/call
# 22 times (111µs+4.28ms) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicRef at line 234, avg 200µs/call | ||
209 | 726 | 1.53ms | 1452 | 168ms | return if not assert_keyword_type($state, $schema, 'string') # spent 159ms making 726 calls to JSON::Schema::Modern::Utilities::assert_uri_reference, avg 219µs/call
# spent 8.60ms making 726 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 12µs/call |
210 | or not assert_uri_reference($state, $schema); | ||||
211 | 726 | 1.32ms | return 1; | ||
212 | } | ||||
213 | |||||
214 | 193905 | 33.7ms | # spent 64.4s (651ms+63.7) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_ref which was called 38781 times, avg 1.66ms/call:
# 38781 times (651ms+63.7s) by JSON::Schema::Modern::_eval_subschema at line 587 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 1.66ms/call | ||
215 | 38781 | 143ms | 77562 | 10.7s | my $uri = Mojo::URL->new($schema->{'$ref'})->to_abs($state->{initial_schema_uri}); # spent 7.13s making 38781 calls to Mojo::URL::to_abs, avg 184µs/call
# spent 3.58s making 38781 calls to Mojo::URL::new, avg 92µs/call |
216 | 38781 | 378ms | 38781 | 64.4s | $self->eval_subschema_at_uri($data, $schema, $state, $uri); # spent 674s making 38781 calls to JSON::Schema::Modern::Vocabulary::eval_subschema_at_uri, avg 17.4ms/call, recursion: max depth 38, sum of overlapping time 610s |
217 | } | ||||
218 | |||||
219 | sub _traverse_keyword_recursiveRef { shift->_traverse_keyword_ref(@_) } | ||||
220 | |||||
221 | sub _eval_keyword_recursiveRef ($self, $data, $schema, $state) { | ||||
222 | my $uri = Mojo::URL->new($schema->{'$recursiveRef'})->to_abs($state->{initial_schema_uri}); | ||||
223 | my $schema_info = $state->{evaluator}->_fetch_from_uri($uri); | ||||
224 | abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not $schema_info; | ||||
225 | |||||
226 | if (is_type('boolean', $schema_info->{schema}{'$recursiveAnchor'}) and $schema_info->{schema}{'$recursiveAnchor'}) { | ||||
227 | $uri = Mojo::URL->new($schema->{'$recursiveRef'}) | ||||
228 | ->to_abs($state->{recursive_anchor_uri} // $state->{initial_schema_uri}); | ||||
229 | } | ||||
230 | |||||
231 | return $self->eval_subschema_at_uri($data, $schema, $state, $uri); | ||||
232 | } | ||||
233 | |||||
234 | 22 | 52µs | 22 | 4.39ms | # spent 4.45ms (58µs+4.39) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_dynamicRef which was called 22 times, avg 202µs/call:
# 22 times (58µs+4.39ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 202µs/call # spent 4.39ms making 22 calls to JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_ref, avg 200µs/call |
235 | |||||
236 | 12780 | 3.12ms | # spent 44.0s (109ms+43.9) within JSON::Schema::Modern::Vocabulary::Core::_eval_keyword_dynamicRef which was called 2556 times, avg 17.2ms/call:
# 2556 times (109ms+43.9s) by JSON::Schema::Modern::_eval_subschema at line 587 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 17.2ms/call | ||
237 | 2556 | 10.8ms | 5112 | 664ms | my $uri = Mojo::URL->new($schema->{'$dynamicRef'})->to_abs($state->{initial_schema_uri}); # spent 375ms making 2556 calls to Mojo::URL::to_abs, avg 147µs/call
# spent 288ms making 2556 calls to Mojo::URL::new, avg 113µs/call |
238 | 2556 | 5.58ms | 2556 | 638ms | my $schema_info = $state->{evaluator}->_fetch_from_uri($uri); # spent 638ms making 2556 calls to JSON::Schema::Modern::_fetch_from_uri, avg 250µs/call |
239 | 2556 | 1.06ms | abort($state, 'EXCEPTION: unable to find resource %s', $uri) if not $schema_info; | ||
240 | |||||
241 | # If the initially resolved starting point URI includes a fragment that was created by the | ||||
242 | # "$dynamicAnchor" keyword, ... | ||||
243 | 2556 | 8.22ms | 5112 | 3.42ms | if (length $uri->fragment and exists $schema_info->{schema}{'$dynamicAnchor'} # spent 3.42ms making 5112 calls to Mojo::URL::fragment, avg 668ns/call |
244 | and $uri->fragment eq (my $anchor = $schema_info->{schema}{'$dynamicAnchor'})) { | ||||
245 | # ...the initial URI MUST be replaced by the URI (including the fragment) for the outermost | ||||
246 | # schema resource in the dynamic scope that defines an identically named fragment with | ||||
247 | # "$dynamicAnchor". | ||||
248 | 2556 | 1.45ms | foreach my $base_scope ($state->{dynamic_scope}->@*) { | ||
249 | 2556 | 3.96ms | 5112 | 286ms | my $test_uri = Mojo::URL->new($base_scope)->fragment($anchor); # spent 284ms making 2556 calls to Mojo::URL::new, avg 111µs/call
# spent 2.08ms making 2556 calls to Mojo::URL::fragment, avg 812ns/call |
250 | 2556 | 3.48ms | 2556 | 453ms | my $dynamic_anchor_subschema_info = $state->{evaluator}->_fetch_from_uri($test_uri); # spent 453ms making 2556 calls to JSON::Schema::Modern::_fetch_from_uri, avg 177µs/call |
251 | 2556 | 1.97ms | if (($dynamic_anchor_subschema_info->{schema}->{'$dynamicAnchor'}//'') eq $anchor) { | ||
252 | 2556 | 7.62ms | $uri = $test_uri; | ||
253 | 2556 | 5.23ms | last; | ||
254 | } | ||||
255 | } | ||||
256 | } | ||||
257 | |||||
258 | 2556 | 37.6ms | 2556 | 0s | return $self->eval_subschema_at_uri($data, $schema, $state, $uri); # spent 89.9s making 2556 calls to JSON::Schema::Modern::Vocabulary::eval_subschema_at_uri, avg 35.2ms/call, recursion: max depth 34, sum of overlapping time 89.9s |
259 | } | ||||
260 | |||||
261 | 44 | 24µs | # spent 4.37ms (425µs+3.94) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_vocabulary which was called 11 times, avg 397µs/call:
# 11 times (425µs+3.94ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 397µs/call | ||
262 | 11 | 20µs | 11 | 105µs | return if not assert_keyword_type($state, $schema, 'object'); # spent 105µs making 11 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 10µs/call |
263 | |||||
264 | return E($state, '$vocabulary can only appear at the schema resource root') | ||||
265 | 11 | 3µs | if length($state->{schema_path}); | ||
266 | |||||
267 | 11 | 7µs | my $valid = 1; | ||
268 | |||||
269 | 11 | 2µs | my @vocabulary_classes; | ||
270 | 11 | 54µs | 11 | 13µs | foreach my $uri (sort keys $schema->{'$vocabulary'}->%*) { # spent 13µs making 11 calls to JSON::Schema::Modern::Vocabulary::Core::CORE:sort, avg 1µs/call |
271 | 31 | 149µs | 31 | 384µs | $valid = 0, next if not assert_keyword_type({ %$state, _schema_path_suffix => $uri }, $schema, 'boolean'); # spent 384µs making 31 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 12µs/call |
272 | 31 | 108µs | 31 | 3.44ms | $valid = 0, next if not assert_uri({ %$state, _schema_path_suffix => $uri }, undef, $uri); # spent 3.44ms making 31 calls to JSON::Schema::Modern::Utilities::assert_uri, avg 111µs/call |
273 | } | ||||
274 | |||||
275 | # we cannot return an error here for invalid or incomplete vocabulary lists, because | ||||
276 | # - the specification vocabulary schemas themselves don't list Core, | ||||
277 | # - it is possible for a metaschema to $ref to another metaschema that uses an unrecognized | ||||
278 | # vocabulary uri while still validating those vocabulary keywords (e.g. | ||||
279 | # https://spec.openapis.org/oas/3.1/schema-base/2021-05-20) | ||||
280 | # Instead, we will verify these constraints when we actually use the metaschema, in | ||||
281 | # _traverse_keyword_schema -> __fetch_vocabulary_data | ||||
282 | |||||
283 | 11 | 24µs | return $valid; | ||
284 | } | ||||
285 | |||||
286 | # we do nothing with $vocabulary yet at evaluation time. When we know we are in a metaschema, | ||||
287 | # we can scan the URIs included here and either abort if a vocabulary is enabled that we do not | ||||
288 | # understand, or turn on and off certain keyword behaviours based on the boolean values seen. | ||||
289 | |||||
290 | 448 | 87µs | # spent 1.85ms (530µs+1.32) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_comment which was called 112 times, avg 17µs/call:
# 112 times (530µs+1.32ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 17µs/call | ||
291 | 112 | 117µs | 112 | 1.32ms | return if not assert_keyword_type($state, $schema, 'string'); # spent 1.32ms making 112 calls to JSON::Schema::Modern::Utilities::assert_keyword_type, avg 12µs/call |
292 | 112 | 199µs | return 1; | ||
293 | } | ||||
294 | |||||
295 | # we do nothing with $comment at evaluation time, including not collecting its value for annotations. | ||||
296 | |||||
297 | sub _traverse_keyword_definitions { shift->traverse_object_schemas(@_) } | ||||
298 | 12 | 64µs | 12 | 89.3ms | # spent 89.3ms (60µs+89.3) within JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_defs which was called 12 times, avg 7.44ms/call:
# 12 times (60µs+89.3ms) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 7.44ms/call # spent 99.2ms making 12 calls to JSON::Schema::Modern::Vocabulary::traverse_object_schemas, avg 8.26ms/call, recursion: max depth 2, sum of overlapping time 9.89ms |
299 | |||||
300 | # we do nothing directly with $defs at evaluation time, including not collecting its value for | ||||
301 | # annotations. | ||||
302 | |||||
303 | |||||
304 | # translate vocabulary URIs into classes, caching the results (if any) | ||||
305 | 4 | 0s | # spent 485µs (56+429) within JSON::Schema::Modern::Vocabulary::Core::__fetch_vocabulary_data which was called:
# once (56µs+429µs) by JSON::Schema::Modern::Vocabulary::Core::_traverse_keyword_schema at line 138 | ||
306 | 1 | 1µs | if (not exists $schema_info->{schema}{'$vocabulary'}) { | ||
307 | # "If "$vocabulary" is absent, an implementation MAY determine behavior based on the meta-schema | ||||
308 | # if it is recognized from the URI value of the referring schema's "$schema" keyword." | ||||
309 | my $metaschema_uri = $state->{evaluator}->METASCHEMA_URIS->{$schema_info->{specification_version}}; | ||||
310 | return $state->{evaluator}->_get_metaschema_vocabulary_classes($metaschema_uri)->@*; | ||||
311 | } | ||||
312 | |||||
313 | 1 | 0s | my $valid = 1; | ||
314 | 1 | 1µs | $valid = E($state, '$vocabulary can only appear at the document root') if length $schema_info->{document_path}; | ||
315 | 1 | 0s | $valid = E($state, 'metaschemas must have an $id') if not exists $schema_info->{schema}{'$id'}; | ||
316 | |||||
317 | 1 | 1µs | return (undef, []) if not $valid; | ||
318 | |||||
319 | 1 | 0s | my @vocabulary_classes; | ||
320 | |||||
321 | 1 | 8µs | 1 | 2µs | foreach my $uri (sort keys $schema_info->{schema}{'$vocabulary'}->%*) { # spent 2µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::CORE:sort |
322 | 8 | 6µs | 8 | 155µs | my $class_info = $state->{evaluator}->_get_vocabulary_class($uri); # spent 155µs making 8 calls to JSON::Schema::Modern::_get_vocabulary_class, avg 19µs/call |
323 | $valid = E({ %$state, _schema_path_suffix => $uri }, '"%s" is not a known vocabulary', $uri), next | ||||
324 | 8 | 44µs | 8 | 31µs | if $schema_info->{schema}{'$vocabulary'}{$uri} and not $class_info; # spent 31µs making 8 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:8], avg 4µs/call |
325 | |||||
326 | 8 | 0s | next if not $class_info; # vocabulary is not known, but marked as false in the metaschema | ||
327 | |||||
328 | 8 | 4µs | my ($spec_version, $class) = @$class_info; | ||
329 | $valid = E({ %$state, _schema_path_suffix => $uri }, '"%s" uses %s, but the metaschema itself uses %s', | ||||
330 | $uri, $spec_version, $schema_info->{specification_version}), next | ||||
331 | 8 | 3µs | if $spec_version ne $schema_info->{specification_version}; | ||
332 | |||||
333 | 8 | 3µs | push @vocabulary_classes, $class; | ||
334 | } | ||||
335 | |||||
336 | @vocabulary_classes = sort { | ||||
337 | 16 | 33µs | 31 | 86µs | $a->evaluation_order <=> $b->evaluation_order # spent 70µs making 1 call to JSON::Schema::Modern::Vocabulary::Core::CORE:sort
# spent 3µs making 5 calls to JSON::Schema::Modern::Vocabulary::MetaData::evaluation_order, avg 600ns/call
# spent 3µs making 3 calls to JSON::Schema::Modern::Vocabulary::evaluation_order, avg 1µs/call
# spent 2µs making 4 calls to JSON::Schema::Modern::Vocabulary::Applicator::evaluation_order, avg 500ns/call
# spent 2µs making 3 calls to JSON::Schema::Modern::Vocabulary::Core::evaluation_order, avg 667ns/call
# spent 2µs making 5 calls to JSON::Schema::Modern::Vocabulary::FormatAnnotation::evaluation_order, avg 400ns/call
# spent 2µs making 5 calls to JSON::Schema::Modern::Vocabulary::Validation::evaluation_order, avg 400ns/call
# spent 1µs making 3 calls to JSON::Schema::Modern::Vocabulary::Content::evaluation_order, avg 333ns/call
# spent 1µs making 2 calls to JSON::Schema::Modern::Vocabulary::Unevaluated::evaluation_order, avg 500ns/call |
338 | || ($a->evaluation_order == 999 ? 0 | ||||
339 | : ($valid = E($state, '%s and %s have a conflicting evaluation_order', sort $a, $b))) | ||||
340 | } @vocabulary_classes; | ||||
341 | |||||
342 | 1 | 0s | $valid = E($state, 'the first vocabulary (by evaluation_order) must be Core') | ||
343 | if ($vocabulary_classes[0]//'') ne 'JSON::Schema::Modern::Vocabulary::Core'; | ||||
344 | |||||
345 | $state->{evaluator}->_set_metaschema_vocabulary_classes($schema_info->{canonical_uri}, | ||||
346 | 1 | 2µs | 1 | 171µs | [ $schema_info->{specification_version}, \@vocabulary_classes ]) if $valid; # spent 171µs making 1 call to JSON::Schema::Modern::_set_metaschema_vocabulary_classes |
347 | |||||
348 | 1 | 2µs | return ($schema_info->{specification_version}, $valid ? \@vocabulary_classes : []); | ||
349 | } | ||||
350 | |||||
351 | 1 | 7µs | 1; | ||
352 | 1 | 22µs | 1 | 335µs | __END__ # spent 335µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[B/Hooks/EndOfScope/XS.pm:26] |