[Belfast-pm] Template Toolkit, passing in a hash?
Simon McCartney
simon at asidua.com
Tue Jul 6 05:23:34 CDT 2004
On Tue, Jul 06, 2004 at 11:06:53AM +0100, Tony Bowden wrote:
> > My next option would be to pass the subroutine in and only call it when
> > needed in the template. But this means changing my handler everytime I
> > want to add a new subroutine to the module.
> >
> > Is there a better way? Am I missing something?
>
> You can pass in subrefs:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> use Template;
>
> my $tt = Template->new();
> $tt->process(\*DATA, {
> foo => sub { 1 + 2 },
> bar => sub { 3 ** 8 },
> });
>
> __DATA__
> [% foo %]
> [% bar %]
>
>
> However, this is probably not what you really want to be doing. Without
> more information though, we probably won't know the better way.
I'm trying to limit the knock on effect of adding functionality. Your
fragment suggests not using a template handler and just using straight CGI
(with mod_perl), this is maybe what I'm looking for, the best way to do the
processing.
> If you're doing DBI stuff with TT, you might want to look at Class::DBI,
> which plays very nicely with TT...
Yeah, I've been working on Class::DBI'ing my existing non-presentation code..
-simonm (E: simon at asidua.com W: +44 28 9072 5060 M: +44 7710 836915)
I'm not an alcholic, I'm a liquid crusader fighting the evils of the
tee-total taliban.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 185 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/belfast-pm/attachments/20040706/f2b92f37/attachment.bin
More information about the Belfast-pm
mailing list