← 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 11:58:52 2013
Reported on Tue Oct 15 12:01:57 2013

Filename/usr/lib/perl5/Template.pm
StatementsExecuted 65 statements in 1.81ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.40ms6.36msTemplate::::BEGIN@29Template::BEGIN@29
1112.71ms7.37msTemplate::::BEGIN@32Template::BEGIN@32
1111.62ms2.82msTemplate::::BEGIN@30Template::BEGIN@30
1111.54ms1.96msTemplate::::BEGIN@27Template::BEGIN@27
11174µs74µsTemplate::::_outputTemplate::_output
11157µs701msTemplate::::processTemplate::process
11137µs19.9msTemplate::::_initTemplate::_init
11127µs64µsTemplate::::BEGIN@28Template::BEGIN@28
11123µs23µsTemplate::::BEGIN@24Template::BEGIN@24
11122µs104µsTemplate::::BEGIN@31Template::BEGIN@31
11118µs26µsTemplate::::BEGIN@22Template::BEGIN@22
11115µs105µsTemplate::::BEGIN@33Template::BEGIN@33
11114µs4.58msTemplate::::BEGIN@25Template::BEGIN@25
11110µs23µsTemplate::::BEGIN@23Template::BEGIN@23
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
22332µs234µs
# spent 26µs (18+8) within Template::BEGIN@22 which was called: # once (18µs+8µs) by C4::Templates::BEGIN@33 at line 22
use strict;
# spent 26µs making 1 call to Template::BEGIN@22 # spent 8µs making 1 call to strict::import
23324µs235µs
# spent 23µs (10+12) within Template::BEGIN@23 which was called: # once (10µs+12µs) by C4::Templates::BEGIN@33 at line 23
use warnings;
# spent 23µs making 1 call to Template::BEGIN@23 # spent 12µs making 1 call to warnings::import
24343µs123µs
# spent 23µs within Template::BEGIN@24 which was called: # once (23µs+0s) by C4::Templates::BEGIN@33 at line 24
use 5.006;
# spent 23µs making 1 call to Template::BEGIN@24
25345µs29.15ms
# spent 4.58ms (14µs+4.57) within Template::BEGIN@25 which was called: # once (14µs+4.57ms) by C4::Templates::BEGIN@33 at line 25
use base 'Template::Base';
# spent 4.58ms making 1 call to Template::BEGIN@25 # spent 4.57ms making 1 call to base::import
26
273149µs11.96ms
# spent 1.96ms (1.54+419µs) within Template::BEGIN@27 which was called: # once (1.54ms+419µs) by C4::Templates::BEGIN@33 at line 27
use Template::Config;
# spent 1.96ms making 1 call to Template::BEGIN@27
28336µs2101µs
# spent 64µs (27+37) within Template::BEGIN@28 which was called: # once (27µs+37µs) by C4::Templates::BEGIN@33 at line 28
use Template::Constants;
# spent 64µs making 1 call to Template::BEGIN@28 # spent 37µs making 1 call to Exporter::import
293145µs16.36ms
# spent 6.36ms (4.40+1.96) within Template::BEGIN@29 which was called: # once (4.40ms+1.96ms) by C4::Templates::BEGIN@33 at line 29
use Template::Provider;
# spent 6.36ms making 1 call to Template::BEGIN@29
303159µs12.82ms
# spent 2.82ms (1.62+1.20) within Template::BEGIN@30 which was called: # once (1.62ms+1.20ms) by C4::Templates::BEGIN@33 at line 30
use Template::Service;
# spent 2.82ms making 1 call to Template::BEGIN@30
31347µs2186µs
# spent 104µs (22+82) within Template::BEGIN@31 which was called: # once (22µs+82µs) by C4::Templates::BEGIN@33 at line 31
use File::Basename;
# spent 104µs making 1 call to Template::BEGIN@31 # spent 82µs making 1 call to Exporter::import
323183µs27.43ms
# spent 7.37ms (2.71+4.66) within Template::BEGIN@32 which was called: # once (2.71ms+4.66ms) by C4::Templates::BEGIN@33 at line 32
use File::Path;
# spent 7.37ms making 1 call to Template::BEGIN@32 # spent 51µs making 1 call to Exporter::import
333783µs2195µs
# spent 105µs (15+90) within Template::BEGIN@33 which was called: # once (15µs+90µs) by C4::Templates::BEGIN@33 at line 33
use Scalar::Util qw(blessed);
# spent 105µs making 1 call to Template::BEGIN@33 # spent 90µs making 1 call to Exporter::import
34
351800nsour $VERSION = '2.22';
361400nsour $ERROR = '';
371300nsour $DEBUG = 0;
381600nsour $BINMODE = 0 unless defined $BINMODE;
391300nsour $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 701ms (57µs+701) within Template::process which was called: # once (57µs+701ms) by C4::Templates::output at line 132 of /usr/share/koha/lib/C4/Templates.pm
sub process {
5414µs my ($self, $template, $vars, $outstream, @opts) = @_;
5512µs my ($output, $error);
5612µs my $options = (@opts == 1) && ref($opts[0]) eq 'HASH'
57 ? shift(@opts) : { @opts };
58
59 $options->{ binmode } = $BINMODE
6014µs 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...
641600ns $self->DEBUG("set binmode\n") if $DEBUG && $options->{ binmode };
65
66110µs1700ms $output = $self->{ SERVICE }->process($template, $vars);
# spent 700ms making 1 call to Template::Service::process
67
6812µs if (defined $output) {
6911µs $outstream ||= $self->{ OUTPUT };
7011µs 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
7617µs174µs return ($self->error($error))
# spent 74µs making 1 call to Template::_output
77 if ($error = &_output($outstream, \$output, $options));
78
7918µs 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 19.9ms (37µs+19.8) within Template::_init which was called: # once (37µs+19.8ms) by Template::Base::new at line 65 of Template/Base.pm
sub _init {
12112µs my ($self, $config) = @_;
122
123 # convert any textual DEBUG args to numerical form
12412µs my $debug = $config->{ DEBUG };
12511µs $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
12912µs 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 }
138115µs119.8ms || Template::Config->service($config)
# spent 19.8ms making 1 call to Template::Config::service
139 || return $self->error(Template::Config->error);
140
14114µs $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT;
14212µs $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH };
143
14415µs return $self;
145}
146
147
148#------------------------------------------------------------------------
149# _output($where, $text)
150#------------------------------------------------------------------------
151
152
# spent 74µs within Template::_output which was called: # once (74µs+0s) by Template::process at line 76
sub _output {
15313µs my ($where, $textref, $options) = @_;
1541400ns my $reftype;
1551800ns my $error = 0;
156
157 # call a CODE reference
15815µs 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') {
167158µs $$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
209115µs return $error;
210}
211
212
21317µs1;
214
215__END__