Bill Moseley wrote:
> When initializing an app I'm reading in a template and then running
> it through the parser to check for any obvious syntax errors.
> 
> Something like this:
> 
>     my $text = read_file( $path );
>     my $parser = Template::Parser->new;
>     $parser->parse( $text ) || die $parser->error;
> 
> I want to die at application startup.
> 
> Later when serving requests I might do:
> 
>     $tt->process(\$text);
> 
> What I'm wondering is if there's a way I can "process" but use the
> return value from $parser->parse to avoid re-parsing the text.

Looking at Template::Parser::parse() it says it returns a hash that can be used 
by Template::Document. The docs for Template::Document seem to say you can 
process by using the TT context.

So maybe something like this?:
----------------------------------------------------
use Template::Document;
my $doc = Template::Document->new($parser_result);
$doc->process($tt->context);

# $parser_result is return from $parser->parse() above.
# $tt is your later instantiation of Template
----------------------------------------------------

I have never used this so who knows whether it will work or not. Just a guess 
from reading a little code and docs.

-- Josh

_______________________________________________
templates mailing list
templates@template-toolkit.org
http://mail.template-toolkit.org/mailman/listinfo/templates

Reply via email to