Re: [htmltmpl] Patch to fix global_vars and loop problem...
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-05-12 22:57:11
|
hmm... I dont consider this to be a bug... here you create a global variable called 'gvar' > $t->param(gvar =3D> "global variable"); here you are creating a loop specific variable called 'gvar' > { loopvar =3D> "GVar should be set", gvar =3D> "Loop GVar = 1" }, These two 'gvar's are two different variables.=20 In this case > { loopvar =3D> "GVar should be blank again", gvar =3D> undef = }, you are saying that the loop specific 'gvar' is not part of the loop - = ie equivalent to: { loopvar =3D> "GVar should be blank again" } thus requesting the outer global gvar to come into scope. Consider: t->param(gvar =3D> "Global gvar"); my $gvar_val; my @loop; for.... { if (something) { $gvar_val =3D "Loop GVar 1"; } elsif (somethign else) { $gvar_val =3D ""; } my $tmp; $tmp->{loopvar} =3D ...; $tmp->{gvar} =3D $gvar; push @loop, $tmp; } t->param(testloop =3D>\@loop); What would you expect the TMPL_LOOP to do in that example?=20 I would have expected that the third iteration to use the global gvar = value. Mathew > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > test.tmpl: > ---------- > Global Variable gvar is: <tmpl_var name=3Dgvar> >=20 > Loop: <tmpl_loop name=3Dtestloop> > loopvar: <tmpl_var name=3Dloopvar> > gvar : <tmpl_var name=3Dgvar> > </tmpl_loop> > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > test.pl > ------- >=20 > use strict; > use HTML::Template; >=20 > my $t =3D new HTML::Template(filename =3D> "test.tmpl", global_vars = =3D> 1,) > || die; >=20 > my $testloop =3D [ > { loopvar =3D> "GVar should be set", gvar =3D> "Loop GVar = 1" }, > { loopvar =3D> "GVar should be blank", gvar =3D> "" = }, > { loopvar =3D> "GVar should be blank again", gvar =3D> undef = }, > ]; >=20 > $t->param(gvar =3D> "global variable"); > $t->param(testloop =3D> $testloop); > print $t->output(); > = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >=20 > When you run test.pl.. you get the following output: > = ------------------------------------------------------------------------ > Global Variable gvar is: global variable >=20 > Loop:=20 > loopvar: GVar should be set=20 > gvar : Loop GVar 1 > =20 > loopvar: GVar should be blank > gvar :=20 > =20 > loopvar: GVar should be blank again > gvar : global variable > = ------------------------------------------------------------------------ >=20 > Now, the issue is that "gvar" in the third iteration of the loop, > "should have been blank"... i explicitely set it to "undef" in the > code.. however, since global_vars was on, it ignored my "undef".=20 |