Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/Template/Directive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,11 @@ sub if {
#------------------------------------------------------------------------

sub foreach {
my ($self, $target, $list, $args, $block, $label) = @_;
my ($self, $target, $list, $args, $block, $else, $label) = @_;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I read this, I've the feeling that this going to break previous behaviors where foreach was called with a label, as the label is going to be shift in else statement.

One suggestion would be to move the else as last argument of this function and use an extra helper in the parser that would wrap this function

$args = shift @$args;
$args = @$args ? ', { ' . join(', ', @$args) . ' }' : '';
$label ||= 'LOOP';
$else ||= '';

my ($loop_save, $loop_set, $loop_restore, $setiter);
if ($target) {
Expand All @@ -449,6 +450,7 @@ sub foreach {
$loop_restore = '$stash = $context->delocalise()';
}
$block = pad($block, 3) if $PRETTY;
$else = pad($else, 3) if $PRETTY;

return <<EOF;

Expand All @@ -466,10 +468,14 @@ do {
$loop_save;
\$stash->set('loop', \$_tt_list);
eval {
unless (\$_tt_list->size()){
$else
} else {
$label: while (! \$_tt_error) {
$loop_set;
$block;
(\$_tt_value, \$_tt_error) = \$_tt_list->get_next();
}
}
};
$loop_restore;
Expand Down
Loading