package IIa66da94aed9b371a0ee16b72f938ea09::tag_for; use strict; use base qw/II720d6e18aa34327713eb014408fc9144/; sub start { my ($this, $tag, $attr, $attrseq, $origtext) = @_; my $var = "#{$attr->{each}}"; my $in = $attr->{invar} ? "#{$attr->{invar}}" : $attr->{inexpr}; my ($from, $num) = ($attr->{from}, $attr->{num}); $this->harakiri("missing in") unless $in; my $iter = "#{ITERATION.$attr->{each}}"; $this->evaluate for $var, $in, $from, $num, $iter; $this->addCode("my \$in = $in;"); $this->addCode('my $loop = ref($in) eq "ARRAY" ? $in : ref($in) eq "CODE" ? &{$in} : [];'); $this->addCode("$iter = -1;"); if (length($from) && length($num)) { $this->addCode("for my \$f (grep {defined} \@{\$loop}[$from..($from + $num - 1)]) {"); } else { $this->addCode("for my \$f (\@\$loop) {"); } $this->{Indent}++; $this->addCode("$iter++;"); $this->addCode("$var = \$f;"); return; } sub end { my $this = shift; $this->endBracket(@_); } 1; 