Filename | /mnt/catalyst/koha/C4/Output/JSONStream.pm |
Statements | Executed 22 statements in 428µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 638µs | 651µs | BEGIN@39 | C4::Output::JSONStream::
2 | 2 | 1 | 26µs | 26µs | param | C4::Output::JSONStream::
1 | 1 | 1 | 9µs | 17µs | BEGIN@40 | C4::Output::JSONStream::
1 | 1 | 1 | 9µs | 98µs | BEGIN@42 | C4::Output::JSONStream::
1 | 1 | 1 | 8µs | 8µs | new | C4::Output::JSONStream::
1 | 1 | 1 | 6µs | 6µs | clear | C4::Output::JSONStream::
1 | 1 | 1 | 5µs | 52µs | output | C4::Output::JSONStream::
1 | 1 | 1 | 2µs | 2µs | content_type | C4::Output::JSONStream::
0 | 0 | 0 | 0s | 0s | true | C4::Output::JSONStream::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package C4::Output::JSONStream; | ||||
2 | # | ||||
3 | # Copyright 2008 LibLime | ||||
4 | # | ||||
5 | # This file is part of Koha. | ||||
6 | # | ||||
7 | # Koha is free software; you can redistribute it and/or modify it under the | ||||
8 | # terms of the GNU General Public License as published by the Free Software | ||||
9 | # Foundation; either version 2 of the License, or (at your option) any later | ||||
10 | # version. | ||||
11 | # | ||||
12 | # Koha is distributed in the hope that it will be useful, but WITHOUT ANY | ||||
13 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||||
14 | # A PARTICULAR PURPOSE. See the GNU General Public License for more details. | ||||
15 | # | ||||
16 | # You should have received a copy of the GNU General Public License along | ||||
17 | # with Koha; if not, write to the Free Software Foundation, Inc., | ||||
18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||||
19 | |||||
20 | =head1 NAME | ||||
21 | |||||
22 | C4::Output::JSONStream - progressively build JSON data | ||||
23 | |||||
24 | =head1 SYNOPSIS | ||||
25 | |||||
26 | my $json = new C4::Output::JSONStream; | ||||
27 | |||||
28 | $json->param( issues => [ 'yes!', 'please', 'no', { emphasis = 'NO' } ] ); | ||||
29 | $json->param( stuff => 'realia' ); | ||||
30 | |||||
31 | print $json->output; | ||||
32 | |||||
33 | =head1 DESCRIPTION | ||||
34 | |||||
35 | This module allows you to build JSON incrementally. | ||||
36 | |||||
37 | =cut | ||||
38 | |||||
39 | 2 | 29µs | 2 | 664µs | # spent 651µs (638+13) within C4::Output::JSONStream::BEGIN@39 which was called:
# once (638µs+13µs) by C4::Service::BEGIN@51 at line 39 # spent 651µs making 1 call to C4::Output::JSONStream::BEGIN@39
# spent 13µs making 1 call to strict::import |
40 | 2 | 22µs | 2 | 25µs | # spent 17µs (9+8) within C4::Output::JSONStream::BEGIN@40 which was called:
# once (9µs+8µs) by C4::Service::BEGIN@51 at line 40 # spent 17µs making 1 call to C4::Output::JSONStream::BEGIN@40
# spent 8µs making 1 call to warnings::import |
41 | |||||
42 | 2 | 317µs | 2 | 187µs | # spent 98µs (9+89) within C4::Output::JSONStream::BEGIN@42 which was called:
# once (9µs+89µs) by C4::Service::BEGIN@51 at line 42 # spent 98µs making 1 call to C4::Output::JSONStream::BEGIN@42
# spent 89µs making 1 call to JSON::import |
43 | |||||
44 | # spent 8µs within C4::Output::JSONStream::new which was called:
# once (8µs+0s) by C4::Service::new at line 89 of C4/Service.pm | ||||
45 | 1 | 400ns | my $class = shift; | ||
46 | 1 | 2µs | my $self = { | ||
47 | data => {}, | ||||
48 | options => {} | ||||
49 | }; | ||||
50 | |||||
51 | 1 | 3µs | bless $self, $class; | ||
52 | |||||
53 | 1 | 4µs | return $self; | ||
54 | } | ||||
55 | |||||
56 | # spent 26µs within C4::Output::JSONStream::param which was called 2 times, avg 13µs/call:
# once (16µs+0s) by C4::Service::return_error at line 128 of C4/Service.pm
# once (10µs+0s) by C4::Service::return_error at line 127 of C4/Service.pm | ||||
57 | 2 | 800ns | my $self = shift; | ||
58 | |||||
59 | 2 | 2µs | if ( @_ % 2 != 0 ) { | ||
60 | die 'param() received odd number of arguments (should be called with param => "value" pairs)'; | ||||
61 | } | ||||
62 | |||||
63 | 2 | 28µs | for ( my $i = 0; $i < $#_; $i += 2 ) { | ||
64 | $self->{data}->{$_[$i]} = $_[$i + 1]; | ||||
65 | } | ||||
66 | } | ||||
67 | |||||
68 | # spent 52µs (5+47) within C4::Output::JSONStream::output which was called:
# once (5µs+47µs) by C4::Service::return_error at line 130 of C4/Service.pm | ||||
69 | 1 | 400ns | my $self = shift; | ||
70 | |||||
71 | 1 | 5µs | 2 | 48µs | return to_json( $self->{data} ); # spent 47µs making 1 call to JSON::to_json
# spent 1µs making 1 call to JSON::XS::DESTROY |
72 | } | ||||
73 | |||||
74 | =head 2 clear | ||||
75 | |||||
76 | $json->clear(); | ||||
77 | |||||
78 | This clears any in-progress data from the object so it can be used to create | ||||
79 | something new. Parameters are kept, it's just the data that goes away. | ||||
80 | |||||
81 | =cut | ||||
82 | |||||
83 | # spent 6µs within C4::Output::JSONStream::clear which was called:
# once (6µs+0s) by C4::Service::return_error at line 125 of C4/Service.pm | ||||
84 | 1 | 400ns | my $self = shift; | ||
85 | 1 | 9µs | $self->{data} = {}; | ||
86 | } | ||||
87 | |||||
88 | =head2 content_type | ||||
89 | |||||
90 | my $ct = $json->content_type(); | ||||
91 | |||||
92 | Returns a string containing the content type of the stuff that this class | ||||
93 | returns, suitable for passing to L<C4::JSONStream::output_with_http_headers>. | ||||
94 | In this case, it says 'json'. | ||||
95 | |||||
96 | =cut | ||||
97 | |||||
98 | # spent 2µs within C4::Output::JSONStream::content_type which was called:
# once (2µs+0s) by C4::Service::return_error at line 130 of C4/Service.pm | ||||
99 | 1 | 2µs | return 'json'; | ||
100 | } | ||||
101 | |||||
102 | =head2 true | ||||
103 | |||||
104 | my $true = $json->true(); | ||||
105 | |||||
106 | This provides a 'true' value, as some format types need a special value. | ||||
107 | |||||
108 | =cut | ||||
109 | |||||
110 | sub true { | ||||
111 | return JSON::true; | ||||
112 | } | ||||
113 | |||||
114 | |||||
115 | 1 | 3µs | 1; |