| Filename | /usr/lib/x86_64-linux-gnu/perl5/5.28/Template/Document.pm |
| Statements | Executed 11908395 statements in 100s |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 384174 | 1 | 1 | 86.2s | 87.3s | Template::Document::new |
| 384174 | 1 | 1 | 11.1s | 2133s | Template::Document::process (recurses: max depth 41, inclusive time 39745s) |
| 384174 | 2 | 2 | 2.83s | 4.19s | Template::Document::AUTOLOAD |
| 383161 | 1 | 1 | 733ms | 733ms | Template::Document::blocks |
| 1 | 1 | 1 | 16µs | 19µs | Template::Document::BEGIN@24 |
| 1 | 1 | 1 | 11µs | 28µs | Template::Document::BEGIN@25 |
| 1 | 1 | 1 | 6µs | 49µs | Template::Document::BEGIN@26 |
| 1 | 1 | 1 | 6µs | 19µs | Template::Document::BEGIN@27 |
| 1 | 1 | 1 | 5µs | 5µs | Template::Document::BEGIN@34 |
| 0 | 0 | 0 | 0s | 0s | Template::Document::_dump |
| 0 | 0 | 0 | 0s | 0s | Template::Document::as_perl |
| 0 | 0 | 0 | 0s | 0s | Template::Document::block |
| 0 | 0 | 0 | 0s | 0s | Template::Document::catch_warnings |
| 0 | 0 | 0 | 0s | 0s | Template::Document::variables |
| 0 | 0 | 0 | 0s | 0s | Template::Document::write_perl_file |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | ##============================================================= -*-Perl-*- | ||||
| 2 | # | ||||
| 3 | # Template::Document | ||||
| 4 | # | ||||
| 5 | # DESCRIPTION | ||||
| 6 | # Module defining a class of objects which encapsulate compiled | ||||
| 7 | # templates, storing additional block definitions and metadata | ||||
| 8 | # as well as the compiled Perl sub-routine representing the main | ||||
| 9 | # template content. | ||||
| 10 | # | ||||
| 11 | # AUTHOR | ||||
| 12 | # Andy Wardley <abw@wardley.org> | ||||
| 13 | # | ||||
| 14 | # COPYRIGHT | ||||
| 15 | # Copyright (C) 1996-2007 Andy Wardley. All Rights Reserved. | ||||
| 16 | # | ||||
| 17 | # This module is free software; you can redistribute it and/or | ||||
| 18 | # modify it under the same terms as Perl itself. | ||||
| 19 | # | ||||
| 20 | #============================================================================ | ||||
| 21 | |||||
| 22 | package Template::Document; | ||||
| 23 | |||||
| 24 | 2 | 27µs | 2 | 22µs | # spent 19µs (16+3) within Template::Document::BEGIN@24 which was called:
# once (16µs+3µs) by Template::Provider::BEGIN@46 at line 24 # spent 19µs making 1 call to Template::Document::BEGIN@24
# spent 3µs making 1 call to strict::import |
| 25 | 2 | 20µs | 2 | 46µs | # spent 28µs (11+17) within Template::Document::BEGIN@25 which was called:
# once (11µs+17µs) by Template::Provider::BEGIN@46 at line 25 # spent 28µs making 1 call to Template::Document::BEGIN@25
# spent 17µs making 1 call to warnings::import |
| 26 | 2 | 24µs | 2 | 92µs | # spent 49µs (6+43) within Template::Document::BEGIN@26 which was called:
# once (6µs+43µs) by Template::Provider::BEGIN@46 at line 26 # spent 49µs making 1 call to Template::Document::BEGIN@26
# spent 43µs making 1 call to base::import |
| 27 | 2 | 123µs | 2 | 32µs | # spent 19µs (6+13) within Template::Document::BEGIN@27 which was called:
# once (6µs+13µs) by Template::Provider::BEGIN@46 at line 27 # spent 19µs making 1 call to Template::Document::BEGIN@27
# spent 13µs making 1 call to Exporter::import |
| 28 | |||||
| 29 | 1 | 300ns | our $VERSION = 2.79; | ||
| 30 | 1 | 300ns | our $DEBUG = 0 unless defined $DEBUG; | ||
| 31 | 1 | 200ns | our $ERROR = ''; | ||
| 32 | our ($COMPERR, $AUTOLOAD, $UNICODE); | ||||
| 33 | |||||
| 34 | # spent 5µs within Template::Document::BEGIN@34 which was called:
# once (5µs+0s) by Template::Provider::BEGIN@46 at line 47 | ||||
| 35 | # UNICODE is supported in versions of Perl from 5.008 onwards | ||||
| 36 | 1 | 4µs | if ($UNICODE = $] > 5.007 ? 1 : 0) { | ||
| 37 | 1 | 1µs | if ($] > 5.008) { | ||
| 38 | # utf8::is_utf8() available from Perl 5.8.1 onwards | ||||
| 39 | *is_utf8 = \&utf8::is_utf8; | ||||
| 40 | } | ||||
| 41 | elsif ($] == 5.008) { | ||||
| 42 | # use Encode::is_utf8() for Perl 5.8.0 | ||||
| 43 | require Encode; | ||||
| 44 | *is_utf8 = \&Encode::is_utf8; | ||||
| 45 | } | ||||
| 46 | } | ||||
| 47 | 1 | 1.06ms | 1 | 5µs | } # spent 5µs making 1 call to Template::Document::BEGIN@34 |
| 48 | |||||
| 49 | |||||
| 50 | #======================================================================== | ||||
| 51 | # ----- PUBLIC METHODS ----- | ||||
| 52 | #======================================================================== | ||||
| 53 | |||||
| 54 | #------------------------------------------------------------------------ | ||||
| 55 | # new(\%document) | ||||
| 56 | # | ||||
| 57 | # Creates a new self-contained Template::Document object which | ||||
| 58 | # encapsulates a compiled Perl sub-routine, $block, any additional | ||||
| 59 | # BLOCKs defined within the document ($defblocks, also Perl sub-routines) | ||||
| 60 | # and additional $metadata about the document. | ||||
| 61 | #------------------------------------------------------------------------ | ||||
| 62 | |||||
| 63 | # spent 87.3s (86.2+1.10) within Template::Document::new which was called 384174 times, avg 227µs/call:
# 384174 times (86.2s+1.10s) by Template::Provider::_compile at line 894 of Template/Provider.pm, avg 227µs/call | ||||
| 64 | 384174 | 259ms | my ($class, $doc) = @_; | ||
| 65 | 384174 | 714ms | my ($block, $defblocks, $variables, $metadata) = @$doc{ qw( BLOCK DEFBLOCKS VARIABLES METADATA ) }; | ||
| 66 | 384174 | 196ms | $defblocks ||= { }; | ||
| 67 | 384174 | 157ms | $metadata ||= { }; | ||
| 68 | |||||
| 69 | # evaluate Perl code in $block to create sub-routine reference if necessary | ||||
| 70 | 384174 | 340ms | unless (ref $block) { | ||
| 71 | 384174 | 1.68s | local $SIG{__WARN__} = \&catch_warnings; | ||
| 72 | 384174 | 311ms | $COMPERR = ''; | ||
| 73 | |||||
| 74 | # DON'T LOOK NOW! - blindly untainting can make you go blind! | ||||
| 75 | 384174 | 2.96s | 384174 | 1.10s | $block =~ /(.*)/s; # spent 1.10s making 384174 calls to Template::Document::CORE:match, avg 3µs/call |
| 76 | 384174 | 777ms | $block = $1; | ||
| 77 | |||||
| 78 | 384174 | 72.4s | $block = eval $block; # spent 6.01s executing statements in 384174 string evals (merged) # includes 3.84s spent executing 215704 calls to 1 sub defined therein. | ||
| 79 | 384174 | 849ms | return $class->error($@) | ||
| 80 | unless defined $block; | ||||
| 81 | } | ||||
| 82 | |||||
| 83 | # same for any additional BLOCK definitions | ||||
| 84 | @$defblocks{ keys %$defblocks } = | ||||
| 85 | # MORE BLIND UNTAINTING - turn away if you're squeamish | ||||
| 86 | map { | ||||
| 87 | 384174 | 988ms | ref($_) | ||
| 88 | ? $_ | ||||
| 89 | : ( /(.*)/s && eval($1) or return $class->error($@) ) | ||||
| 90 | } values %$defblocks; | ||||
| 91 | |||||
| 92 | 384174 | 5.03s | bless { | ||
| 93 | %$metadata, | ||||
| 94 | _BLOCK => $block, | ||||
| 95 | _DEFBLOCKS => $defblocks, | ||||
| 96 | _VARIABLES => $variables, | ||||
| 97 | _HOT => 0, | ||||
| 98 | }, $class; | ||||
| 99 | } | ||||
| 100 | |||||
| 101 | |||||
| 102 | #------------------------------------------------------------------------ | ||||
| 103 | # block() | ||||
| 104 | # | ||||
| 105 | # Returns a reference to the internal sub-routine reference, _BLOCK, | ||||
| 106 | # that constitutes the main document template. | ||||
| 107 | #------------------------------------------------------------------------ | ||||
| 108 | |||||
| 109 | sub block { | ||||
| 110 | return $_[0]->{ _BLOCK }; | ||||
| 111 | } | ||||
| 112 | |||||
| 113 | |||||
| 114 | #------------------------------------------------------------------------ | ||||
| 115 | # blocks() | ||||
| 116 | # | ||||
| 117 | # Returns a reference to a hash array containing any BLOCK definitions | ||||
| 118 | # from the template. The hash keys are the BLOCK name and the values | ||||
| 119 | # are references to Template::Document objects. Returns 0 (# an empty hash) | ||||
| 120 | # if no blocks are defined. | ||||
| 121 | #------------------------------------------------------------------------ | ||||
| 122 | |||||
| 123 | # spent 733ms within Template::Document::blocks which was called 383161 times, avg 2µs/call:
# 383161 times (733ms+0s) by Template::Context::process at line 339 of Template/Context.pm, avg 2µs/call | ||||
| 124 | 383161 | 1.78s | return $_[0]->{ _DEFBLOCKS }; | ||
| 125 | } | ||||
| 126 | |||||
| 127 | |||||
| 128 | #----------------------------------------------------------------------- | ||||
| 129 | # variables() | ||||
| 130 | # | ||||
| 131 | # Returns a reference to a hash of variables used in the template. | ||||
| 132 | # This requires the TRACE_VARS option to be enabled. | ||||
| 133 | #----------------------------------------------------------------------- | ||||
| 134 | |||||
| 135 | sub variables { | ||||
| 136 | return $_[0]->{ _VARIABLES }; | ||||
| 137 | } | ||||
| 138 | |||||
| 139 | #------------------------------------------------------------------------ | ||||
| 140 | # process($context) | ||||
| 141 | # | ||||
| 142 | # Process the document in a particular context. Checks for recursion, | ||||
| 143 | # registers the document with the context via visit(), processes itself, | ||||
| 144 | # and then unwinds with a large gin and tonic. | ||||
| 145 | #------------------------------------------------------------------------ | ||||
| 146 | |||||
| 147 | # spent 2133s (11.1+2122) within Template::Document::process which was called 384174 times, avg 5.55ms/call:
# 384174 times (11.1s+2122s) by Template::Context::process at line 347 of Template/Context.pm, avg 5.55ms/call | ||||
| 148 | 384174 | 203ms | my ($self, $context) = @_; | ||
| 149 | 384174 | 418ms | my $defblocks = $self->{ _DEFBLOCKS }; | ||
| 150 | 384174 | 116ms | my $output; | ||
| 151 | |||||
| 152 | |||||
| 153 | # check we're not already visiting this template | ||||
| 154 | return $context->throw(Template::Constants::ERROR_FILE, | ||||
| 155 | "recursion into '$self->{ name }'") | ||||
| 156 | 384174 | 203ms | if $self->{ _HOT } && ! $context->{ RECURSION }; ## RETURN ## | ||
| 157 | |||||
| 158 | 384174 | 1.06s | 384174 | 1.29s | $context->visit($self, $defblocks); # spent 1.29s making 384174 calls to Template::Context::visit, avg 3µs/call |
| 159 | |||||
| 160 | 384174 | 249ms | $self->{ _HOT } = 1; | ||
| 161 | 384174 | 269ms | eval { | ||
| 162 | 384174 | 194ms | my $block = $self->{ _BLOCK }; | ||
| 163 | 384174 | 689ms | 384174 | 41865s | $output = &$block($context); # spent 14272s making 146492 calls to Template::Document::__ANON__[input text:9], avg 97.4ms/call
# spent 12599s making 7982 calls to Template::Document::__ANON__[input text:10], avg 1.58s/call
# spent 11751s making 1990 calls to Template::Document::__ANON__[input text:18], avg 5.91s/call
# spent 1483s making 2 calls to Template::Document::__ANON__[/root/tor-browser-build/projects/snowflake/build:37], avg 741s/call
# spent 632s making 1991 calls to Template::Document::__ANON__[input text:43], avg 317ms/call
# spent 408s making 1008 calls to Template::Document::__ANON__[input text:35], avg 405ms/call
# spent 235s making 1991 calls to Template::Document::__ANON__[input text:17], avg 118ms/call
# spent 228s making 2978 calls to Template::Document::__ANON__[input text:13], avg 76.7ms/call
# spent 224s making 996 calls to Template::Document::__ANON__[/root/tor-browser-build/projects/go/build:90], avg 225ms/call
# spent 15.7s making 995 calls to Template::Document::__ANON__[input text:30], avg 15.7ms/call
# spent 4.95s making 28 calls to Template::Document::__ANON__[input text:11], avg 177ms/call
# spent 4.80s making 1991 calls to Template::Document::__ANON__[input text:22], avg 2.41ms/call
# spent 4.25s making 215704 calls to Template::Document::__ANON__[(eval 100)[Template/Document.pm:78]:16], avg 20µs/call
# spent 1.97s making 9 calls to Template::Document::__ANON__[input text:21], avg 219ms/call
# spent 1.01s making 15 calls to Template::Document::__ANON__[/root/tor-browser-build/projects/common/runc-config.json:263], avg 67.5ms/call
# spent 23.7ms making 1 call to Template::Document::__ANON__[input text:25]
# spent 2.76ms making 1 call to Template::Document::__ANON__[input text:12] |
| 164 | }; | ||||
| 165 | 384174 | 304ms | $self->{ _HOT } = 0; | ||
| 166 | |||||
| 167 | 384174 | 963ms | 384174 | 967ms | $context->leave(); # spent 967ms making 384174 calls to Template::Context::leave, avg 3µs/call |
| 168 | |||||
| 169 | 384174 | 130ms | die $context->catch($@) | ||
| 170 | if $@; | ||||
| 171 | |||||
| 172 | 384174 | 1.89s | return $output; | ||
| 173 | } | ||||
| 174 | |||||
| 175 | |||||
| 176 | #------------------------------------------------------------------------ | ||||
| 177 | # AUTOLOAD | ||||
| 178 | # | ||||
| 179 | # Provides pseudo-methods for read-only access to various internal | ||||
| 180 | # members. | ||||
| 181 | #------------------------------------------------------------------------ | ||||
| 182 | |||||
| 183 | # spent 4.19s (2.83+1.36) within Template::Document::AUTOLOAD which was called 384174 times, avg 11µs/call:
# 383161 times (2.82s+1.36s) by Template::Service::process at line 132 of Template/Service.pm, avg 11µs/call
# 1013 times (10.1ms+1.45ms) by RBM::process_template at line 663 of /root/tor-browser-build/rbm/lib/RBM.pm, avg 11µs/call | ||||
| 184 | 384174 | 204ms | my $self = shift; | ||
| 185 | 384174 | 316ms | my $method = $AUTOLOAD; | ||
| 186 | |||||
| 187 | 384174 | 2.91s | 384174 | 1.36s | $method =~ s/.*:://; # spent 1.36s making 384174 calls to Template::Document::CORE:subst, avg 4µs/call |
| 188 | 384174 | 1.80s | return if $method eq 'DESTROY'; | ||
| 189 | # my ($pkg, $file, $line) = caller(); | ||||
| 190 | # print STDERR "called $self->AUTOLOAD($method) from $file line $line\n"; | ||||
| 191 | return $self->{ $method }; | ||||
| 192 | } | ||||
| 193 | |||||
| 194 | |||||
| 195 | #======================================================================== | ||||
| 196 | # ----- PRIVATE METHODS ----- | ||||
| 197 | #======================================================================== | ||||
| 198 | |||||
| 199 | |||||
| 200 | #------------------------------------------------------------------------ | ||||
| 201 | # _dump() | ||||
| 202 | # | ||||
| 203 | # Debug method which returns a string representing the internal state | ||||
| 204 | # of the object. | ||||
| 205 | #------------------------------------------------------------------------ | ||||
| 206 | |||||
| 207 | sub _dump { | ||||
| 208 | my $self = shift; | ||||
| 209 | my $dblks; | ||||
| 210 | my $output = "$self : $self->{ name }\n"; | ||||
| 211 | |||||
| 212 | $output .= "BLOCK: $self->{ _BLOCK }\nDEFBLOCKS:\n"; | ||||
| 213 | |||||
| 214 | if ($dblks = $self->{ _DEFBLOCKS }) { | ||||
| 215 | foreach my $b (keys %$dblks) { | ||||
| 216 | $output .= " $b: $dblks->{ $b }\n"; | ||||
| 217 | } | ||||
| 218 | } | ||||
| 219 | |||||
| 220 | return $output; | ||||
| 221 | } | ||||
| 222 | |||||
| 223 | |||||
| 224 | #======================================================================== | ||||
| 225 | # ----- CLASS METHODS ----- | ||||
| 226 | #======================================================================== | ||||
| 227 | |||||
| 228 | #------------------------------------------------------------------------ | ||||
| 229 | # as_perl($content) | ||||
| 230 | # | ||||
| 231 | # This method expects a reference to a hash passed as the first argument | ||||
| 232 | # containing 3 items: | ||||
| 233 | # METADATA # a hash of template metadata | ||||
| 234 | # BLOCK # string containing Perl sub definition for main block | ||||
| 235 | # DEFBLOCKS # hash containing further subs for addional BLOCK defs | ||||
| 236 | # It returns a string containing Perl code which, when evaluated and | ||||
| 237 | # executed, will instantiate a new Template::Document object with the | ||||
| 238 | # above data. On error, it returns undef with an appropriate error | ||||
| 239 | # message set in $ERROR. | ||||
| 240 | #------------------------------------------------------------------------ | ||||
| 241 | |||||
| 242 | sub as_perl { | ||||
| 243 | my ($class, $content) = @_; | ||||
| 244 | my ($block, $defblocks, $metadata) = @$content{ qw( BLOCK DEFBLOCKS METADATA ) }; | ||||
| 245 | |||||
| 246 | $block =~ s/\s+$//; | ||||
| 247 | |||||
| 248 | $defblocks = join('', map { | ||||
| 249 | my $code = $defblocks->{ $_ }; | ||||
| 250 | $code =~ s/\s*$//; | ||||
| 251 | " '$_' => $code,\n"; | ||||
| 252 | } keys %$defblocks); | ||||
| 253 | $defblocks =~ s/\s+$//; | ||||
| 254 | |||||
| 255 | $metadata = join('', map { | ||||
| 256 | my $x = $metadata->{ $_ }; | ||||
| 257 | $x =~ s/(['\\])/\\$1/g; | ||||
| 258 | " '$_' => '$x',\n"; | ||||
| 259 | } keys %$metadata); | ||||
| 260 | $metadata =~ s/\s+$//; | ||||
| 261 | |||||
| 262 | return <<EOF | ||||
| 263 | #------------------------------------------------------------------------ | ||||
| 264 | # Compiled template generated by the Template Toolkit version $Template::VERSION | ||||
| 265 | #------------------------------------------------------------------------ | ||||
| 266 | |||||
| 267 | $class->new({ | ||||
| 268 | METADATA => { | ||||
| 269 | $metadata | ||||
| 270 | }, | ||||
| 271 | BLOCK => $block, | ||||
| 272 | DEFBLOCKS => { | ||||
| 273 | $defblocks | ||||
| 274 | }, | ||||
| 275 | }); | ||||
| 276 | EOF | ||||
| 277 | } | ||||
| 278 | |||||
| 279 | |||||
| 280 | #------------------------------------------------------------------------ | ||||
| 281 | # write_perl_file($filename, \%content) | ||||
| 282 | # | ||||
| 283 | # This method calls as_perl() to generate the Perl code to represent a | ||||
| 284 | # compiled template with the content passed as the second argument. | ||||
| 285 | # It then writes this to the file denoted by the first argument. | ||||
| 286 | # | ||||
| 287 | # Returns 1 on success. On error, sets the $ERROR package variable | ||||
| 288 | # to contain an error message and returns undef. | ||||
| 289 | #------------------------------------------------------------------------ | ||||
| 290 | |||||
| 291 | sub write_perl_file { | ||||
| 292 | my ($class, $file, $content) = @_; | ||||
| 293 | my ($fh, $tmpfile); | ||||
| 294 | |||||
| 295 | return $class->error("invalid filename: $file") | ||||
| 296 | unless $file =~ /^(.+)$/s; | ||||
| 297 | |||||
| 298 | eval { | ||||
| 299 | require File::Temp; | ||||
| 300 | require File::Basename; | ||||
| 301 | ($fh, $tmpfile) = File::Temp::tempfile( | ||||
| 302 | DIR => File::Basename::dirname($file) | ||||
| 303 | ); | ||||
| 304 | my $perlcode = $class->as_perl($content) || die $!; | ||||
| 305 | |||||
| 306 | if ($UNICODE && is_utf8($perlcode)) { | ||||
| 307 | $perlcode = "use utf8;\n\n$perlcode"; | ||||
| 308 | binmode $fh, ":utf8"; | ||||
| 309 | } | ||||
| 310 | print $fh $perlcode; | ||||
| 311 | close($fh); | ||||
| 312 | }; | ||||
| 313 | return $class->error($@) if $@; | ||||
| 314 | return rename($tmpfile, $file) | ||||
| 315 | || $class->error($!); | ||||
| 316 | } | ||||
| 317 | |||||
| 318 | |||||
| 319 | #------------------------------------------------------------------------ | ||||
| 320 | # catch_warnings($msg) | ||||
| 321 | # | ||||
| 322 | # Installed as | ||||
| 323 | #------------------------------------------------------------------------ | ||||
| 324 | |||||
| 325 | sub catch_warnings { | ||||
| 326 | $COMPERR .= join('', @_); | ||||
| 327 | } | ||||
| 328 | |||||
| 329 | |||||
| 330 | 1 | 5µs | 1; | ||
| 331 | |||||
| 332 | __END__ |