← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Thu Dec 15 15:23:56 2022
Reported on Thu Dec 15 15:27:03 2022

Filename/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Result.pm
StatementsExecuted 62 statements in 5.44ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.16ms6.56msJSON::Schema::Modern::Result::::BEGIN@20JSON::Schema::Modern::Result::BEGIN@20
11131µs51µsJSON::Schema::Modern::Result::::BEGIN@13JSON::Schema::Modern::Result::BEGIN@13
11128µs3.05msJSON::Schema::Modern::Result::::BUILDJSON::Schema::Modern::Result::BUILD
11121µs30µsJSON::Schema::Modern::Result::::__ANON__[:38]JSON::Schema::Modern::Result::__ANON__[:38]
11119µs21µsJSON::Schema::Modern::Result::::BEGIN@21JSON::Schema::Modern::Result::BEGIN@21
11117µs19µsJSON::Schema::Modern::::BEGIN@1.81 JSON::Schema::Modern::BEGIN@1.81
11114µs54µsJSON::Schema::Modern::Result::::BEGIN@23JSON::Schema::Modern::Result::BEGIN@23
11113µs626µsJSON::Schema::Modern::Result::::BEGIN@11JSON::Schema::Modern::Result::BEGIN@11
11111µs14µsJSON::Schema::Modern::Result::::__ANON__[:29]JSON::Schema::Modern::Result::__ANON__[:29]
1119µs18µsJSON::Schema::Modern::Result::::BEGIN@15JSON::Schema::Modern::Result::BEGIN@15
1119µs15µsJSON::Schema::Modern::Result::::BEGIN@16JSON::Schema::Modern::Result::BEGIN@16
1118µs24µsJSON::Schema::Modern::Result::::BEGIN@14JSON::Schema::Modern::Result::BEGIN@14
1118µs34µsJSON::Schema::Modern::Result::::BEGIN@29JSON::Schema::Modern::Result::BEGIN@29
1118µs103µsJSON::Schema::Modern::Result::::BEGIN@70JSON::Schema::Modern::Result::BEGIN@70
1118µs8µsJSON::Schema::Modern::Result::::BEGIN@9JSON::Schema::Modern::Result::BEGIN@9
1117µs449µsJSON::Schema::Modern::Result::::BEGIN@18JSON::Schema::Modern::Result::BEGIN@18
1116µs83µsJSON::Schema::Modern::::BEGIN@2.82 JSON::Schema::Modern::BEGIN@2.82
1116µs92µsJSON::Schema::Modern::Result::::BEGIN@12JSON::Schema::Modern::Result::BEGIN@12
1116µs46µsJSON::Schema::Modern::Result::::BEGIN@19JSON::Schema::Modern::Result::BEGIN@19
1116µs85µsJSON::Schema::Modern::Result::::BEGIN@25JSON::Schema::Modern::Result::BEGIN@25
1116µs256µsJSON::Schema::Modern::Result::::BEGIN@26JSON::Schema::Modern::Result::BEGIN@26
1115µs200µsJSON::Schema::Modern::Result::::BEGIN@10JSON::Schema::Modern::Result::BEGIN@10
1115µs299µsJSON::Schema::Modern::Result::::BEGIN@17JSON::Schema::Modern::Result::BEGIN@17
1114µs19µsJSON::Schema::Modern::Result::::BEGIN@24JSON::Schema::Modern::Result::BEGIN@24
1112µs2µsJSON::Schema::Modern::Result::::BEGIN@22JSON::Schema::Modern::Result::BEGIN@22
2212µs2µsJSON::Schema::Modern::Result::::__ANON__JSON::Schema::Modern::Result::__ANON__ (xsub)
1110s0sJSON::Schema::Modern::Result::::OUTPUT_FORMATSJSON::Schema::Modern::Result::OUTPUT_FORMATS (xsub)
0000s0sJSON::Schema::Modern::Result::::TO_JSONJSON::Schema::Modern::Result::TO_JSON
0000s0sJSON::Schema::Modern::Result::::__ANON__[:31]JSON::Schema::Modern::Result::__ANON__[:31]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:32]JSON::Schema::Modern::Result::__ANON__[:32]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:45]JSON::Schema::Modern::Result::__ANON__[:45]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:47]JSON::Schema::Modern::Result::__ANON__[:47]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:54]JSON::Schema::Modern::Result::__ANON__[:54]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:63]JSON::Schema::Modern::Result::__ANON__[:63]
0000s0sJSON::Schema::Modern::Result::::__ANON__[:65]JSON::Schema::Modern::Result::__ANON__[:65]
0000s0sJSON::Schema::Modern::Result::::_map_urisJSON::Schema::Modern::Result::_map_uris
0000s0sJSON::Schema::Modern::Result::::combineJSON::Schema::Modern::Result::combine
0000s0sJSON::Schema::Modern::Result::::countJSON::Schema::Modern::Result::count
0000s0sJSON::Schema::Modern::Result::::dumpJSON::Schema::Modern::Result::dump
0000s0sJSON::Schema::Modern::Result::::formatJSON::Schema::Modern::Result::format
0000s0sJSON::Schema::Modern::Result::::resultJSON::Schema::Modern::Result::result
0000s0sJSON::Schema::Modern::Result::::stringifyJSON::Schema::Modern::Result::stringify
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1221µs221µs
# spent 19µs (17+2) within JSON::Schema::Modern::BEGIN@1.81 which was called: # once (17µs+2µs) by JSON::Schema::Modern::BEGIN@34 at line 1
use strict;
# spent 19µs making 1 call to JSON::Schema::Modern::BEGIN@1.81 # spent 2µs making 1 call to strict::import
2230µs2160µs
# spent 83µs (6+77) within JSON::Schema::Modern::BEGIN@2.82 which was called: # once (6µs+77µs) by JSON::Schema::Modern::BEGIN@34 at line 2
use warnings;
# spent 83µs making 1 call to JSON::Schema::Modern::BEGIN@2.82 # spent 77µs making 1 call to warnings::import
3package 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
711µsour $VERSION = '0.559';
8
9227µs18µs
# spent 8µs within JSON::Schema::Modern::Result::BEGIN@9 which was called: # once (8µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 9
use 5.020;
# spent 8µs making 1 call to JSON::Schema::Modern::Result::BEGIN@9
10221µs2395µ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
use Moo;
# spent 200µs making 1 call to JSON::Schema::Modern::Result::BEGIN@10 # spent 195µs making 1 call to Moo::import
11327µs31.24ms
# spent 626µs (13+613) within JSON::Schema::Modern::Result::BEGIN@11 which was called: # once (13µs+613µs) by JSON::Schema::Modern::BEGIN@34 at line 11
use strictures 2;
# spent 626µs making 1 call to JSON::Schema::Modern::Result::BEGIN@11 # spent 597µs making 1 call to strictures::import # spent 16µs making 1 call to strictures::VERSION
12228µs2178µs
# spent 92µs (6+86) within JSON::Schema::Modern::Result::BEGIN@12 which was called: # once (6µs+86µs) by JSON::Schema::Modern::BEGIN@34 at line 12
use experimental qw(signatures postderef);
# spent 92µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12 # spent 86µs making 1 call to experimental::import
13222µs254µs
# spent 51µs (31+20) within JSON::Schema::Modern::Result::BEGIN@13 which was called: # once (31µs+20µs) by JSON::Schema::Modern::BEGIN@34 at line 13
use if "$]" >= 5.022, experimental => 're_strict';
# spent 51µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13 # spent 3µs making 1 call to if::import
14218µs226µs
# spent 24µs (8+16) within JSON::Schema::Modern::Result::BEGIN@14 which was called: # once (8µs+16µs) by JSON::Schema::Modern::BEGIN@34 at line 14
no if "$]" >= 5.031009, feature => 'indirect';
# spent 24µs making 1 call to JSON::Schema::Modern::Result::BEGIN@14 # spent 2µs making 1 call to if::unimport
15225µs220µs
# spent 18µs (9+9) within JSON::Schema::Modern::Result::BEGIN@15 which was called: # once (9µs+9µs) by JSON::Schema::Modern::BEGIN@34 at line 15
no if "$]" >= 5.033001, feature => 'multidimensional';
# spent 18µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15 # spent 2µs making 1 call to if::unimport
16215µs215µs
# spent 15µs (9+6) within JSON::Schema::Modern::Result::BEGIN@16 which was called: # once (9µs+6µs) by JSON::Schema::Modern::BEGIN@34 at line 16
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
# spent 15µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16 # spent 0s making 1 call to if::unimport
17221µs2593µs
# spent 299µs (5+294) within JSON::Schema::Modern::Result::BEGIN@17 which was called: # once (5µs+294µs) by JSON::Schema::Modern::BEGIN@34 at line 17
use MooX::TypeTiny;
# spent 299µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17 # spent 294µs making 1 call to MooX::TypeTiny::import
18257µs2891µs
# spent 449µs (7+442) within JSON::Schema::Modern::Result::BEGIN@18 which was called: # once (7µs+442µs) by JSON::Schema::Modern::BEGIN@34 at line 18
use Types::Standard qw(ArrayRef InstanceOf Enum Bool);
# spent 449µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18 # spent 442µs making 1 call to Exporter::Tiny::import
19217µs286µs
# spent 46µs (6+40) within JSON::Schema::Modern::Result::BEGIN@19 which was called: # once (6µs+40µs) by JSON::Schema::Modern::BEGIN@34 at line 19
use MooX::HandlesVia;
# spent 46µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19 # spent 40µs making 1 call to MooX::HandlesVia::import
202623µs26.56ms
# spent 6.56ms (1.16+5.41) within JSON::Schema::Modern::Result::BEGIN@20 which was called: # once (1.16ms+5.41ms) by JSON::Schema::Modern::BEGIN@34 at line 20
use JSON::Schema::Modern::Annotation;
# spent 6.56ms making 1 call to JSON::Schema::Modern::Result::BEGIN@20 # spent 0s making 1 call to JSON::Schema::Modern::Result::__ANON__
21236µs223µs
# spent 21µs (19+2) within JSON::Schema::Modern::Result::BEGIN@21 which was called: # once (19µs+2µs) by JSON::Schema::Modern::BEGIN@34 at line 21
use JSON::Schema::Modern::Error;
# spent 21µs making 1 call to JSON::Schema::Modern::Result::BEGIN@21 # spent 2µs making 1 call to JSON::Schema::Modern::Result::__ANON__
22217µs12µs
# spent 2µs within JSON::Schema::Modern::Result::BEGIN@22 which was called: # once (2µs+0s) by JSON::Schema::Modern::BEGIN@34 at line 22
use JSON::PP ();
# spent 2µs making 1 call to JSON::Schema::Modern::Result::BEGIN@22
23335µs369µs
# spent 54µs (14+40) within JSON::Schema::Modern::Result::BEGIN@23 which was called: # once (14µs+40µs) by JSON::Schema::Modern::BEGIN@34 at line 23
use List::Util 1.50 qw(any uniq all);
# spent 54µs making 1 call to JSON::Schema::Modern::Result::BEGIN@23 # spent 8µs making 1 call to UNIVERSAL::VERSION # spent 7µs making 1 call to List::Util::import
24213µs234µs
# spent 19µs (4+15) within JSON::Schema::Modern::Result::BEGIN@24 which was called: # once (4µs+15µs) by JSON::Schema::Modern::BEGIN@34 at line 24
use Scalar::Util qw(refaddr blessed);
# spent 19µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24 # spent 15µs making 1 call to Exporter::import
25217µs2164µs
# spent 85µs (6+79) within JSON::Schema::Modern::Result::BEGIN@25 which was called: # once (6µs+79µs) by JSON::Schema::Modern::BEGIN@34 at line 25
use Safe::Isa;
# spent 85µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25 # spent 79µs making 1 call to Exporter::import
262120µs2506µs
# spent 256µs (6+250) within JSON::Schema::Modern::Result::BEGIN@26 which was called: # once (6µs+250µs) by JSON::Schema::Modern::BEGIN@34 at line 26
use namespace::clean;
# spent 256µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26 # spent 250µs making 1 call to namespace::clean::import
27
28use overload
2917µs13µs
# spent 14µs (11+3) within JSON::Schema::Modern::Result::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Result.pm:29] which was called: # once (11µs+3µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 149 of JSON/Schema/Modern/Document/OpenAPI.pm # spent 34µs (8+26) within JSON::Schema::Modern::Result::BEGIN@29 which was called: # once (8µs+26µs) by JSON::Schema::Modern::BEGIN@34 at line 33
'bool' => sub { $_[0]->valid },
# 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 },
332268µs260µs fallback => 1;
# spent 34µs making 1 call to JSON::Schema::Modern::Result::BEGIN@29 # spent 26µs making 1 call to overload::import
34
35has valid => (
36 is => 'ro',
37 isa => InstanceOf['JSON::PP::Boolean'],
38110µs19µs
# spent 30µs (21+9) within JSON::Schema::Modern::Result::__ANON__[/Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern/Result.pm:38] which was called: # once (21µs+9µs) by JSON::Schema::Modern::Result::new at line 154 of (eval 436)[Sub/Quote.pm:3]
coerce => sub { $_[0] ? JSON::PP::true : JSON::PP::false },
# spent 9µs making 1 call to JSON::PP::true
3915µs2992µs);
# spent 851µs making 1 call to MooX::HandlesVia::has # spent 141µs making 1 call to Types::Standard::InstanceOf
40sub result { shift->valid } # backcompat only
41
42has 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 },
4814µs2839µs);
# spent 787µs making 1 call to MooX::HandlesVia::has # spent 52µs making 1 call to Types::Standard::InstanceOf
49
50has $_.'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 coerce => do {
6120s my $type = $_;
62 sub ($arrayref) {
63 return $arrayref if all { blessed $_ } $arrayref->@*;
64 return [ map +(('JSON::Schema::Modern::'.ucfirst $type)->new($_)), $arrayref->@* ];
65 },
6623µs },
67125µs612.7ms) foreach qw(error annotation);
# spent 9.70ms making 2 calls to MooX::HandlesVia::has, avg 4.85ms/call # spent 2.29ms making 2 calls to Types::Standard::ArrayRef, avg 1.14ms/call # spent 741µs making 2 calls to Types::Standard::InstanceOf, avg 370µs/call
68
69# strict_basic can only be used with draft2019-09.
702809µs2198µs
# spent 103µs (8+95) within JSON::Schema::Modern::Result::BEGIN@70 which was called: # once (8µs+95µs) by JSON::Schema::Modern::BEGIN@34 at line 70
use constant OUTPUT_FORMATS => [qw(flag basic strict_basic detailed verbose terse data_only)];
# spent 103µs making 1 call to JSON::Schema::Modern::Result::BEGIN@70 # spent 95µs making 1 call to constant::import
71
7214µs21.40mshas output_format => (
# spent 746µs making 1 call to Types::Standard::Enum # spent 653µs making 1 call to MooX::HandlesVia::has
73 is => 'rw',
74 isa => Enum(OUTPUT_FORMATS),
75 default => 'basic',
76);
77
7812µs2360µshas formatted_annotations => (
# spent 358µs making 1 call to MooX::HandlesVia::has # spent 2µs making 1 call to Types::Standard::Bool
79 is => 'ro',
80 isa => Bool,
81 default => 1,
82);
83
8425µs
# spent 3.05ms (28µs+3.02) within JSON::Schema::Modern::Result::BUILD which was called: # once (28µs+3.02ms) by JSON::Schema::Modern::Result::new at line 168 of (eval 436)[Sub/Quote.pm:3]
sub BUILD ($self, $) {
8513.02ms33.02ms warn 'result is false but there are no errors' if not $self->valid and not $self->error_count;
# spent 3.02ms making 1 call to JSON::Schema::Modern::Result::valid # spent 5µs making 2 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:8], avg 2µs/call
86}
87
88sub format ($self, $style, $formatted_annotations = undef) {
89 $formatted_annotations //= $self->formatted_annotations;
90
91 if ($style eq 'flag') {
92 return +{ valid => $self->valid };
93 }
94 elsif ($style eq 'basic') {
95 return +{
96 valid => $self->valid,
97 $self->valid
98 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ())
99 : (errors => [ map $_->TO_JSON, $self->errors ]),
100 };
101 }
102 # note: strict_basic will NOT be supported after draft 2019-09!
103 elsif ($style eq 'strict_basic') {
104 return +{
105 valid => $self->valid,
106 $self->valid
107 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map _map_uris($_->TO_JSON), $self->annotations ]) : ())
108 : (errors => [ map _map_uris($_->TO_JSON), $self->errors ]),
109 };
110 }
111 elsif ($style eq 'terse') {
112 my (%instance_locations, %keyword_locations);
113
114 my @errors = grep {
115 my ($keyword, $error) = ($_->keyword, $_->error);
116
117 my $keep = 0+!!(
118 not $keyword
119 or (
120 not grep $keyword eq $_, qw(allOf anyOf if then else dependentSchemas contains propertyNames)
121 and ($keyword ne 'oneOf' or $error ne 'no subschemas are valid')
122 and ($keyword ne 'prefixItems' or $error eq 'item not permitted')
123 and ($keyword ne 'items' or $error eq 'item not permitted' or $error eq 'additional item not permitted')
124 and ($keyword ne 'additionalItems' or $error eq 'additional item not permitted')
125 and (not grep $keyword eq $_, qw(properties patternProperties)
126 or $error eq 'property not permitted')
127 and ($keyword ne 'additionalProperties' or $error eq 'additional property not permitted'))
128 and ($keyword ne 'dependentRequired' or $error ne 'not all dependencies are satisfied')
129 );
130
131 ++$instance_locations{$_->instance_location} if $keep;
132 ++$keyword_locations{$_->keyword_location} if $keep;
133
134 $keep;
135 }
136 $self->errors;
137
138 die 'uh oh, have no errors left to report' if not $self->valid and not @errors;
139
140 return +{
141 valid => $self->valid,
142 $self->valid
143 ? ($formatted_annotations && $self->annotation_count ? (annotations => [ map $_->TO_JSON, $self->annotations ]) : ())
144 : (errors => [ map $_->TO_JSON, @errors ]),
145 };
146 }
147 elsif ($style eq 'data_only') {
148 return 'valid' if not $self->error_count;
149 # Note: this output is going to be confusing when coming from a schema with a 'oneOf', 'not',
150 # etc. Perhaps generating the strings with indentation levels, as derived from a nested format,
151 # might be more readable.
152 return join("\n", uniq(map $_->stringify, $self->errors));
153 }
154
155 die 'unsupported output format';
156}
157
158sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count }
159
160sub combine ($self, $other, $swap) {
161 die 'wrong type for & operation' if not $other->$_isa(__PACKAGE__);
162
163 return $self if refaddr($other) == refaddr($self);
164
165 return ref($self)->new(
166 valid => $self->valid && $other->valid,
167 annotations => [
168 $self->annotations,
169 $other->annotations,
170 ],
171 errors => [
172 $self->errors,
173 $other->errors,
174 ],
175 output_format => $self->output_format,
176 formatted_annotations => $self->formatted_annotations || $other->formatted_annotations,
177 );
178}
179
180
181sub stringify ($self) {
182 return $self->format('data_only');
183}
184
185sub TO_JSON ($self) {
186 die 'cannot produce JSON output for data_only format' if $self->output_format eq 'data_only';
187 $self->format($self->output_format);
188}
189
190sub dump ($self) {
191 my $encoder = JSON::MaybeXS->new(utf8 => 0, convert_blessed => 1, canonical => 1, pretty => 1);
192 $encoder->indent_length(2) if $encoder->can('indent_length');
193 $encoder->encode($self);
194}
195
196# turns the JSON pointers in instance_location, keyword_location into a URI fragments,
197# for strict draft-201909 adherence
198sub _map_uris ($data) {
199 return +{
200 %$data,
201 map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string),
202 qw(instanceLocation keywordLocation),
203 };
204}
205
206124µs1;
207162µs1366µs__END__
 
# spent 0s within JSON::Schema::Modern::Result::OUTPUT_FORMATS which was called: # once (0s+0s) by OpenAPI::Modern::BEGIN@26 at line 59 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm
sub JSON::Schema::Modern::Result::OUTPUT_FORMATS; # xsub
# spent 2µs within JSON::Schema::Modern::Result::__ANON__ which was called 2 times, avg 1µs/call: # once (2µs+0s) by JSON::Schema::Modern::Result::BEGIN@21 at line 21 # once (0s+0s) by JSON::Schema::Modern::Result::BEGIN@20 at line 20
sub JSON::Schema::Modern::Result::__ANON__; # xsub