Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm |
Statements | Executed 58 statements in 2.88ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.73ms | 10.5ms | BEGIN@20 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 32µs | 35µs | BEGIN@1.81 | JSON::Schema::Modern::
1 | 1 | 1 | 22µs | 179µs | BEGIN@19 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 22µs | 26µs | BUILD | JSON::Schema::Modern::Result::
1 | 1 | 1 | 21µs | 83µs | BEGIN@23 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 18µs | 18µs | BEGIN@21 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 18µs | 22µs | __ANON__[:29] | JSON::Schema::Modern::Result::
1 | 1 | 1 | 15µs | 599µs | BEGIN@11 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 15µs | 279µs | BEGIN@26 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 14µs | 45µs | BEGIN@24 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 14µs | 48µs | BEGIN@29 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 11µs | 32µs | BEGIN@13 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 11µs | 20µs | BEGIN@15 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 11µs | 777µs | BEGIN@18 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 10µs | 10µs | BEGIN@9 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 9µs | 21µs | BEGIN@14 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 9µs | 53µs | BEGIN@63 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 8µs | 19µs | BEGIN@16 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 8µs | 125µs | BEGIN@25 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 6µs | 97µs | BEGIN@12 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 6µs | 7µs | __ANON__[:38] | JSON::Schema::Modern::Result::
1 | 1 | 1 | 5µs | 200µs | BEGIN@10 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 5µs | 322µs | BEGIN@17 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 4µs | 32µs | BEGIN@2.82 | JSON::Schema::Modern::
1 | 1 | 1 | 4µs | 4µs | BEGIN@22 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 1µs | 1µs | OUTPUT_FORMATS (xsub) | JSON::Schema::Modern::Result::
2 | 2 | 1 | 1µs | 1µs | __ANON__ (xsub) | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | TO_JSON | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | __ANON__[:31] | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | __ANON__[:32] | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | __ANON__[:45] | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | __ANON__[:47] | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | __ANON__[:54] | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | _map_uris | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | combine | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | count | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | dump | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | format | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | result | JSON::Schema::Modern::Result::
0 | 0 | 0 | 0s | 0s | stringify | JSON::Schema::Modern::Result::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 29µs | 2 | 38µs | # spent 35µs (32+3) within JSON::Schema::Modern::BEGIN@1.81 which was called:
# once (32µs+3µs) by JSON::Schema::Modern::BEGIN@34 at line 1 # spent 35µs making 1 call to JSON::Schema::Modern::BEGIN@1.81
# spent 3µs making 1 call to strict::import |
2 | 2 | 42µs | 2 | 60µs | # spent 32µs (4+28) within JSON::Schema::Modern::BEGIN@2.82 which was called:
# once (4µs+28µs) by JSON::Schema::Modern::BEGIN@34 at line 2 # spent 32µs making 1 call to JSON::Schema::Modern::BEGIN@2.82
# spent 28µs making 1 call to warnings::import |
3 | package JSON::Schema::Modern::Result; | ||||
4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||
5 | # ABSTRACT: Contains the result of a JSON Schema evaluation | ||||
6 | |||||
7 | 1 | 1µs | our $VERSION = '0.556'; | ||
8 | |||||
9 | 2 | 26µs | 1 | 10µs | # spent 10µs within JSON::Schema::Modern::Result::BEGIN@9 which was called:
# once (10µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 9 # spent 10µs making 1 call to JSON::Schema::Modern::Result::BEGIN@9 |
10 | 2 | 20µs | 2 | 395µs | # spent 200µs (5+195) within JSON::Schema::Modern::Result::BEGIN@10 which was called:
# once (5µs+195µs) by JSON::Schema::Modern::BEGIN@34 at line 10 # spent 200µs making 1 call to JSON::Schema::Modern::Result::BEGIN@10
# spent 195µs making 1 call to Moo::import |
11 | 3 | 29µs | 3 | 1.18ms | # spent 599µs (15+584) within JSON::Schema::Modern::Result::BEGIN@11 which was called:
# once (15µs+584µs) by JSON::Schema::Modern::BEGIN@34 at line 11 # spent 599µs making 1 call to JSON::Schema::Modern::Result::BEGIN@11
# spent 568µs making 1 call to strictures::import
# spent 16µs making 1 call to strictures::VERSION |
12 | 2 | 30µs | 2 | 188µs | # spent 97µs (6+91) within JSON::Schema::Modern::Result::BEGIN@12 which was called:
# once (6µs+91µs) by JSON::Schema::Modern::BEGIN@34 at line 12 # spent 97µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12
# spent 91µs making 1 call to experimental::import |
13 | 2 | 23µs | 2 | 34µs | # spent 32µs (11+21) within JSON::Schema::Modern::Result::BEGIN@13 which was called:
# once (11µs+21µs) by JSON::Schema::Modern::BEGIN@34 at line 13 # spent 32µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13
# spent 2µs making 1 call to if::import |
14 | 2 | 23µs | 2 | 22µs | # spent 21µs (9+12) within JSON::Schema::Modern::Result::BEGIN@14 which was called:
# once (9µs+12µs) by JSON::Schema::Modern::BEGIN@34 at line 14 # spent 21µs making 1 call to JSON::Schema::Modern::Result::BEGIN@14
# spent 1µs making 1 call to if::unimport |
15 | 2 | 17µs | 2 | 20µs | # spent 20µs (11+9) within JSON::Schema::Modern::Result::BEGIN@15 which was called:
# once (11µs+9µs) by JSON::Schema::Modern::BEGIN@34 at line 15 # spent 20µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15
# spent 0s making 1 call to if::unimport |
16 | 2 | 14µs | 2 | 20µs | # spent 19µs (8+11) within JSON::Schema::Modern::Result::BEGIN@16 which was called:
# once (8µs+11µs) by JSON::Schema::Modern::BEGIN@34 at line 16 # spent 19µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16
# spent 1µs making 1 call to if::unimport |
17 | 2 | 22µs | 2 | 639µs | # spent 322µs (5+317) within JSON::Schema::Modern::Result::BEGIN@17 which was called:
# once (5µs+317µs) by JSON::Schema::Modern::BEGIN@34 at line 17 # spent 322µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17
# spent 317µs making 1 call to MooX::TypeTiny::import |
18 | 2 | 67µs | 2 | 1.54ms | # spent 777µs (11+766) within JSON::Schema::Modern::Result::BEGIN@18 which was called:
# once (11µs+766µs) by JSON::Schema::Modern::BEGIN@34 at line 18 # spent 777µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18
# spent 766µs making 1 call to Exporter::Tiny::import |
19 | 2 | 57µs | 2 | 336µs | # spent 179µs (22+157) within JSON::Schema::Modern::Result::BEGIN@19 which was called:
# once (22µs+157µs) by JSON::Schema::Modern::BEGIN@34 at line 19 # spent 179µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19
# spent 157µs making 1 call to MooX::HandlesVia::import |
20 | 2 | 763µs | 2 | 10.5ms | # spent 10.5ms (1.73+8.77) within JSON::Schema::Modern::Result::BEGIN@20 which was called:
# once (1.73ms+8.77ms) by JSON::Schema::Modern::BEGIN@34 at line 20 # spent 10.5ms making 1 call to JSON::Schema::Modern::Result::BEGIN@20
# spent 1µs making 1 call to JSON::Schema::Modern::Result::__ANON__ |
21 | 2 | 36µs | 2 | 18µs | # spent 18µs within JSON::Schema::Modern::Result::BEGIN@21 which was called:
# once (18µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 21 # spent 18µs making 1 call to JSON::Schema::Modern::Result::BEGIN@21
# spent 0s making 1 call to JSON::Schema::Modern::Result::__ANON__ |
22 | 2 | 28µs | 1 | 4µs | # spent 4µs within JSON::Schema::Modern::Result::BEGIN@22 which was called:
# once (4µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 22 # spent 4µs making 1 call to JSON::Schema::Modern::Result::BEGIN@22 |
23 | 3 | 124µs | 3 | 107µs | # spent 83µs (21+62) within JSON::Schema::Modern::Result::BEGIN@23 which was called:
# once (21µs+62µs) by JSON::Schema::Modern::BEGIN@34 at line 23 # spent 83µs making 1 call to JSON::Schema::Modern::Result::BEGIN@23
# spent 12µs making 1 call to List::Util::import
# spent 12µs making 1 call to UNIVERSAL::VERSION |
24 | 2 | 37µs | 2 | 76µs | # spent 45µs (14+31) within JSON::Schema::Modern::Result::BEGIN@24 which was called:
# once (14µs+31µs) by JSON::Schema::Modern::BEGIN@34 at line 24 # spent 45µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24
# spent 31µs making 1 call to Exporter::import |
25 | 2 | 35µs | 2 | 242µs | # spent 125µs (8+117) within JSON::Schema::Modern::Result::BEGIN@25 which was called:
# once (8µs+117µs) by JSON::Schema::Modern::BEGIN@34 at line 25 # spent 125µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25
# spent 117µs making 1 call to Exporter::import |
26 | 2 | 158µs | 2 | 543µs | # spent 279µs (15+264) within JSON::Schema::Modern::Result::BEGIN@26 which was called:
# once (15µs+264µs) by JSON::Schema::Modern::BEGIN@34 at line 26 # spent 279µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26
# spent 264µs making 1 call to namespace::clean::import |
27 | |||||
28 | use overload | ||||
29 | 1 | 15µs | 1 | 4µs | # spent 22µs (18+4) within JSON::Schema::Modern::Result::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm:29] which was called:
# once (18µs+4µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 149 of JSON/Schema/Modern/Document/OpenAPI.pm
# spent 48µs (14+34) within JSON::Schema::Modern::Result::BEGIN@29 which was called:
# once (14µs+34µs) by JSON::Schema::Modern::BEGIN@34 at line 33 # spent 4µs making 1 call to JSON::Schema::Modern::Result::valid |
30 | '&' => \&combine, | ||||
31 | '0+' => sub { Scalar::Util::refaddr($_[0]) }, | ||||
32 | '""' => sub { $_[0]->stringify }, | ||||
33 | 2 | 267µs | 2 | 82µs | fallback => 1; # spent 48µs making 1 call to JSON::Schema::Modern::Result::BEGIN@29
# spent 34µs making 1 call to overload::import |
34 | |||||
35 | has valid => ( | ||||
36 | is => 'ro', | ||||
37 | isa => InstanceOf['JSON::PP::Boolean'], | ||||
38 | 1 | 5µs | 1 | 1µs | # spent 7µs (6+1000ns) within JSON::Schema::Modern::Result::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm:38] which was called:
# once (6µs+1000ns) by JSON::Schema::Modern::Result::new at line 114 of (eval 433)[Sub/Quote.pm:3] # spent 1µs making 1 call to JSON::PP::true |
39 | 1 | 9µs | 2 | 1.35ms | ); # spent 1.25ms making 1 call to MooX::HandlesVia::has
# spent 99µs making 1 call to Types::Standard::InstanceOf |
40 | sub result { shift->valid } # backcompat only | ||||
41 | |||||
42 | has exception => ( | ||||
43 | is => 'ro', | ||||
44 | isa => InstanceOf['JSON::PP::Boolean'], | ||||
45 | coerce => sub { $_[0] ? JSON::PP::true : JSON::PP::false }, | ||||
46 | lazy => 1, | ||||
47 | default => sub { any { $_->exception } $_[0]->errors }, | ||||
48 | 1 | 15µs | 2 | 1.76ms | ); # spent 1.63ms making 1 call to MooX::HandlesVia::has
# spent 133µs making 1 call to Types::Standard::InstanceOf |
49 | |||||
50 | has $_.'s' => ( | ||||
51 | is => 'bare', | ||||
52 | isa => ArrayRef[InstanceOf['JSON::Schema::Modern::'.ucfirst]], | ||||
53 | lazy => 1, | ||||
54 | default => sub { [] }, | ||||
55 | handles_via => 'Array', | ||||
56 | handles => { | ||||
57 | $_.'s' => 'elements', | ||||
58 | $_.'_count' => 'count', | ||||
59 | }, | ||||
60 | 1 | 40µs | 6 | 14.2ms | ) foreach qw(error annotation); # spent 9.52ms making 2 calls to MooX::HandlesVia::has, avg 4.76ms/call
# spent 3.63ms making 2 calls to Types::Standard::ArrayRef, avg 1.82ms/call
# spent 1.08ms making 2 calls to Types::Standard::InstanceOf, avg 542µs/call |
61 | |||||
62 | # strict_basic can only be used with draft2019-09. | ||||
63 | 2 | 843µs | 2 | 97µs | # spent 53µs (9+44) within JSON::Schema::Modern::Result::BEGIN@63 which was called:
# once (9µs+44µs) by JSON::Schema::Modern::BEGIN@34 at line 63 # spent 53µs making 1 call to JSON::Schema::Modern::Result::BEGIN@63
# spent 44µs making 1 call to constant::import |
64 | |||||
65 | 1 | 4µs | 2 | 2.34ms | has output_format => ( # spent 1.56ms making 1 call to MooX::HandlesVia::has
# spent 786µs making 1 call to Types::Standard::Enum |
66 | is => 'rw', | ||||
67 | isa => Enum(OUTPUT_FORMATS), | ||||
68 | default => 'basic', | ||||
69 | ); | ||||
70 | |||||
71 | 1 | 5µs | 2 | 584µs | has formatted_annotations => ( # spent 581µs making 1 call to MooX::HandlesVia::has
# spent 3µs making 1 call to Types::Standard::Bool |
72 | is => 'ro', | ||||
73 | isa => Bool, | ||||
74 | default => 1, | ||||
75 | ); | ||||
76 | |||||
77 | 2 | 7µs | # spent 26µs (22+4) within JSON::Schema::Modern::Result::BUILD which was called:
# once (22µs+4µs) by JSON::Schema::Modern::Result::new at line 128 of (eval 433)[Sub/Quote.pm:3] | ||
78 | 1 | 12µs | 3 | 4µs | warn 'result is false but there are no errors' if not $self->valid and not $self->error_count; # spent 3µs making 1 call to JSON::Schema::Modern::Result::valid
# spent 1µs making 2 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:7], avg 500ns/call |
79 | } | ||||
80 | |||||
81 | sub format ($self, $style, $formatted_annotations = undef) { | ||||
82 | $formatted_annotations //= $self->formatted_annotations; | ||||
83 | |||||
84 | if ($style eq 'flag') { | ||||
85 | return +{ valid => $self->valid }; | ||||
86 | } | ||||
87 | elsif ($style eq 'basic') { | ||||
88 | return +{ | ||||
89 | valid => $self->valid, | ||||
90 | $self->valid | ||||
91 | ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ()) | ||||
92 | : (errors => [ map $_->TO_JSON, $self->errors ]), | ||||
93 | }; | ||||
94 | } | ||||
95 | # note: strict_basic will NOT be supported after draft 2019-09! | ||||
96 | elsif ($style eq 'strict_basic') { | ||||
97 | return +{ | ||||
98 | valid => $self->valid, | ||||
99 | $self->valid | ||||
100 | ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map _map_uris($_->TO_JSON), $self->annotations ]) : ()) | ||||
101 | : (errors => [ map _map_uris($_->TO_JSON), $self->errors ]), | ||||
102 | }; | ||||
103 | } | ||||
104 | elsif ($style eq 'terse') { | ||||
105 | my (%instance_locations, %keyword_locations); | ||||
106 | |||||
107 | my @errors = grep { | ||||
108 | my ($keyword, $error) = ($_->keyword, $_->error); | ||||
109 | |||||
110 | my $keep = 0+!!( | ||||
111 | not $keyword | ||||
112 | or ( | ||||
113 | not grep $keyword eq $_, qw(allOf anyOf if then else dependentSchemas contains propertyNames) | ||||
114 | and ($keyword ne 'oneOf' or $error ne 'no subschemas are valid') | ||||
115 | and ($keyword ne 'prefixItems' or $error eq 'item not permitted') | ||||
116 | and ($keyword ne 'items' or $error eq 'item not permitted' or $error eq 'additional item not permitted') | ||||
117 | and ($keyword ne 'additionalItems' or $error eq 'additional item not permitted') | ||||
118 | and (not grep $keyword eq $_, qw(properties patternProperties) | ||||
119 | or $error eq 'property not permitted') | ||||
120 | and ($keyword ne 'additionalProperties' or $error eq 'additional property not permitted')) | ||||
121 | and ($keyword ne 'dependentRequired' or $error ne 'not all dependencies are satisfied') | ||||
122 | ); | ||||
123 | |||||
124 | ++$instance_locations{$_->instance_location} if $keep; | ||||
125 | ++$keyword_locations{$_->keyword_location} if $keep; | ||||
126 | |||||
127 | $keep; | ||||
128 | } | ||||
129 | $self->errors; | ||||
130 | |||||
131 | die 'uh oh, have no errors left to report' if not $self->valid and not @errors; | ||||
132 | |||||
133 | return +{ | ||||
134 | valid => $self->valid, | ||||
135 | $self->valid | ||||
136 | ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ()) | ||||
137 | : (errors => [ map $_->TO_JSON, @errors ]), | ||||
138 | }; | ||||
139 | } | ||||
140 | elsif ($style eq 'data_only') { | ||||
141 | return 'valid' if not $self->error_count; | ||||
142 | # Note: this output is going to be confusing when coming from a schema with a 'oneOf', 'not', | ||||
143 | # etc. Perhaps generating the strings with indentation levels, as derived from a nested format, | ||||
144 | # might be more readable. | ||||
145 | return join("\n", uniq(map $_->stringify, $self->errors)); | ||||
146 | } | ||||
147 | |||||
148 | die 'unsupported output format'; | ||||
149 | } | ||||
150 | |||||
151 | sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count } | ||||
152 | |||||
153 | sub combine ($self, $other, $swap) { | ||||
154 | die 'wrong type for & operation' if not $other->$_isa(__PACKAGE__); | ||||
155 | |||||
156 | return $self if refaddr($other) == refaddr($self); | ||||
157 | |||||
158 | return ref($self)->new( | ||||
159 | valid => $self->valid && $other->valid, | ||||
160 | annotations => [ | ||||
161 | $self->annotations, | ||||
162 | $other->annotations, | ||||
163 | ], | ||||
164 | errors => [ | ||||
165 | $self->errors, | ||||
166 | $other->errors, | ||||
167 | ], | ||||
168 | output_format => $self->output_format, | ||||
169 | formatted_annotations => $self->formatted_annotations || $other->formatted_annotations, | ||||
170 | ); | ||||
171 | } | ||||
172 | |||||
173 | |||||
174 | sub stringify ($self) { | ||||
175 | return $self->format('data_only'); | ||||
176 | } | ||||
177 | |||||
178 | sub TO_JSON ($self) { | ||||
179 | die 'cannot produce JSON output for data_only format' if $self->output_format eq 'data_only'; | ||||
180 | $self->format($self->output_format); | ||||
181 | } | ||||
182 | |||||
183 | sub dump ($self) { | ||||
184 | my $encoder = JSON::MaybeXS->new(utf8 => 0, convert_blessed => 1, canonical => 1, pretty => 1); | ||||
185 | $encoder->indent_length(2) if $encoder->can('indent_length'); | ||||
186 | $encoder->encode($self); | ||||
187 | } | ||||
188 | |||||
189 | # turns the JSON pointers in instance_location, keyword_location into a URI fragments, | ||||
190 | # for strict draft-201909 adherence | ||||
191 | sub _map_uris ($data) { | ||||
192 | return +{ | ||||
193 | %$data, | ||||
194 | map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string), | ||||
195 | qw(instanceLocation keywordLocation), | ||||
196 | }; | ||||
197 | } | ||||
198 | |||||
199 | 1 | 23µs | 1; | ||
200 | |||||
201 | 1 | 49µs | 1 | 534µs | __END__ # spent 534µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[B/Hooks/EndOfScope/XS.pm:26] |
# spent 1µs within JSON::Schema::Modern::Result::OUTPUT_FORMATS which was called:
# once (1µs+0s) by OpenAPI::Modern::BEGIN@26 at line 59 of JSON/Schema/Modern.pm | |||||
sub JSON::Schema::Modern::Result::__ANON__; # xsub |