← 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/usr/lib/x86_64-linux-gnu/perl5/5.20/Template.pm
StatementsExecuted 29 statements in 4.25ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1117.03ms10.2msTemplate::::BEGIN@29Template::BEGIN@29
1112.40ms2.63msTemplate::::BEGIN@27Template::BEGIN@27
1112.39ms3.82msTemplate::::BEGIN@30Template::BEGIN@30
11115µs15µsTemplate::::BEGIN@24Template::BEGIN@24
11112µs23µsTemplate::::BEGIN@22Template::BEGIN@22
11112µs21µsTemplate::::BEGIN@23Template::BEGIN@23
11111µs47µsTemplate::::BEGIN@31Template::BEGIN@31
1119µs16.3msTemplate::::BEGIN@25Template::BEGIN@25
1119µs24µsTemplate::::BEGIN@28Template::BEGIN@28
1119µs32µsTemplate::::BEGIN@32Template::BEGIN@32
1118µs29µsTemplate::::BEGIN@33Template::BEGIN@33
0000s0sTemplate::::_initTemplate::_init
0000s0sTemplate::::_outputTemplate::_output
0000s0sTemplate::::contextTemplate::context
0000s0sTemplate::::processTemplate::process
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
22236µs234µs
# spent 23µs (12+11) within Template::BEGIN@22 which was called: # once (12µs+11µs) by C4::Templates::BEGIN@33 at line 22
use strict;
# spent 23µs making 1 call to Template::BEGIN@22 # spent 11µs making 1 call to strict::import
23227µs231µs
# spent 21µs (12+10) within Template::BEGIN@23 which was called: # once (12µs+10µs) by C4::Templates::BEGIN@33 at line 23
use warnings;
# spent 21µs making 1 call to Template::BEGIN@23 # spent 10µs making 1 call to warnings::import
24249µs115µs
# spent 15µs within Template::BEGIN@24 which was called: # once (15µs+0s) by C4::Templates::BEGIN@33 at line 24
use 5.006;
# spent 15µs making 1 call to Template::BEGIN@24
25232µs232.5ms
# spent 16.3ms (9µs+16.3) within Template::BEGIN@25 which was called: # once (9µs+16.3ms) by C4::Templates::BEGIN@33 at line 25
use base 'Template::Base';
# spent 16.3ms making 1 call to Template::BEGIN@25 # spent 16.3ms making 1 call to base::import
26
2721.54ms12.63ms
# spent 2.63ms (2.40+235µs) within Template::BEGIN@27 which was called: # once (2.40ms+235µs) by C4::Templates::BEGIN@33 at line 27
use Template::Config;
# spent 2.63ms making 1 call to Template::BEGIN@27
28222µs239µs
# spent 24µs (9+15) within Template::BEGIN@28 which was called: # once (9µs+15µs) by C4::Templates::BEGIN@33 at line 28
use Template::Constants;
# spent 24µs making 1 call to Template::BEGIN@28 # spent 15µs making 1 call to Exporter::import
292701µs110.2ms
# spent 10.2ms (7.03+3.14) within Template::BEGIN@29 which was called: # once (7.03ms+3.14ms) by C4::Templates::BEGIN@33 at line 29
use Template::Provider;
# spent 10.2ms making 1 call to Template::BEGIN@29
3021.16ms13.82ms
# spent 3.82ms (2.39+1.43) within Template::BEGIN@30 which was called: # once (2.39ms+1.43ms) by C4::Templates::BEGIN@33 at line 30
use Template::Service;
# spent 3.82ms making 1 call to Template::BEGIN@30
31235µs282µs
# spent 47µs (11+35) within Template::BEGIN@31 which was called: # once (11µs+35µs) by C4::Templates::BEGIN@33 at line 31
use File::Basename;
# spent 47µs making 1 call to Template::BEGIN@31 # spent 35µs making 1 call to Exporter::import
32225µs254µs
# spent 32µs (9+23) within Template::BEGIN@32 which was called: # once (9µs+23µs) by C4::Templates::BEGIN@33 at line 32
use File::Path;
# spent 32µs making 1 call to Template::BEGIN@32 # spent 23µs making 1 call to Exporter::import
332608µs250µs
# spent 29µs (8+21) within Template::BEGIN@33 which was called: # once (8µs+21µs) by C4::Templates::BEGIN@33 at line 33
use Scalar::Util qw(blessed);
# spent 29µs making 1 call to Template::BEGIN@33 # spent 21µs making 1 call to Exporter::import
34
351300nsour $VERSION = '2.24';
361100nsour $ERROR = '';
371200nsour $DEBUG = 0;
381200nsour $BINMODE = 0 unless defined $BINMODE;
3910sour $AUTOLOAD;
40
41# preload all modules if we're running under mod_perl
421500nsTemplate::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
53sub process {
54 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
66 $output = $self->{ SERVICE }->process($template, $vars);
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
76 return ($self->error($error))
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
112sub template {
113 shift->context->template(@_);
114}
115
116
117#========================================================================
118# -- PRIVATE METHODS --
119#========================================================================
120
121#------------------------------------------------------------------------
122# _init(\%config)
123#------------------------------------------------------------------------
124sub _init {
125 my ($self, $config) = @_;
126
127 # convert any textual DEBUG args to numerical form
128 my $debug = $config->{ DEBUG };
129 $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
133 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 }
142 || Template::Config->service($config)
143 || return $self->error(Template::Config->error);
144
145 $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT;
146 $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH };
147
148 return $self;
149}
150
151
152#------------------------------------------------------------------------
153# _output($where, $text)
154#------------------------------------------------------------------------
155
156sub _output {
157 my ($where, $textref, $options) = @_;
158 my $reftype;
159 my $error = 0;
160
161 # call a CODE reference
162 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') {
171 $$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
213 return $error;
214}
215
216
21713µs1;
218
219__END__