Skip Menu |

This queue is for tickets about the HTML-Template-Compiled CPAN distribution.

Maintainer(s)' notes

Note: there is a bug with caching and TMPL_INCLUDE_VAR since 0.97_004 until 0.98. either use an earlier version or upgrade to 0.98_001. Another workaround is to precompile all templates to file_cache_dir. The bug happens when including a template via INCLUDE_VAR and the template is not yet compiled or has changed.

I'm sorry if the change about aliases came quite unannounced. I didn't expect any problems since dollar signs are not allowed in template vars, but I heard from at least one case where people were doing exactly this.
Please do not use unallowed characters in template vars. Allowed are (from the HTML::Template::FAQ): Numbers, letters, '.', '/', '+', '-' and '_'.
This should work in HTML::Template::Compiled::Classic.
in HTML::Template::Compiled you should be only using numbers, letters and _.
The dot, for example, is special. If you need to get a hash key from the template parameters with special charcaters, you can try <tmpl_var _.$var$name$with$dollars >

There will be a workaround in the next version:
local $HTML::Template::Compiled::Compiler::DISABLE_NEW_ALIAS = 1;


Please report any bug you find.
The code is now hosted on https://github.com/perlpunk/HTML-Template-Compiled
If you have a bug report, you can also post it there in the "Issues" section.
In the bugreport, please include, if possible, the module version, perl version and a testcase that reproduces the error; that makes it easier to find the bug.

The issue with not reloading includes of includes should be fixed in version 0.95_003. If you have any problems though please report!

Using query() and the dot syntax might not work together always. If you have a tmpL_var name="..foo" (going up the stash one level) the var foo is not detected and will not be reported by the query() function. Since the dot syntax is for dereferencing hashes and method calls the query function might not make sense anyway. I believe it is a bad idea to let the program do things if the template is using a certain variable.

Thanks!

Report information
The Basics
Id: 30693
Status: resolved
Priority: 0/
Queue: HTML-Template-Compiled

People
Owner: Nobody in particular
Requestors: ac0v [...] sys-network.de
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.89
Fixed in: 0.93



