#!/usr/bin/perl -w
#
# This short program illustrates a possible bug with HTML::Template
# when using global_vars and nested loops. It seems that variables in
# the outer loop are unavailable in to the inner loop unless they are
# used in the outer loop.
#
# Tested with version 2.5.
#

use strict;
use HTML::Template;

my $loop = [
             { data => 'A',
               subloop => [
                            { subdata => 1 },
                            { subdata => 2 }
                          ]
             },
             { data => 'B',
               subloop => [
                            { subdata => 1 },
                            { subdata => 2 }
                          ]
             }
           ];

my $fails = <<END
<tmpl_loop name=loop>
<tmpl_loop name=subloop>
Outer loop data in inner loop: <tmpl_var name=data>
Inner loop data: <tmpl_var name=subdata>
</tmpl_loop>
</tmpl_loop>
END
;

my $works = <<END
<tmpl_loop name=loop>
Outer loop data: <tmpl_var name=data>
<tmpl_loop name=subloop>
Outer loop data in inner loop: <tmpl_var name=data>
Inner loop data: <tmpl_var name=subdata>
</tmpl_loop>
</tmpl_loop>
END
;

my $t1 = new HTML::Template( scalarref => \$fails,
                             die_on_bad_params => 0,
                             global_vars => 1);

my $t2 = new HTML::Template( scalarref => \$works,
                             die_on_bad_params => 0,
                             global_vars => 1);

$t1->param( loop => $loop );
$t2->param( loop => $loop );

print $t1->output;
print $t2->output;


