Takes an AST returned by parse_tree and translates it into perl code using
functions stored in the $DIRECTIVES hashref.
A template that looked like the following:
Foo
[% GET foo %]
[% GET bar %]
Bar
would parse to the following perl code:
# Generated by Template::Alloy::Compile v1.001 on Thu Jun 7 12:58:33 2007
# From file /home/paul/bar.tt
my $blocks = {};
my $meta = {};
my $code = sub {
my ($self, $out_ref, $var) = @_;
$$out_ref .= 'Foo';
# "GET" Line 2 char 2 (chars 6 to 15)
$var = $self->play_expr(['foo', 0]);
$$out_ref .= defined($var) ? $var : $self->undefined_get(['foo', 0]);
# "GET" Line 3 char 2 (chars 22 to 31)
$var = $self->play_expr(['bar', 0]);
$$out_ref .= defined($var) ? $var : $self->undefined_get(['bar', 0]);
$$out_ref .= 'Bar';
return 1;
};
{
blocks => $blocks,
meta => $meta,
code => $code,
};
As you can see the output is quite a bit more complex than the
AST, but under mod_perl conditions, the perl will run faster than
playing the AST each time.