| Filename | /usr/lib/perl5/Template.pm |
| Statements | Executed 65 statements in 1.81ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 4.40ms | 6.36ms | Template::BEGIN@29 |
| 1 | 1 | 1 | 2.71ms | 7.37ms | Template::BEGIN@32 |
| 1 | 1 | 1 | 1.62ms | 2.82ms | Template::BEGIN@30 |
| 1 | 1 | 1 | 1.54ms | 1.96ms | Template::BEGIN@27 |
| 1 | 1 | 1 | 74µs | 74µs | Template::_output |
| 1 | 1 | 1 | 57µs | 701ms | Template::process |
| 1 | 1 | 1 | 37µs | 19.9ms | Template::_init |
| 1 | 1 | 1 | 27µs | 64µs | Template::BEGIN@28 |
| 1 | 1 | 1 | 23µs | 23µs | Template::BEGIN@24 |
| 1 | 1 | 1 | 22µs | 104µs | Template::BEGIN@31 |
| 1 | 1 | 1 | 18µs | 26µs | Template::BEGIN@22 |
| 1 | 1 | 1 | 15µs | 105µs | Template::BEGIN@33 |
| 1 | 1 | 1 | 14µs | 4.58ms | Template::BEGIN@25 |
| 1 | 1 | 1 | 10µs | 23µs | Template::BEGIN@23 |
| 0 | 0 | 0 | 0s | 0s | Template::context |
| 0 | 0 | 0 | 0s | 0s | Template::service |
| 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 | 32µs | 2 | 34µs | # spent 26µs (18+8) within Template::BEGIN@22 which was called:
# once (18µs+8µs) by C4::Templates::BEGIN@33 at line 22 # spent 26µs making 1 call to Template::BEGIN@22
# spent 8µs making 1 call to strict::import |
| 23 | 3 | 24µs | 2 | 35µs | # spent 23µs (10+12) within Template::BEGIN@23 which was called:
# once (10µs+12µs) by C4::Templates::BEGIN@33 at line 23 # spent 23µs making 1 call to Template::BEGIN@23
# spent 12µs making 1 call to warnings::import |
| 24 | 3 | 43µs | 1 | 23µs | # spent 23µs within Template::BEGIN@24 which was called:
# once (23µs+0s) by C4::Templates::BEGIN@33 at line 24 # spent 23µs making 1 call to Template::BEGIN@24 |
| 25 | 3 | 45µs | 2 | 9.15ms | # spent 4.58ms (14µs+4.57) within Template::BEGIN@25 which was called:
# once (14µs+4.57ms) by C4::Templates::BEGIN@33 at line 25 # spent 4.58ms making 1 call to Template::BEGIN@25
# spent 4.57ms making 1 call to base::import |
| 26 | |||||
| 27 | 3 | 149µs | 1 | 1.96ms | # spent 1.96ms (1.54+419µs) within Template::BEGIN@27 which was called:
# once (1.54ms+419µs) by C4::Templates::BEGIN@33 at line 27 # spent 1.96ms making 1 call to Template::BEGIN@27 |
| 28 | 3 | 36µs | 2 | 101µs | # spent 64µs (27+37) within Template::BEGIN@28 which was called:
# once (27µs+37µs) by C4::Templates::BEGIN@33 at line 28 # spent 64µs making 1 call to Template::BEGIN@28
# spent 37µs making 1 call to Exporter::import |
| 29 | 3 | 145µs | 1 | 6.36ms | # spent 6.36ms (4.40+1.96) within Template::BEGIN@29 which was called:
# once (4.40ms+1.96ms) by C4::Templates::BEGIN@33 at line 29 # spent 6.36ms making 1 call to Template::BEGIN@29 |
| 30 | 3 | 159µs | 1 | 2.82ms | # spent 2.82ms (1.62+1.20) within Template::BEGIN@30 which was called:
# once (1.62ms+1.20ms) by C4::Templates::BEGIN@33 at line 30 # spent 2.82ms making 1 call to Template::BEGIN@30 |
| 31 | 3 | 47µs | 2 | 186µs | # spent 104µs (22+82) within Template::BEGIN@31 which was called:
# once (22µs+82µs) by C4::Templates::BEGIN@33 at line 31 # spent 104µs making 1 call to Template::BEGIN@31
# spent 82µs making 1 call to Exporter::import |
| 32 | 3 | 183µs | 2 | 7.43ms | # spent 7.37ms (2.71+4.66) within Template::BEGIN@32 which was called:
# once (2.71ms+4.66ms) by C4::Templates::BEGIN@33 at line 32 # spent 7.37ms making 1 call to Template::BEGIN@32
# spent 51µs making 1 call to Exporter::import |
| 33 | 3 | 783µs | 2 | 195µs | # spent 105µs (15+90) within Template::BEGIN@33 which was called:
# once (15µs+90µs) by C4::Templates::BEGIN@33 at line 33 # spent 105µs making 1 call to Template::BEGIN@33
# spent 90µs making 1 call to Exporter::import |
| 34 | |||||
| 35 | 1 | 800ns | our $VERSION = '2.22'; | ||
| 36 | 1 | 400ns | our $ERROR = ''; | ||
| 37 | 1 | 300ns | our $DEBUG = 0; | ||
| 38 | 1 | 600ns | our $BINMODE = 0 unless defined $BINMODE; | ||
| 39 | 1 | 300ns | 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 701ms (57µs+701) within Template::process which was called:
# once (57µs+701ms) by C4::Templates::output at line 132 of /usr/share/koha/lib/C4/Templates.pm | ||||
| 54 | 11 | 42µ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 | 700ms | $output = $self->{ SERVICE }->process($template, $vars); # spent 700ms 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 | 74µs | return ($self->error($error)) # spent 74µ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 19.9ms (37µs+19.8) within Template::_init which was called:
# once (37µs+19.8ms) by Template::Base::new at line 65 of Template/Base.pm | ||||
| 121 | 8 | 32µ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 | 19.8ms | || Template::Config->service($config) # spent 19.8ms 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 74µs within Template::_output which was called:
# once (74µs+0s) by Template::process at line 76 | ||||
| 153 | 6 | 82µ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 | 7µs | 1; | ||
| 214 | |||||
| 215 | __END__ |