Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm |
Statements | Executed 58 statements in 2.78ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.49ms | 8.73ms | BEGIN@20 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 32µs | 35µs | BEGIN@1.81 | JSON::Schema::Modern::
1 | 1 | 1 | 27µs | 64µs | __ANON__[:38] | JSON::Schema::Modern::Result::
1 | 1 | 1 | 20µs | 38µs | BEGIN@16 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 19µs | 880µs | BEGIN@11 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 19µs | 70µs | BEGIN@23 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 16µs | 29µs | BUILD | JSON::Schema::Modern::Result::
1 | 1 | 1 | 15µs | 47µs | BEGIN@13 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 15µs | 16µs | BEGIN@21 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 14µs | 25µs | BEGIN@15 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 14µs | 17µs | __ANON__[:29] | JSON::Schema::Modern::Result::
1 | 1 | 1 | 12µs | 277µs | BEGIN@10 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 12µs | 31µs | BEGIN@14 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 12µs | 46µs | BEGIN@29 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 10µs | 65µs | BEGIN@63 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 10µs | 10µs | BEGIN@9 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 9µs | 142µs | BEGIN@12 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 9µs | 394µs | BEGIN@26 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 8µs | 704µs | BEGIN@17 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 8µs | 602µs | BEGIN@18 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 8µs | 98µs | BEGIN@25 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 7µs | 24µs | BEGIN@24 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 5µs | 32µs | BEGIN@2.82 | JSON::Schema::Modern::
1 | 1 | 1 | 5µs | 76µs | BEGIN@19 | JSON::Schema::Modern::Result::
1 | 1 | 1 | 3µs | 3µs | BEGIN@22 | JSON::Schema::Modern::Result::
2 | 2 | 1 | 2µs | 2µs | __ANON__ (xsub) | JSON::Schema::Modern::Result::
1 | 1 | 1 | 1µs | 1µs | OUTPUT_FORMATS (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 | 32µ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 | 43µs | 2 | 59µs | # spent 32µs (5+27) within JSON::Schema::Modern::BEGIN@2.82 which was called:
# once (5µs+27µs) by JSON::Schema::Modern::BEGIN@34 at line 2 # spent 32µs making 1 call to JSON::Schema::Modern::BEGIN@2.82
# spent 27µ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.552'; | ||
8 | |||||
9 | 2 | 34µ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 | 32µs | 2 | 542µs | # spent 277µs (12+265) within JSON::Schema::Modern::Result::BEGIN@10 which was called:
# once (12µs+265µs) by JSON::Schema::Modern::BEGIN@34 at line 10 # spent 277µs making 1 call to JSON::Schema::Modern::Result::BEGIN@10
# spent 265µs making 1 call to Moo::import |
11 | 3 | 38µs | 3 | 1.74ms | # spent 880µs (19+861) within JSON::Schema::Modern::Result::BEGIN@11 which was called:
# once (19µs+861µs) by JSON::Schema::Modern::BEGIN@34 at line 11 # spent 880µs making 1 call to JSON::Schema::Modern::Result::BEGIN@11
# spent 842µs making 1 call to strictures::import
# spent 19µs making 1 call to strictures::VERSION |
12 | 2 | 41µs | 2 | 275µs | # spent 142µs (9+133) within JSON::Schema::Modern::Result::BEGIN@12 which was called:
# once (9µs+133µs) by JSON::Schema::Modern::BEGIN@34 at line 12 # spent 142µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12
# spent 133µs making 1 call to experimental::import |
13 | 2 | 35µs | 2 | 50µs | # spent 47µs (15+32) within JSON::Schema::Modern::Result::BEGIN@13 which was called:
# once (15µs+32µs) by JSON::Schema::Modern::BEGIN@34 at line 13 # spent 47µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13
# spent 3µs making 1 call to if::import |
14 | 2 | 34µs | 2 | 33µs | # spent 31µs (12+19) within JSON::Schema::Modern::Result::BEGIN@14 which was called:
# once (12µs+19µs) by JSON::Schema::Modern::BEGIN@34 at line 14 # spent 31µs making 1 call to JSON::Schema::Modern::Result::BEGIN@14
# spent 2µs making 1 call to if::unimport |
15 | 2 | 27µs | 2 | 26µs | # spent 25µs (14+11) within JSON::Schema::Modern::Result::BEGIN@15 which was called:
# once (14µs+11µs) by JSON::Schema::Modern::BEGIN@34 at line 15 # spent 25µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15
# spent 1µs making 1 call to if::unimport |
16 | 2 | 20µs | 2 | 42µs | # spent 38µs (20+18) within JSON::Schema::Modern::Result::BEGIN@16 which was called:
# once (20µs+18µs) by JSON::Schema::Modern::BEGIN@34 at line 16 # spent 38µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16
# spent 4µs making 1 call to if::unimport |
17 | 2 | 33µs | 2 | 1.40ms | # spent 704µs (8+696) within JSON::Schema::Modern::Result::BEGIN@17 which was called:
# once (8µs+696µs) by JSON::Schema::Modern::BEGIN@34 at line 17 # spent 704µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17
# spent 696µs making 1 call to MooX::TypeTiny::import |
18 | 2 | 33µs | 2 | 1.20ms | # spent 602µs (8+594) within JSON::Schema::Modern::Result::BEGIN@18 which was called:
# once (8µs+594µs) by JSON::Schema::Modern::BEGIN@34 at line 18 # spent 602µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18
# spent 594µs making 1 call to Exporter::Tiny::import |
19 | 2 | 26µs | 2 | 147µs | # spent 76µs (5+71) within JSON::Schema::Modern::Result::BEGIN@19 which was called:
# once (5µs+71µs) by JSON::Schema::Modern::BEGIN@34 at line 19 # spent 76µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19
# spent 71µs making 1 call to MooX::HandlesVia::import |
20 | 2 | 812µs | 2 | 8.73ms | # spent 8.73ms (1.49+7.24) within JSON::Schema::Modern::Result::BEGIN@20 which was called:
# once (1.49ms+7.24ms) by JSON::Schema::Modern::BEGIN@34 at line 20 # spent 8.73ms 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 | 17µs | # spent 16µs (15+1000ns) within JSON::Schema::Modern::Result::BEGIN@21 which was called:
# once (15µs+1000ns) by JSON::Schema::Modern::BEGIN@34 at line 21 # spent 16µs making 1 call to JSON::Schema::Modern::Result::BEGIN@21
# spent 1µs making 1 call to JSON::Schema::Modern::Result::__ANON__ |
22 | 2 | 24µs | 1 | 3µs | # spent 3µs within JSON::Schema::Modern::Result::BEGIN@22 which was called:
# once (3µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 22 # spent 3µs making 1 call to JSON::Schema::Modern::Result::BEGIN@22 |
23 | 3 | 50µs | 3 | 90µs | # spent 70µs (19+51) within JSON::Schema::Modern::Result::BEGIN@23 which was called:
# once (19µs+51µs) by JSON::Schema::Modern::BEGIN@34 at line 23 # spent 70µs making 1 call to JSON::Schema::Modern::Result::BEGIN@23
# spent 12µs making 1 call to UNIVERSAL::VERSION
# spent 8µs making 1 call to List::Util::import |
24 | 2 | 21µs | 2 | 41µs | # spent 24µs (7+17) within JSON::Schema::Modern::Result::BEGIN@24 which was called:
# once (7µs+17µs) by JSON::Schema::Modern::BEGIN@34 at line 24 # spent 24µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24
# spent 17µs making 1 call to Exporter::import |
25 | 2 | 24µs | 2 | 188µs | # spent 98µs (8+90) within JSON::Schema::Modern::Result::BEGIN@25 which was called:
# once (8µs+90µs) by JSON::Schema::Modern::BEGIN@34 at line 25 # spent 98µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25
# spent 90µs making 1 call to Exporter::import |
26 | 2 | 148µs | 2 | 779µs | # spent 394µs (9+385) within JSON::Schema::Modern::Result::BEGIN@26 which was called:
# once (9µs+385µs) by JSON::Schema::Modern::BEGIN@34 at line 26 # spent 394µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26
# spent 385µs making 1 call to namespace::clean::import |
27 | |||||
28 | use overload | ||||
29 | 1 | 11µs | 1 | 3µs | # spent 46µs (12+34) within JSON::Schema::Modern::Result::BEGIN@29 which was called:
# once (12µs+34µs) by JSON::Schema::Modern::BEGIN@34 at line 33
# spent 17µs (14+3) 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 (14µs+3µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 149 of JSON/Schema/Modern/Document/OpenAPI.pm # spent 3µ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 | 260µs | 2 | 80µs | fallback => 1; # spent 46µ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 | 44µs | 1 | 37µs | # spent 64µs (27+37) 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 (27µs+37µs) by JSON::Schema::Modern::Result::new at line 114 of (eval 433)[Sub/Quote.pm:3] # spent 37µs making 1 call to JSON::PP::true |
39 | 1 | 6µs | 2 | 1.14ms | ); # spent 1.04ms making 1 call to MooX::HandlesVia::has
# spent 101µ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 | 8µs | 2 | 1.22ms | ); # spent 1.14ms making 1 call to MooX::HandlesVia::has
# spent 81µ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 | 38µs | 6 | 16.3ms | ) foreach qw(error annotation); # spent 12.5ms making 2 calls to MooX::HandlesVia::has, avg 6.23ms/call
# spent 2.67ms making 2 calls to Types::Standard::ArrayRef, avg 1.33ms/call
# spent 1.20ms making 2 calls to Types::Standard::InstanceOf, avg 598µs/call |
61 | |||||
62 | # strict_basic can only be used with draft2019-09. | ||||
63 | 2 | 760µs | 2 | 120µs | # spent 65µs (10+55) within JSON::Schema::Modern::Result::BEGIN@63 which was called:
# once (10µs+55µs) by JSON::Schema::Modern::BEGIN@34 at line 63 # spent 65µs making 1 call to JSON::Schema::Modern::Result::BEGIN@63
# spent 55µs making 1 call to constant::import |
64 | |||||
65 | 1 | 6µs | 2 | 2.46ms | has output_format => ( # spent 1.27ms making 1 call to Types::Standard::Enum
# spent 1.19ms making 1 call to MooX::HandlesVia::has |
66 | is => 'rw', | ||||
67 | isa => Enum(OUTPUT_FORMATS), | ||||
68 | default => 'basic', | ||||
69 | ); | ||||
70 | |||||
71 | 1 | 5µs | 2 | 695µs | has formatted_annotations => ( # spent 693µs making 1 call to MooX::HandlesVia::has
# spent 2µs making 1 call to Types::Standard::Bool |
72 | is => 'ro', | ||||
73 | isa => Bool, | ||||
74 | default => 1, | ||||
75 | ); | ||||
76 | |||||
77 | 2 | 3µs | # spent 29µs (16+13) within JSON::Schema::Modern::Result::BUILD which was called:
# once (16µs+13µs) by JSON::Schema::Modern::Result::new at line 128 of (eval 433)[Sub/Quote.pm:3] | ||
78 | 1 | 19µs | 3 | 13µs | warn 'result is false but there are no errors' if not $self->valid and not $self->error_count; # spent 9µs making 1 call to JSON::Schema::Modern::Result::valid
# spent 4µs making 2 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:7], avg 2µs/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 | |||||
141 | die 'unsupported output format'; | ||||
142 | } | ||||
143 | |||||
144 | sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count } | ||||
145 | |||||
146 | sub combine ($self, $other, $swap) { | ||||
147 | die 'wrong type for & operation' if not $other->$_isa(__PACKAGE__); | ||||
148 | |||||
149 | return $self if refaddr($other) == refaddr($self); | ||||
150 | |||||
151 | return ref($self)->new( | ||||
152 | valid => $self->valid && $other->valid, | ||||
153 | annotations => [ | ||||
154 | $self->annotations, | ||||
155 | $other->annotations, | ||||
156 | ], | ||||
157 | errors => [ | ||||
158 | $self->errors, | ||||
159 | $other->errors, | ||||
160 | ], | ||||
161 | output_format => $self->output_format, | ||||
162 | formatted_annotations => $self->formatted_annotations || $other->formatted_annotations, | ||||
163 | ); | ||||
164 | } | ||||
165 | |||||
166 | sub stringify ($self) { | ||||
167 | $self->error_count ? join("\n", $self->errors) : 'valid' | ||||
168 | } | ||||
169 | |||||
170 | sub TO_JSON ($self) { | ||||
171 | $self->format($self->output_format); | ||||
172 | } | ||||
173 | |||||
174 | sub dump ($self) { | ||||
175 | my $encoder = JSON::MaybeXS->new(utf8 => 0, convert_blessed => 1, canonical => 1, pretty => 1); | ||||
176 | $encoder->indent_length(2) if $encoder->can('indent_length'); | ||||
177 | $encoder->encode($self); | ||||
178 | } | ||||
179 | |||||
180 | # turns the JSON pointers in instance_location, keyword_location into a URI fragments, | ||||
181 | # for strict draft-201909 adherence | ||||
182 | sub _map_uris ($data) { | ||||
183 | return +{ | ||||
184 | %$data, | ||||
185 | map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string), | ||||
186 | qw(instanceLocation keywordLocation), | ||||
187 | }; | ||||
188 | } | ||||
189 | |||||
190 | 1 | 31µs | 1; | ||
191 | |||||
192 | 1 | 47µs | 1 | 458µs | __END__ # spent 458µ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 |