Jose Luis Mart�nez wrote:
I'm going to migrate all my scripts from mod_cgi to mod_perl (for apache
1.3). Can you give me some tips on what are the best practices for
having TT on a mod_perl server?

I was thinking of loading TT when apache starts (our applications
allways use TT). Is this safe? Should I consider something special?

How should I use the template object? I've seen in the list that someone
recomended creating only one instance of the template object, and have
it global with 'our'. Can this cause problems?

The idea is that you want to keep using the same processor object so you can take advantage of caching and perform any object initialization only once.


Instead of using 'our' you can make it a package lexical with 'my' and create a method for controlled access (all code off the top of my head, untested, etc.):

package My::Template;

use strict;
use Template;

my ( $TEMPLATE );

sub init {
    my ( $class ) = @_;
    $TEMPLATE = Template->new( ... );
}

sub get_processor {
    return $TEMPLATE;
}

And then initialize it in a 'startup.pl':

#!/usr/bin/perl

use strict;
use My::Template;

My::Template->init();

And then use it in one of your handlers:

package My::Handler;

use strict;
use My::Template;

sub handler($$) {
    my ( $class, $r ) = @_;
    my ( $html );
    my $text = $class->get_template_text( ... );
    my $vars = $class->get_template_vars( ... );
    My::Template->get_processor()->process(
        $text, $vars, \$html );
    $r->print( $html );
    ...
}

HTH

Chris

--
Chris Winters ([EMAIL PROTECTED])
Building enterprise-capable snack solutions since 1988.


_______________________________________________ templates mailing list [EMAIL PROTECTED] http://lists.template-toolkit.org/mailman/listinfo/templates

Reply via email to