On 04/09/2012 02:28 PM, Manfred Lotz wrote:
Hi all,
Let's say I use Template:Toolkit like this:
<-----------------snip------------------->
#! /usr/bin/perl
use strict;
use warnings;
use Template;
my $variables = { nrme => "Manfred", };
my $cmd = 'Hi [% name %], how are you.';
my $template = Template->new();
$template->process(\$cmd, $variables)
or die $template->error(), "\n";
<-----------------snap------------------->
and accidentally I have a typo in $variables (nrme instead of name).
The output is: Hi , how are you.
IMHO, this is really bad. I would like to get an error saying that a
variable could not be substituted.
even if it were possible, i don't think it makes much sense. in many
cases you will fill up a hash (or hash tree) with more data than is used
in the template. this is an easy way to handle different templates with
a common set of data. so many values (not variables) may go unused. and
if there is a tree, not a single level hash, some tags could be the same
name but at different levels. and some may be used and some ignored. so
even your regex checker (in a followup post) can't handle that.
now the opposite is possible. showing which template tags are not found
in the data. most templaters will replace that with a null string. it
should be easy enough to add an option to let the undef value generate a
warning or the template code could do that for you. the problem there is
correlating the tag in the template with the proper slot in the data
tree. so it may be possible but annoying. it is better to just eyeball
the two things and fix any problems. this is also why using template
components and include files is a win. you can test smaller data trees
on an include file and fix typos easily.
uri
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/