in reply to What protects me from doing this stupid thing..?
will do what you want. Or$template->param( some_var => 10, (some_var => $hash{some_possibly_undefined_key}) x!! exists($hash{so +me_possibly_undefined_key}), );
However, you might also try using Params::Validate$template->param( some_var => exists $hash{some_possibly_undefined_key} ? $hash{some_p +ossibly_undefined_key} : 10; );
To actually answer your question, some things are hard to protect against and it is best to just try to avoid some constructs. For example you can write{ package MyTemplate; use base Template; use Params::Validate qw (validate); sub param { my $self = shift; my %p = validate(@_, { some_var => { default => 12, } }); $self->SUPER::param(%p); } }
if ($a == 0)or you can write
if (0 == $a)using the second will keep you from the problem of writing if ($a = 0).
|
---|