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 $self->iterate_over_children($context);
60 # It doesn't seem that iterate_over_children() can ever fail, because
61 # I'm not sure that render() can return false. In PDF::Template, where
62 # this module got most of its code, render() can certainly return false,
63 # in the case of page-breaks. I left the code in because it didn't seem
65 #unless ($self->iterate_over_children($context))
72 $iterator->exit_scope;
74 return 0 if $iterator->more_params;
79 # These methods are used in PDF::Template to calculate pagebreaks. I'm not sure
80 # if they will ever be needed in Excel::Template.
84 # my ($context, $attr) = @_;
86 # my $iterator = $self->_make_iterator($context);
90 # $iterator->enter_scope;
91 # while ($iterator->can_continue)
94 # $total += $self->SUPER::total_of($context, $attr);
96 # $iterator->exit_scope;
104 # my ($context, $attr) = @_;
106 # my $iterator = $self->_make_iterator($context);
108 # my $max = $context->get($self, $attr);
110 # $iterator->enter_scope;
111 # while ($iterator->can_continue)
114 # my $v = $self->SUPER::max_of($context, $attr);
116 # $max = $v if $max < $v;
118 # $iterator->exit_scope;
128 Excel::Template::Container::Loop - Excel::Template::Container::Loop
140 Excel::Template::Container
148 This is the name of the loop. It's used to identify within the parameter set
149 what variables to expose to the children nodes each iteration.
168 ... Children here ...
171 In the above example, the children nodes would have access to the LOOPY array
172 of hashes as parameters. Each iteration through the array would expose a
173 different hash of parameters to the children.
175 These loops work just like HTML::Template's loops. (I promise I'll give more
178 There is one difference - I prefer using Perl-like scoping, so accessing of
179 variables outside the LOOP scope from within is perfectly acceptable. You can
180 also hide outside variables with inner values, if you desire, just like Perl.
184 Rob Kinyon (rob.kinyon@gmail.com)