← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 16:10:05 2022
Reported on Wed Dec 14 16:12:58 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm
StatementsExecuted 62 statements in 3.08ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.58ms7.65msJSON::Schema::Modern::Result::::BEGIN@20JSON::Schema::Modern::Result::BEGIN@20
11141µs109µsJSON::Schema::Modern::Result::::BEGIN@23JSON::Schema::Modern::Result::BEGIN@23
11123µs26µsJSON::Schema::Modern::::BEGIN@1.81 JSON::Schema::Modern::BEGIN@1.81
11118µs55µsJSON::Schema::Modern::Result::::BUILDJSON::Schema::Modern::Result::BUILD
11117µs28µsJSON::Schema::Modern::Result::::BEGIN@15JSON::Schema::Modern::Result::BEGIN@15
11117µs18µsJSON::Schema::Modern::Result::::BEGIN@21JSON::Schema::Modern::Result::BEGIN@21
11117µs20µsJSON::Schema::Modern::Result::::__ANON__[:38]JSON::Schema::Modern::Result::__ANON__[:38]
11114µs71µsJSON::Schema::Modern::Result::::BEGIN@70JSON::Schema::Modern::Result::BEGIN@70
11113µs677µsJSON::Schema::Modern::Result::::BEGIN@11JSON::Schema::Modern::Result::BEGIN@11
11112µs39µsJSON::Schema::Modern::Result::::BEGIN@13JSON::Schema::Modern::Result::BEGIN@13
11112µs75µsJSON::Schema::Modern::Result::::BEGIN@29JSON::Schema::Modern::Result::BEGIN@29
11110µs21µsJSON::Schema::Modern::Result::::BEGIN@16JSON::Schema::Modern::Result::BEGIN@16
11110µs12µsJSON::Schema::Modern::Result::::__ANON__[:29]JSON::Schema::Modern::Result::__ANON__[:29]
1119µs35µsJSON::Schema::Modern::Result::::BEGIN@24JSON::Schema::Modern::Result::BEGIN@24
1118µs21µsJSON::Schema::Modern::Result::::BEGIN@14JSON::Schema::Modern::Result::BEGIN@14
1118µs8µsJSON::Schema::Modern::Result::::BEGIN@9JSON::Schema::Modern::Result::BEGIN@9
1117µs105µsJSON::Schema::Modern::Result::::BEGIN@12JSON::Schema::Modern::Result::BEGIN@12
1117µs436µsJSON::Schema::Modern::Result::::BEGIN@18JSON::Schema::Modern::Result::BEGIN@18
1116µs422µsJSON::Schema::Modern::Result::::BEGIN@17JSON::Schema::Modern::Result::BEGIN@17
1116µs57µsJSON::Schema::Modern::Result::::BEGIN@19JSON::Schema::Modern::Result::BEGIN@19
1116µs106µsJSON::Schema::Modern::Result::::BEGIN@25JSON::Schema::Modern::Result::BEGIN@25
1116µs276µsJSON::Schema::Modern::Result::::BEGIN@26JSON::Schema::Modern::Result::BEGIN@26
1115µs65µsJSON::Schema::Modern::::BEGIN@2.82 JSON::Schema::Modern::BEGIN@2.82
1115µs242µsJSON::Schema::Modern::Result::::BEGIN@10JSON::Schema::Modern::Result::BEGIN@10
1114µs4µsJSON::Schema::Modern::Result::::BEGIN@22JSON::Schema::Modern::Result::BEGIN@22
2212µs2µsJSON::Schema::Modern::Result::::__ANON__JSON::Schema::Modern::Result::__ANON__ (xsub)
1111µs1µsJSON::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
1224µs229µs
# spent 26µs (23+3) within JSON::Schema::Modern::BEGIN@1.81 which was called: # once (23µs+3µs) by JSON::Schema::Modern::BEGIN@34 at line 1
use strict;
# spent 26µs making 1 call to JSON::Schema::Modern::BEGIN@1.81 # spent 3µs making 1 call to strict::import
2231µs2125µs
# spent 65µs (5+60) within JSON::Schema::Modern::BEGIN@2.82 which was called: # once (5µs+60µs) by JSON::Schema::Modern::BEGIN@34 at line 2
use warnings;
# spent 65µs making 1 call to JSON::Schema::Modern::BEGIN@2.82 # spent 60µ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
717µsour $VERSION = '0.558';
8
9224µ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
10225µs2479µs
# spent 242µs (5+237) within JSON::Schema::Modern::Result::BEGIN@10 which was called: # once (5µs+237µs) by JSON::Schema::Modern::BEGIN@34 at line 10
use Moo;
# spent 242µs making 1 call to JSON::Schema::Modern::Result::BEGIN@10 # spent 237µs making 1 call to Moo::import
11352µs31.34ms
# spent 677µs (13+664) within JSON::Schema::Modern::Result::BEGIN@11 which was called: # once (13µs+664µs) by JSON::Schema::Modern::BEGIN@34 at line 11
use strictures 2;
# spent 677µs making 1 call to JSON::Schema::Modern::Result::BEGIN@11 # spent 646µs making 1 call to strictures::import # spent 17µs making 1 call to strictures::VERSION
12233µs2203µs
# spent 105µs (7+98) within JSON::Schema::Modern::Result::BEGIN@12 which was called: # once (7µs+98µs) by JSON::Schema::Modern::BEGIN@34 at line 12
use experimental qw(signatures postderef);
# spent 105µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12 # spent 98µs making 1 call to experimental::import
13226µs243µs
# spent 39µs (12+27) within JSON::Schema::Modern::Result::BEGIN@13 which was called: # once (12µs+27µs) by JSON::Schema::Modern::BEGIN@34 at line 13
use if "$]" >= 5.022, experimental => 're_strict';
# spent 39µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13 # spent 4µs making 1 call to if::import
14225µs223µs
# spent 21µs (8+13) within JSON::Schema::Modern::Result::BEGIN@14 which was called: # once (8µs+13µ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 2µs making 1 call to if::unimport
15217µs230µs
# spent 28µs (17+11) within JSON::Schema::Modern::Result::BEGIN@15 which was called: # once (17µs+11µs) by JSON::Schema::Modern::BEGIN@34 at line 15
no if "$]" >= 5.033001, feature => 'multidimensional';
# spent 28µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15 # spent 2µs making 1 call to if::unimport
16214µs222µs
# spent 21µs (10+11) within JSON::Schema::Modern::Result::BEGIN@16 which was called: # once (10µs+11µs) by JSON::Schema::Modern::BEGIN@34 at line 16
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
# spent 21µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16 # spent 1µs making 1 call to if::unimport
17231µs2838µs
# spent 422µs (6+416) within JSON::Schema::Modern::Result::BEGIN@17 which was called: # once (6µs+416µs) by JSON::Schema::Modern::BEGIN@34 at line 17
use MooX::TypeTiny;
# spent 422µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17 # spent 416µs making 1 call to MooX::TypeTiny::import
18226µs2865µs
# spent 436µs (7+429) within JSON::Schema::Modern::Result::BEGIN@18 which was called: # once (7µs+429µs) by JSON::Schema::Modern::BEGIN@34 at line 18
use Types::Standard qw(ArrayRef InstanceOf Enum Bool);
# spent 436µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18 # spent 429µs making 1 call to Exporter::Tiny::import
19218µs2108µs
# spent 57µs (6+51) within JSON::Schema::Modern::Result::BEGIN@19 which was called: # once (6µs+51µs) by JSON::Schema::Modern::BEGIN@34 at line 19
use MooX::HandlesVia;
# spent 57µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19 # spent 51µs making 1 call to MooX::HandlesVia::import
202722µs27.65ms
# spent 7.65ms (1.58+6.07) within JSON::Schema::Modern::Result::BEGIN@20 which was called: # once (1.58ms+6.07ms) by JSON::Schema::Modern::BEGIN@34 at line 20
use JSON::Schema::Modern::Annotation;
# spent 7.65ms making 1 call to JSON::Schema::Modern::Result::BEGIN@20 # spent 1µs making 1 call to JSON::Schema::Modern::Result::__ANON__
21235µs219µs
# spent 18µs (17+1) within JSON::Schema::Modern::Result::BEGIN@21 which was called: # once (17µs+1µs) 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 1µs making 1 call to JSON::Schema::Modern::Result::__ANON__
22235µ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
23364µs3134µs
# spent 109µs (41+68) within JSON::Schema::Modern::Result::BEGIN@23 which was called: # once (41µs+68µs) by JSON::Schema::Modern::BEGIN@34 at line 23
use List::Util 1.50 qw(any uniq all);
# spent 109µs making 1 call to JSON::Schema::Modern::Result::BEGIN@23 # spent 14µs making 1 call to List::Util::import # spent 11µs making 1 call to UNIVERSAL::VERSION
24224µs261µs
# spent 35µs (9+26) within JSON::Schema::Modern::Result::BEGIN@24 which was called: # once (9µs+26µs) by JSON::Schema::Modern::BEGIN@34 at line 24
use Scalar::Util qw(refaddr blessed);
# spent 35µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24 # spent 26µs making 1 call to Exporter::import
25226µs2206µs
# spent 106µs (6+100) within JSON::Schema::Modern::Result::BEGIN@25 which was called: # once (6µs+100µs) by JSON::Schema::Modern::BEGIN@34 at line 25
use Safe::Isa;
# spent 106µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25 # spent 100µs making 1 call to Exporter::import
262118µs2546µs
# spent 276µs (6+270) within JSON::Schema::Modern::Result::BEGIN@26 which was called: # once (6µs+270µs) by JSON::Schema::Modern::BEGIN@34 at line 26
use namespace::clean;
# spent 276µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26 # spent 270µs making 1 call to namespace::clean::import
27
28use overload
2916µs12µs
# spent 12µs (10+2) 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 (10µs+2µs) by JSON::Schema::Modern::Document::OpenAPI::traverse at line 149 of JSON/Schema/Modern/Document/OpenAPI.pm # spent 75µs (12+63) within JSON::Schema::Modern::Result::BEGIN@29 which was called: # once (12µs+63µs) by JSON::Schema::Modern::BEGIN@34 at line 33
'bool' => sub { $_[0]->valid },
# spent 2µs making 1 call to JSON::Schema::Modern::Result::valid
30 '&' => \&combine,
31 '0+' => sub { Scalar::Util::refaddr($_[0]) },
32 '""' => sub { $_[0]->stringify },
332539µs2138µs fallback => 1;
# spent 75µs making 1 call to JSON::Schema::Modern::Result::BEGIN@29 # spent 63µs making 1 call to overload::import
34
35has valid => (
36 is => 'ro',
37 isa => InstanceOf['JSON::PP::Boolean'],
38116µs13µs
# spent 20µs (17+3) 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 (17µs+3µ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 3µs making 1 call to JSON::PP::true
39117µs21.57ms);
# spent 1.45ms making 1 call to MooX::HandlesVia::has # spent 121µ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 },
48111µs21.92ms);
# spent 1.83ms making 1 call to MooX::HandlesVia::has # spent 91µ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 },
6628µs },
67152µs616.1ms) foreach qw(error annotation);
# spent 12.2ms making 2 calls to MooX::HandlesVia::has, avg 6.09ms/call # spent 2.67ms making 2 calls to Types::Standard::ArrayRef, avg 1.33ms/call # spent 1.24ms making 2 calls to Types::Standard::InstanceOf, avg 618µs/call
68
69# strict_basic can only be used with draft2019-09.
702886µs2128µs
# spent 71µs (14+57) within JSON::Schema::Modern::Result::BEGIN@70 which was called: # once (14µs+57µ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 71µs making 1 call to JSON::Schema::Modern::Result::BEGIN@70 # spent 57µs making 1 call to constant::import
71
7215µs22.45mshas output_format => (
# spent 1.28ms making 1 call to MooX::HandlesVia::has # spent 1.18ms making 1 call to Types::Standard::Enum
73 is => 'rw',
74 isa => Enum(OUTPUT_FORMATS),
75 default => 'basic',
76);
77
7814µs2589µshas formatted_annotations => (
# spent 586µs making 1 call to MooX::HandlesVia::has # spent 3µs making 1 call to Types::Standard::Bool
79 is => 'ro',
80 isa => Bool,
81 default => 1,
82);
83
8421µs
# spent 55µs (18+37) within JSON::Schema::Modern::Result::BUILD which was called: # once (18µs+37µs) by JSON::Schema::Modern::Result::new at line 168 of (eval 436)[Sub/Quote.pm:3]
sub BUILD ($self, $) {
85116µs337µs warn 'result is false but there are no errors' if not $self->valid and not $self->error_count;
# spent 34µs making 2 calls to JSON::PP::Boolean::__ANON__[JSON/PP/Boolean.pm:7], avg 17µs/call # spent 3µs making 1 call to JSON::Schema::Modern::Result::valid
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
206120µs1;
207
2081117µs1690µ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 2µs within JSON::Schema::Modern::Result::__ANON__ which was called 2 times, avg 1µs/call: # once (1µs+0s) by JSON::Schema::Modern::Result::BEGIN@21 at line 21 # once (1µs+0s) by JSON::Schema::Modern::Result::BEGIN@20 at line 20
sub JSON::Schema::Modern::Result::__ANON__; # xsub