Hi

I am trying to setup our web server to use only one template object (created
at startup), rather than creating a template object per request and would
appreciate any comments on whether I'm doing this the right way.  I've
looked at some of the discussion about this in the mailing list and have
only grasped a few bits and pieces about how it should be setup (I've had to
ignore things like 'memoize' which look like they do deeper magic than I am
capable of).  I understand that there are a number of ways of doing this but
this is how I've tried it so far:

In my server startup script I have created a template object with some
configuration options which I do not want to change, e.g. COMPILE_DIR and
COMPILE_EXT and thrown in a default value for some configuration options
which I want to change on each request (e.g. INCLUDE_PATH).

On each request I want to be able to change the INCLUDE_PATH and the
PRE_PROCESS configuration options because each request may be delivering a
template from another path and it may need to pre_process a particular
template which defines things like colours on the page.

In order to do this I have done the following (some of which has involved
mangling with the internal data structures in template - I didn't want to do
this!):

my $template = my template object created at startup

# set the include path
my $provider = $template->context->{ LOAD_TEMPLATES }->[0];
$provider->include_path('my include path');

# set some per-request template configuration options
my $service = $template->service();
$service->{ PRE_PROCESS } = ['default_config', 'this_request_config'];

I then have to use service to deliver the output to get the new
configurations option to be used
which I can't get to direct straight to STDOUT like I could with calling
process on the template object

my $output = $service->process(template_file,$vars);
print $output;

This seems to be doing what I want it to do but I'm particularly unsure
about whether I could get into problems with a simultaneous request using
the same template object.  Could I ever get the wrong template being
pre-processed for a request because I have set it differently on another
request?

As I said, ANY feedback would be really useful.

Thanks

Colin



Reply via email to