]> Dogcows Code - chaz/p5-CGI-Ex/blob - lib/CGI/Ex/Template.pm
CGI::Ex 2.24
[chaz/p5-CGI-Ex] / lib / CGI / Ex / Template.pm
1 package CGI::Ex::Template;
2
3 =head1 NAME
4
5 CGI::Ex::Template - Template::Alloy based TT2/TT3/HT/HTE/Tmpl/Velocity engine.
6
7 =cut
8
9 use strict;
10 use warnings;
11 use Template::Alloy 1.004;
12 use base qw(Template::Alloy);
13 use vars qw($VERSION
14 $QR_PRIVATE
15 $WHILE_MAX
16 $MAX_EVAL_RECURSE
17 $MAX_MACRO_RECURSE
18 $STAT_TTL
19 $EXTRA_COMPILE_EXT
20 $PERL_COMPILE_EXT
21 $SCALAR_OPS
22 $FILTER_OPS
23 $LIST_OPS
24 $HASH_OPS
25 $VOBJS
26 );
27
28 $VERSION = '2.24';
29
30 ### install true symbol table aliases that can be localized
31 *QR_PRIVATE = *Template::Alloy::QR_PRIVATE;
32 *WHILE_MAX = *Template::Alloy::WHILE_MAX;
33 *MAX_EVAL_RECURSE = *Template::Alloy::MAX_EVAL_RECURSE;
34 *MAX_MACRO_RECURSE = *Template::Alloy::MAX_MACRO_RECURSE;
35 *STAT_TTL = *Template::Alloy::STAT_TTL;
36 *EXTRA_COMPILE_EXT = *Template::Alloy::EXTRA_COMPILE_EXT;
37 *PERL_COMPILE_EXT = *Template::Alloy::PERL_COMPILE_EXT;
38 *SCALAR_OPS = *Template::Alloy::SCALAR_OPS;
39 *FILTER_OPS = *Template::Alloy::FILTER_OPS;
40 *LIST_OPS = *Template::Alloy::LIST_OPS;
41 *HASH_OPS = *Template::Alloy::HASH_OPS;
42 *VOBJS = *Template::Alloy::VOBJS;
43
44 1;
45
46 __END__
47
48 =head1 SYNOPSIS
49
50 =head2 Template::Toolkit style usage
51
52 my $t = Template::Alloy->new(
53 INCLUDE_PATH => ['/path/to/templates'],
54 );
55
56 my $swap = {
57 key1 => 'val1',
58 key2 => 'val2',
59 code => sub { 42 },
60 hash => {a => 'b'},
61 };
62
63 # print to STDOUT
64 $t->process('my/template.tt', $swap)
65 || die $t->error;
66
67 # process into a variable
68 my $out = '';
69 $t->process('my/template.tt', $swap, \$out);
70
71 ### Alloy uses the same syntax and configuration as Template::Toolkit
72
73
74 =head2 HTML::Template::Expr style usage
75
76 my $t = Template::Alloy->new(
77 filename => 'my/template.ht',
78 path => ['/path/to/templates'],
79 );
80
81 my $swap = {
82 key1 => 'val1',
83 key2 => 'val2',
84 code => sub { 42 },
85 hash => {a => 'b'},
86 };
87
88 $t->param($swap);
89
90 # print to STDOUT (errors die)
91 $t->output(print_to => \*STDOUT);
92
93 # process into a variable
94 my $out = $t->output;
95
96 ### Alloy can also use the same syntax and configuration as HTML::Template
97
98 =head2 Text::Tmpl style usage
99
100 my $t = Template::Alloy->new;
101
102 my $swap = {
103 key1 => 'val1',
104 key2 => 'val2',
105 code => sub { 42 },
106 hash => {a => 'b'},
107 };
108
109 $t->set_delimiters('#[', ']#');
110 $t->set_strip(0);
111 $t->set_values($swap);
112 $t->set_dir('/path/to/templates');
113
114 my $out = $t->parse_file('my/template.tmpl');
115
116 my $str = "Foo #[echo $key1]# Bar";
117 my $out = $t->parse_string($str);
118
119
120 ### Alloy uses the same syntax and configuration as Text::Tmpl
121
122 =head2 Velocity (VTL) style usage
123
124 my $t = Template::Alloy->new;
125
126 my $swap = {
127 key1 => 'val1',
128 key2 => 'val2',
129 code => sub { 42 },
130 hash => {a => 'b'},
131 };
132
133 my $out = $t->merge('my/template.vtl', $swap);
134
135 my $str = "#set($foo 1 + 3) ($foo) ($bar) ($!baz)";
136 my $out = $t->merge(\$str, $swap);
137
138 =head1 DESCRIPTION
139
140 CGI::Ex::Template is the original base for the code that is now
141 Template::Alloy. Template::Alloy employed enough complexity and
142 featureset to warrant moving it out to a separate namespace.
143
144 CGI::Ex::Template is now a place holder subclass of Template::Alloy.
145 You can use CGI::Ex::Template as a standalone module - but it is
146 suggested that you use Template::Alloy directly instead.
147
148 For examples of usage, configuration, syntax, bugs, vmethods,
149 directives, etc please refer to the L<Template::Alloy> documentation.
150
151 =head1 LICENSE
152
153 This module may be distributed under the same terms as Perl itself.
154
155 =head1 AUTHOR
156
157 Paul Seamons <perl at seamons dot com>
158
159 =cut
This page took 0.039477 seconds and 4 git commands to generate.