1 package Excel::Template::Iterator;
7 @ISA = qw(Excel::Template::Base);
9 use Excel::Template::Base;
15 my $self = $class->SUPER::new(@_);
17 unless (Excel::Template::Factory::isa($self->{CONTEXT}, 'CONTEXT'))
19 die "Internal Error: No context object passed to ", __PACKAGE__, $/;
22 $self->{MAXITERS} ||= 0;
24 # This is the index we will work on NEXT, in whatever direction the
28 # This is a short-circuit parameter to let the iterator function in a
30 $self->{NO_PARAMS} = 0;
31 unless ($self->{NAME} =~ /\w/)
33 $self->{NO_PARAMS} = 1;
35 warn "INTERNAL ERROR: 'NAME' was blank was blank when passed to ", __PACKAGE__, $/ if $^W;
40 # Cache the reference to the appropriate data.
41 $self->{DATA} = $self->{CONTEXT}->param($self->{NAME});
43 unless (UNIVERSAL::isa($self->{DATA}, 'ARRAY'))
45 $self->{NO_PARAMS} = 1;
46 warn "'$self->{NAME}' does not have a list of parameters", $/ if $^W;
51 unless (@{$self->{DATA}})
53 $self->{NO_PARAMS} = 1;
56 $self->{MAX_INDEX} = $#{$self->{DATA}};
65 return 0 if $self->{NO_PARAMS};
67 for my $x ($self->{DATA}[$self->{INDEX}])
69 $x->{uc $_} = delete $x->{$_} for keys %$x;
72 push @{$self->{CONTEXT}{PARAM_MAP}}, $self->{DATA}[$self->{INDEX}];
81 return 0 if $self->{NO_PARAMS};
83 # There has to be the base parameter map and at least the one that
84 # Iterator::enter_scope() added on top.
85 @{$self->{CONTEXT}{PARAM_MAP}} > 1 ||
86 die "Internal Error: ", __PACKAGE__, "'s internal param_map off!", $/;
88 pop @{$self->{CONTEXT}{PARAM_MAP}};
97 return 0 if $self->{NO_PARAMS};
99 return 1 if $self->more_params;
108 return 0 if $self->{NO_PARAMS};
110 return 1 if $self->{MAX_INDEX} > $self->{INDEX};
115 # Call this method BEFORE incrementing the index to the next value.
120 my $data = $self->{DATA}[$self->{INDEX}];
122 # Perl's arrays are 0-indexed. Thus, the first element is at index "0".
123 # This means that odd-numbered elements are at even indices, and vice-versa.
124 # This also means that MAX (the number of elements in the array) can never
125 # be the value of an index. It is NOT the last index in the array.
127 $data->{'__FIRST__'} ||= ($self->{INDEX} == 0);
128 $data->{'__INNER__'} ||= (0 < $self->{INDEX} && $self->{INDEX} < $self->{MAX_INDEX});
129 $data->{'__LAST__'} ||= ($self->{INDEX} == $self->{MAX_INDEX});
130 $data->{'__ODD__'} ||= !($self->{INDEX} % 2);
139 return 0 if $self->{NO_PARAMS};
141 return 0 unless $self->more_params;
158 return 0 if $self->{NO_PARAMS};
175 return 0 if $self->{NO_PARAMS};
187 Excel::Template::Iterator
191 This is meant for internal use only. Documentation is provided for subclassing.
211 This is a helper class for LOOP
221 Go to the previous iteration of the loop
225 Determines if the iterator can continue.
227 Currently, this wraps more_params(), but there other possible situations, such as the page ending.
231 Determines if the iterator for the loop has more parameters that it can consume
235 Go to the next iteration of the loop
243 Rob Kinyon (rob.kinyon@gmail.com)