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];