1Template::Alloy::CompilUes(e3r)Contributed Perl DocumentTaetmipolnate::Alloy::Compile(3)
2
3
4

NAME

6       Template::Alloy::Compile - Compile role - allows for compiling the AST
7       to perl code
8

DESCRIPTION

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

TODO

15       ·   Translate compile_RAWPERL to actually output rather than calling
16           play_RAWPERL.
17

ROLE METHODS

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 play‐
63           ing 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

AUTHOR

70       Paul Seamons <paul at seamons dot com>
71

LICENSE

73       This module may be distributed under the same terms as Perl itself.
74
75
76
77perl v5.8.8                       2007-07-24       Template::Alloy::Compile(3)
Impressum