I do think that it would help to be able to use scalar
or array references through load_tmpl without any
extra effort. Of course one can overload it as needed
as proposed by others.
Here is an overload example which keeps the old API in
place but just passes all parameters through if it is
an even number allowing full HTML::Template
functionality to be used -- why not, since it has to
be installed anyway?
I have written standard perl tests for scalar, array
and file samples which could be added to the tests for
CGI::Application if desired.
my $data = '<html>
<head><title>Test Template</title>
<body>
My Home Directory is <TMPL_VAR NAME=HOME>
<p>
My Path is set to <TMPL_VAR NAME=PATH>
</body>
</html>';
my $t = $webapp->load_tmpl( scalarref => \$data );
$t->param( HOME => 'whatever' );
$t->param( HOME => 'wherever' );
return $t->output;
Sincerely,
David Scott
# overload of CGI::Application::load_tmpl(
[$file,<options>] | <options> );
sub load_tmpl {
my $self = shift;
my ($tmpl_file, @extra_params) = ( @_ % 2 == 0 ) ?
( undef, @_ ) : @_;
# add tmpl_path to path array of one is set,
otherwise add a path arg
my $tmpl_path;
if ( $tmpl_file && ($tmpl_path = $self->tmpl_path)
) {
my $found = 0;
for( my $x = 0; $x < @extra_params; $x += 2 )
{
if ($extra_params[$x] eq 'path' and
ref $extra_params[$x+1] and
ref $extra_params[$x+1] eq 'ARRAY') {
unshift @{$extra_params[$x+1]},
$tmpl_path;
$found = 1;
last;
}
}
push(@extra_params, path => [ $tmpl_path ])
unless $found;
}
require HTML::Template;
my $t = ( $tmpl_file) ?
HTML::Template->new_file($tmpl_file,
@extra_params) :
HTML::Template->new(@extra_params);
return $t;
}
__________________________________
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th
http://taxes.yahoo.com/filing.html
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.