← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 17:10:45 2013
Reported on Tue Oct 15 17:11:22 2013

Filename/usr/lib/perl5/Template.pm
StatementsExecuted 65 statements in 1.93ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1116.57ms12.2msTemplate::::BEGIN@29Template::BEGIN@29
1112.78ms6.89msTemplate::::BEGIN@32Template::BEGIN@32
1111.37ms2.60msTemplate::::BEGIN@30Template::BEGIN@30
1111.27ms1.65msTemplate::::BEGIN@27Template::BEGIN@27
111119µs119µsTemplate::::_outputTemplate::_output
11165µs830msTemplate::::processTemplate::process
11130µs30µsTemplate::::BEGIN@24Template::BEGIN@24
11126µs23.4msTemplate::::_initTemplate::_init
11120µs24µsTemplate::::BEGIN@22Template::BEGIN@22
11118µs46µsTemplate::::BEGIN@28Template::BEGIN@28
11116µs41µsTemplate::::BEGIN@23Template::BEGIN@23
11113µs65µsTemplate::::BEGIN@31Template::BEGIN@31
11112µs44µsTemplate::::BEGIN@33Template::BEGIN@33
11111µs5.19msTemplate::::BEGIN@25Template::BEGIN@25
0000s0sTemplate::::contextTemplate::context
0000s0sTemplate::::serviceTemplate::service
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1#============================================================= -*-perl-*-
2#
3# Template
4#
5# DESCRIPTION
6# Module implementing a simple, user-oriented front-end to the Template
7# Toolkit.
8#
9# AUTHOR
10# Andy Wardley <abw@wardley.org>
11#
12# COPYRIGHT
13# Copyright (C) 1996-2009 Andy Wardley. All Rights Reserved.
14#
15# This module is free software; you can redistribute it and/or
16# modify it under the same terms as Perl itself.
17#
18#========================================================================
19
20package Template;
21
22351µs229µs
# spent 24µs (20+4) within Template::BEGIN@22 which was called: # once (20µs+4µs) by C4::Templates::BEGIN@33 at line 22
use strict;
# spent 24µs making 1 call to Template::BEGIN@22 # spent 4µs making 1 call to strict::import
23336µs266µs
# spent 41µs (16+25) within Template::BEGIN@23 which was called: # once (16µs+25µs) by C4::Templates::BEGIN@33 at line 23
use warnings;
# spent 41µs making 1 call to Template::BEGIN@23 # spent 25µs making 1 call to warnings::import
24353µs130µs
# spent 30µs within Template::BEGIN@24 which was called: # once (30µs+0s) by C4::Templates::BEGIN@33 at line 24
use 5.006;
# spent 30µs making 1 call to Template::BEGIN@24
25346µs210.4ms
# spent 5.19ms (11µs+5.18) within Template::BEGIN@25 which was called: # once (11µs+5.18ms) by C4::Templates::BEGIN@33 at line 25
use base 'Template::Base';
# spent 5.19ms making 1 call to Template::BEGIN@25 # spent 5.18ms making 1 call to base::import
26
273199µs11.65ms
# spent 1.65ms (1.27+384µs) within Template::BEGIN@27 which was called: # once (1.27ms+384µs) by C4::Templates::BEGIN@33 at line 27
use Template::Config;
# spent 1.65ms making 1 call to Template::BEGIN@27
28333µs274µs
# spent 46µs (18+28) within Template::BEGIN@28 which was called: # once (18µs+28µs) by C4::Templates::BEGIN@33 at line 28
use Template::Constants;
# spent 46µs making 1 call to Template::BEGIN@28 # spent 28µs making 1 call to Exporter::import
293202µs112.2ms
# spent 12.2ms (6.57+5.61) within Template::BEGIN@29 which was called: # once (6.57ms+5.61ms) by C4::Templates::BEGIN@33 at line 29
use Template::Provider;
# spent 12.2ms making 1 call to Template::BEGIN@29
303158µs12.60ms
# spent 2.60ms (1.37+1.23) within Template::BEGIN@30 which was called: # once (1.37ms+1.23ms) by C4::Templates::BEGIN@33 at line 30
use Template::Service;
# spent 2.60ms making 1 call to Template::BEGIN@30
31331µs2116µs
# spent 65µs (13+51) within Template::BEGIN@31 which was called: # once (13µs+51µs) by C4::Templates::BEGIN@33 at line 31
use File::Basename;
# spent 65µs making 1 call to Template::BEGIN@31 # spent 52µs making 1 call to Exporter::import
323161µs26.94ms
# spent 6.89ms (2.78+4.12) within Template::BEGIN@32 which was called: # once (2.78ms+4.12ms) by C4::Templates::BEGIN@33 at line 32
use File::Path;
# spent 6.89ms making 1 call to Template::BEGIN@32 # spent 44µs making 1 call to Exporter::import
333745µs276µs
# spent 44µs (12+32) within Template::BEGIN@33 which was called: # once (12µs+32µs) by C4::Templates::BEGIN@33 at line 33
use Scalar::Util qw(blessed);
# spent 44µs making 1 call to Template::BEGIN@33 # spent 32µs making 1 call to Exporter::import
34
3511µsour $VERSION = '2.22';
361400nsour $ERROR = '';
371400nsour $DEBUG = 0;
381500nsour $BINMODE = 0 unless defined $BINMODE;
391100nsour $AUTOLOAD;
40
41# preload all modules if we're running under mod_perl
4212µsTemplate::Config->preload() if $ENV{ MOD_PERL };
43
44
45#------------------------------------------------------------------------
46# process($input, \%replace, $output)
47#
48# Main entry point for the Template Toolkit. The Template module
49# delegates most of the processing effort to the underlying SERVICE
50# object, an instance of the Template::Service class.
51#------------------------------------------------------------------------
52
53
# spent 830ms (65µs+830) within Template::process which was called: # once (65µs+830ms) by C4::Templates::output at line 132 of /usr/share/koha/lib/C4/Templates.pm
sub process {
541153µs my ($self, $template, $vars, $outstream, @opts) = @_;
55 my ($output, $error);
56 my $options = (@opts == 1) && ref($opts[0]) eq 'HASH'
57 ? shift(@opts) : { @opts };
58
59 $options->{ binmode } = $BINMODE
60 unless defined $options->{ binmode };
61
62 # we're using this for testing in t/output.t and t/filter.t so
63 # don't remove it if you don't want tests to fail...
64 $self->DEBUG("set binmode\n") if $DEBUG && $options->{ binmode };
65
661830ms $output = $self->{ SERVICE }->process($template, $vars);
# spent 830ms making 1 call to Template::Service::process
67
68 if (defined $output) {
69 $outstream ||= $self->{ OUTPUT };
70 unless (ref $outstream) {
71 my $outpath = $self->{ OUTPUT_PATH };
72 $outstream = "$outpath/$outstream" if $outpath;
73 }
74
75 # send processed template to output stream, checking for error
761119µs return ($self->error($error))
# spent 119µs making 1 call to Template::_output
77 if ($error = &_output($outstream, \$output, $options));
78
79 return 1;
80 }
81 else {
82 return $self->error($self->{ SERVICE }->error);
83 }
84}
85
86
87#------------------------------------------------------------------------
88# service()
89#
90# Returns a reference to the the internal SERVICE object which handles
91# all requests for this Template object
92#------------------------------------------------------------------------
93
94sub service {
95 my $self = shift;
96 return $self->{ SERVICE };
97}
98
99
100#------------------------------------------------------------------------
101# context()
102#
103# Returns a reference to the the CONTEXT object withint the SERVICE
104# object.
105#------------------------------------------------------------------------
106
107sub context {
108 my $self = shift;
109 return $self->{ SERVICE }->{ CONTEXT };
110}
111
112
113#========================================================================
114# -- PRIVATE METHODS --
115#========================================================================
116
117#------------------------------------------------------------------------
118# _init(\%config)
119#------------------------------------------------------------------------
120
# spent 23.4ms (26µs+23.4) within Template::_init which was called: # once (26µs+23.4ms) by Template::Base::new at line 65 of Template/Base.pm
sub _init {
121825µs my ($self, $config) = @_;
122
123 # convert any textual DEBUG args to numerical form
124 my $debug = $config->{ DEBUG };
125 $config->{ DEBUG } = Template::Constants::debug_flags($self, $debug)
126 || return if defined $debug && $debug !~ /^\d+$/;
127
128 # prepare a namespace handler for any CONSTANTS definition
129 if (my $constants = $config->{ CONSTANTS }) {
130 my $ns = $config->{ NAMESPACE } ||= { };
131 my $cns = $config->{ CONSTANTS_NAMESPACE } || 'constants';
132 $constants = Template::Config->constants($constants)
133 || return $self->error(Template::Config->error);
134 $ns->{ $cns } = $constants;
135 }
136
137 $self->{ SERVICE } = $config->{ SERVICE }
138123.4ms || Template::Config->service($config)
# spent 23.4ms making 1 call to Template::Config::service
139 || return $self->error(Template::Config->error);
140
141 $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT;
142 $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH };
143
144 return $self;
145}
146
147
148#------------------------------------------------------------------------
149# _output($where, $text)
150#------------------------------------------------------------------------
151
152
# spent 119µs within Template::_output which was called: # once (119µs+0s) by Template::process at line 76
sub _output {
1536125µs my ($where, $textref, $options) = @_;
154 my $reftype;
155 my $error = 0;
156
157 # call a CODE reference
158 if (($reftype = ref($where)) eq 'CODE') {
159 &$where($$textref);
160 }
161 # print to a glob (such as \*STDOUT)
162 elsif ($reftype eq 'GLOB') {
163 print $where $$textref;
164 }
165 # append output to a SCALAR ref
166 elsif ($reftype eq 'SCALAR') {
167 $$where .= $$textref;
168 }
169 # push onto ARRAY ref
170 elsif ($reftype eq 'ARRAY') {
171 push @$where, $$textref;
172 }
173 # call the print() method on an object that implements the method
174 # (e.g. IO::Handle, Apache::Request, etc)
175 elsif (blessed($where) && $where->can('print')) {
176 $where->print($$textref);
177 }
178 # a simple string is taken as a filename
179 elsif (! $reftype) {
180 local *FP;
181 # make destination directory if it doesn't exist
182 my $dir = dirname($where);
183 eval { mkpath($dir) unless -d $dir; };
184 if ($@) {
185 # strip file name and line number from error raised by die()
186 ($error = $@) =~ s/ at \S+ line \d+\n?$//;
187 }
188 elsif (open(FP, ">$where")) {
189 # binmode option can be 1 or a specific layer, e.g. :utf8
190 my $bm = $options->{ binmode };
191 if ($bm && $bm eq 1) {
192 binmode FP;
193 }
194 elsif ($bm){
195 binmode FP, $bm;
196 }
197 print FP $$textref;
198 close FP;
199 }
200 else {
201 $error = "$where: $!";
202 }
203 }
204 # give up, we've done our best
205 else {
206 $error = "output_handler() cannot determine target type ($where)\n";
207 }
208
209 return $error;
210}
211
212
21316µs1;
214
215__END__