← Index
NYTProf Performance Profile   « block view • line view • sub view »
For /usr/share/koha/opac/cgi-bin/opac/opac-search.pl
  Run on Tue Oct 15 11:58:52 2013
Reported on Tue Oct 15 12:01:42 2013

Filename/usr/lib/perl5/Template/VMethods.pm
StatementsExecuted 41 statements in 3.54ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
22245µs92µsTemplate::VMethods::::text_matchTemplate::VMethods::text_match
21136µs36µsTemplate::VMethods::::CORE:regcompTemplate::VMethods::CORE:regcomp (opcode)
11118µs22µsTemplate::VMethods::::BEGIN@24Template::VMethods::BEGIN@24
11118µs35µsTemplate::VMethods::::BEGIN@379Template::VMethods::BEGIN@379
11117µs40µsTemplate::VMethods::::BEGIN@104Template::VMethods::BEGIN@104
11116µs108µsTemplate::VMethods::::BEGIN@26Template::VMethods::BEGIN@26
11115µs27µsTemplate::VMethods::::BEGIN@110Template::VMethods::BEGIN@110
11112µs25µsTemplate::VMethods::::BEGIN@406Template::VMethods::BEGIN@406
11111µs22µsTemplate::VMethods::::BEGIN@412Template::VMethods::BEGIN@412
11111µs22µsTemplate::VMethods::::BEGIN@25Template::VMethods::BEGIN@25
21111µs11µsTemplate::VMethods::::CORE:matchTemplate::VMethods::CORE:match (opcode)
0000s0sTemplate::VMethods::::__ANON__[:183]Template::VMethods::__ANON__[:183]
0000s0sTemplate::VMethods::::_list_sort_make_keyTemplate::VMethods::_list_sort_make_key
0000s0sTemplate::VMethods::::hash_definedTemplate::VMethods::hash_defined
0000s0sTemplate::VMethods::::hash_deleteTemplate::VMethods::hash_delete
0000s0sTemplate::VMethods::::hash_eachTemplate::VMethods::hash_each
0000s0sTemplate::VMethods::::hash_existsTemplate::VMethods::hash_exists
0000s0sTemplate::VMethods::::hash_hashTemplate::VMethods::hash_hash
0000s0sTemplate::VMethods::::hash_importTemplate::VMethods::hash_import
0000s0sTemplate::VMethods::::hash_itemTemplate::VMethods::hash_item
0000s0sTemplate::VMethods::::hash_itemsTemplate::VMethods::hash_items
0000s0sTemplate::VMethods::::hash_keysTemplate::VMethods::hash_keys
0000s0sTemplate::VMethods::::hash_listTemplate::VMethods::hash_list
0000s0sTemplate::VMethods::::hash_nsortTemplate::VMethods::hash_nsort
0000s0sTemplate::VMethods::::hash_pairsTemplate::VMethods::hash_pairs
0000s0sTemplate::VMethods::::hash_sizeTemplate::VMethods::hash_size
0000s0sTemplate::VMethods::::hash_sortTemplate::VMethods::hash_sort
0000s0sTemplate::VMethods::::hash_valuesTemplate::VMethods::hash_values
0000s0sTemplate::VMethods::::list_definedTemplate::VMethods::list_defined
0000s0sTemplate::VMethods::::list_firstTemplate::VMethods::list_first
0000s0sTemplate::VMethods::::list_grepTemplate::VMethods::list_grep
0000s0sTemplate::VMethods::::list_hashTemplate::VMethods::list_hash
0000s0sTemplate::VMethods::::list_importTemplate::VMethods::list_import
0000s0sTemplate::VMethods::::list_itemTemplate::VMethods::list_item
0000s0sTemplate::VMethods::::list_joinTemplate::VMethods::list_join
0000s0sTemplate::VMethods::::list_lastTemplate::VMethods::list_last
0000s0sTemplate::VMethods::::list_listTemplate::VMethods::list_list
0000s0sTemplate::VMethods::::list_maxTemplate::VMethods::list_max
0000s0sTemplate::VMethods::::list_mergeTemplate::VMethods::list_merge
0000s0sTemplate::VMethods::::list_nsortTemplate::VMethods::list_nsort
0000s0sTemplate::VMethods::::list_popTemplate::VMethods::list_pop
0000s0sTemplate::VMethods::::list_pushTemplate::VMethods::list_push
0000s0sTemplate::VMethods::::list_reverseTemplate::VMethods::list_reverse
0000s0sTemplate::VMethods::::list_shiftTemplate::VMethods::list_shift
0000s0sTemplate::VMethods::::list_sizeTemplate::VMethods::list_size
0000s0sTemplate::VMethods::::list_sliceTemplate::VMethods::list_slice
0000s0sTemplate::VMethods::::list_sortTemplate::VMethods::list_sort
0000s0sTemplate::VMethods::::list_spliceTemplate::VMethods::list_splice
0000s0sTemplate::VMethods::::list_uniqueTemplate::VMethods::list_unique
0000s0sTemplate::VMethods::::list_unshiftTemplate::VMethods::list_unshift
0000s0sTemplate::VMethods::::root_decTemplate::VMethods::root_dec
0000s0sTemplate::VMethods::::root_incTemplate::VMethods::root_inc
0000s0sTemplate::VMethods::::text_chunkTemplate::VMethods::text_chunk
0000s0sTemplate::VMethods::::text_definedTemplate::VMethods::text_defined
0000s0sTemplate::VMethods::::text_hashTemplate::VMethods::text_hash
0000s0sTemplate::VMethods::::text_itemTemplate::VMethods::text_item
0000s0sTemplate::VMethods::::text_lengthTemplate::VMethods::text_length
0000s0sTemplate::VMethods::::text_listTemplate::VMethods::text_list
0000s0sTemplate::VMethods::::text_removeTemplate::VMethods::text_remove
0000s0sTemplate::VMethods::::text_repeatTemplate::VMethods::text_repeat
0000s0sTemplate::VMethods::::text_replaceTemplate::VMethods::text_replace
0000s0sTemplate::VMethods::::text_searchTemplate::VMethods::text_search
0000s0sTemplate::VMethods::::text_sizeTemplate::VMethods::text_size
0000s0sTemplate::VMethods::::text_splitTemplate::VMethods::text_split
0000s0sTemplate::VMethods::::text_substrTemplate::VMethods::text_substr
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::VMethods
4#
5# DESCRIPTION
6# Module defining virtual methods for the Template Toolkit
7#
8# AUTHOR
9# Andy Wardley <abw@wardley.org>
10#
11# COPYRIGHT
12# Copyright (C) 1996-2006 Andy Wardley. All Rights Reserved.
13#
14# This module is free software; you can redistribute it and/or
15# modify it under the same terms as Perl itself.
16#
17# REVISION
18# $Id: VMethods.pm 1245 2009-07-04 17:02:52Z abw $
19#
20#============================================================================
21
22package Template::VMethods;
23
24334µs226µs
# spent 22µs (18+4) within Template::VMethods::BEGIN@24 which was called: # once (18µs+4µs) by Template::Stash::BEGIN@24 at line 24
use strict;
# spent 22µs making 1 call to Template::VMethods::BEGIN@24 # spent 4µs making 1 call to strict::import
25327µs234µs
# spent 22µs (11+12) within Template::VMethods::BEGIN@25 which was called: # once (11µs+12µs) by Template::Stash::BEGIN@24 at line 25
use warnings;
# spent 22µs making 1 call to Template::VMethods::BEGIN@25 # spent 11µs making 1 call to warnings::import
263451µs2199µs
# spent 108µs (16+92) within Template::VMethods::BEGIN@26 which was called: # once (16µs+92µs) by Template::Stash::BEGIN@24 at line 26
use Scalar::Util 'blessed';
# spent 108µs making 1 call to Template::VMethods::BEGIN@26 # spent 92µs making 1 call to Exporter::import
2711µsrequire Template::Stash;
28
2911µsour $VERSION = 2.16;
301800nsour $DEBUG = 0 unless defined $DEBUG;
311400nsour $PRIVATE = $Template::Stash::PRIVATE;
32
3315µsour $ROOT_VMETHODS = {
34 inc => \&root_inc,
35 dec => \&root_dec,
36};
37
38116µsour $TEXT_VMETHODS = {
39 item => \&text_item,
40 list => \&text_list,
41 hash => \&text_hash,
42 length => \&text_length,
43 size => \&text_size,
44 defined => \&text_defined,
45 match => \&text_match,
46 search => \&text_search,
47 repeat => \&text_repeat,
48 replace => \&text_replace,
49 remove => \&text_remove,
50 split => \&text_split,
51 chunk => \&text_chunk,
52 substr => \&text_substr,
53};
54
55115µsour $HASH_VMETHODS = {
56 item => \&hash_item,
57 hash => \&hash_hash,
58 size => \&hash_size,
59 each => \&hash_each,
60 keys => \&hash_keys,
61 values => \&hash_values,
62 items => \&hash_items,
63 pairs => \&hash_pairs,
64 list => \&hash_list,
65 exists => \&hash_exists,
66 defined => \&hash_defined,
67 delete => \&hash_delete,
68 import => \&hash_import,
69 sort => \&hash_sort,
70 nsort => \&hash_nsort,
71};
72
73118µsour $LIST_VMETHODS = {
74 item => \&list_item,
75 list => \&list_list,
76 hash => \&list_hash,
77 push => \&list_push,
78 pop => \&list_pop,
79 unshift => \&list_unshift,
80 shift => \&list_shift,
81 max => \&list_max,
82 size => \&list_size,
83 defined => \&list_defined,
84 first => \&list_first,
85 last => \&list_last,
86 reverse => \&list_reverse,
87 grep => \&list_grep,
88 join => \&list_join,
89 sort => \&list_sort,
90 nsort => \&list_nsort,
91 unique => \&list_unique,
92 import => \&list_import,
93 merge => \&list_merge,
94 slice => \&list_slice,
95 splice => \&list_splice,
96};
97
98
99#========================================================================
100# root virtual methods
101#========================================================================
102
103sub root_inc {
104361µs264µs
# spent 40µs (17+24) within Template::VMethods::BEGIN@104 which was called: # once (17µs+24µs) by Template::Stash::BEGIN@24 at line 104
no warnings;
# spent 40µs making 1 call to Template::VMethods::BEGIN@104 # spent 24µs making 1 call to warnings::unimport
105 my $item = shift;
106 ++$item;
107}
108
109sub root_dec {
11031.63ms239µs
# spent 27µs (15+12) within Template::VMethods::BEGIN@110 which was called: # once (15µs+12µs) by Template::Stash::BEGIN@24 at line 110
no warnings;
# spent 27µs making 1 call to Template::VMethods::BEGIN@110 # spent 12µs making 1 call to warnings::unimport
111 my $item = shift;
112 --$item;
113}
114
115
116#========================================================================
117# text virtual methods
118#========================================================================
119
120sub text_item {
121 $_[0];
122}
123
124sub text_list {
125 [ $_[0] ];
126}
127
128sub text_hash {
129 { value => $_[0] };
130}
131
132sub text_length {
133 length $_[0];
134}
135
136sub text_size {
137 return 1;
138}
139
140sub text_defined {
141 return 1;
142}
143
144
# spent 92µs (45+47) within Template::VMethods::text_match which was called 2 times, avg 46µs/call: # once (24µs+23µs) by Template::Stash::XS::get at line 22 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-bottom.inc # once (22µs+24µs) by Template::Stash::XS::get at line 8 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/doc-head-close.inc
sub text_match {
145891µs my ($str, $search, $global) = @_;
146 return $str unless defined $str and defined $search;
147447µs my @matches = $global ? ($str =~ /$search/g)
# spent 36µs making 2 calls to Template::VMethods::CORE:regcomp, avg 18µs/call # spent 11µs making 2 calls to Template::VMethods::CORE:match, avg 5µs/call
148 : ($str =~ /$search/);
149 return @matches ? \@matches : '';
150}
151
152sub text_search {
153 my ($str, $pattern) = @_;
154 return $str unless defined $str and defined $pattern;
155 return $str =~ /$pattern/;
156}
157
158sub text_repeat {
159 my ($str, $count) = @_;
160 $str = '' unless defined $str;
161 return '' unless $count;
162 $count ||= 1;
163 return $str x $count;
164}
165
166sub text_replace {
167 my ($text, $pattern, $replace, $global) = @_;
168 $text = '' unless defined $text;
169 $pattern = '' unless defined $pattern;
170 $replace = '' unless defined $replace;
171 $global = 1 unless defined $global;
172
173 if ($replace =~ /\$\d+/) {
174 # replacement string may contain backrefs
175 my $expand = sub {
176 my ($chunk, $start, $end) = @_;
177 $chunk =~ s{ \\(\\|\$) | \$ (\d+) }{
178 $1 ? $1
179 : ($2 > $#$start || $2 == 0) ? ''
180 : substr($text, $start->[$2], $end->[$2] - $start->[$2]);
181 }exg;
182 $chunk;
183 };
184 if ($global) {
185 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }eg;
186 }
187 else {
188 $text =~ s{$pattern}{ &$expand($replace, [@-], [@+]) }e;
189 }
190 }
191 else {
192 if ($global) {
193 $text =~ s/$pattern/$replace/g;
194 }
195 else {
196 $text =~ s/$pattern/$replace/;
197 }
198 }
199 return $text;
200}
201
202sub text_remove {
203 my ($str, $search) = @_;
204 return $str unless defined $str and defined $search;
205 $str =~ s/$search//g;
206 return $str;
207}
208
209sub text_split {
210 my ($str, $split, $limit) = @_;
211 $str = '' unless defined $str;
212
213 # we have to be very careful about spelling out each possible
214 # combination of arguments because split() is very sensitive
215 # to them, for example C<split(' ', ...)> behaves differently
216 # to C<$space=' '; split($space, ...)>
217
218 if (defined $limit) {
219 return [ defined $split
220 ? split($split, $str, $limit)
221 : split(' ', $str, $limit) ];
222 }
223 else {
224 return [ defined $split
225 ? split($split, $str)
226 : split(' ', $str) ];
227 }
228}
229
230sub text_chunk {
231 my ($string, $size) = @_;
232 my @list;
233 $size ||= 1;
234 if ($size < 0) {
235 # sexeger! It's faster to reverse the string, search
236 # it from the front and then reverse the output than to
237 # search it from the end, believe it nor not!
238 $string = reverse $string;
239 $size = -$size;
240 unshift(@list, scalar reverse $1)
241 while ($string =~ /((.{$size})|(.+))/g);
242 }
243 else {
244 push(@list, $1) while ($string =~ /((.{$size})|(.+))/g);
245 }
246 return \@list;
247}
248
249sub text_substr {
250 my ($text, $offset, $length, $replacement) = @_;
251 $offset ||= 0;
252
253 if(defined $length) {
254 if (defined $replacement) {
255 substr( $text, $offset, $length, $replacement );
256 return $text;
257 }
258 else {
259 return substr( $text, $offset, $length );
260 }
261 }
262 else {
263 return substr( $text, $offset );
264 }
265}
266
267
268#========================================================================
269# hash virtual methods
270#========================================================================
271
272
273sub hash_item {
274 my ($hash, $item) = @_;
275 $item = '' unless defined $item;
276 return if $PRIVATE && $item =~ /$PRIVATE/;
277 $hash->{ $item };
278}
279
280sub hash_hash {
281 $_[0];
282}
283
284sub hash_size {
285 scalar keys %{$_[0]};
286}
287
288sub hash_each {
289 # this will be changed in TT3 to do what hash_pairs() does
290 [ %{ $_[0] } ];
291}
292
293sub hash_keys {
294 [ keys %{ $_[0] } ];
295}
296
297sub hash_values {
298 [ values %{ $_[0] } ];
299}
300
301sub hash_items {
302 [ %{ $_[0] } ];
303}
304
305sub hash_pairs {
306 [ map {
307 { key => $_ , value => $_[0]->{ $_ } }
308 }
309 sort keys %{ $_[0] }
310 ];
311}
312
313sub hash_list {
314 my ($hash, $what) = @_;
315 $what ||= '';
316 return ($what eq 'keys') ? [ keys %$hash ]
317 : ($what eq 'values') ? [ values %$hash ]
318 : ($what eq 'each') ? [ %$hash ]
319 : # for now we do what pairs does but this will be changed
320 # in TT3 to return [ $hash ] by default
321 [ map { { key => $_ , value => $hash->{ $_ } } }
322 sort keys %$hash
323 ];
324}
325
326sub hash_exists {
327 exists $_[0]->{ $_[1] };
328}
329
330sub hash_defined {
331 # return the item requested, or 1 if no argument
332 # to indicate that the hash itself is defined
333 my $hash = shift;
334 return @_ ? defined $hash->{ $_[0] } : 1;
335}
336
337sub hash_delete {
338 my $hash = shift;
339 delete $hash->{ $_ } for @_;
340}
341
342sub hash_import {
343 my ($hash, $imp) = @_;
344 $imp = {} unless ref $imp eq 'HASH';
345 @$hash{ keys %$imp } = values %$imp;
346 return '';
347}
348
349sub hash_sort {
350 my ($hash) = @_;
351 [ sort { lc $hash->{$a} cmp lc $hash->{$b} } (keys %$hash) ];
352}
353
354sub hash_nsort {
355 my ($hash) = @_;
356 [ sort { $hash->{$a} <=> $hash->{$b} } (keys %$hash) ];
357}
358
359
360#========================================================================
361# list virtual methods
362#========================================================================
363
364
365sub list_item {
366 $_[0]->[ $_[1] || 0 ];
367}
368
369sub list_list {
370 $_[0];
371}
372
373sub list_hash {
374 my $list = shift;
375 if (@_) {
376 my $n = shift || 0;
377 return { map { ($n++, $_) } @$list };
378 }
3793148µs252µs
# spent 35µs (18+17) within Template::VMethods::BEGIN@379 which was called: # once (18µs+17µs) by Template::Stash::BEGIN@24 at line 379
no warnings;
# spent 35µs making 1 call to Template::VMethods::BEGIN@379 # spent 17µs making 1 call to warnings::unimport
380 return { @$list };
381}
382
383sub list_push {
384 my $list = shift;
385 push(@$list, @_);
386 return '';
387}
388
389sub list_pop {
390 my $list = shift;
391 pop(@$list);
392}
393
394sub list_unshift {
395 my $list = shift;
396 unshift(@$list, @_);
397 return '';
398}
399
400sub list_shift {
401 my $list = shift;
402 shift(@$list);
403}
404
405sub list_max {
406349µs238µs
# spent 25µs (12+13) within Template::VMethods::BEGIN@406 which was called: # once (12µs+13µs) by Template::Stash::BEGIN@24 at line 406
no warnings;
# spent 25µs making 1 call to Template::VMethods::BEGIN@406 # spent 13µs making 1 call to warnings::unimport
407 my $list = shift;
408 $#$list;
409}
410
411sub list_size {
4123948µs233µs
# spent 22µs (11+11) within Template::VMethods::BEGIN@412 which was called: # once (11µs+11µs) by Template::Stash::BEGIN@24 at line 412
no warnings;
# spent 22µs making 1 call to Template::VMethods::BEGIN@412 # spent 11µs making 1 call to warnings::unimport
413 my $list = shift;
414 $#$list + 1;
415}
416
417sub list_defined {
418 # return the item requested, or 1 if no argument to
419 # indicate that the hash itself is defined
420 my $list = shift;
421 return @_ ? defined $list->[$_[0]] : 1;
422}
423
424sub list_first {
425 my $list = shift;
426 return $list->[0] unless @_;
427 return [ @$list[0..$_[0]-1] ];
428}
429
430sub list_last {
431 my $list = shift;
432 return $list->[-1] unless @_;
433 return [ @$list[-$_[0]..-1] ];
434}
435
436sub list_reverse {
437 my $list = shift;
438 [ reverse @$list ];
439}
440
441sub list_grep {
442 my ($list, $pattern) = @_;
443 $pattern ||= '';
444 return [ grep /$pattern/, @$list ];
445}
446
447sub list_join {
448 my ($list, $joint) = @_;
449 join(defined $joint ? $joint : ' ',
450 map { defined $_ ? $_ : '' } @$list);
451}
452
453sub _list_sort_make_key {
454 my ($item, $fields) = @_;
455 my @keys;
456
457 if (ref($item) eq 'HASH') {
458 @keys = map { $item->{ $_ } } @$fields;
459 }
460 elsif (blessed $item) {
461 @keys = map { $item->can($_) ? $item->$_() : $item } @$fields;
462 }
463 else {
464 @keys = $item;
465 }
466
467 # ugly hack to generate a single string using a delimiter that is
468 # unlikely (but not impossible) to be found in the wild.
469 return lc join('/*^UNLIKELY^*/', map { defined $_ ? $_ : '' } @keys);
470}
471
472sub list_sort {
473 my ($list, @fields) = @_;
474 return $list unless @$list > 1; # no need to sort 1 item lists
475 return [
476 @fields # Schwartzian Transform
477 ? map { $_->[0] } # for case insensitivity
478 sort { $a->[1] cmp $b->[1] }
479 map { [ $_, _list_sort_make_key($_, \@fields) ] }
480 @$list
481 : map { $_->[0] }
482 sort { $a->[1] cmp $b->[1] }
483 map { [ $_, lc $_ ] }
484 @$list,
485 ];
486}
487
488sub list_nsort {
489 my ($list, @fields) = @_;
490 return $list unless @$list > 1; # no need to sort 1 item lists
491 return [
492 @fields # Schwartzian Transform
493 ? map { $_->[0] } # for case insensitivity
494 sort { $a->[1] <=> $b->[1] }
495 map { [ $_, _list_sort_make_key($_, \@fields) ] }
496 @$list
497 : map { $_->[0] }
498 sort { $a->[1] <=> $b->[1] }
499 map { [ $_, lc $_ ] }
500 @$list,
501 ];
502}
503
504sub list_unique {
505 my %u;
506 [ grep { ++$u{$_} == 1 } @{$_[0]} ];
507}
508
509sub list_import {
510 my $list = shift;
511 push(@$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_);
512 return $list;
513}
514
515sub list_merge {
516 my $list = shift;
517 return [ @$list, grep defined, map ref eq 'ARRAY' ? @$_ : undef, @_ ];
518}
519
520sub list_slice {
521 my ($list, $from, $to) = @_;
522 $from ||= 0;
523 $to = $#$list unless defined $to;
524 $from += @$list if $from < 0;
525 $to += @$list if $to < 0;
526 return [ @$list[$from..$to] ];
527}
528
529sub list_splice {
530 my ($list, $offset, $length, @replace) = @_;
531 if (@replace) {
532 # @replace can contain a list of multiple replace items, or
533 # be a single reference to a list
534 @replace = @{ $replace[0] }
535 if @replace == 1 && ref $replace[0] eq 'ARRAY';
536 return [ splice @$list, $offset, $length, @replace ];
537 }
538 elsif (defined $length) {
539 return [ splice @$list, $offset, $length ];
540 }
541 elsif (defined $offset) {
542 return [ splice @$list, $offset ];
543 }
544 else {
545 return [ splice(@$list) ];
546 }
547}
548
549140µs1;
550
551__END__
 
# spent 11µs within Template::VMethods::CORE:match which was called 2 times, avg 5µs/call: # 2 times (11µs+0s) by Template::VMethods::text_match at line 147, avg 5µs/call
sub Template::VMethods::CORE:match; # opcode
# spent 36µs within Template::VMethods::CORE:regcomp which was called 2 times, avg 18µs/call: # 2 times (36µs+0s) by Template::VMethods::text_match at line 147, avg 18µs/call
sub Template::VMethods::CORE:regcomp; # opcode