in reply to Re: Overriding Template Toolkit Internals
in thread Overriding Template Toolkit Internals

Actually, a reponse to one of my messages to that list lead to the following code:

package Onsite::Template::Context; use strict; use base qw/ Template::Context /; sub include { my $self = shift; my $template = $_[0]; join "\n", "<!-- START: $template -->", $self->SUPER::include(@_), "<!-- END: $template -->"; } 1;

Then, in the code that actually uses Template Toolkit:

use Template; use Template::Config; $Template::Config::CONTEXT = 'Onsite::Template::Context';

That solved the problem nicely without my rude hack. Basically, the Config module has globals that control all of the modules that it uses. When a Template object is instantiated, &Template::Config::load is called which then will require all modules, allowing them to be overridden at run time. It's a neat solution.

The only thing about it that bugs me is that I kept reading and reading through the online Template Toolkit documentation and didn't see that anywhere. I'm sure it's there, I just can't find it.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.