1Template::Alloy::CompilUes(e3r)Contributed Perl DocumentTaetmipolnate::Alloy::Compile(3)
2
3
4
6 Template::Alloy::Compile - Compile role - allows for compiling the AST
7 to perl code
8
10 The Template::Alloy::Compile role allows for taking the AST returned by
11 the Parse role, and translating it into a perl code document. This is
12 in contrast Template::Alloy::Play which executes the AST directly.
13
15 ยท Translate compile_RAWPERL to actually output rather than calling
16 play_RAWPERL.
17
19 "compile_tree"
20 Takes an AST returned by parse_tree and translates it into perl
21 code using functions stored in the $DIRECTIVES hashref.
22
23 A template that looked like the following:
24
25 Foo
26 [% GET foo %]
27 [% GET bar %]
28 Bar
29
30 would parse to the following perl code:
31
32 # Generated by Template::Alloy::Compile v1.001 on Thu Jun 7 12:58:33 2007
33 # From file /home/paul/bar.tt
34
35 my $blocks = {};
36 my $meta = {};
37 my $code = sub {
38 my ($self, $out_ref, $var) = @_;
39
40 $$out_ref .= 'Foo';
41
42 # "GET" Line 2 char 2 (chars 6 to 15)
43 $var = $self->play_expr(['foo', 0]);
44 $$out_ref .= defined($var) ? $var : $self->undefined_get(['foo', 0]);
45
46 # "GET" Line 3 char 2 (chars 22 to 31)
47 $var = $self->play_expr(['bar', 0]);
48 $$out_ref .= defined($var) ? $var : $self->undefined_get(['bar', 0]);
49
50 $$out_ref .= 'Bar';
51
52 return 1;
53 };
54
55 {
56 blocks => $blocks,
57 meta => $meta,
58 code => $code,
59 };
60
61 As you can see the output is quite a bit more complex than the AST,
62 but under mod_perl conditions, the perl will run faster than
63 playing the AST each time.
64
65 "compile_expr"
66 Takes an AST variable or expression and returns perl code that can
67 lookup the variable.
68
70 Paul Seamons <paul at seamons dot com>
71
73 This module may be distributed under the same terms as Perl itself.
74
75
76
77perl v5.12.0 2008-09-17 Template::Alloy::Compile(3)