line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package CGI::Application::Plugin::AnyTemplate::Driver::Petal; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::Petal - Petal plugin to AnyTemplate |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 DESCRIPTION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
This is a driver for L, which |
11
|
|
|
|
|
|
|
provides the implementation details specific to rendering templates via |
12
|
|
|
|
|
|
|
the L templating system. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
All C drivers are designed to be used the same way. For |
15
|
|
|
|
|
|
|
general usage instructions, see the documentation of |
16
|
|
|
|
|
|
|
L. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 EMBEDDED COMPONENT SYNTAX (Petal) |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
B |
21
|
|
|
|
|
|
|
B >> tags.> |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
var: |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
The C syntax for embedding components is: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
this text gets replaced by the output of some_run_mode |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
This can be overridden by the following configuration variables: |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
embed_tag_name # default 'CGIAPP' |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
For instance by setting the following values in your configuration file: |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
embed_tag_name 'MYAPP' |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Then the embedded component tag will look like: |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
this text gets replaced by the output of some_run_mode |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Note that when creating documents to be included as components, they |
48
|
|
|
|
|
|
|
must be complete XML documents. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=cut |
52
|
|
|
|
|
|
|
|
53
|
16
|
|
|
16
|
|
40450
|
use strict; |
|
16
|
|
|
|
|
37
|
|
|
16
|
|
|
|
|
696
|
|
54
|
16
|
|
|
16
|
|
90
|
use Carp; |
|
16
|
|
|
|
|
33
|
|
|
16
|
|
|
|
|
1262
|
|
55
|
|
|
|
|
|
|
|
56
|
16
|
|
|
16
|
|
101
|
use CGI::Application::Plugin::AnyTemplate::ComponentHandler; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
366
|
|
57
|
|
|
|
|
|
|
|
58
|
16
|
|
|
16
|
|
89
|
use CGI::Application::Plugin::AnyTemplate::Base; |
|
16
|
|
|
|
|
30
|
|
|
16
|
|
|
|
|
460
|
|
59
|
16
|
|
|
16
|
|
89
|
use vars qw(@ISA); |
|
16
|
|
|
|
|
35
|
|
|
16
|
|
|
|
|
8202
|
|
60
|
|
|
|
|
|
|
@ISA = ('CGI::Application::Plugin::AnyTemplate::Base'); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 CONFIGURATION |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
The L driver |
65
|
|
|
|
|
|
|
accepts the following config parameters: |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=over 4 |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=item embed_tag_name |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
The name of the tag used for embedding components. Defaults to |
72
|
|
|
|
|
|
|
C. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=item template_extension |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
If C is true, then |
77
|
|
|
|
|
|
|
L will append the value of |
78
|
|
|
|
|
|
|
C to C. By default |
79
|
|
|
|
|
|
|
the C is C<.xhtml>. |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item emulate_associate_query |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
B |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
If this config parameter is true, then L |
86
|
|
|
|
|
|
|
will copy all of the webapp's query params into the template. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
This is similar to what would happen if you used L's |
89
|
|
|
|
|
|
|
C feature with the webapp's query object: |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $driver = HTML::Template->new( |
92
|
|
|
|
|
|
|
associate => $self->query, |
93
|
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
By default C is false. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
All other configuration parameters are passed on unchanged to L. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub driver_config_keys { |
104
|
6
|
|
|
6
|
1
|
21
|
qw/ |
105
|
|
|
|
|
|
|
embed_tag_name |
106
|
|
|
|
|
|
|
template_extension |
107
|
|
|
|
|
|
|
emulate_associate_query |
108
|
|
|
|
|
|
|
/; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub default_driver_config { |
112
|
|
|
|
|
|
|
( |
113
|
6
|
|
|
6
|
1
|
35
|
template_extension => '.xhtml', |
114
|
|
|
|
|
|
|
embed_tag_name => 'CGIAPP', |
115
|
|
|
|
|
|
|
emulate_associate_query => 0, |
116
|
|
|
|
|
|
|
); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 required_modules |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
The C function returns the modules required for this driver |
122
|
|
|
|
|
|
|
to operate. In this case: C. |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=cut |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub required_modules { |
127
|
16
|
|
|
16
|
1
|
1824
|
return qw( |
128
|
|
|
|
|
|
|
Petal |
129
|
|
|
|
|
|
|
); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 DRIVER METHODS |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=over 4 |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item initialize |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Initializes the L driver. See the docs for |
139
|
|
|
|
|
|
|
L for details. |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=cut |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# create the Petal object, |
144
|
|
|
|
|
|
|
# using: |
145
|
|
|
|
|
|
|
# $self->{'driver_config'} # config info |
146
|
|
|
|
|
|
|
# $self->{'include_paths'} # the paths to search for the template file |
147
|
|
|
|
|
|
|
# $self->filename # the template file |
148
|
|
|
|
|
|
|
sub initialize { |
149
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
$self->_require_prerequisite_modules; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# TODO: check out how Petal caching works |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my %config = %{ $self->{'native_config'}}; |
|
0
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$config{'base_dir'} = $self->{'include_paths'}; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my $filename = $self->filename; |
159
|
0
|
|
|
|
|
|
my $string_ref = $self->string_ref; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
my $driver; |
163
|
0
|
0
|
|
|
|
|
if ($filename) { |
|
|
0
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$config{'file'} = $filename; |
165
|
0
|
|
|
|
|
|
$driver = Petal->new(%config); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
elsif ($string_ref) { |
168
|
0
|
|
|
|
|
|
croak "Petal: creating templates from strings is not supported in Petal"; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
else { |
171
|
0
|
|
|
|
|
|
croak "Petal: either file or string must be specified"; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
0
|
|
|
|
|
|
$self->{'driver'} = $driver; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=item render_template |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
Fills the L object with C<< $self->param >> |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
If the param C is true, then set params for each of |
184
|
|
|
|
|
|
|
$self->{'webapp'}->query, mimicking L's associate |
185
|
|
|
|
|
|
|
mechanism. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Also set up a L |
188
|
|
|
|
|
|
|
object so that the C callback will work. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Returns the output of the filled template as a string reference. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
See the docs for L for details. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=back |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
sub render_template { |
199
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
200
|
|
|
|
|
|
|
|
201
|
0
|
|
|
|
|
|
my $driver_config = $self->{'driver_config'}; |
202
|
|
|
|
|
|
|
|
203
|
0
|
|
|
|
|
|
my $template = $self->{'driver'}; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
# emulate HTML::Template's 'associate' behaviour |
206
|
0
|
0
|
|
|
|
|
if ($driver_config->{'emulate_associate_query'}) { |
207
|
0
|
|
|
|
|
|
my $params = $self->get_param_hash; |
208
|
0
|
0
|
|
|
|
|
if ($self->{'webapp'}) { |
209
|
0
|
|
|
|
|
|
foreach ($self->{'webapp'}->query->param) { |
210
|
0
|
|
0
|
|
|
|
$params->{$_} ||= $self->{'webapp'}->query->param($_); |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
} |
213
|
|
|
|
|
|
|
} |
214
|
|
|
|
|
|
|
|
215
|
0
|
|
|
|
|
|
my $component_handler = $self->{'component_handler_class'}->new( |
216
|
|
|
|
|
|
|
'webapp' => $self->{'webapp'}, |
217
|
|
|
|
|
|
|
'containing_template' => $self, |
218
|
|
|
|
|
|
|
); |
219
|
|
|
|
|
|
|
|
220
|
0
|
|
|
|
|
|
my $params = $self->get_param_hash; |
221
|
0
|
|
|
|
|
|
$params->{$driver_config->{'embed_tag_name'}} = $component_handler; |
222
|
|
|
|
|
|
|
|
223
|
0
|
|
|
|
|
|
my $output = $template->process($params); |
224
|
0
|
|
|
|
|
|
return \$output; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
=head1 SEE ALSO |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate |
230
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Base |
231
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::ComponentHandler |
232
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate |
233
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr |
234
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable |
235
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit |
236
|
|
|
|
|
|
|
CGI::Application::Plugin::AnyTemplate::Driver::Petal |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
CGI::Application |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
Template::Toolkit |
241
|
|
|
|
|
|
|
HTML::Template |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
HTML::Template::Pluggable |
244
|
|
|
|
|
|
|
HTML::Template::Plugin::Dot |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Petal |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Exporter::Renaming |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
CGI::Application::Plugin::TT |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=head1 AUTHOR |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
Michael Graham, C<< >> |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
Copyright 2005 Michael Graham, All Rights Reserved. |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
263
|
|
|
|
|
|
|
under the same terms as Perl itself. |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
=cut |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
1; |
268
|
|
|
|
|
|
|
|
269
|
|
|
|
|
|
|
|