← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:34 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm
StatementsExecuted 58 statements in 2.88ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.73ms10.5msJSON::Schema::Modern::Result::::BEGIN@20JSON::Schema::Modern::Result::BEGIN@20
11132µs35µsJSON::Schema::Modern::::BEGIN@1.81 JSON::Schema::Modern::BEGIN@1.81
11122µs179µsJSON::Schema::Modern::Result::::BEGIN@19JSON::Schema::Modern::Result::BEGIN@19
11122µs26µsJSON::Schema::Modern::Result::::BUILDJSON::Schema::Modern::Result::BUILD
11121µs83µsJSON::Schema::Modern::Result::::BEGIN@23JSON::Schema::Modern::Result::BEGIN@23
11118µs18µsJSON::Schema::Modern::Result::::BEGIN@21JSON::Schema::Modern::Result::BEGIN@21
11118µs22µsJSON::Schema::Modern::Result::::__ANON__[:29]JSON::Schema::Modern::Result::__ANON__[:29]
11115µs599µsJSON::Schema::Modern::Result::::BEGIN@11JSON::Schema::Modern::Result::BEGIN@11
11115µs279µsJSON::Schema::Modern::Result::::BEGIN@26JSON::Schema::Modern::Result::BEGIN@26
11114µs45µsJSON::Schema::Modern::Result::::BEGIN@24JSON::Schema::Modern::Result::BEGIN@24
11114µs48µsJSON::Schema::Modern::Result::::BEGIN@29JSON::Schema::Modern::Result::BEGIN@29
11111µs32µsJSON::Schema::Modern::Result::::BEGIN@13JSON::Schema::Modern::Result::BEGIN@13
11111µs20µsJSON::Schema::Modern::Result::::BEGIN@15JSON::Schema::Modern::Result::BEGIN@15
11111µs777µsJSON::Schema::Modern::Result::::BEGIN@18JSON::Schema::Modern::Result::BEGIN@18
11110µs10µsJSON::Schema::Modern::Result::::BEGIN@9JSON::Schema::Modern::Result::BEGIN@9
1119µs21µsJSON::Schema::Modern::Result::::BEGIN@14JSON::Schema::Modern::Result::BEGIN@14
1119µs53µsJSON::Schema::Modern::Result::::BEGIN@63JSON::Schema::Modern::Result::BEGIN@63
1118µs19µsJSON::Schema::Modern::Result::::BEGIN@16JSON::Schema::Modern::Result::BEGIN@16
1118µs125µsJSON::Schema::Modern::Result::::BEGIN@25JSON::Schema::Modern::Result::BEGIN@25
1116µs97µsJSON::Schema::Modern::Result::::BEGIN@12JSON::Schema::Modern::Result::BEGIN@12
1116µs7µsJSON::Schema::Modern::Result::::__ANON__[:38]JSON::Schema::Modern::Result::__ANON__[:38]
1115µs200µsJSON::Schema::Modern::Result::::BEGIN@10JSON::Schema::Modern::Result::BEGIN@10
1115µs322µsJSON::Schema::Modern::Result::::BEGIN@17JSON::Schema::Modern::Result::BEGIN@17
1114µs32µsJSON::Schema::Modern::::BEGIN@2.82 JSON::Schema::Modern::BEGIN@2.82
1114µs4µsJSON::Schema::Modern::Result::::BEGIN@22JSON::Schema::Modern::Result::BEGIN@22
1111µs1µsJSON::Schema::Modern::Result::::OUTPUT_FORMATSJSON::Schema::Modern::Result::OUTPUT_FORMATS (xsub)
2211µs1µsJSON::Schema::Modern::Result::::__ANON__JSON::Schema::Modern::Result::__ANON__ (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::::_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
1229µs238µ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
use strict;
# spent 35µs making 1 call to JSON::Schema::Modern::BEGIN@1.81 # spent 3µs making 1 call to strict::import
2242µs260µ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
use warnings;
# spent 32µs making 1 call to JSON::Schema::Modern::BEGIN@2.82 # spent 28µ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.556';
8
9226µs110µ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
use 5.020;
# spent 10µs making 1 call to JSON::Schema::Modern::Result::BEGIN@9
10220µ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
11329µs31.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
use strictures 2;
# 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
12230µs2188µ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
use experimental qw(signatures postderef);
# spent 97µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12 # spent 91µs making 1 call to experimental::import
13223µs234µ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
use if "$]" >= 5.022, experimental => 're_strict';
# spent 32µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13 # spent 2µs making 1 call to if::import
14223µs222µ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
no if "$]" >= 5.031009, feature => 'indirect';
# spent 21µs making 1 call to JSON::Schema::Modern::Result::BEGIN@14 # spent 1µs making 1 call to if::unimport
15217µs220µ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
no if "$]" >= 5.033001, feature => 'multidimensional';
# spent 20µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15 # spent 0s making 1 call to if::unimport
16214µs220µ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
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
# spent 19µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16 # spent 1µs making 1 call to if::unimport
17222µs2639µ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
use MooX::TypeTiny;
# spent 322µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17 # spent 317µs making 1 call to MooX::TypeTiny::import
18267µs21.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
use Types::Standard qw(ArrayRef InstanceOf Enum Bool);
# spent 777µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18 # spent 766µs making 1 call to Exporter::Tiny::import
19257µs2336µ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
use MooX::HandlesVia;
# spent 179µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19 # spent 157µs making 1 call to MooX::HandlesVia::import
202763µs210.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
use JSON::Schema::Modern::Annotation;
# 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__
21236µs218µ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
use JSON::Schema::Modern::Error;
# spent 18µs making 1 call to JSON::Schema::Modern::Result::BEGIN@21 # spent 0s making 1 call to JSON::Schema::Modern::Result::__ANON__
22228µs14µ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
use JSON::PP ();
# spent 4µs making 1 call to JSON::Schema::Modern::Result::BEGIN@22
233124µs3107µ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
use List::Util 1.50 qw(any uniq);
# 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
24237µs276µ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
use Scalar::Util 'refaddr';
# spent 45µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24 # spent 31µs making 1 call to Exporter::import
25235µs2242µ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
use Safe::Isa;
# spent 125µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25 # spent 117µs making 1 call to Exporter::import
262158µs2543µ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
use namespace::clean;
# spent 279µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26 # spent 264µs making 1 call to namespace::clean::import
27
28use overload
29115µs14µ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
'bool' => sub { $_[0]->valid },
# 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 },
332267µs282µ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
35has valid => (
36 is => 'ro',
37 isa => InstanceOf['JSON::PP::Boolean'],
3815µs11µ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]
coerce => sub { $_[0] ? JSON::PP::true : JSON::PP::false },
# spent 1µs making 1 call to JSON::PP::true
3919µs21.35ms);
# spent 1.25ms making 1 call to MooX::HandlesVia::has # spent 99µ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 },
48115µs21.76ms);
# spent 1.63ms making 1 call to MooX::HandlesVia::has # spent 133µ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 },
60140µs614.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.
632843µs297µ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
use constant OUTPUT_FORMATS => [qw(flag basic strict_basic detailed verbose terse data_only)];
# spent 53µs making 1 call to JSON::Schema::Modern::Result::BEGIN@63 # spent 44µs making 1 call to constant::import
64
6514µs22.34mshas 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
7115µs2584µshas 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
7727µ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]
sub BUILD ($self, $) {
78112µs34µ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
81sub 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
151sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count }
152
153sub 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
174sub stringify ($self) {
175 return $self->format('data_only');
176}
177
178sub 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
183sub 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
191sub _map_uris ($data) {
192 return +{
193 %$data,
194 map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string),
195 qw(instanceLocation keywordLocation),
196 };
197}
198
199123µs1;
200
201149µs1534µs__END__
 
# 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::OUTPUT_FORMATS; # xsub
# spent 1µs within JSON::Schema::Modern::Result::__ANON__ which was called 2 times, avg 500ns/call: # once (1µs+0s) by JSON::Schema::Modern::Result::BEGIN@20 at line 20 # once (0s+0s) by JSON::Schema::Modern::Result::BEGIN@21 at line 21
sub JSON::Schema::Modern::Result::__ANON__; # xsub