1 package Excel::Template::Container::Loop;
7 @ISA = qw(Excel::Template::Container);
9 use Excel::Template::Container;
15 my $self = $class->SUPER::new(@_);
17 if (exists $self->{MAXITERS} && $self->{MAXITERS} < 1)
19 die "<loop> MAXITERS must be greater than or equal to 1", $/;
23 $self->{MAXITERS} = 0;
34 return Excel::Template::Factory->create('ITERATOR',
35 NAME => $context->get($self, 'NAME'),
36 MAXITERS => $context->get($self, 'MAXITERS'),
46 unless ($self->{ITERATOR} && $self->{ITERATOR}->more_params)
48 $self->{ITERATOR} = $self->make_iterator($context);
50 my $iterator = $self->{ITERATOR};
52 $iterator->enter_scope;
54 while ($iterator->can_continue)
58 unless ($self->iterate_over_children($context))
65 $iterator->exit_scope;
67 return 0 if $iterator->more_params;
75 my ($context, $attr) = @_;
77 my $iterator = $self->make_iterator($context);
81 $iterator->enter_scope;
82 while ($iterator->can_continue)
85 $total += $self->SUPER::total_of($context, $attr);
87 $iterator->exit_scope;
95 my ($context, $attr) = @_;
97 my $iterator = $self->make_iterator($context);
99 my $max = $context->get($self, $attr);
101 $iterator->enter_scope;
102 while ($iterator->can_continue)
105 my $v = $self->SUPER::max_of($context, $attr);
107 $max = $v if $max < $v;
109 $iterator->exit_scope;
119 Excel::Template::Container::Loop
131 Excel::Template::Container
139 This is the name of the loop. It's used to identify within the parameter set
140 what variables to expose to the children nodes each iteration.
159 ... Children here ...
162 In the above example, the children nodes would have access to the LOOPY array
163 of hashes as parameters. Each iteration through the array would expose a
164 different hash of parameters to the children.
166 These loops work just like HTML::Template's loops. (I promise I'll give more
169 There is one difference - I prefer using Perl-like scoping, so accessing of
170 variables outside the LOOP scope from within is perfectly acceptable. You can
171 also hide outside variables with inner values, if you desire, just like Perl.
175 Rob Kinyon (rkinyon@columbus.rr.com)