Filename | /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Content.pm |
Statements | Executed 56 statements in 963µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 28µs | 30µs | BEGIN@1.317 | Module::Runtime::
1 | 1 | 1 | 20µs | 63µs | _traverse_keyword_contentEncoding | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 20µs | 83µs | _traverse_keyword_contentMediaType | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 19µs | 90µs | _traverse_keyword_contentSchema | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 10µs | 600µs | BEGIN@11 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 10µs | 28µs | BEGIN@13 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 8µs | 19µs | BEGIN@14 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 8µs | 16µs | BEGIN@16 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 8µs | 8µs | BEGIN@9 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 7µs | 16µs | BEGIN@15 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 5µs | 202µs | BEGIN@10 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 5µs | 22µs | BEGIN@17 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 5µs | 16µs | BEGIN@18 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 5µs | 30µs | BEGIN@19 | JSON::Schema::Modern::Vocabulary::Content::
2 | 2 | 1 | 5µs | 5µs | keywords | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 4µs | 70µs | BEGIN@12 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 4µs | 176µs | BEGIN@20 | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 4µs | 23µs | BEGIN@2.318 | Module::Runtime::
3 | 1 | 1 | 1µs | 1µs | evaluation_order | JSON::Schema::Modern::Vocabulary::Content::
1 | 1 | 1 | 1µs | 1µs | vocabulary | JSON::Schema::Modern::Vocabulary::Content::
0 | 0 | 0 | 0s | 0s | _eval_keyword_contentEncoding | JSON::Schema::Modern::Vocabulary::Content::
0 | 0 | 0 | 0s | 0s | _eval_keyword_contentMediaType | JSON::Schema::Modern::Vocabulary::Content::
0 | 0 | 0 | 0s | 0s | _eval_keyword_contentSchema | JSON::Schema::Modern::Vocabulary::Content::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 25µs | 2 | 32µs | # spent 30µs (28+2) within Module::Runtime::BEGIN@1.317 which was called:
# once (28µs+2µs) by Module::Runtime::require_module at line 1 # spent 30µs making 1 call to Module::Runtime::BEGIN@1.317
# spent 2µs making 1 call to strict::import |
2 | 2 | 33µs | 2 | 42µs | # spent 23µs (4+19) within Module::Runtime::BEGIN@2.318 which was called:
# once (4µs+19µs) by Module::Runtime::require_module at line 2 # spent 23µs making 1 call to Module::Runtime::BEGIN@2.318
# spent 19µs making 1 call to warnings::import |
3 | package JSON::Schema::Modern::Vocabulary::Content; | ||||
4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||
5 | # ABSTRACT: Implementation of the JSON Schema Content vocabulary | ||||
6 | |||||
7 | 1 | 0s | our $VERSION = '0.559'; | ||
8 | |||||
9 | 2 | 26µs | 1 | 8µs | # spent 8µs within JSON::Schema::Modern::Vocabulary::Content::BEGIN@9 which was called:
# once (8µs+0s) by Module::Runtime::require_module at line 9 # spent 8µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@9 |
10 | 2 | 20µs | 2 | 399µs | # spent 202µs (5+197) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@10 which was called:
# once (5µs+197µs) by Module::Runtime::require_module at line 10 # spent 202µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@10
# spent 197µs making 1 call to Moo::import |
11 | 3 | 23µs | 3 | 1.19ms | # spent 600µs (10+590) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@11 which was called:
# once (10µs+590µs) by Module::Runtime::require_module at line 11 # spent 600µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@11
# spent 577µs making 1 call to strictures::import
# spent 12µs making 1 call to strictures::VERSION |
12 | 2 | 31µs | 2 | 136µs | # spent 70µs (4+66) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@12 which was called:
# once (4µs+66µs) by Module::Runtime::require_module at line 12 # spent 70µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@12
# spent 66µs making 1 call to experimental::import |
13 | 2 | 21µs | 2 | 30µs | # spent 28µs (10+18) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@13 which was called:
# once (10µs+18µs) by Module::Runtime::require_module at line 13 # spent 28µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@13
# spent 2µs making 1 call to if::import |
14 | 2 | 20µs | 2 | 20µs | # spent 19µs (8+11) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@14 which was called:
# once (8µs+11µs) by Module::Runtime::require_module at line 14 # spent 19µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@14
# spent 1µs making 1 call to if::unimport |
15 | 2 | 18µs | 2 | 16µs | # spent 16µs (7+9) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@15 which was called:
# once (7µs+9µs) by Module::Runtime::require_module at line 15 # spent 16µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@15
# spent 0s making 1 call to if::unimport |
16 | 2 | 13µs | 2 | 17µs | # spent 16µs (8+8) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@16 which was called:
# once (8µs+8µs) by Module::Runtime::require_module at line 16 # spent 16µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@16
# spent 1µs making 1 call to if::unimport |
17 | 2 | 15µs | 2 | 39µs | # spent 22µs (5+17) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@17 which was called:
# once (5µs+17µs) by Module::Runtime::require_module at line 17 # spent 22µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@17
# spent 17µs making 1 call to Exporter::import |
18 | 2 | 15µs | 2 | 27µs | # spent 16µs (5+11) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@18 which was called:
# once (5µs+11µs) by Module::Runtime::require_module at line 18 # spent 16µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@18
# spent 11µs making 1 call to Feature::Compat::Try::import |
19 | 2 | 15µs | 2 | 55µs | # spent 30µs (5+25) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@19 which was called:
# once (5µs+25µs) by Module::Runtime::require_module at line 19 # spent 30µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@19
# spent 25µs making 1 call to Exporter::import |
20 | 2 | 585µs | 2 | 348µs | # spent 176µs (4+172) within JSON::Schema::Modern::Vocabulary::Content::BEGIN@20 which was called:
# once (4µs+172µs) by Module::Runtime::require_module at line 20 # spent 176µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::BEGIN@20
# spent 172µs making 1 call to namespace::clean::import |
21 | |||||
22 | 1 | 1µs | 1 | 321µs | with 'JSON::Schema::Modern::Vocabulary'; # spent 321µs making 1 call to Moo::with |
23 | |||||
24 | # spent 1µs within JSON::Schema::Modern::Vocabulary::Content::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 | ||||
25 | 1 | 2µs | 'https://json-schema.org/draft/2019-09/vocab/content' => 'draft2019-09', | ||
26 | 'https://json-schema.org/draft/2020-12/vocab/content' => 'draft2020-12'; | ||||
27 | } | ||||
28 | |||||
29 | 3 | 4µs | # spent 1µs within JSON::Schema::Modern::Vocabulary::Content::evaluation_order which was called 3 times, avg 333ns/call:
# 3 times (1µs+0s) by JSON::Schema::Modern::Vocabulary::Core::CORE:sort at line 337 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Vocabulary/Core.pm, avg 333ns/call | ||
30 | |||||
31 | 6 | 1µs | # spent 5µs within JSON::Schema::Modern::Vocabulary::Content::keywords which was called 2 times, avg 2µs/call:
# once (3µs+0s) by JSON::Schema::Modern::_eval_subschema at line 572 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
# once (2µs+0s) by JSON::Schema::Modern::_traverse_subschema at line 480 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||
32 | return ( | ||||
33 | 2 | 6µs | qw(contentEncoding contentMediaType), | ||
34 | $spec_version ne 'draft7' ? 'contentSchema' : (), | ||||
35 | ); | ||||
36 | } | ||||
37 | |||||
38 | 4 | 6µs | # spent 63µs (20+43) within JSON::Schema::Modern::Vocabulary::Content::_traverse_keyword_contentEncoding which was called:
# once (20µs+43µs) by JSON::Schema::Modern::Vocabulary::Content::_traverse_keyword_contentMediaType at line 66 | ||
39 | 1 | 31µs | 1 | 43µs | return if not assert_keyword_type($state, $schema, 'string'); # spent 43µs making 1 call to JSON::Schema::Modern::Utilities::assert_keyword_type |
40 | 1 | 3µs | return 1; | ||
41 | } | ||||
42 | |||||
43 | sub _eval_keyword_contentEncoding ($self, $data, $schema, $state) { | ||||
44 | return 1 if not is_type('string', $data); | ||||
45 | |||||
46 | A($state, $schema->{$state->{keyword}}); | ||||
47 | |||||
48 | if ($state->{validate_content_schemas}) { | ||||
49 | my $decoder = $state->{evaluator}->get_encoding($schema->{contentEncoding}); | ||||
50 | abort($state, 'cannot find decoder for contentEncoding "%s"', $schema->{contentEncoding}) | ||||
51 | if not $decoder; | ||||
52 | |||||
53 | # decode the data now, so we can report errors for the right keyword | ||||
54 | try { | ||||
55 | $state->{_content_ref} = $decoder->(\$data); | ||||
56 | } | ||||
57 | catch ($e) { | ||||
58 | chomp $e; | ||||
59 | return E($state, 'could not decode %s string: %s', $schema->{contentEncoding}, $e); | ||||
60 | }; | ||||
61 | } | ||||
62 | |||||
63 | return 1; | ||||
64 | } | ||||
65 | |||||
66 | 1 | 13µs | 1 | 63µs | # spent 83µs (20+63) within JSON::Schema::Modern::Vocabulary::Content::_traverse_keyword_contentMediaType which was called:
# once (20µs+63µs) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm # spent 63µs making 1 call to JSON::Schema::Modern::Vocabulary::Content::_traverse_keyword_contentEncoding |
67 | |||||
68 | sub _eval_keyword_contentMediaType ($self, $data, $schema, $state) { | ||||
69 | return 1 if not is_type('string', $data); | ||||
70 | |||||
71 | A($state, $schema->{$state->{keyword}}); | ||||
72 | |||||
73 | if ($state->{validate_content_schemas}) { | ||||
74 | my $decoder = $state->{evaluator}->get_media_type($schema->{contentMediaType}); | ||||
75 | abort($state, 'cannot find decoder for contentMediaType "%s"', $schema->{contentMediaType}) | ||||
76 | if not $decoder; | ||||
77 | |||||
78 | # contentEncoding failed to decode the content | ||||
79 | return 1 if exists $schema->{contentEncoding} and not exists $state->{_content_ref}; | ||||
80 | |||||
81 | # decode the data now, so we can report errors for the right keyword | ||||
82 | try { | ||||
83 | $state->{_content_ref} = $decoder->($state->{_content_ref} // \$data); | ||||
84 | } | ||||
85 | catch ($e) { | ||||
86 | chomp $e; | ||||
87 | delete $state->{_content_ref}; | ||||
88 | return E($state, 'could not decode %s string: %s', $schema->{contentMediaType}, $e); | ||||
89 | } | ||||
90 | } | ||||
91 | |||||
92 | return 1; | ||||
93 | } | ||||
94 | |||||
95 | 4 | 2µs | # spent 90µs (19+71) within JSON::Schema::Modern::Vocabulary::Content::_traverse_keyword_contentSchema which was called:
# once (19µs+71µs) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||
96 | # since contentSchema should never be assumed to be evaluated in the context of the containing | ||||
97 | # schema, it is not appropriate to gather identifiers found therein -- but we can still validate | ||||
98 | # the subschema. | ||||
99 | 1 | 10µs | 1 | 71µs | $self->traverse_subschema($schema, +{ %$state, identifiers => [] }); # spent 71µs making 1 call to JSON::Schema::Modern::Vocabulary::traverse_subschema |
100 | } | ||||
101 | |||||
102 | sub _eval_keyword_contentSchema ($self, $data, $schema, $state) { | ||||
103 | return 1 if not exists $schema->{contentMediaType}; | ||||
104 | return 1 if not is_type('string', $data); | ||||
105 | |||||
106 | A($state, dclone($schema->{contentSchema})); | ||||
107 | return 1 if not $state->{validate_content_schemas}; | ||||
108 | |||||
109 | return 1 if not exists $state->{_content_ref}; # contentMediaType failed to decode the content | ||||
110 | |||||
111 | return 1 if $self->eval($state->{_content_ref}->$*, $schema->{contentSchema}, | ||||
112 | { %$state, schema_path => $state->{schema_path}.'/contentSchema' }); | ||||
113 | return E($state, 'subschema is not valid'); | ||||
114 | } | ||||
115 | |||||
116 | 1 | 6µs | 1; | ||
117 | 1 | 18µs | 1 | 253µs | __END__ # spent 253µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[B/Hooks/EndOfScope/XS.pm:26] |