Filename | /usr/lib/x86_64-linux-gnu/perl5/5.28/Template.pm |
Statements | Executed 9384703 statements in 15.7s |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
375387 | 1 | 1 | 8.26s | 1623s | process (recurses: max depth 40, inclusive time 29402s) | Template::
375387 | 1 | 1 | 5.51s | 141s | _init | Template::
375387 | 1 | 1 | 2.32s | 2.32s | _output | Template::
1 | 1 | 1 | 4.45ms | 6.26ms | BEGIN@29 | Template::
1 | 1 | 1 | 3.24ms | 3.44ms | BEGIN@32 | Template::
1 | 1 | 1 | 1.25ms | 2.23ms | BEGIN@30 | Template::
1 | 1 | 1 | 1.06ms | 1.34ms | BEGIN@27 | Template::
1 | 1 | 1 | 10µs | 12µs | BEGIN@22 | Template::
1 | 1 | 1 | 8µs | 42µs | BEGIN@31 | Template::
1 | 1 | 1 | 8µs | 8µs | BEGIN@24 | Template::
1 | 1 | 1 | 7µs | 26µs | BEGIN@33 | Template::
1 | 1 | 1 | 6µs | 19µs | BEGIN@28 | Template::
1 | 1 | 1 | 6µs | 3.25ms | BEGIN@25 | Template::
1 | 1 | 1 | 5µs | 19µs | BEGIN@23 | Template::
3 | 3 | 1 | 3µs | 3µs | __ANON__ (xsub) | Template::
0 | 0 | 0 | 0s | 0s | context | Template::
0 | 0 | 0 | 0s | 0s | service | Template::
0 | 0 | 0 | 0s | 0s | template | 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-2014 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 | 2 | 18µs | 2 | 15µs | # spent 12µs (10+3) within Template::BEGIN@22 which was called:
# once (10µs+3µs) by RBM::BEGIN@9 at line 22 # spent 12µs making 1 call to Template::BEGIN@22
# spent 2µs making 1 call to strict::import |
23 | 2 | 18µs | 2 | 32µs | # spent 19µs (5+14) within Template::BEGIN@23 which was called:
# once (5µs+14µs) by RBM::BEGIN@9 at line 23 # spent 19µs making 1 call to Template::BEGIN@23
# spent 14µs making 1 call to warnings::import |
24 | 2 | 35µs | 1 | 8µs | # spent 8µs within Template::BEGIN@24 which was called:
# once (8µs+0s) by RBM::BEGIN@9 at line 24 # spent 8µs making 1 call to Template::BEGIN@24 |
25 | 2 | 24µs | 2 | 6.49ms | # spent 3.25ms (6µs+3.24) within Template::BEGIN@25 which was called:
# once (6µs+3.24ms) by RBM::BEGIN@9 at line 25 # spent 3.25ms making 1 call to Template::BEGIN@25
# spent 3.24ms making 1 call to base::import |
26 | |||||
27 | 2 | 115µs | 2 | 1.34ms | # spent 1.34ms (1.06+280µs) within Template::BEGIN@27 which was called:
# once (1.06ms+280µs) by RBM::BEGIN@9 at line 27 # spent 1.34ms making 1 call to Template::BEGIN@27
# spent 900ns making 1 call to Template::__ANON__ |
28 | 2 | 19µs | 2 | 33µs | # spent 19µs (6+13) within Template::BEGIN@28 which was called:
# once (6µs+13µs) by RBM::BEGIN@9 at line 28 # spent 19µs making 1 call to Template::BEGIN@28
# spent 13µs making 1 call to Exporter::import |
29 | 2 | 122µs | 2 | 6.27ms | # spent 6.26ms (4.45+1.81) within Template::BEGIN@29 which was called:
# once (4.45ms+1.81ms) by RBM::BEGIN@9 at line 29 # spent 6.26ms making 1 call to Template::BEGIN@29
# spent 900ns making 1 call to Template::__ANON__ |
30 | 2 | 176µs | 2 | 2.23ms | # spent 2.23ms (1.25+977µs) within Template::BEGIN@30 which was called:
# once (1.25ms+977µs) by RBM::BEGIN@9 at line 30 # spent 2.23ms making 1 call to Template::BEGIN@30
# spent 1µs making 1 call to Template::__ANON__ |
31 | 2 | 23µs | 2 | 76µs | # spent 42µs (8+34) within Template::BEGIN@31 which was called:
# once (8µs+34µs) by RBM::BEGIN@9 at line 31 # spent 42µs making 1 call to Template::BEGIN@31
# spent 34µs making 1 call to Exporter::import |
32 | 2 | 112µs | 2 | 3.47ms | # spent 3.44ms (3.24+197µs) within Template::BEGIN@32 which was called:
# once (3.24ms+197µs) by RBM::BEGIN@9 at line 32 # spent 3.44ms making 1 call to Template::BEGIN@32
# spent 32µs making 1 call to Exporter::import |
33 | 2 | 836µs | 2 | 46µs | # spent 26µs (7+19) within Template::BEGIN@33 which was called:
# once (7µs+19µs) by RBM::BEGIN@9 at line 33 # spent 26µs making 1 call to Template::BEGIN@33
# spent 19µs making 1 call to Exporter::import |
34 | |||||
35 | 1 | 400ns | our $VERSION = '2.27'; | ||
36 | 1 | 200ns | our $ERROR = ''; | ||
37 | 1 | 100ns | our $DEBUG = 0; | ||
38 | 1 | 300ns | our $BINMODE = 0 unless defined $BINMODE; | ||
39 | our $AUTOLOAD; | ||||
40 | |||||
41 | # preload all modules if we're running under mod_perl | ||||
42 | 1 | 500ns | 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 1623s (8.26+1614) within Template::process which was called 375387 times, avg 4.32ms/call:
# 375387 times (8.26s+1614s) by RBM::process_template at line 673 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 4.32ms/call | ||||
54 | 375387 | 377ms | my ($self, $template, $vars, $outstream, @opts) = @_; | ||
55 | 375387 | 132ms | my ($output, $error); | ||
56 | 375387 | 702ms | my $options = (@opts == 1) && ref($opts[0]) eq 'HASH' | ||
57 | ? shift(@opts) : { @opts }; | ||||
58 | |||||
59 | $options->{ binmode } = $BINMODE | ||||
60 | 375387 | 292ms | 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 | 375387 | 342ms | $self->DEBUG("set binmode\n") if $DEBUG && $options->{ binmode }; | ||
65 | |||||
66 | 375387 | 1.39s | 375387 | 1623s | $output = $self->{ SERVICE }->process($template, $vars); # spent 31014s making 375387 calls to Template::Service::process, avg 82.6ms/call, recursion: max depth 40, sum of overlapping time 29391s |
67 | |||||
68 | 375387 | 222ms | if (defined $output) { | ||
69 | 375387 | 183ms | $outstream ||= $self->{ OUTPUT }; | ||
70 | 375387 | 193ms | 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 | 375387 | 1.03s | 375387 | 2.32s | return ($self->error($error)) # spent 2.32s making 375387 calls to Template::_output, avg 6µs/call |
77 | if ($error = &_output($outstream, \$output, $options)); | ||||
78 | |||||
79 | 375387 | 2.37s | 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 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 CONTEXT object within the SERVICE | ||||
104 | # object. | ||||
105 | #------------------------------------------------------------------------ | ||||
106 | |||||
107 | sub context { | ||||
108 | my $self = shift; | ||||
109 | return $self->{ SERVICE }->{ CONTEXT }; | ||||
110 | } | ||||
111 | |||||
112 | sub template { | ||||
113 | shift->context->template(@_); | ||||
114 | } | ||||
115 | |||||
116 | |||||
117 | #======================================================================== | ||||
118 | # -- PRIVATE METHODS -- | ||||
119 | #======================================================================== | ||||
120 | |||||
121 | #------------------------------------------------------------------------ | ||||
122 | # _init(\%config) | ||||
123 | #------------------------------------------------------------------------ | ||||
124 | # spent 141s (5.51+135) within Template::_init which was called 375387 times, avg 375µs/call:
# 375387 times (5.51s+135s) by Template::Base::new at line 65 of Template/Base.pm, avg 375µs/call | ||||
125 | 375387 | 229ms | my ($self, $config) = @_; | ||
126 | |||||
127 | # convert any textual DEBUG args to numerical form | ||||
128 | 375387 | 314ms | my $debug = $config->{ DEBUG }; | ||
129 | 375387 | 209ms | $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 | 375387 | 230ms | 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 | 375387 | 1.75s | 375387 | 135s | || Template::Config->service($config) # spent 135s making 375387 calls to Template::Config::service, avg 360µs/call |
143 | || return $self->error(Template::Config->error); | ||||
144 | |||||
145 | 375387 | 634ms | $self->{ OUTPUT } = $config->{ OUTPUT } || \*STDOUT; | ||
146 | 375387 | 409ms | $self->{ OUTPUT_PATH } = $config->{ OUTPUT_PATH }; | ||
147 | |||||
148 | 375387 | 1.44s | return $self; | ||
149 | } | ||||
150 | |||||
151 | |||||
152 | #------------------------------------------------------------------------ | ||||
153 | # _output($where, $text) | ||||
154 | #------------------------------------------------------------------------ | ||||
155 | |||||
156 | # spent 2.32s within Template::_output which was called 375387 times, avg 6µs/call:
# 375387 times (2.32s+0s) by Template::process at line 76, avg 6µs/call | ||||
157 | 375387 | 202ms | my ($where, $textref, $options) = @_; | ||
158 | 375387 | 116ms | my $reftype; | ||
159 | 375387 | 159ms | my $error = 0; | ||
160 | |||||
161 | # call a CODE reference | ||||
162 | 375387 | 810ms | 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 | 375387 | 336ms | $$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 | 375387 | 1.60s | return $error; | ||
214 | } | ||||
215 | |||||
216 | |||||
217 | 1 | 6µs | 1; | ||
218 | |||||
219 | __END__ | ||||
sub Template::__ANON__; # xsub |