Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#8 undef VAR check option

open
nobody
None
5
2008-07-21
2008-07-21
No

Hello,

for my personal usage, i've hack a little bit the code to check and croak when a VAR is undefined.

I thing that the modification isn't complex. Indeed, only a few lines are needed :
1)
In the "_parse" method for sub template in loops, I've added
no_undef_value => $options->{no_undef_value}; around line #2150,

2)
in the output function, 2 modifications are needed :
Around the line #2722

elsif($options->{no_undef_value}){
my $var_name=undef;
foreach my $curr_var_name (keys(%{$self->{param_map}})){
if($line == $self->{param_map}{$curr_var_name}){
$var_name = $curr_var_name;
last;
}
}
$var_name = "Unknown" if(!defined($var_name));
croak("HTML::Template::output() : The element '$var_name' is undef while the option 'no_undef_value' is set");
}

Note : the lookup for the variable name isn't mandatory but it helps me to debug...

What do you think about that?

Discussion

  • Exemple of evolution

     
    Attachments