Templa...ompile(3pm)
π NAME π
okay so bestie, welcome to Template::Alloy::Compile β it's the Compile role, and what it does is let you take an AST and turn it into actual perl code. It ships as part of the Template::Alloy distribution, under the Perl User Contributed docs (the 3pm girlies know π
).
πΈ DESCRIPTION πΈ
so here's the tea π΅ β the Template::Alloy::Compile role is the one that takes the AST that the Parse role hands you back, and translates it into a perl code document. β¨
and the way that it's different from Template::Alloy::Play is literally everything, because Play just goes ahead and executes the AST directly, no translation era. Compile is the "write it down as perl first" icon. π
π¦ TODO π¦
- Translate
compile_RAWPERLto actually output rather than callingplay_RAWPERL.
not me putting this here but okay we're being honest about it π
π ROLE METHODS π
π compile_tree
Takes an AST that came back from parse_tree and translates it into perl code, using the functions stored in the $DIRECTIVES hashref. slay.
A template that looked like this:
Foo
[% GET foo %]
[% GET bar %]
Bar
would parse to this 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,
};
and as you can see, the output is quite a bit more complex than the AST was. but here's why that's a flex πͺ β under mod_perl conditions, the perl will run faster than playing the AST every single time. lowkey the whole point. π₯
π§ compile_expr
Takes an AST variable or expression, and returns perl code that can lookup the variable. that's it, that's the job. π
π«Ά AUTHOR π«Ά
Paul Seamons <paul@seamons.com>
π LICENSE π
This module may be distributed under the same terms as Perl itself.
and that's the whole page bestie, no cap β this was perl v5.38.2, dated 2024-03-07, and yes the header/footer both say Templa...ompile(3pm) because they truncate it, iconic behavior tbh πβ¨ bye!!
π¦ where this page comes from
- debian trixie: libtemplate-alloy-perl 1.022-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtemplate-alloy-perl 1.022-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtemplate-alloy-perl 1.022-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms