← Index
NYTProf Performance Profile   « line view »
For starman worker -M FindBin --max-requests 50 --workers 2 --user=kohadev-koha --group kohadev-koha --pid /var/run/koha/kohadev/plack.pid --daemonize --access-log /var/log/koha/kohadev/plack.log --error-log /var/log/koha/kohadev/plack-error.log -E deployment --socket /var/run/koha/kohadev/plack.sock /etc/koha/sites/kohadev/plack.psgi
  Run on Fri Jan 8 14:31:06 2016
Reported on Fri Jan 8 14:33:27 2016

Filename/usr/lib/x86_64-linux-gnu/perl5/5.20/Template.pm
StatementsExecuted 25 statements in 60µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11111.7ms19.1msTemplate::::BEGIN@29Template::BEGIN@29
1116.20ms7.29msTemplate::::BEGIN@30Template::BEGIN@30
1111.23ms1.44msTemplate::::BEGIN@27Template::BEGIN@27
41195µs547msTemplate::::processTemplate::process
41179µs20.5msTemplate::::_initTemplate::_init
41160µs60µsTemplate::::_outputTemplate::_output
11120µs66µsTemplate::::BEGIN@31Template::BEGIN@31
11118µs41µsTemplate::::BEGIN@32Template::BEGIN@32
11117µs17µsTemplate::::BEGIN@24Template::BEGIN@24
11114µs26µsTemplate::::BEGIN@22Template::BEGIN@22
11111µs34µsTemplate::::BEGIN@28Template::BEGIN@28
11110µs30µsTemplate::::BEGIN@33Template::BEGIN@33
1118µs7.97msTemplate::::BEGIN@25Template::BEGIN@25
1118µs13µsTemplate::::BEGIN@23Template::BEGIN@23
0000s0sTemplate::::contextTemplate::context
0000s0sTemplate::::serviceTemplate::service
0000s0sTemplate::::templateTemplate::template
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-2012 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
22238µs
# spent 26µs (14+12) within Template::BEGIN@22 which was called: # once (14µs+12µs) by C4::Templates::BEGIN@33 at line 22
use strict;
# spent 26µs making 1 call to Template::BEGIN@22 # spent 12µs making 1 call to strict::import
23218µs
# spent 13µs (8+5) within Template::BEGIN@23 which was called: # once (8µs+5µs) by C4::Templates::BEGIN@33 at line 23
use warnings;
# spent 13µs making 1 call to Template::BEGIN@23 # spent 5µs making 1 call to warnings::import
24117µs
# spent 17µs within Template::BEGIN@24 which was called: # once (17µs+0s) by C4::Templates::BEGIN@33 at line 24
use 5.006;
# spent 17µs making 1 call to Template::BEGIN@24
25215.9ms
# spent 7.97ms (8µs+7.97) within Template::BEGIN@25 which was called: # once (8µs+7.97ms) by C4::Templates::BEGIN@33 at line 25
use base 'Template::Base';
# spent 7.97ms making 1 call to Template::BEGIN@25 # spent 7.97ms making 1 call to base::import
26
2711.44ms
# spent 1.44ms (1.23+204µs) within Template::BEGIN@27 which was called: # once (1.23ms+204µs) by C4::Templates::BEGIN@33 at line 27
use Template::Config;
# spent 1.44ms making 1 call to Template::BEGIN@27
28256µs
# spent 34µs (11+22) within Template::BEGIN@28 which was called: # once (11µs+22µs) by C4::Templates::BEGIN@33 at line 28
use Template::Constants;
# spent 34µs making 1 call to Template::BEGIN@28 # spent 22µs making 1 call to Exporter::import
29119.1ms
# spent 19.1ms (11.7+7.41) within Template::BEGIN@29 which was called: # once (11.7ms+7.41ms) by C4::Templates::BEGIN@33 at line 29
use Template::Provider;
# spent 19.1ms making 1 call to Template::BEGIN@29
3017.29ms
# spent 7.29ms (6.20+1.08) within Template::BEGIN@30 which was called: # once (6.20ms+1.08ms) by C4::Templates::BEGIN@33 at line 30
use Template::Service;
# spent 7.29ms making 1 call to Template::BEGIN@30
312113µs
# spent 66µs (20+47) within Template::BEGIN@31 which was called: # once (20µs+47µs) by C4::Templates::BEGIN@33 at line 31
use File::Basename;
# spent 66µs making 1 call to Template::BEGIN@31 # spent 47µs making 1 call to Exporter::import
32265µs
# spent 41µs (18+24) within Template::BEGIN@32 which was called: # once (18µs+24µs) by C4::Templates::BEGIN@33 at line 32
use File::Path;
# spent 41µs making 1 call to Template::BEGIN@32 # spent 24µs making 1 call to Exporter::import
33250µs
# spent 30µs (10+20) within Template::BEGIN@33 which was called: # once (10µs+20µs) by C4::Templates::BEGIN@33 at line 33
use Scalar::Util qw(blessed);
# spent 30µs making 1 call to Template::BEGIN@33 # spent 20µs making 1 call to Exporter::import
34
35our $VERSION = '2.24';
36our $ERROR = '';
37our $DEBUG = 0;
38our $BINMODE = 0 unless defined $BINMODE;
39our $AUTOLOAD;
40
41# preload all modules if we're running under mod_perl
42Template::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 547ms (95µs+547) within Template::process which was called 4 times, avg 137ms/call: # 4 times (95µs+547ms) by C4::Templates::output at line 121 of C4/Templates.pm, avg 137ms/call
sub process {
541900ns my ($self, $template, $vars, $outstream, @opts) = @_;
551200ns my ($output, $error);
5611µ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...
641500ns $self->DEBUG("set binmode\n") if $DEBUG && $options->{ binmode };
65
6619µs4546ms $output = $self->{ SERVICE }->process($template, $vars);
# spent 546ms making 4 calls to Template::Service::process, avg 137ms/call
67
681500ns if (defined $output) {
691400ns $outstream ||= $self->{ OUTPUT };
701700ns 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
7616µs460µs return ($self->error($error))
# spent 60µs making 4 calls to Template::_output, avg 15µs/call
77 if ($error = &_output($outstream, \$output, $options));
78
7915µ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
112sub template {
113 shift->context->template(@_);
114}
115
116
117#========================================================================
118# -- PRIVATE METHODS --
119#========================================================================
120
121#------------------------------------------------------------------------
122# _init(\%config)
123#------------------------------------------------------------------------
124
# spent 20.5ms (79µs+20.4) within Template::_init which was called 4 times, avg 5.13ms/call: # 4 times (79µs+20.4ms) by Template::Base::new at line 65 of Template/Base.pm, avg 5.13ms/call
sub _init {
1251400ns my ($self, $config) = @_;
126
127 # convert any textual DEBUG args to numerical form
1281500ns my $debug = $config->{ DEBUG };
1291300ns $config->{ DEBUG } = Template::Constants::debug_flags($self, $debug)
130 || return if defined $debug && $debug !~ /^\d+$/;
131
132 # prepare a namespace handler for any CONSTANTS definition
1331600ns if (my $constants = $config->{ CONSTANTS }) {
134 my $ns = $config->{ NAMESPACE } ||= { };
135 my $cns = $config->{ CONSTANTS_NAMESPACE } || 'constants';
136 $constants = Template::Config->constants($constants)
137 || return $self->error(Template::Config->error);
138 $ns->{ $cns } = $constants;
139 }
140
141 $self->{ SERVICE } = $config->{ SERVICE }
14218µs420.4ms || Template::Config->service($config)
# spent 20.4ms making 4 calls to Template::Config::service, avg 5.11ms/call
143 || return $self->error(Template::Config->error);
144
14512µs $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT;
14612µs $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH };
147
14812µs return $self;
149}
150
151
152#------------------------------------------------------------------------
153# _output($where, $text)
154#------------------------------------------------------------------------
155
156
# spent 60µs within Template::_output which was called 4 times, avg 15µs/call: # 4 times (60µs+0s) by Template::process at line 76, avg 15µs/call
sub _output {
1571600ns my ($where, $textref, $options) = @_;
1581200ns my $reftype;
1591500ns my $error = 0;
160
161 # call a CODE reference
16212µs if (($reftype = ref($where)) eq 'CODE') {
163 &$where($$textref);
164 }
165 # print to a glob (such as \*STDOUT)
166 elsif ($reftype eq 'GLOB') {
167 print $where $$textref;
168 }
169 # append output to a SCALAR ref
170 elsif ($reftype eq 'SCALAR') {
171110µs $$where .= $$textref;
172 }
173 # push onto ARRAY ref
174 elsif ($reftype eq 'ARRAY') {
175 push @$where, $$textref;
176 }
177 # call the print() method on an object that implements the method
178 # (e.g. IO::Handle, Apache::Request, etc)
179 elsif (blessed($where) && $where->can('print')) {
180 $where->print($$textref);
181 }
182 # a simple string is taken as a filename
183 elsif (! $reftype) {
184 local *FP;
185 # make destination directory if it doesn't exist
186 my $dir = dirname($where);
187 eval { mkpath($dir) unless -d $dir; };
188 if ($@) {
189 # strip file name and line number from error raised by die()
190 ($error = $@) =~ s/ at \S+ line \d+\n?$//;
191 }
192 elsif (open(FP, ">$where")) {
193 # binmode option can be 1 or a specific layer, e.g. :utf8
194 my $bm = $options->{ binmode };
195 if ($bm && $bm eq 1) {
196 binmode FP;
197 }
198 elsif ($bm){
199 binmode FP, $bm;
200 }
201 print FP $$textref;
202 close FP;
203 }
204 else {
205 $error = "$where: $!";
206 }
207 }
208 # give up, we've done our best
209 else {
210 $error = "output_handler() cannot determine target type ($where)\n";
211 }
212
21313µs return $error;
214}
215
216
2171;
218
219__END__