← 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:02:30 2013

Filename/usr/lib/perl5/Template/Iterator.pm
StatementsExecuted 1094 statements in 4.24ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
79541.25ms1.25msTemplate::Iterator::::get_nextTemplate::Iterator::get_next
3784567µs822µsTemplate::Iterator::::AUTOLOADTemplate::Iterator::AUTOLOAD
1211243µs278µsTemplate::Iterator::::newTemplate::Iterator::new
1274237µs237µsTemplate::Iterator::::get_firstTemplate::Iterator::get_first
3711234µs234µsTemplate::Iterator::::CORE:substTemplate::Iterator::CORE:subst (opcode)
2511119µs119µsTemplate::Iterator::::oddTemplate::Iterator::odd
11127µs33µsTemplate::Iterator::::BEGIN@24Template::Iterator::BEGIN@24
11126µs108µsTemplate::Iterator::::BEGIN@26Template::Iterator::BEGIN@26
251121µs21µsTemplate::Iterator::::CORE:matchTemplate::Iterator::CORE:match (opcode)
11117µs60µsTemplate::Iterator::::BEGIN@27Template::Iterator::BEGIN@27
11117µs41µsTemplate::Iterator::::BEGIN@25Template::Iterator::BEGIN@25
11115µs58µsTemplate::Iterator::::BEGIN@29Template::Iterator::BEGIN@29
11114µs88µsTemplate::Iterator::::BEGIN@31Template::Iterator::BEGIN@31
11111µs11µsTemplate::Iterator::::BEGIN@28Template::Iterator::BEGIN@28
11110µs45µsTemplate::Iterator::::BEGIN@32Template::Iterator::BEGIN@32
0000s0sTemplate::Iterator::::_dumpTemplate::Iterator::_dump
0000s0sTemplate::Iterator::::evenTemplate::Iterator::even
0000s0sTemplate::Iterator::::get_allTemplate::Iterator::get_all
0000s0sTemplate::Iterator::::parityTemplate::Iterator::parity
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::Iterator
4#
5# DESCRIPTION
6#
7# Module defining an iterator class which is used by the FOREACH
8# directive for iterating through data sets. This may be
9# sub-classed to define more specific iterator types.
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
22package Template::Iterator;
23
24343µs240µs
# spent 33µs (27+7) within Template::Iterator::BEGIN@24 which was called: # once (27µs+7µs) by Template::Config::load at line 24
use strict;
# spent 33µs making 1 call to Template::Iterator::BEGIN@24 # spent 7µs making 1 call to strict::import
25343µs264µs
# spent 41µs (17+24) within Template::Iterator::BEGIN@25 which was called: # once (17µs+24µs) by Template::Config::load at line 25
use warnings;
# spent 41µs making 1 call to Template::Iterator::BEGIN@25 # spent 24µs making 1 call to warnings::import
26347µs2190µs
# spent 108µs (26+82) within Template::Iterator::BEGIN@26 which was called: # once (26µs+82µs) by Template::Config::load at line 26
use base 'Template::Base';
# spent 108µs making 1 call to Template::Iterator::BEGIN@26 # spent 82µs making 1 call to base::import
27344µs2102µs
# spent 60µs (17+43) within Template::Iterator::BEGIN@27 which was called: # once (17µs+43µs) by Template::Config::load at line 27
use Template::Constants;
# spent 60µs making 1 call to Template::Iterator::BEGIN@27 # spent 42µs making 1 call to Exporter::import
28336µs111µs
# spent 11µs within Template::Iterator::BEGIN@28 which was called: # once (11µs+0s) by Template::Config::load at line 28
use Template::Exception;
# spent 11µs making 1 call to Template::Iterator::BEGIN@28
29339µs2102µs
# spent 58µs (15+43) within Template::Iterator::BEGIN@29 which was called: # once (15µs+43µs) by Template::Config::load at line 29
use Scalar::Util qw(blessed);
# spent 58µs making 1 call to Template::Iterator::BEGIN@29 # spent 43µs making 1 call to Exporter::import
30
31340µs2162µs
# spent 88µs (14+74) within Template::Iterator::BEGIN@31 which was called: # once (14µs+74µs) by Template::Config::load at line 31
use constant ODD => 'odd';
# spent 88µs making 1 call to Template::Iterator::BEGIN@31 # spent 74µs making 1 call to constant::import
323950µs281µs
# spent 45µs (10+35) within Template::Iterator::BEGIN@32 which was called: # once (10µs+35µs) by Template::Config::load at line 32
use constant EVEN => 'even';
# spent 45µs making 1 call to Template::Iterator::BEGIN@32 # spent 35µs making 1 call to constant::import
33
341500nsour $VERSION = 2.68;
351500nsour $DEBUG = 0 unless defined $DEBUG;
361100nsour $AUTOLOAD;
37
38#========================================================================
39# ----- CLASS METHODS -----
40#========================================================================
41
42#------------------------------------------------------------------------
43# new(\@target, \%options)
44#
45# Constructor method which creates and returns a reference to a new
46# Template::Iterator object. A reference to the target data (array
47# or hash) may be passed for the object to iterate through.
48#------------------------------------------------------------------------
49
50
# spent 278µs (243+35) within Template::Iterator::new which was called 12 times, avg 23µs/call: # 12 times (243µs+35µs) by Template::Config::iterator at line 177 of Template/Config.pm, avg 23µs/call
sub new {
511210µs my $class = shift;
521211µs my $data = shift || [ ];
531214µs my $params = shift || { };
54
5512139µs1235µs if (ref $data eq 'HASH') {
# spent 35µs making 12 calls to Scalar::Util::blessed, avg 3µs/call
56 # map a hash into a list of { key => ???, value => ??? } hashes,
57 # one for each key, sorted by keys
58 $data = [ map { { key => $_, value => $data->{ $_ } } }
59 sort keys %$data ];
60 }
61 elsif (blessed($data) && $data->can('as_list')) {
62 $data = $data->as_list();
63 }
64 elsif (ref $data ne 'ARRAY') {
65 # coerce any non-list data into an array reference
66 $data = [ $data ] ;
67 }
68
69 bless {
7012118µs _DATA => $data,
71 _ERROR => '',
72 }, $class;
73}
74
75
76#========================================================================
77# ----- PUBLIC OBJECT METHODS -----
78#========================================================================
79
80#------------------------------------------------------------------------
81# get_first()
82#
83# Initialises the object for iterating through the target data set. The
84# first record is returned, if defined, along with the STATUS_OK value.
85# If there is no target data, or the data is an empty set, then undef
86# is returned with the STATUS_DONE value.
87#------------------------------------------------------------------------
88
89
# spent 237µs within Template::Iterator::get_first which was called 12 times, avg 20µs/call: # 5 times (94µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc:32] at line 20 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc, avg 19µs/call # 2 times (49µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc:31] at line 14 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc, avg 24µs/call # once (25µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 522 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt # once (23µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 393 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt # once (22µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc:32] at line 22 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc # once (20µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc:111] at line 80 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc # once (4µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 394 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt
sub get_first {
901216µs my $self = shift;
911216µs my $data = $self->{ _DATA };
92
931219µs $self->{ _DATASET } = $self->{ _DATA };
94127µs my $size = scalar @$data;
95124µs my $index = 0;
96
97127µs return (undef, Template::Constants::STATUS_DONE) unless $size;
98
99 # initialise various counters, flags, etc.
1001198µs @$self{ qw( SIZE MAX INDEX COUNT FIRST LAST ) }
101 = ( $size, $size - 1, $index, 1, 1, $size > 1 ? 0 : 1, undef );
1021140µs @$self{ qw( PREV NEXT ) } = ( undef, $self->{ _DATASET }->[ $index + 1 ]);
103
1041178µs return $self->{ _DATASET }->[ $index ];
105}
106
- -
109#------------------------------------------------------------------------
110# get_next()
111#
112# Called repeatedly to access successive elements in the data set.
113# Should only be called after calling get_first() or a warning will
114# be raised and (undef, STATUS_DONE) returned.
115#------------------------------------------------------------------------
116
117
# spent 1.25ms within Template::Iterator::get_next which was called 79 times, avg 16µs/call: # 28 times (285µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc:32] at line 14 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc, avg 10µs/call # 25 times (552µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 515 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt, avg 22µs/call # 20 times (352µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc:31] at line 8 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc, avg 18µs/call # 4 times (32µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc:111] at line 81 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc, avg 8µs/call # 2 times (30µs+0s) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 394 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt, avg 15µs/call
sub get_next {
1187968µs my $self = shift;
11979169µs my ($max, $index) = @$self{ qw( MAX INDEX ) };
1207970µs my $data = $self->{ _DATASET };
121
122 # warn about incorrect usage
1237976µs unless (defined $index) {
124 my ($pack, $file, $line) = caller();
125 warn("iterator get_next() called before get_first() at $file line $line\n");
126 return (undef, Template::Constants::STATUS_DONE); ## RETURN ##
127 }
128
129 # if there's still some data to go...
1307964µs if ($index < $max) {
131 # update counters and flags
1326872µs $index++;
13368215µs @$self{ qw( INDEX COUNT FIRST LAST ) }
134 = ( $index, $index + 1, 0, $index == $max ? 1 : 0 );
13568211µs @$self{ qw( PREV NEXT ) } = @$data[ $index - 1, $index + 1 ];
13668372µs return $data->[ $index ]; ## RETURN ##
137 }
138 else {
1391143µs return (undef, Template::Constants::STATUS_DONE); ## RETURN ##
140 }
141}
142
143
144#------------------------------------------------------------------------
145# get_all()
146#
147# Method which returns all remaining items in the iterator as a Perl list
148# reference. May be called at any time in the life-cycle of the iterator.
149# The get_first() method will be called automatically if necessary, and
150# then subsequent get_next() calls are made, storing each returned
151# result until the list is exhausted.
152#------------------------------------------------------------------------
153
154sub get_all {
155 my $self = shift;
156 my ($max, $index) = @$self{ qw( MAX INDEX ) };
157 my @data;
158
159 # handle cases where get_first() has yet to be called.
160 unless (defined $index) {
161 my ($first, $status) = $self->get_first;
162
163 # refresh $max and $index, after get_first updates MAX and INDEX
164 ($max, $index) = @$self{ qw( MAX INDEX ) };
165
166 # empty lists are handled here.
167 if ($status && $status == Template::Constants::STATUS_DONE) {
168 return (undef, Template::Constants::STATUS_DONE); ## RETURN ##
169 }
170
171 push @data, $first;
172
173 ## if there's nothing left in the iterator, return the single value.
174 unless ($index < $max) {
175 return \@data;
176 }
177 }
178
179 # if there's still some data to go...
180 if ($index < $max) {
181 $index++;
182 push @data, @{ $self->{ _DATASET } } [ $index..$max ];
183
184 # update counters and flags
185 @$self{ qw( INDEX COUNT FIRST LAST ) }
186 = ( $max, $max + 1, 0, 1 );
187
188 return \@data; ## RETURN ##
189 }
190 else {
191 return (undef, Template::Constants::STATUS_DONE); ## RETURN ##
192 }
193}
194
195
# spent 119µs within Template::Iterator::odd which was called 25 times, avg 5µs/call: # 25 times (119µs+0s) by Template::Stash::XS::get at line 419 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt, avg 5µs/call
sub odd {
19625175µs shift->{ COUNT } % 2 ? 1 : 0
197}
198
199sub even {
200 shift->{ COUNT } % 2 ? 0 : 1
201}
202
203sub parity {
204 shift->{ COUNT } % 2 ? ODD : EVEN;
205}
206
207
208#------------------------------------------------------------------------
209# AUTOLOAD
210#
211# Provides access to internal fields (e.g. size, first, last, max, etc)
212#------------------------------------------------------------------------
213
214
# spent 822µs (567+255) within Template::Iterator::AUTOLOAD which was called 37 times, avg 22µs/call: # 25 times (469µs+190µs) by Template::Stash::XS::get at line 501 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt, avg 26µs/call # 5 times (35µs+25µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc:32] at line 11 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc, avg 12µs/call # 2 times (23µs+15µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc:31] at line 5 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/page-numbers.inc, avg 19µs/call # once (13µs+8µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 384 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt # once (12µs+5µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc:111] at line 71 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/masthead.inc # once (6µs+4µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 513 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt # once (5µs+3µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt:541] at line 385 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/modules/opac-results.tt # once (4µs+3µs) by Template::Document::__ANON__[/usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc:32] at line 13 of /usr/share/koha/opac/htdocs/opac-tmpl/prog/en-NZ/includes/opac-facets.inc
sub AUTOLOAD {
2153746µs my $self = shift;
2163726µs my $item = $AUTOLOAD;
21737446µs37234µs $item =~ s/.*:://;
# spent 234µs making 37 calls to Template::Iterator::CORE:subst, avg 6µs/call
2183797µs return if $item eq 'DESTROY';
219
220 # alias NUMBER to COUNT for backwards compatability
22125115µs2521µs $item = 'COUNT' if $item =~ /NUMBER/i;
# spent 21µs making 25 calls to Template::Iterator::CORE:match, avg 836ns/call
222
22325153µs return $self->{ uc $item };
224}
225
226
227#========================================================================
228# ----- PRIVATE DEBUG METHODS -----
229#========================================================================
230
231#------------------------------------------------------------------------
232# _dump()
233#
234# Debug method which returns a string detailing the internal state of
235# the iterator object.
236#------------------------------------------------------------------------
237
238sub _dump {
239 my $self = shift;
240 join('',
241 " Data: ", $self->{ _DATA }, "\n",
242 " Index: ", $self->{ INDEX }, "\n",
243 "Number: ", $self->{ NUMBER }, "\n",
244 " Max: ", $self->{ MAX }, "\n",
245 " Size: ", $self->{ SIZE }, "\n",
246 " First: ", $self->{ FIRST }, "\n",
247 " Last: ", $self->{ LAST }, "\n",
248 "\n"
249 );
250}
251
252
25314µs1;
254
255__END__
 
# spent 21µs within Template::Iterator::CORE:match which was called 25 times, avg 836ns/call: # 25 times (21µs+0s) by Template::Iterator::AUTOLOAD at line 221, avg 836ns/call
sub Template::Iterator::CORE:match; # opcode
# spent 234µs within Template::Iterator::CORE:subst which was called 37 times, avg 6µs/call: # 37 times (234µs+0s) by Template::Iterator::AUTOLOAD at line 217, avg 6µs/call
sub Template::Iterator::CORE:subst; # opcode