very good points :-) How is the attached as a patch...
simran. On Wed, 2004-05-12 at 14:09, Sam Tregar wrote: > On Wed, 12 May 2004, simran wrote: > > > + foreach my $row (@$value) { > > + foreach my $key (keys %$row) { > > + $row->{$key} ||= ""; > > + } > > + } > > Hmmmm. What happens when $row->{$key} is "0"? What happens when > undef is set in a loop within a loop? > > I think the real fix is to find a way to use exists() rather than > defined() when looking for the variable setting. That way it doesn't > matter what the value of the var is, just whether it's set or not. > Maybe you could give that a try? > > Thanks, > -sam > > > ------------------------------------------------------- > This SF.Net email is sponsored by Sleepycat Software > Learn developer strategies Cisco, Motorola, Ericsson & Lucent use to > deliver higher performing products faster, at low TCO. > http://www.sleepycat.com/telcomwpreg.php?From=osdnemail3 > _______________________________________________ > Html-template-users mailing list > [EMAIL PROTECTED] > https://lists.sourceforge.net/lists/listinfo/html-template-users
--- Template.pm.orig 2004-05-12 14:37:56.000000000 +1000 +++ Template.pm 2004-05-12 16:49:36.000000000 +1000 @@ -2468,7 +2468,7 @@ } else { (ref($param_map->{$param}) eq 'HTML::Template::VAR') or croak("HTML::Template::param() : attempt to set parameter '$param' with a scalar - parameter is not a TMPL_VAR!"); - ${$param_map->{$param}} = $value; + ${$param_map->{$param}} = defined($value) ? $value : ""; } } }
#!/usr/bin/perl use strict; use HTML::Template; my $t = new HTML::Template(filename => "test.tmpl", global_vars => 1,die_on_bad_params => 0) || die; my $testloop = [ { loopvar => "GVar should be set ", gvar => "Loop GVar 1", innerloop => [ { test => "test" } ] }, { loopvar => "GVar should be blank", gvar => "" , innerloop => [] }, { loopvar => "GVar should be zero", gvar => 0 , innerloop => [] }, { loopvar => "GVar should be blank", gvar => undef , innerloop => [] }, { loopvar => "GVar should be global default", , innerloop => [] }, { loopvar => "GVar should be blank again", gvar => undef , innerloop => [ { gvar => undef } ] }, ]; $t->param(gvar => "global variable"); $t->param(gvar2 => "global variable 2"); $t->param(testloop => $testloop); print $t->output();
Global Variable gvar is: <tmpl_var name=gvar> Loop: <tmpl_loop name=testloop> loopvar: <tmpl_var name=loopvar> gvar : <tmpl_var name=gvar> <tmpl_loop name=innerloop> inner loop gvar: <tmpl_var name=gvar> </tmpl_loop> </tmpl_loop>