Filename | /usr/lib/perl5/Template.pm |
Statements | Executed 65 statements in 1.93ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 6.57ms | 12.2ms | BEGIN@29 | Template::
1 | 1 | 1 | 2.78ms | 6.89ms | BEGIN@32 | Template::
1 | 1 | 1 | 1.37ms | 2.60ms | BEGIN@30 | Template::
1 | 1 | 1 | 1.27ms | 1.65ms | BEGIN@27 | Template::
1 | 1 | 1 | 119µs | 119µs | _output | Template::
1 | 1 | 1 | 65µs | 830ms | process | Template::
1 | 1 | 1 | 30µs | 30µs | BEGIN@24 | Template::
1 | 1 | 1 | 26µs | 23.4ms | _init | Template::
1 | 1 | 1 | 20µs | 24µs | BEGIN@22 | Template::
1 | 1 | 1 | 18µs | 46µs | BEGIN@28 | Template::
1 | 1 | 1 | 16µs | 41µs | BEGIN@23 | Template::
1 | 1 | 1 | 13µs | 65µs | BEGIN@31 | Template::
1 | 1 | 1 | 12µs | 44µs | BEGIN@33 | Template::
1 | 1 | 1 | 11µs | 5.19ms | BEGIN@25 | Template::
0 | 0 | 0 | 0s | 0s | context | Template::
0 | 0 | 0 | 0s | 0s | service | Template::
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 | |||||
20 | package Template; | ||||
21 | |||||
22 | 3 | 51µs | 2 | 29µ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 # spent 24µs making 1 call to Template::BEGIN@22
# spent 4µs making 1 call to strict::import |
23 | 3 | 36µs | 2 | 66µ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 # spent 41µs making 1 call to Template::BEGIN@23
# spent 25µs making 1 call to warnings::import |
24 | 3 | 53µs | 1 | 30µs | # spent 30µs within Template::BEGIN@24 which was called:
# once (30µs+0s) by C4::Templates::BEGIN@33 at line 24 # spent 30µs making 1 call to Template::BEGIN@24 |
25 | 3 | 46µs | 2 | 10.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 # spent 5.19ms making 1 call to Template::BEGIN@25
# spent 5.18ms making 1 call to base::import |
26 | |||||
27 | 3 | 199µs | 1 | 1.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 # spent 1.65ms making 1 call to Template::BEGIN@27 |
28 | 3 | 33µs | 2 | 74µ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 # spent 46µs making 1 call to Template::BEGIN@28
# spent 28µs making 1 call to Exporter::import |
29 | 3 | 202µs | 1 | 12.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 # spent 12.2ms making 1 call to Template::BEGIN@29 |
30 | 3 | 158µs | 1 | 2.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 # spent 2.60ms making 1 call to Template::BEGIN@30 |
31 | 3 | 31µs | 2 | 116µ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 # spent 65µs making 1 call to Template::BEGIN@31
# spent 52µs making 1 call to Exporter::import |
32 | 3 | 161µs | 2 | 6.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 # spent 6.89ms making 1 call to Template::BEGIN@32
# spent 44µs making 1 call to Exporter::import |
33 | 3 | 745µs | 2 | 76µ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 # spent 44µs making 1 call to Template::BEGIN@33
# spent 32µs making 1 call to Exporter::import |
34 | |||||
35 | 1 | 1µs | our $VERSION = '2.22'; | ||
36 | 1 | 400ns | our $ERROR = ''; | ||
37 | 1 | 400ns | our $DEBUG = 0; | ||
38 | 1 | 500ns | our $BINMODE = 0 unless defined $BINMODE; | ||
39 | 1 | 100ns | our $AUTOLOAD; | ||
40 | |||||
41 | # preload all modules if we're running under mod_perl | ||||
42 | 1 | 2µs | Template::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 | ||||
54 | 11 | 53µ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 | |||||
66 | 1 | 830ms | $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 | ||||
76 | 1 | 119µ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 | |||||
94 | sub 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 | |||||
107 | sub 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 | ||||
121 | 8 | 25µ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 } | ||||
138 | 1 | 23.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 | ||||
153 | 6 | 125µ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 | |||||
213 | 1 | 6µs | 1; | ||
214 | |||||
215 | __END__ |