At 01:19 PM 2/12/2002 -0500, Perrin Harkins wrote:
>> So, if I wanted global object that would only ever be initialized once,
>> would I need to do something like run it from a startup script  with
>> PerlRequire, rather than within a handler module?
>
>You can do this in many ways.  You can put it in a global, and always access
>it from there.  You can make a singleton object that will hold it and return
>it whenever you ask (TemplateSingleton->get_instance() or something).

Given the chocie of constructing the Template object once per child versus 
constructing it in the apache root process (before forking) and letting it be shared, 
is there any advantage of one approach over the other?  I've been taking the latter 
approach, doing something like:

---  in startup.perl, which is run by PerlRequire in httpd.conf ---
$Project::TemplateBasePath = "/absolute/path/to/ttemplate";
$Project::template = Template->new
            (INCLUDE_PATH => $Project::TemplateBasePath,
             PRE_CHOMP => 1,
             );

--- In an individual handler --
$data = {
  ...
};
$Project::template->process($templatefilename, $data, $apache) 
  or die "Template process error [".$Project::template->error."]"; 



Matthew Pressly



Reply via email to