Filename | /usr/share/perl5/JSON.pm |
Statements | Executed 106 statements in 2.38ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 8.26ms | 16.5ms | _load_pp | JSON::
4 | 4 | 1 | 312µs | 432µs | _overrride_overload | JSON::Boolean::
1 | 1 | 1 | 91µs | 587µs | _load_xs | JSON::
3 | 3 | 3 | 64µs | 554µs | import | JSON::
1 | 1 | 1 | 52µs | 52µs | _set_module | JSON::
1 | 1 | 1 | 20µs | 20µs | init | JSON::Backend::PP::
1 | 1 | 1 | 16µs | 20µs | BEGIN@4 | JSON::
1 | 1 | 1 | 15µs | 135µs | BEGIN@6 | JSON::
1 | 1 | 1 | 15µs | 44µs | BEGIN@284 | JSON::
1 | 1 | 1 | 12µs | 27µs | BEGIN@349 | JSON::Backend::PP::
1 | 1 | 1 | 6µs | 6µs | BEGIN@9 | JSON::
1 | 1 | 1 | 4µs | 4µs | BEGIN@5 | JSON::
0 | 0 | 0 | 0s | 0s | __ANON__[:352] | JSON::Backend::PP::
0 | 0 | 0 | 0s | 0s | __ANON__[:353] | JSON::Backend::PP::
0 | 0 | 0 | 0s | 0s | __ANON__[:298] | JSON::
0 | 0 | 0 | 0s | 0s | backend | JSON::
0 | 0 | 0 | 0s | 0s | false | JSON::
0 | 0 | 0 | 0s | 0s | from_json | JSON::
0 | 0 | 0 | 0s | 0s | is_pp | JSON::
0 | 0 | 0 | 0s | 0s | is_xs | JSON::
0 | 0 | 0 | 0s | 0s | jsonToObj | JSON::
0 | 0 | 0 | 0s | 0s | null | JSON::
0 | 0 | 0 | 0s | 0s | objToJson | JSON::
0 | 0 | 0 | 0s | 0s | property | JSON::
0 | 0 | 0 | 0s | 0s | pureperl_only_methods | JSON::
0 | 0 | 0 | 0s | 0s | require_xs_version | JSON::
0 | 0 | 0 | 0s | 0s | to_json | JSON::
0 | 0 | 0 | 0s | 0s | true | JSON::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package JSON; | ||||
2 | |||||
3 | |||||
4 | 3 | 26µs | 2 | 25µs | # spent 20µs (16+4) within JSON::BEGIN@4 which was called:
# once (16µs+4µs) by C4::Auth::BEGIN@23 at line 4 # spent 20µs making 1 call to JSON::BEGIN@4
# spent 4µs making 1 call to strict::import |
5 | 3 | 25µs | 1 | 4µs | # spent 4µs within JSON::BEGIN@5 which was called:
# once (4µs+0s) by C4::Auth::BEGIN@23 at line 5 # spent 4µs making 1 call to JSON::BEGIN@5 |
6 | 3 | 72µs | 2 | 255µs | # spent 135µs (15+120) within JSON::BEGIN@6 which was called:
# once (15µs+120µs) by C4::Auth::BEGIN@23 at line 6 # spent 135µs making 1 call to JSON::BEGIN@6
# spent 120µs making 1 call to base::import |
7 | 1 | 3µs | @JSON::EXPORT = qw(from_json to_json jsonToObj objToJson encode_json decode_json); | ||
8 | |||||
9 | # spent 6µs within JSON::BEGIN@9 which was called:
# once (6µs+0s) by C4::Auth::BEGIN@23 at line 12 | ||||
10 | 1 | 600ns | $JSON::VERSION = '2.21'; | ||
11 | 1 | 7µs | $JSON::DEBUG = 0 unless (defined $JSON::DEBUG); | ||
12 | 1 | 1.14ms | 1 | 6µs | } # spent 6µs making 1 call to JSON::BEGIN@9 |
13 | |||||
14 | 1 | 500ns | my $Module_XS = 'JSON::XS'; | ||
15 | 1 | 200ns | my $Module_PP = 'JSON::PP'; | ||
16 | 1 | 200ns | my $XS_Version = '2.27'; | ||
17 | |||||
18 | |||||
19 | # XS and PP common methods | ||||
20 | |||||
21 | 1 | 4µs | my @PublicMethods = qw/ | ||
22 | ascii latin1 utf8 pretty indent space_before space_after relaxed canonical allow_nonref | ||||
23 | allow_blessed convert_blessed filter_json_object filter_json_single_key_object | ||||
24 | shrink max_depth max_size encode decode decode_prefix allow_unknown | ||||
25 | /; | ||||
26 | |||||
27 | 1 | 2µs | my @Properties = qw/ | ||
28 | ascii latin1 utf8 indent space_before space_after relaxed canonical allow_nonref | ||||
29 | allow_blessed convert_blessed shrink max_depth max_size allow_unknown | ||||
30 | /; | ||||
31 | |||||
32 | 1 | 200ns | my @XSOnlyMethods = qw//; # Currently nothing | ||
33 | |||||
34 | 1 | 4µs | my @PPOnlyMethods = qw/ | ||
35 | indent_length sort_by | ||||
36 | allow_singlequote allow_bignum loose allow_barekey escape_slash as_nonblessed | ||||
37 | /; # JSON::PP specific | ||||
38 | |||||
39 | |||||
40 | # used in _load_xs and _load_pp ($INSTALL_ONLY is not used currently) | ||||
41 | 1 | 300ns | my $_INSTALL_DONT_DIE = 1; # When _load_xs fails to load XS, don't die. | ||
42 | 1 | 200ns | my $_INSTALL_ONLY = 2; # Don't call _set_methods() | ||
43 | 1 | 200ns | my $_ALLOW_UNSUPPORTED = 0; | ||
44 | 1 | 200ns | my $_UNIV_CONV_BLESSED = 0; | ||
45 | |||||
46 | |||||
47 | # Check the environment variable to decide worker module. | ||||
48 | |||||
49 | 1 | 1µs | unless ($JSON::Backend) { | ||
50 | 1 | 200ns | $JSON::DEBUG and Carp::carp("Check used worker module..."); | ||
51 | |||||
52 | 1 | 1µs | my $backend = exists $ENV{PERL_JSON_BACKEND} ? $ENV{PERL_JSON_BACKEND} : 1; | ||
53 | |||||
54 | 1 | 7µs | 2 | 17.1ms | if ($backend eq '1' or $backend =~ /JSON::XS\s*,\s*JSON::PP/) { # spent 16.5ms making 1 call to JSON::_load_pp
# spent 587µs making 1 call to JSON::_load_xs |
55 | _load_xs($_INSTALL_DONT_DIE) or _load_pp(); | ||||
56 | } | ||||
57 | elsif ($backend eq '0' or $backend eq 'JSON::PP') { | ||||
58 | _load_pp(); | ||||
59 | } | ||||
60 | elsif ($backend eq '2' or $backend eq 'JSON::XS') { | ||||
61 | _load_xs(); | ||||
62 | } | ||||
63 | else { | ||||
64 | Carp::croak "The value of environmental variable 'PERL_JSON_BACKEND' is invalid."; | ||||
65 | } | ||||
66 | } | ||||
67 | |||||
68 | |||||
69 | # spent 554µs (64+490) within JSON::import which was called 3 times, avg 185µs/call:
# once (24µs+208µs) by C4::Auth::BEGIN@23 at line 23 of /usr/share/koha/lib/C4/Auth.pm
# once (20µs+175µs) by OpenILS::QueryParser::BEGIN@5 at line 5 of /usr/share/koha/lib/OpenILS/QueryParser.pm
# once (21µs+107µs) by main::BEGIN@58 at line 58 of /usr/share/koha/opac/cgi-bin/opac/opac-search.pl | ||||
70 | 3 | 4µs | my $pkg = shift; | ||
71 | 3 | 1µs | my @what_to_export; | ||
72 | 3 | 1µs | my $no_export; | ||
73 | |||||
74 | 3 | 5µs | for my $tag (@_) { | ||
75 | 4 | 4µs | if ($tag eq '-support_by_pp') { | ||
76 | if (!$_ALLOW_UNSUPPORTED++) { | ||||
77 | JSON::Backend::XS | ||||
78 | ->support_by_pp(@PPOnlyMethods) if ($JSON::Backend eq $Module_XS); | ||||
79 | } | ||||
80 | next; | ||||
81 | } | ||||
82 | elsif ($tag eq '-no_export') { | ||||
83 | $no_export++, next; | ||||
84 | } | ||||
85 | elsif ( $tag eq '-convert_blessed_universally' ) { | ||||
86 | eval q| | ||||
87 | require B; | ||||
88 | *UNIVERSAL::TO_JSON = sub { | ||||
89 | my $b_obj = B::svref_2object( $_[0] ); | ||||
90 | return $b_obj->isa('B::HV') ? { %{ $_[0] } } | ||||
91 | : $b_obj->isa('B::AV') ? [ @{ $_[0] } ] | ||||
92 | : undef | ||||
93 | ; | ||||
94 | } | ||||
95 | | if ( !$_UNIV_CONV_BLESSED++ ); | ||||
96 | next; | ||||
97 | } | ||||
98 | 4 | 5µs | push @what_to_export, $tag; | ||
99 | } | ||||
100 | |||||
101 | 3 | 1µs | return if ($no_export); | ||
102 | |||||
103 | 3 | 29µs | 3 | 98µs | __PACKAGE__->export_to_level(1, $pkg, @what_to_export); # spent 98µs making 3 calls to Exporter::export_to_level, avg 33µs/call |
104 | } | ||||
105 | |||||
106 | |||||
107 | # OBSOLETED | ||||
108 | |||||
109 | sub jsonToObj { | ||||
110 | my $alternative = 'from_json'; | ||||
111 | if (defined $_[0] and UNIVERSAL::isa($_[0], 'JSON')) { | ||||
112 | shift @_; $alternative = 'decode'; | ||||
113 | } | ||||
114 | Carp::carp "'jsonToObj' will be obsoleted. Please use '$alternative' instead."; | ||||
115 | return JSON::from_json(@_); | ||||
116 | }; | ||||
117 | |||||
118 | sub objToJson { | ||||
119 | my $alternative = 'to_json'; | ||||
120 | if (defined $_[0] and UNIVERSAL::isa($_[0], 'JSON')) { | ||||
121 | shift @_; $alternative = 'encode'; | ||||
122 | } | ||||
123 | Carp::carp "'objToJson' will be obsoleted. Please use '$alternative' instead."; | ||||
124 | JSON::to_json(@_); | ||||
125 | }; | ||||
126 | |||||
127 | |||||
128 | # INTERFACES | ||||
129 | |||||
130 | sub to_json ($@) { | ||||
131 | my $json = new JSON; | ||||
132 | |||||
133 | if (@_ == 2 and ref $_[1] eq 'HASH') { | ||||
134 | my $opt = $_[1]; | ||||
135 | for my $method (keys %$opt) { | ||||
136 | $json->$method( $opt->{$method} ); | ||||
137 | } | ||||
138 | } | ||||
139 | |||||
140 | $json->encode($_[0]); | ||||
141 | } | ||||
142 | |||||
143 | |||||
144 | sub from_json ($@) { | ||||
145 | my $json = new JSON; | ||||
146 | |||||
147 | if (@_ == 2 and ref $_[1] eq 'HASH') { | ||||
148 | my $opt = $_[1]; | ||||
149 | for my $method (keys %$opt) { | ||||
150 | $json->$method( $opt->{$method} ); | ||||
151 | } | ||||
152 | } | ||||
153 | |||||
154 | return $json->decode( $_[0] ); | ||||
155 | } | ||||
156 | |||||
157 | |||||
158 | sub true { $JSON::true } | ||||
159 | |||||
160 | sub false { $JSON::false } | ||||
161 | |||||
162 | sub null { undef; } | ||||
163 | |||||
164 | |||||
165 | sub require_xs_version { $XS_Version; } | ||||
166 | |||||
167 | sub backend { | ||||
168 | my $proto = shift; | ||||
169 | $JSON::Backend; | ||||
170 | } | ||||
171 | |||||
172 | #*module = *backend; | ||||
173 | |||||
174 | |||||
175 | sub is_xs { | ||||
176 | return $_[0]->module eq $Module_XS; | ||||
177 | } | ||||
178 | |||||
179 | |||||
180 | sub is_pp { | ||||
181 | return $_[0]->module eq $Module_PP; | ||||
182 | } | ||||
183 | |||||
184 | |||||
185 | sub pureperl_only_methods { @PPOnlyMethods; } | ||||
186 | |||||
187 | |||||
188 | sub property { | ||||
189 | my ($self, $name, $value) = @_; | ||||
190 | |||||
191 | if (@_ == 1) { | ||||
192 | my %props; | ||||
193 | for $name (@Properties) { | ||||
194 | my $method = 'get_' . $name; | ||||
195 | if ($name eq 'max_size') { | ||||
196 | my $value = $self->$method(); | ||||
197 | $props{$name} = $value == 1 ? 0 : $value; | ||||
198 | next; | ||||
199 | } | ||||
200 | $props{$name} = $self->$method(); | ||||
201 | } | ||||
202 | return \%props; | ||||
203 | } | ||||
204 | elsif (@_ > 3) { | ||||
205 | Carp::croak('property() can take only the option within 2 arguments.'); | ||||
206 | } | ||||
207 | elsif (@_ == 2) { | ||||
208 | if ( my $method = $self->can('get_' . $name) ) { | ||||
209 | if ($name eq 'max_size') { | ||||
210 | my $value = $self->$method(); | ||||
211 | return $value == 1 ? 0 : $value; | ||||
212 | } | ||||
213 | $self->$method(); | ||||
214 | } | ||||
215 | } | ||||
216 | else { | ||||
217 | $self->$name($value); | ||||
218 | } | ||||
219 | |||||
220 | } | ||||
221 | |||||
- - | |||||
224 | # INTERNAL | ||||
225 | |||||
226 | # spent 587µs (91+496) within JSON::_load_xs which was called:
# once (91µs+496µs) by C4::Auth::BEGIN@23 at line 54 | ||||
227 | 1 | 500ns | my $opt = shift; | ||
228 | |||||
229 | 1 | 200ns | $JSON::DEBUG and Carp::carp "Load $Module_XS."; | ||
230 | |||||
231 | # if called after install module, overload is disable.... why? | ||||
232 | 1 | 1µs | 1 | 233µs | JSON::Boolean::_overrride_overload($Module_XS); # spent 233µs making 1 call to JSON::Boolean::_overrride_overload |
233 | 1 | 2µs | 1 | 195µs | JSON::Boolean::_overrride_overload($Module_PP); # spent 195µs making 1 call to JSON::Boolean::_overrride_overload |
234 | |||||
235 | 1 | 65µs | eval qq| # spent 81µs executing statements in string eval # includes 68µs spent executing 1 call to 1 sub defined therein. | ||
236 | use $Module_XS $XS_Version (); | ||||
237 | |; | ||||
238 | |||||
239 | 1 | 600ns | if ($@) { | ||
240 | 1 | 1µs | if (defined $opt and $opt & $_INSTALL_DONT_DIE) { | ||
241 | 1 | 200ns | $JSON::DEBUG and Carp::carp "Can't load $Module_XS...($@)"; | ||
242 | 1 | 4µs | return 0; | ||
243 | } | ||||
244 | Carp::croak $@; | ||||
245 | } | ||||
246 | |||||
247 | unless (defined $opt and $opt & $_INSTALL_ONLY) { | ||||
248 | _set_module( $JSON::Backend = $Module_XS ); | ||||
249 | my $data = join("", <DATA>); # this code is from Jcode 2.xx. | ||||
250 | close(DATA); | ||||
251 | eval $data; | ||||
252 | JSON::Backend::XS->init; | ||||
253 | } | ||||
254 | |||||
255 | return 1; | ||||
256 | }; | ||||
257 | |||||
258 | |||||
259 | # spent 16.5ms (8.26+8.26) within JSON::_load_pp which was called:
# once (8.26ms+8.26ms) by C4::Auth::BEGIN@23 at line 54 | ||||
260 | 1 | 700ns | my $opt = shift; | ||
261 | |||||
262 | 1 | 300ns | $JSON::DEBUG and Carp::carp "Load $Module_PP."; | ||
263 | |||||
264 | # if called after install module, overload is disable.... why? | ||||
265 | 1 | 2µs | 1 | 2µs | JSON::Boolean::_overrride_overload($Module_XS); # spent 2µs making 1 call to JSON::Boolean::_overrride_overload |
266 | 1 | 1µs | 1 | 1µs | JSON::Boolean::_overrride_overload($Module_PP); # spent 1µs making 1 call to JSON::Boolean::_overrride_overload |
267 | |||||
268 | 1 | 22µs | eval qq| require $Module_PP |; # spent 93µs executing statements in string eval | ||
269 | 1 | 600ns | if ($@) { | ||
270 | Carp::croak $@; | ||||
271 | } | ||||
272 | |||||
273 | 1 | 6µs | unless (defined $opt and $opt & $_INSTALL_ONLY) { | ||
274 | 1 | 5µs | 1 | 52µs | _set_module( $JSON::Backend = $Module_PP ); # spent 52µs making 1 call to JSON::_set_module |
275 | 1 | 6µs | 1 | 20µs | JSON::Backend::PP->init; # spent 20µs making 1 call to JSON::Backend::PP::init |
276 | } | ||||
277 | }; | ||||
278 | |||||
279 | |||||
280 | # spent 52µs within JSON::_set_module which was called:
# once (52µs+0s) by JSON::_load_pp at line 274 | ||||
281 | 1 | 1µs | my $module = shift; | ||
282 | |||||
283 | 1 | 6µs | local $^W; | ||
284 | 3 | 352µs | 2 | 72µs | # spent 44µs (15+29) within JSON::BEGIN@284 which was called:
# once (15µs+29µs) by C4::Auth::BEGIN@23 at line 284 # spent 44µs making 1 call to JSON::BEGIN@284
# spent 29µs making 1 call to strict::unimport |
285 | |||||
286 | 1 | 3µs | $JSON::true = ${"$module\::true"}; | ||
287 | 1 | 2µs | $JSON::false = ${"$module\::false"}; | ||
288 | |||||
289 | 1 | 13µs | push @JSON::ISA, $module; | ||
290 | 1 | 11µs | push @{"$module\::Boolean::ISA"}, qw(JSON::Boolean); | ||
291 | |||||
292 | 1 | 8µs | *{"JSON::is_bool"} = \&{"$module\::is_bool"}; | ||
293 | |||||
294 | 1 | 4µs | for my $method ($module eq $Module_XS ? @PPOnlyMethods : @XSOnlyMethods) { | ||
295 | *{"JSON::$method"} = sub { | ||||
296 | Carp::carp("$method is not supported in $module."); | ||||
297 | $_[0]; | ||||
298 | }; | ||||
299 | } | ||||
300 | |||||
301 | 1 | 9µs | return 1; | ||
302 | } | ||||
303 | |||||
- - | |||||
306 | # | ||||
307 | # JSON Boolean | ||||
308 | # | ||||
309 | |||||
310 | package JSON::Boolean; | ||||
311 | |||||
312 | 1 | 600ns | my %Installed; | ||
313 | |||||
314 | sub _overrride_overload { | ||||
315 | 4 | 10µs | return if ($Installed{ $_[0] }++); | ||
316 | |||||
317 | 2 | 2µs | my $boolean = $_[0] . '::Boolean'; | ||
318 | |||||
319 | 2 | 292µs | eval sprintf(q| # spent 24µs executing statements in string eval # includes 22µs spent executing 1 call to 3 subs defined therein. # spent 16µs executing statements in string eval # includes 14µs spent executing 1 call to 3 subs defined therein. | ||
320 | package %s; | ||||
321 | use overload ( | ||||
322 | '""' => sub { ${$_[0]} == 1 ? 'true' : 'false' }, | ||||
323 | 'eq' => sub { | ||||
324 | my ($obj, $op) = ref ($_[0]) ? ($_[0], $_[1]) : ($_[1], $_[0]); | ||||
325 | if ($op eq 'true' or $op eq 'false') { | ||||
326 | return "$obj" eq 'true' ? 'true' eq $op : 'false' eq $op; | ||||
327 | } | ||||
328 | else { | ||||
329 | return $obj ? 1 == $op : 0 == $op; | ||||
330 | } | ||||
331 | }, | ||||
332 | ); | ||||
333 | |, $boolean); | ||||
334 | |||||
335 | 2 | 600ns | if ($@) { Carp::croak $@; } | ||
336 | |||||
337 | 2 | 8µs | return 1; | ||
338 | } | ||||
339 | |||||
340 | |||||
341 | # | ||||
342 | # Helper classes for Backend Module (PP) | ||||
343 | # | ||||
344 | |||||
345 | package JSON::Backend::PP; | ||||
346 | |||||
347 | # spent 20µs within JSON::Backend::PP::init which was called:
# once (20µs+0s) by JSON::_load_pp at line 275 | ||||
348 | 1 | 1µs | local $^W; | ||
349 | 3 | 128µs | 2 | 42µs | # spent 27µs (12+15) within JSON::Backend::PP::BEGIN@349 which was called:
# once (12µs+15µs) by C4::Auth::BEGIN@23 at line 349 # spent 27µs making 1 call to JSON::Backend::PP::BEGIN@349
# spent 15µs making 1 call to strict::unimport |
350 | 1 | 4µs | *{"JSON::decode_json"} = \&{"JSON::PP::decode_json"}; | ||
351 | 1 | 3µs | *{"JSON::encode_json"} = \&{"JSON::PP::encode_json"}; | ||
352 | 1 | 5µs | *{"JSON::PP::is_xs"} = sub { 0 }; | ||
353 | 1 | 4µs | *{"JSON::PP::is_pp"} = sub { 1 }; | ||
354 | 1 | 4µs | return 1; | ||
355 | } | ||||
356 | |||||
357 | # | ||||
358 | # To save memory, the below lines are read only when XS backend is used. | ||||
359 | # | ||||
360 | |||||
361 | package JSON; | ||||
362 | |||||
363 | 1 | 40µs | 1; | ||
364 | __DATA__ |