On Tue, 15 Jan 2002, Venkataramana Mokkapati wrote:

> Thanks for your attention...
>
> Me thinks, its a good idea for HTML::Template to automatically interpolate
>
> [11,22,33] as [{anon => 11}, {anon => 22}, {anon => 33}]
>
> I do the following all the time when using HTML::Template
>
> $a = [11,22,33];
> $template->param(Info => [map {{anon => $_}} @$a]);

Well, it may be ugly in the most basic case, which is what we have here,
but I have a feeling that Sam would shoot this down for adding uneeded
complexity.  You could always subclass HTML::Template, but the question then
becomes, what does it auto-vivify the <TMPL_VAR> names inside the loop to?

package My::Template

use HTML::Template;
use Carp;

our @ISA = qw(HTML::Template);

sub param {
        my $self  = shift;

        # Let HTML::Template handle special case
        return $self->SUPER::param(@_) if @_ == 1;

        croak(__PACKAGE__ . "->param() : You gave me an odd number of parameters to 
param()!")
            unless ((@_ % 2) == 0);

        my %params = @_;
        foreach my $var (keyys %params) {
                my $val = $params{$var};
                if (ref $val eq 'ARRAY' && !ref $val->[0]) {
                        my $new_val = [];
                        for (@$val) {
                                push(@$new_val, { "${var}_value" => $_ });
                        }
                        $params{$var} = $new_val;
                }
        }
        return $self->SUPER::param(%params);
}

__END__

I have no idea if that would actually work, I just wrote it on the fly.

-- 
Chris Reinhardt
[EMAIL PROTECTED]
Systems Architect
Dynamic DNS Network Services
http://www.dyndns.org/


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to