use_ok(
'HTML::Template'
);
my
$tmpl_string
=
'<tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop>'
;
my
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2}, {
a
=> 3,
b
=> 4}]);
my
$output
=
$template
->output;
is(clean(
$output
),
'1:2 3:4'
,
'normal loop'
);
$tmpl_string
=
'<tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop><tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop>'
;
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2}, {
a
=> 3,
b
=> 4}]);
$output
=
$template
->output;
is(clean(
$output
),
'1:2 3:4 1:2 3:4'
,
'repeated loop, same vars'
);
$tmpl_string
=
'<tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop><tmpl_loop foo><tmpl_var a>:0 </tmpl_loop>'
;
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2}, {
a
=> 3,
b
=> 4}]);
$output
=
$template
->output;
is(clean(
$output
),
'1:2 3:4 1:0 3:0'
,
'repeated loop, different vars, more in 1st'
);
$tmpl_string
=
'<tmpl_loop foo><tmpl_var a>:0 </tmpl_loop><tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop>'
;
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2}, {
a
=> 3,
b
=> 4}]);
$output
=
$template
->output;
is(clean(
$output
),
'1:0 3:0 1:2 3:4'
,
'repeated loop, different vars, more in 2nd'
);
$tmpl_string
=
'<tmpl_loop foo><tmpl_var a>:0 </tmpl_loop><tmpl_loop foo><tmpl_var a>:<tmpl_var b> </tmpl_loop><tmpl_loop foo><tmpl_var b>:<tmpl_var c> </tmpl_loop>'
;
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2,
c
=> 3}, {
a
=> 3,
b
=> 4,
c
=> 5}]);
$output
=
$template
->output;
is(clean(
$output
),
'1:0 3:0 1:2 3:4 2:3 4:5'
,
'repeated loop 3x, different vars'
);
$tmpl_string
=
q|
<tmpl_loop foo>
<tmpl_var a>:0
</tmpl_loop>
<tmpl_loop foo>
<tmpl_if d>?<tmpl_else>!</tmpl_if>
<tmpl_var a>:<tmpl_var b>
</tmpl_loop>
<tmpl_loop foo>
<tmpl_if e>!<tmpl_else>?</tmpl_if>
<tmpl_var b>:<tmpl_var c>
</tmpl_loop>
|
;
$template
= HTML::Template->new_scalar_ref( \
$tmpl_string
);
$template
->param(
foo
=> [{
a
=> 1,
b
=>2,
c
=> 3,
d
=> 1}, {
a
=> 3,
b
=> 4,
c
=> 5,
e
=> 1}]);
$output
=
$template
->output;
is(clean(
$output
),
'1:0 3:0 ? 1:2 ! 3:4 ? 2:3 ! 4:5'
,
'repeated loop 3x, w/conditionals'
);
sub
clean {
my
$string
=
shift
;
$string
=~ s/\s+/ /g;
$string
=~ s/^\s+//;
$string
=~ s/\s+$//;
return
$string
;
}