Subject: | no context hashref in perl tales |
Date: | Thu, 7 Dec 2006 14:07:38 +0100 |
To: | bug-Template-TAL [...] rt.cpan.org |
From: | Willi Langenberger <wlang [...] wu-wien.ac.at> |
Hi!
There is a bug in Template::TAL::Language::PerlValue. Contradictory to
the documentation, there is no ``$context'' hashref available for
perl TALES expressions. Patch included.
Here are the details:
Module: Template-TAL-0.9 > Template::TAL::Language::PerlValue
Documentaion:
http://search.cpan.org/~tomi/Template-TAL-0.9/lib/Template/TAL/Language/PerlValue.pm
[...]
In your perl code, you will have access to a $context hashref, which
is the local TAL context. Altering this hash will change the
context.
However, this does not work.
<body tal:define="x string:hallo">
<p tal:content="perl: $context->{x}">tal variable</p>
</body>
gives the following error:
Global symbol "$context" requires explicit package name at (eval 13) line 1.
The following patch maps the list of contexts in one "$context"
hashref:
----8<-------------------------
$ diff -u Template/TAL/Language/PerlValue.pm.ori Template/TAL/Language/PerlValue.pm
--- Template/TAL/Language/PerlValue.pm.ori 2006-10-06 17:48:22.000000000 +0200
+++ Template/TAL/Language/PerlValue.pm 2006-12-07 12:58:09.722759264 +0100
@@ -45,6 +45,7 @@
sub process_tales_perl {
# use really weird variable names, to try to avoid clashing with things.
my ($___class, $___path, $___contexts, $___plugins) = @_;
+ my $context = { map(%$_, reverse @$___contexts) };
my $___res = eval($___path);
die $@ if $@;
return $___res;
----8<-------------------------
Thanks for bringing the cool ZPTs to Perl!!!
\wlang{}
--
Willi.Langenberger@wu-wien.ac.at Fax: +43/1/31336/9207
Zentrum fuer Informatikdienste, Wirtschaftsuniversitaet Wien, Austria