Subject: allow LOOP also for a single value
The <%LOOP ... %> Function is only usable for arrayrefs. It would be great if it would act like perl's for. So it should run the loop once if we iterate over an an single value. Why do I/we need this? Many modules for XML handling are creating array references only if there in more than one element in an hierarchy. So if you'll pass this data to a LOOP in your HTC, you'll run into problems. (this means that nothing is shown, if there is one element instead of an arrayref). I think it's not very usefull to prepare all data for HTC before passing it to HTC via $htc->param(). I've attached a small diff for HTC's Compiler.pm, which upgrades all single values whose are used in an loop to an array ref before looping. What do you think about it?
Subject: Compiler.diff
497c497,498 < ${indent}if (UNIVERSAL::isa(my \$array = $varstr, 'ARRAY') )\{ --- > ${indent}if ( defined $varstr )\{ > ${indent}${ind}my \$array = ref $varstr && ref $varstr eq 'ARRAY' ? $varstr : [$varstr];
sry - there was some crap in the diff, fixed diff is attached.
497c497,498 < ${indent}if (UNIVERSAL::isa(my \$array = $varstr, 'ARRAY') )\{ --- > ${indent}if ( defined $varstr )\{ > ${indent}${ind}my \$array = ref $varstr eq 'ARRAY' ? $varstr : [$varstr];
On Di. 13. Nov. 2007, 10:10:00, ACID wrote: Show quoted text
> The <%LOOP ... %> Function is only usable for arrayrefs. It would be > great if it would act like perl's for.
actually perl's for iterates over arrays/lists. if you have an arrayref you have to dereference it. if the variable is not an array ref you have that to check yourself. 'for' doesn't do that for you. Show quoted text
> So it should run the loop once if > we iterate over an an single value. > > Why do I/we need this? > Many modules for XML handling are creating array references only if > there in more than one element in an hierarchy. So if you'll pass this > data to a LOOP in your HTC, you'll run into problems. (this means that > nothing is shown, if there is one element instead of an arrayref).
i'll have a look, though i think the templating shouldn't try to be too smart.
On Di. 13. Nov. 2007, 10:34:50, ACID wrote: Show quoted text
> ref $varstr eq 'ARRAY' ? $varstr : [$varstr];
Actually this is different from my code in that I do UNIVERSAL::isa instead of ref() which allows to iterate over an object which is an array. But I guess that this functionality is not really needed...
From: ac0v [...] sys-network.de
Hi Tina, I've found another problem with LOOP, which also affects EACH. If someone overloads @{} it's not possible to use LOOP in the template. Why do I need this? The overload problem occurs while passing object created by SOAP::WSDL to my Templates. I've attached a small test script and a possible patch for the Compiler.pm which has a changed LOOP and EACH. This patch would waste the requested feature "allow LOOP also for a single value" for me :) Regards, Andreas
#!perl use lib qw(blib/lib); use Test::More tests => 1; BEGIN { use_ok('HTML::Template::Compiled') }; my @test_values = qw(some multi values); package MyOverloadSample; use overload '@{}' => sub { \@test_values; }; sub new { return bless \(my $anon), shift; } package main; { my $htc = HTML::Template::Compiled->new( scalarref => \(my $anon = "<%LOOP test_var %><%= _ %><%/LOOP%>"), out_fh => 0, ); $htc->param(test_var => MyOverloadSample->new()); my $out = $htc->output(); $out =~ s{\s+}{}xmsg; cmp_ok($out, 'eq', (join q{}, @test_values), 'loop with overloaded @{} ok'); }
--- /tmp/HTML-Template-Compiled-0.90/lib/HTML/Template/Compiled/Compiler.pm 2007-11-15 00:41:08.000000000 +0100 +++ /tmp/My-Template-Compiled-0.90/lib/HTML/Template/Compiled/Compiler.pm 2007-11-28 23:07:44.000000000 +0100 @@ -482,10 +482,10 @@ } elsif ($tname eq T_EACH) { $code .= <<"EOM"; -${indent}if (UNIVERSAL::isa(my \$hash = $varstr, 'HASH') ) \{ +${indent}if ( my \%hash = eval \{ my \$var = $varstr; \%\{\$var} } )\{ ${indent}${indent}local \$__ix__ = -1; ${indent}${ind}local (\$__key__,\$__value__); -${indent}${ind}while ((\$__key__,\$__value__) = each %\$hash) \{ +${indent}${ind}while ((\$__key__,\$__value__) = each %hash) \{ ${indent}${indent}\$__ix__++; $insert_break EOM @@ -506,8 +506,8 @@ } $code .= <<"EOM"; -${indent}if (UNIVERSAL::isa(my \$array = $varstr, 'ARRAY') )\{ -${indent}${ind}my \$size = \$#{ \$array }; +my \$array = $varstr; +${indent}if ( my \$size = eval \{ \$#{ \$array } } )\{ $global ${indent}${ind}# loop over $var
On Mi. 28. Nov. 2007, 18:46:58, ACID wrote: Show quoted text
> Why do I need this? > The overload problem occurs while passing object created by SOAP::WSDL > to my Templates. > > I've attached a small test script and a possible patch for the > Compiler.pm which has a changed LOOP and EACH. > > This patch would waste the requested feature "allow LOOP also for a > single value" for me :)
i think i will put this into the next version. it makes it a bit slower overall, but i can probably live with that. this would also just ignore any non-array vars instead of dying which is probably a good thing, only that it is even more different than the HTML::Template behaviour. Could you please test the current version from Sourceforge? http://sourceforge.net/svn/?group_id=147988 thanks, tina
On Fr. 22. Aug. 2008, 05:32:03, TINITA wrote: Show quoted text
> i think i will put this into the next version. [...]
I didn't hear from you, but I guess it will be working. It's in 0.93 now. regards, tina