1 .\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.3
4 .\" ========================================================================
5 .de Sh \" Subsection heading
13 .de Sp \" Vertical space (when we can't use .PP)
17 .de Vb \" Begin verbatim text
22 .de Ve \" End verbatim text
26 .\" Set up some character translations and predefined strings. \*(-- will
27 .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28 .\" double quote, and \*(R" will give a right double quote. | will give a
29 .\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30 .\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31 .\" expand to `' in nroff, nothing in troff, for use with C<>.
33 .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
37 . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38 . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
51 .\" If the F register is turned on, we'll generate index entries on stderr for
52 .\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53 .\" entries marked with X<> in POD. Of course, you'll have to process the
54 .\" output yourself in some meaningful fashion.
57 . tm Index:\\$1\t\\n%\t"\\$2"
63 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
64 .\" way too many mistakes in technical documents.
68 .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69 .\" Fear. Run. Save yourself. No user-serviceable parts.
70 . \" fudge factors for nroff and troff
79 . ds #H ((1u-(\\\\n(.fu%2u))*.13m)
85 . \" simple accents for nroff and troff
95 . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96 . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97 . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98 . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99 . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100 . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
102 . \" troff and (daisy-wheel) nroff accents
103 .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104 .ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105 .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106 .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107 .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108 .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109 .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110 .ds ae a\h'-(\w'a'u*4/10)'e
111 .ds Ae A\h'-(\w'A'u*4/10)'E
112 . \" corrections for vroff
113 .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114 .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115 . \" for low resolution devices (crt and lpr)
116 .if \n(.H>23 .if \n(.V>19 \
129 .\" ========================================================================
131 .IX Title "Template::Iterator 3"
132 .TH Template::Iterator 3 "2009-05-21" "perl v5.8.7" "User Contributed Perl Documentation"
134 Template::Iterator \- Data iterator used by the FOREACH directive
136 .IX Header "SYNOPSIS"
138 \& my $iter = Template::Iterator\->new(\e@data, \e%options);
141 .IX Header "DESCRIPTION"
142 The \f(CW\*(C`Template::Iterator\*(C'\fR module defines a generic data iterator for use
143 by the \f(CW\*(C`FOREACH\*(C'\fR directive.
145 It may be used as the base class for custom iterators.
147 .IX Header "PUBLIC METHODS"
149 .IX Subsection "new($data)"
150 Constructor method. A reference to a list of values is passed as the
151 first parameter. Subsequent calls to \fIget_first()\fR and \fIget_next()\fR calls
152 will return each element from the list.
155 \& my $iter = Template::Iterator\->new([ 'foo', 'bar', 'baz' ]);
158 The constructor will also accept a reference to a hash array and will
159 expand it into a list in which each entry is a hash array containing
160 a '\f(CW\*(C`key\*(C'\fR' and '\f(CW\*(C`value\*(C'\fR' item, sorted according to the hash keys.
163 \& my $iter = Template::Iterator\->new({
164 \& foo => 'Foo Item',
165 \& bar => 'Bar Item',
169 This is equivalent to:
172 \& my $iter = Template::Iterator\->new([
173 \& { key => 'bar', value => 'Bar Item' },
174 \& { key => 'foo', value => 'Foo Item' },
178 When passed a single item which is not an array reference, the constructor
179 will automatically create a list containing that single item.
182 \& my $iter = Template::Iterator\->new('foo');
185 This is equivalent to:
188 \& my $iter = Template::Iterator\->new([ 'foo' ]);
191 Note that a single item which is an object based on a blessed \s-1ARRAY\s0
192 references will \s-1NOT\s0 be treated as an array and will be folded into
193 a list containing that one object reference.
196 \& my $list = bless [ 'foo', 'bar' ], 'MyListClass';
197 \& my $iter = Template::Iterator\->new($list);
203 \& my $iter = Template::Iterator\->new([ $list ]);
206 If the object provides an \f(CW\*(C`as_list()\*(C'\fR method then the Template::Iterator
207 constructor will call that method to return the list of data. For example:
210 \& package MyListObject;
215 \& my $class = shift;
216 \& bless [ @_ ], $class;
225 \& my $list = MyListObject\->new('foo', 'bar');
226 \& my $iter = Template::Iterator\->new($list);
229 This is then functionally equivalent to:
232 \& my $iter = Template::Iterator\->new([ $list ]);
235 The iterator will return only one item, a reference to the \f(CW\*(C`MyListObject\*(C'\fR
236 object, \f(CW$list\fR.
238 By adding an \f(CW\*(C`as_list()\*(C'\fR method to the \f(CW\*(C`MyListObject\*(C'\fR class, we can force
239 the \f(CW\*(C`Template::Iterator\*(C'\fR constructor to treat the object as a list and
240 use the data contained within.
243 \& package MyListObject;
262 \& my $list = MyListObject\->new('foo', 'bar');
263 \& my $iter = Template::Iterator\->new($list);
266 The iterator will now return the two items, '\f(CW\*(C`foo\*(C'\fR' and '\f(CW\*(C`bar\*(C'\fR', which the
267 \&\f(CW\*(C`MyObjectList\*(C'\fR encapsulates.
268 .Sh "\fIget_first()\fP"
269 .IX Subsection "get_first()"
270 Returns a \f(CW\*(C`($value, $error)\*(C'\fR pair for the first item in the iterator set.
271 The \f(CW$error\fR returned may be zero or undefined to indicate a valid datum
272 was successfully returned. Returns an error of \f(CW\*(C`STATUS_DONE\*(C'\fR if the list
274 .Sh "\fIget_next()\fP"
275 .IX Subsection "get_next()"
276 Returns a \f(CW\*(C`($value, $error)\*(C'\fR pair for the next item in the iterator set.
277 Returns an error of \f(CW\*(C`STATUS_DONE\*(C'\fR if all items in the list have been
279 .Sh "\fIget_all()\fP"
280 .IX Subsection "get_all()"
281 Returns a \f(CW\*(C`(\e@values, $error)\*(C'\fR pair for all remaining items in the iterator
282 set. Returns an error of \f(CW\*(C`STATUS_DONE\*(C'\fR if all items in the list have been
285 .IX Subsection "size()"
286 Returns the size of the data set or undef if unknown.
288 .IX Subsection "max()"
289 Returns the maximum index number (i.e. the index of the last element)
290 which is equivalent to \fIsize()\fR \- \f(CW1\fR.
292 .IX Subsection "index()"
293 Returns the current index number which is in the range \f(CW0\fR to \fImax()\fR.
295 .IX Subsection "count()"
296 Returns the current iteration count in the range \f(CW1\fR to \fIsize()\fR. This is
297 equivalent to \fIindex()\fR + \f(CW1\fR.
299 .IX Subsection "first()"
300 Returns a boolean value to indicate if the iterator is currently on
301 the first iteration of the set.
303 .IX Subsection "last()"
304 Returns a boolean value to indicate if the iterator is currently on
305 the last iteration of the set.
307 .IX Subsection "prev()"
308 Returns the previous item in the data set, or \f(CW\*(C`undef\*(C'\fR if the iterator is
311 .IX Subsection "next()"
312 Returns the next item in the data set or \f(CW\*(C`undef\*(C'\fR if the iterator is on the
315 .IX Subsection "parity()"
316 Returns the text string \f(CW\*(C`even\*(C'\fR or \f(CW\*(C`odd\*(C'\fR to indicate the parity of the
317 current iteration count (starting at 1). This is typically used to create
318 striped \fIzebra tables\fR.
322 \& [% FOREACH name IN ['Arthur', 'Ford', 'Trillian'] \-%]
323 \& <tr class="[% loop.parity %]">
324 \& <td>[% name %]</td>
330 This will produce the following output:
346 You can then style the \f(CW\*(C`tr.odd\*(C'\fR and \f(CW\*(C`tr.even\*(C'\fR elements using \s-1CSS:\s0
350 \& background\-color: black;
357 \& background\-color: white;
362 .IX Subsection "odd()"
363 Returns a boolean (0/1) value to indicate if the current iterator count
364 (starting at 1) is an odd number. In other words, this will return a true
365 value for the first iterator, the third, fifth, and so on.
367 .IX Subsection "even()"
368 Returns a boolean (0/1) value to indicate if the current iterator count
369 (starting at 1) is an even number. In other words, this will return a true
370 value for the second iteration, the fourth, sixth, and so on.
373 Andy Wardley <abw@wardley.org> <http://wardley.org/>
375 .IX Header "COPYRIGHT"
376 Copyright (C) 1996\-2007 Andy Wardley. All Rights Reserved.
378 This module is free software; you can redistribute it and/or
379 modify it under the same terms as Perl itself.
381 .IX Header "SEE ALSO"