← Index
NYTProf Performance Profile   « line view »
For svc/members/upsert
  Run on Tue Jan 13 11:50:22 2015
Reported on Tue Jan 13 12:09:51 2015

Filename/mnt/catalyst/koha/C4/Output/JSONStream.pm
StatementsExecuted 22 statements in 428µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111638µs651µsC4::Output::JSONStream::::BEGIN@39C4::Output::JSONStream::BEGIN@39
22126µs26µsC4::Output::JSONStream::::paramC4::Output::JSONStream::param
1119µs17µsC4::Output::JSONStream::::BEGIN@40C4::Output::JSONStream::BEGIN@40
1119µs98µsC4::Output::JSONStream::::BEGIN@42C4::Output::JSONStream::BEGIN@42
1118µs8µsC4::Output::JSONStream::::newC4::Output::JSONStream::new
1116µs6µsC4::Output::JSONStream::::clearC4::Output::JSONStream::clear
1115µs52µsC4::Output::JSONStream::::outputC4::Output::JSONStream::output
1112µs2µsC4::Output::JSONStream::::content_typeC4::Output::JSONStream::content_type
0000s0sC4::Output::JSONStream::::trueC4::Output::JSONStream::true
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package 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
22C4::Output::JSONStream - progressively build JSON data
23
24=head1 SYNOPSIS
25
26my $json = new C4::Output::JSONStream;
27
28$json->param( issues => [ 'yes!', 'please', 'no', { emphasis = 'NO' } ] );
29$json->param( stuff => 'realia' );
30
31print $json->output;
32
33=head1 DESCRIPTION
34
35This module allows you to build JSON incrementally.
36
37=cut
38
39229µs2664µ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
use strict;
# spent 651µs making 1 call to C4::Output::JSONStream::BEGIN@39 # spent 13µs making 1 call to strict::import
40222µs225µ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
use warnings;
# spent 17µs making 1 call to C4::Output::JSONStream::BEGIN@40 # spent 8µs making 1 call to warnings::import
41
422317µs2187µ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
use JSON;
# 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
sub new {
451400ns my $class = shift;
4612µs my $self = {
47 data => {},
48 options => {}
49 };
50
5113µs bless $self, $class;
52
5314µ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
sub param {
572800ns my $self = shift;
58
5922µs if ( @_ % 2 != 0 ) {
60 die 'param() received odd number of arguments (should be called with param => "value" pairs)';
61 }
62
63228µ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
sub output {
691400ns my $self = shift;
70
7115µs248µ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
78This clears any in-progress data from the object so it can be used to create
79something 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
sub clear {
841400ns my $self = shift;
8519µs $self->{data} = {};
86}
87
88=head2 content_type
89
90 my $ct = $json->content_type();
91
92Returns a string containing the content type of the stuff that this class
93returns, suitable for passing to L<C4::JSONStream::output_with_http_headers>.
94In 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
sub content_type {
9912µs return 'json';
100}
101
102=head2 true
103
104 my $true = $json->true();
105
106This provides a 'true' value, as some format types need a special value.
107
108=cut
109
110sub true {
111 return JSON::true;
112}
113
114
11513µs1;