← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:33:55 2022
Reported on Wed Dec 14 15:40:04 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Result.pm
StatementsExecuted 58 statements in 2.78ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1111.49ms8.73msJSON::Schema::Modern::Result::::BEGIN@20JSON::Schema::Modern::Result::BEGIN@20
11132µs35µsJSON::Schema::Modern::::BEGIN@1.81 JSON::Schema::Modern::BEGIN@1.81
11127µs64µsJSON::Schema::Modern::Result::::__ANON__[:38]JSON::Schema::Modern::Result::__ANON__[:38]
11120µs38µsJSON::Schema::Modern::Result::::BEGIN@16JSON::Schema::Modern::Result::BEGIN@16
11119µs880µsJSON::Schema::Modern::Result::::BEGIN@11JSON::Schema::Modern::Result::BEGIN@11
11119µs70µsJSON::Schema::Modern::Result::::BEGIN@23JSON::Schema::Modern::Result::BEGIN@23
11116µs29µsJSON::Schema::Modern::Result::::BUILDJSON::Schema::Modern::Result::BUILD
11115µs47µsJSON::Schema::Modern::Result::::BEGIN@13JSON::Schema::Modern::Result::BEGIN@13
11115µs16µsJSON::Schema::Modern::Result::::BEGIN@21JSON::Schema::Modern::Result::BEGIN@21
11114µs25µsJSON::Schema::Modern::Result::::BEGIN@15JSON::Schema::Modern::Result::BEGIN@15
11114µs17µsJSON::Schema::Modern::Result::::__ANON__[:29]JSON::Schema::Modern::Result::__ANON__[:29]
11112µs277µsJSON::Schema::Modern::Result::::BEGIN@10JSON::Schema::Modern::Result::BEGIN@10
11112µs31µsJSON::Schema::Modern::Result::::BEGIN@14JSON::Schema::Modern::Result::BEGIN@14
11112µs46µsJSON::Schema::Modern::Result::::BEGIN@29JSON::Schema::Modern::Result::BEGIN@29
11110µs65µsJSON::Schema::Modern::Result::::BEGIN@63JSON::Schema::Modern::Result::BEGIN@63
11110µs10µsJSON::Schema::Modern::Result::::BEGIN@9JSON::Schema::Modern::Result::BEGIN@9
1119µs142µsJSON::Schema::Modern::Result::::BEGIN@12JSON::Schema::Modern::Result::BEGIN@12
1119µs394µsJSON::Schema::Modern::Result::::BEGIN@26JSON::Schema::Modern::Result::BEGIN@26
1118µs704µsJSON::Schema::Modern::Result::::BEGIN@17JSON::Schema::Modern::Result::BEGIN@17
1118µs602µsJSON::Schema::Modern::Result::::BEGIN@18JSON::Schema::Modern::Result::BEGIN@18
1118µs98µsJSON::Schema::Modern::Result::::BEGIN@25JSON::Schema::Modern::Result::BEGIN@25
1117µs24µsJSON::Schema::Modern::Result::::BEGIN@24JSON::Schema::Modern::Result::BEGIN@24
1115µs32µsJSON::Schema::Modern::::BEGIN@2.82 JSON::Schema::Modern::BEGIN@2.82
1115µs76µsJSON::Schema::Modern::Result::::BEGIN@19JSON::Schema::Modern::Result::BEGIN@19
1113µs3µ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::::_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
1232µ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
2243µs259µ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
use warnings;
# spent 32µs making 1 call to JSON::Schema::Modern::BEGIN@2.82 # spent 27µ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.552';
8
9234µ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
10232µs2542µ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
use Moo;
# spent 277µs making 1 call to JSON::Schema::Modern::Result::BEGIN@10 # spent 265µs making 1 call to Moo::import
11338µs31.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
use strictures 2;
# 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
12241µs2275µ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
use experimental qw(signatures postderef);
# spent 142µs making 1 call to JSON::Schema::Modern::Result::BEGIN@12 # spent 133µs making 1 call to experimental::import
13235µs250µ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
use if "$]" >= 5.022, experimental => 're_strict';
# spent 47µs making 1 call to JSON::Schema::Modern::Result::BEGIN@13 # spent 3µs making 1 call to if::import
14234µs233µ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
no if "$]" >= 5.031009, feature => 'indirect';
# spent 31µs making 1 call to JSON::Schema::Modern::Result::BEGIN@14 # spent 2µs making 1 call to if::unimport
15227µs226µ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
no if "$]" >= 5.033001, feature => 'multidimensional';
# spent 25µs making 1 call to JSON::Schema::Modern::Result::BEGIN@15 # spent 1µs making 1 call to if::unimport
16220µs242µ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
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
# spent 38µs making 1 call to JSON::Schema::Modern::Result::BEGIN@16 # spent 4µs making 1 call to if::unimport
17233µs21.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
use MooX::TypeTiny;
# spent 704µs making 1 call to JSON::Schema::Modern::Result::BEGIN@17 # spent 696µs making 1 call to MooX::TypeTiny::import
18233µs21.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
use Types::Standard qw(ArrayRef InstanceOf Enum Bool);
# spent 602µs making 1 call to JSON::Schema::Modern::Result::BEGIN@18 # spent 594µs making 1 call to Exporter::Tiny::import
19226µs2147µ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
use MooX::HandlesVia;
# spent 76µs making 1 call to JSON::Schema::Modern::Result::BEGIN@19 # spent 71µs making 1 call to MooX::HandlesVia::import
202812µs28.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
use JSON::Schema::Modern::Annotation;
# 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__
21236µs217µ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
use JSON::Schema::Modern::Error;
# 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__
22224µs13µ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
use JSON::PP ();
# spent 3µs making 1 call to JSON::Schema::Modern::Result::BEGIN@22
23350µs390µ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
use List::Util 1.50 'any';
# 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
24221µs241µ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
use Scalar::Util 'refaddr';
# spent 24µs making 1 call to JSON::Schema::Modern::Result::BEGIN@24 # spent 17µs making 1 call to Exporter::import
25224µs2188µ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
use Safe::Isa;
# spent 98µs making 1 call to JSON::Schema::Modern::Result::BEGIN@25 # spent 90µs making 1 call to Exporter::import
262148µs2779µ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
use namespace::clean;
# spent 394µs making 1 call to JSON::Schema::Modern::Result::BEGIN@26 # spent 385µs making 1 call to namespace::clean::import
27
28use overload
29111µs13µ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
'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 },
332260µs280µ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
35has valid => (
36 is => 'ro',
37 isa => InstanceOf['JSON::PP::Boolean'],
38144µs137µ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]
coerce => sub { $_[0] ? JSON::PP::true : JSON::PP::false },
# spent 37µs making 1 call to JSON::PP::true
3916µs21.14ms);
# spent 1.04ms making 1 call to MooX::HandlesVia::has # spent 101µ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 },
4818µs21.22ms);
# spent 1.14ms making 1 call to MooX::HandlesVia::has # spent 81µ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 },
60138µs616.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.
632760µs2120µ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
use constant OUTPUT_FORMATS => [qw(flag basic strict_basic detailed verbose terse)];
# spent 65µs making 1 call to JSON::Schema::Modern::Result::BEGIN@63 # spent 55µs making 1 call to constant::import
64
6516µs22.46mshas 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
7115µs2695µshas 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
7723µ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]
sub BUILD ($self, $) {
78119µs313µ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
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
141 die 'unsupported output format';
142}
143
144sub count { $_[0]->valid ? $_[0]->annotation_count : $_[0]->error_count }
145
146sub 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
166sub stringify ($self) {
167 $self->error_count ? join("\n", $self->errors) : 'valid'
168}
169
170sub TO_JSON ($self) {
171 $self->format($self->output_format);
172}
173
174sub 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
182sub _map_uris ($data) {
183 return +{
184 %$data,
185 map +($_ => Mojo::URL->new->fragment($data->{$_})->to_string),
186 qw(instanceLocation keywordLocation),
187 };
188}
189
190131µs1;
191
192147µs1458µ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@20 at line 20 # once (1µs+0s) by JSON::Schema::Modern::Result::BEGIN@21 at line 21
sub JSON::Schema::Modern::Result::__ANON__; # xsub