| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | =head1 NAME | 
| 4 |  |  |  |  |  |  |  | 
| 5 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable - HTML::Template::Pluggable driver to AnyTemplate | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # Load Pluggable and your plugins before using this driver. | 
| 10 |  |  |  |  |  |  | use HTML::Template::Pluggable; | 
| 11 |  |  |  |  |  |  | use HTML::Template::Plugin::Dot; | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | This is a driver for L, which | 
| 16 |  |  |  |  |  |  | provides the implementation details specific to rendering templates via | 
| 17 |  |  |  |  |  |  | the L templating system. | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | All C drivers are designed to be used the same way.  For | 
| 20 |  |  |  |  |  |  | general usage instructions, see the documentation of | 
| 21 |  |  |  |  |  |  | L. | 
| 22 |  |  |  |  |  |  |  | 
| 23 |  |  |  |  |  |  | =head1 EMBEDDED COMPONENT SYNTAX (HTML::Template::Pluggable) | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | =head2 Syntax | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | The L syntax for embedding components is: | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  |  | 
| 31 |  |  |  |  |  |  | This can be overridden by the following configuration variables: | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | embed_tag_name       # default 'cgiapp' | 
| 34 |  |  |  |  |  |  |  | 
| 35 |  |  |  |  |  |  | For instance by setting the following value in your configuration file: | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | embed_tag_name       '__acme' | 
| 38 |  |  |  |  |  |  |  | 
| 39 |  |  |  |  |  |  | Then the embedded component tag will look like: | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | The value of C must consist of numbers, letters and | 
| 44 |  |  |  |  |  |  | underscores (C<_>), and must not begin with a number. | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 19 |  |  | 19 |  | 47242 | use strict; | 
|  | 19 |  |  |  |  | 38 |  | 
|  | 19 |  |  |  |  | 701 |  | 
| 50 | 19 |  |  | 19 |  | 107 | use Carp; | 
|  | 19 |  |  |  |  | 39 |  | 
|  | 19 |  |  |  |  | 1302 |  | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 19 |  |  | 19 |  | 118 | use CGI::Application::Plugin::AnyTemplate::ComponentHandler; | 
|  | 19 |  |  |  |  | 40 |  | 
|  | 19 |  |  |  |  | 428 |  | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 19 |  |  | 19 |  | 110 | use CGI::Application::Plugin::AnyTemplate::Base; | 
|  | 19 |  |  |  |  | 41 |  | 
|  | 19 |  |  |  |  | 513 |  | 
| 55 | 19 |  |  | 19 |  | 99 | use vars qw(@ISA); | 
|  | 19 |  |  |  |  | 41 |  | 
|  | 19 |  |  |  |  | 16188 |  | 
| 56 |  |  |  |  |  |  | @ISA = ('CGI::Application::Plugin::AnyTemplate::Base'); | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =head1 CONFIGURATION | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | The L driver | 
| 61 |  |  |  |  |  |  | accepts the following config parameters: | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =over 4 | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =item embed_tag_name | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | The name of the tag used for embedding components.  Defaults to | 
| 68 |  |  |  |  |  |  | C. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =item template_extension | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | If C is true, then | 
| 73 |  |  |  |  |  |  | L will append the value of | 
| 74 |  |  |  |  |  |  | C to C.  By default | 
| 75 |  |  |  |  |  |  | the C is C<.html>. | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =item associate_query | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | B | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | If this config parameter is true, then | 
| 82 |  |  |  |  |  |  | L will | 
| 83 |  |  |  |  |  |  | copy all of the webapp's query params into the template using | 
| 84 |  |  |  |  |  |  | L's C mechanism: | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | my $driver = HTML::Template::Pluggable->new( | 
| 87 |  |  |  |  |  |  | associate => $self->query, | 
| 88 |  |  |  |  |  |  | ); | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | By default C is false. | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | If you provide an C config parameter of your own, that will | 
| 93 |  |  |  |  |  |  | disable the C functionality. | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | =back | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | All other configuration parameters are passed on unchanged to L. | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =cut | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | sub driver_config_keys { | 
| 102 | 20 |  |  | 20 | 1 | 74 | qw/ | 
| 103 |  |  |  |  |  |  | embed_tag_name | 
| 104 |  |  |  |  |  |  | template_extension | 
| 105 |  |  |  |  |  |  | associate_query | 
| 106 |  |  |  |  |  |  | /; | 
| 107 |  |  |  |  |  |  | } | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | sub default_driver_config { | 
| 110 |  |  |  |  |  |  | ( | 
| 111 | 20 |  |  | 20 | 1 | 120 | template_extension => '.html', | 
| 112 |  |  |  |  |  |  | embed_tag_name     => 'cgiapp', | 
| 113 |  |  |  |  |  |  | associate_query    => 0, | 
| 114 |  |  |  |  |  |  | ); | 
| 115 |  |  |  |  |  |  | } | 
| 116 |  |  |  |  |  |  |  | 
| 117 |  |  |  |  |  |  | =head2 required_modules | 
| 118 |  |  |  |  |  |  |  | 
| 119 |  |  |  |  |  |  | The C function returns the modules required for this driver | 
| 120 |  |  |  |  |  |  | to operate.  In this case: L. | 
| 121 |  |  |  |  |  |  |  | 
| 122 |  |  |  |  |  |  | =cut | 
| 123 |  |  |  |  |  |  |  | 
| 124 |  |  |  |  |  |  | sub required_modules { | 
| 125 | 19 |  |  | 19 | 1 | 8297 | return qw( | 
| 126 |  |  |  |  |  |  | HTML::Template | 
| 127 |  |  |  |  |  |  | HTML::Template::Pluggable | 
| 128 |  |  |  |  |  |  | HTML::Template::Plugin::Dot | 
| 129 |  |  |  |  |  |  | ); | 
| 130 |  |  |  |  |  |  | } | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  |  | 
| 133 |  |  |  |  |  |  | =head1 DRIVER METHODS | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | =over 4 | 
| 136 |  |  |  |  |  |  |  | 
| 137 |  |  |  |  |  |  | =item initialize | 
| 138 |  |  |  |  |  |  |  | 
| 139 |  |  |  |  |  |  | Initializes the C driver.  See the docs for | 
| 140 |  |  |  |  |  |  | C for details. | 
| 141 |  |  |  |  |  |  |  | 
| 142 |  |  |  |  |  |  | =cut | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | # create the HTML::Template object, | 
| 145 |  |  |  |  |  |  | # using: | 
| 146 |  |  |  |  |  |  | #   $self->{'driver_config'}  # config info | 
| 147 |  |  |  |  |  |  | #   $self->{'include_paths'}  # the paths to search for the template file | 
| 148 |  |  |  |  |  |  | #   $self->filename           # the template file | 
| 149 |  |  |  |  |  |  | #   $self->string_ref         # ...or the template string | 
| 150 |  |  |  |  |  |  | #   $self->{'webapp'}->query  # for HTML::Template's 'associate' method, | 
| 151 |  |  |  |  |  |  | #                             # so that the query params are included | 
| 152 |  |  |  |  |  |  | #                             # in the template output | 
| 153 |  |  |  |  |  |  | sub initialize { | 
| 154 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 155 |  |  |  |  |  |  |  | 
| 156 | 0 |  |  |  |  |  | $self->_require_prerequisite_modules; | 
| 157 |  |  |  |  |  |  |  | 
| 158 | 0 |  |  |  |  |  | my $string_ref = $self->string_ref; | 
| 159 | 0 |  |  |  |  |  | my $filename   = $self->filename; | 
| 160 |  |  |  |  |  |  |  | 
| 161 | 0 | 0 | 0 |  |  |  | $string_ref or $filename or croak "HTML::Template::Pluggable: file or string must be specified"; | 
| 162 |  |  |  |  |  |  |  | 
| 163 | 0 | 0 |  |  |  |  | my $query    = $self->{'webapp'}->query or croak "HTML::Template::Pluggable webapp query not found"; | 
| 164 |  |  |  |  |  |  |  | 
| 165 | 0 |  |  |  |  |  | my %params = ( | 
| 166 | 0 |  |  |  |  |  | %{ $self->{'native_config'} }, | 
| 167 |  |  |  |  |  |  | path      => $self->{'include_paths'}, | 
| 168 |  |  |  |  |  |  | ); | 
| 169 |  |  |  |  |  |  |  | 
| 170 | 0 | 0 |  |  |  |  | if ($filename) { | 
| 171 | 0 |  |  |  |  |  | $params{'filename'} = $filename; | 
| 172 |  |  |  |  |  |  | } | 
| 173 | 0 | 0 |  |  |  |  | if ($string_ref) { | 
| 174 | 0 |  |  |  |  |  | $params{'scalarref'} = $string_ref; | 
| 175 |  |  |  |  |  |  | } | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 0 | 0 |  |  |  |  | if ($self->{'driver_config'}{'associate_query'}) { | 
| 178 | 0 |  | 0 |  |  |  | $params{'associate'} ||= $query;  # allow user to override associate with their own | 
| 179 |  |  |  |  |  |  | } | 
| 180 |  |  |  |  |  |  |  | 
| 181 | 0 |  |  |  |  |  | $self->{'driver'} = HTML::Template::Pluggable->new(%params); | 
| 182 |  |  |  |  |  |  |  | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  |  | 
| 186 |  |  |  |  |  |  | # If we have already called output, then any stored params have already | 
| 187 |  |  |  |  |  |  | # been stored in the driver.  So when the user calls clear_params on the | 
| 188 |  |  |  |  |  |  | # AT object, we have to call clear_params on the driver as well. | 
| 189 |  |  |  |  |  |  |  | 
| 190 |  |  |  |  |  |  | sub clear_params { | 
| 191 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 192 |  |  |  |  |  |  |  | 
| 193 | 0 | 0 |  |  |  |  | if ($self->{'driver'}) { | 
| 194 | 0 |  |  |  |  |  | $self->{'driver'}->clear_params; | 
| 195 |  |  |  |  |  |  | } | 
| 196 | 0 |  |  |  |  |  | $self->SUPER::clear_params; | 
| 197 |  |  |  |  |  |  | } | 
| 198 |  |  |  |  |  |  |  | 
| 199 |  |  |  |  |  |  | =item render_template | 
| 200 |  |  |  |  |  |  |  | 
| 201 |  |  |  |  |  |  | Fills the C object with C<< $self->param >> | 
| 202 |  |  |  |  |  |  | replacing any magic C<*embed*> tags with the content generated by the | 
| 203 |  |  |  |  |  |  | appropriate runmodes. | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | Returns the output of the filled template as a string reference. | 
| 206 |  |  |  |  |  |  |  | 
| 207 |  |  |  |  |  |  | See the docs for C for details. | 
| 208 |  |  |  |  |  |  |  | 
| 209 |  |  |  |  |  |  | =back | 
| 210 |  |  |  |  |  |  |  | 
| 211 |  |  |  |  |  |  | =cut | 
| 212 |  |  |  |  |  |  |  | 
| 213 |  |  |  |  |  |  | sub render_template { | 
| 214 | 0 |  |  | 0 | 1 |  | my $self = shift; | 
| 215 |  |  |  |  |  |  |  | 
| 216 | 0 |  |  |  |  |  | my $driver_config = $self->{'driver_config'}; | 
| 217 |  |  |  |  |  |  |  | 
| 218 | 0 |  |  |  |  |  | my $component_handler = $self->{'component_handler_class'}->new( | 
| 219 |  |  |  |  |  |  | 'webapp'              => $self->{'webapp'}, | 
| 220 |  |  |  |  |  |  | 'containing_template' => $self, | 
| 221 |  |  |  |  |  |  | ); | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | # fill the template | 
| 224 | 0 |  |  |  |  |  | my $template = $self->{'driver'}; | 
| 225 |  |  |  |  |  |  |  | 
| 226 | 0 |  |  |  |  |  | my $params = $self->get_param_hash; | 
| 227 |  |  |  |  |  |  |  | 
| 228 |  |  |  |  |  |  | # Have to set initial params before the 'cgiapp' embed handler param | 
| 229 | 0 |  |  |  |  |  | $template->param(%$params); | 
| 230 |  |  |  |  |  |  |  | 
| 231 |  |  |  |  |  |  | # Only add the 'cgiapp' embed handler param if it exists in the template | 
| 232 | 0 |  |  |  |  |  | foreach my $tag ($template->query) { | 
| 233 | 0 | 0 |  |  |  |  | if ($tag =~ /^$driver_config->{'embed_tag_name'}\.(?:embed)|(?:dispatch)/) { | 
| 234 | 0 |  |  |  |  |  | $template->param($driver_config->{'embed_tag_name'} => $component_handler); | 
| 235 | 0 |  |  |  |  |  | last; | 
| 236 |  |  |  |  |  |  | } | 
| 237 |  |  |  |  |  |  | } | 
| 238 |  |  |  |  |  |  |  | 
| 239 | 0 |  |  |  |  |  | my $output = $template->output; | 
| 240 | 0 |  |  |  |  |  | return \$output; | 
| 241 |  |  |  |  |  |  | } | 
| 242 |  |  |  |  |  |  |  | 
| 243 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 244 |  |  |  |  |  |  |  | 
| 245 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate | 
| 246 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Base | 
| 247 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::ComponentHandler | 
| 248 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate | 
| 249 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr | 
| 250 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit | 
| 251 |  |  |  |  |  |  | CGI::Application::Plugin::AnyTemplate::Driver::Petal | 
| 252 |  |  |  |  |  |  |  | 
| 253 |  |  |  |  |  |  | CGI::Application | 
| 254 |  |  |  |  |  |  |  | 
| 255 |  |  |  |  |  |  | Template::Toolkit | 
| 256 |  |  |  |  |  |  | HTML::Template | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | HTML::Template::Pluggable | 
| 259 |  |  |  |  |  |  | HTML::Template::Plugin::Dot | 
| 260 |  |  |  |  |  |  |  | 
| 261 |  |  |  |  |  |  | Petal | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  | Exporter::Renaming | 
| 264 |  |  |  |  |  |  |  | 
| 265 |  |  |  |  |  |  | CGI::Application::Plugin::TT | 
| 266 |  |  |  |  |  |  |  | 
| 267 |  |  |  |  |  |  |  | 
| 268 |  |  |  |  |  |  | =head1 AUTHOR | 
| 269 |  |  |  |  |  |  |  | 
| 270 |  |  |  |  |  |  | Michael Graham, C<<  >> | 
| 271 |  |  |  |  |  |  |  | 
| 272 |  |  |  |  |  |  | =head1 COPYRIGHT & LICENSE | 
| 273 |  |  |  |  |  |  |  | 
| 274 |  |  |  |  |  |  | Copyright 2005 Michael Graham, All Rights Reserved. | 
| 275 |  |  |  |  |  |  |  | 
| 276 |  |  |  |  |  |  | This program is free software; you can redistribute it and/or modify it | 
| 277 |  |  |  |  |  |  | under the same terms as Perl itself. | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | =cut | 
| 280 |  |  |  |  |  |  |  | 
| 281 |  |  |  |  |  |  | 1; |