CGI-Application-Plugin-AnyTemplate-0.18000755001750001750 011266661317 20162 5ustar00michaelmichael000000000000TODO000444001750001750 100511266661317 20724 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18 TODO - TT driver should die with Template->error if $driver = Template->new(\%config) fails - [under debate] allow native syntax for include paths to also work in addition to the include_paths param - improve handling of config params (avoid copious copying of hashes) - possibly remove dependency on Clone - emulate creating template from string in Petal (or possibly support Template::TAL) - CPAN installer that lets you pick your template driver(s) - find out how to make subclassing of CAP::AT possible Build.PL000555001750001750 201411266661317 21534 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18use strict; use warnings; use Module::Build; my $builder = Module::Build->new( module_name => 'CGI::Application::Plugin::AnyTemplate', license => 'perl', dist_author => 'Michael Graham ', dist_version_from => 'lib/CGI/Application/Plugin/AnyTemplate.pm', requires => { 'Test::More' => 0, 'Clone' => 0, 'Scalar::Util' => 0, 'CGI::Application' => 0, # We know that CGI::App requires HTML::Template # so we will have at least one templating system # installed 'CGI::Application::Plugin::Forward' => 0, }, meta_add => { no_index => { directory => [ qw/ misc t /] } }, add_to_cleanup => [ 'CGI-Application-Plugin-AnyTemplate-*' ], create_makefile_pl => 'traditional', ); $builder->create_build_script(); MANIFEST.SKIP000555001750001750 17711266661317 22126 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18^_build ^Build$ ^blib ~$ \.cvsignore$ ^\.git \.bak$ CVS ^cover_db ^readme.txt$ ^changes.txt$ ^[^/]*\.html$ \.gz$ \.tar$ \.sw.$ Makefile.PL000444001750001750 122711266661317 22214 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18# Note: this file was auto-generated by Module::Build::Compat version 0.35 use ExtUtils::MakeMaker; WriteMakefile ( 'NAME' => 'CGI::Application::Plugin::AnyTemplate', 'VERSION_FROM' => 'lib/CGI/Application/Plugin/AnyTemplate.pm', 'PREREQ_PM' => { 'CGI::Application' => 0, 'CGI::Application::Plugin::Forward' => 0, 'Clone' => 0, 'Scalar::Util' => 0, 'Test::More' => 0 }, 'INSTALLDIRS' => 'site', 'EXE_FILES' => [], 'PL_FILES' => {} ) ; README000444001750001750 11453511266661317 21171 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18NAME CGI::Application::Plugin::AnyTemplate - Use any templating system from within CGI::Application using a unified interface VERSION Version 0.18 SYNOPSIS In your CGI::Application-based webapp: use base 'CGI::Application'; use CGI::Application::Plugin::AnyTemplate; sub cgiapp_init { my $self = shift; # Set template options $self->template->config( default_type => 'TemplateToolkit', ); } Later on, in a runmode: sub my_runmode { my $self = shift; my %template_params = ( name => 'Winston Churchill', age => 7, ); $self->template->fill('some_template', \%template_params); } DESCRIPTION Template-Independence "CGI::Application::Plugin::AnyTemplate" allows you to use any supported Perl templating system using a single consistent interface. Currently supported templating systems include HTML::Template, HTML::Template::Expr, HTML::Template::Pluggable, Template::Toolkit and Petal. You can access any of these templating systems using the same interface. In this way, you can use the same code and switch templating systems on the fly. This approach has many uses. For instance, it can be useful in migrating your application from one templating system to another. Embedded Components In addition to template abstraction, "AnyTemplate" also provides a *embedded component mechanism*. For instance, you might include a *header* component at the top of every page and a *footer* component at the bottom of every page. These components are actually full CGI::Application run modes, and can do anything normal run mode can do, including processing form parameters and filling in their own templates. See below under "EMBEDDED COMPONENTS" for details. Multiple Named Template Configurations You can set up multiple named template configurations and select between them at run time. sub cgiapp_init { my $self = shift; # Can't use Template::Toolkit any more - # The boss wants everything has to be XML, # so we switch to Petal # Set old-style template options (legacy scripts) $self->template('oldstyle')->config( default_type => 'TemplateToolkit', TemplateToolkit => { POST_CHOMP => 1, } ); # Set new-style template options as default $self->template->config( default_type => 'Petal', auto_add_template_extension => 0, ); } sub old_style_runmode { my $self = shift; # ... # use TemplateToolkit to fill template edit_user.tmpl $self->template('oldstyle')->fill('edit_user', \%params); } sub new_style_runmode { my $self = shift; # ... # use Petal to fill template edit_user.xhml $self->template->fill('edit_user.xhtml', \%params); } Flexible Syntax The syntax is pretty flexible. Pick a style that's most comfortable for you. CGI::Application::Plugin::TT style syntax $self->template->process('edit_user', \%params); or (with slightly less typing): $self->template->fill('edit_user', \%params); CGI::Application load_tmpl style syntax my $template = $self->template->load('edit_user'); $template->param('foo' => 'bar'); $template->output; Verbose syntax (for complete control) my $template = $self->template('named_config')->load( file => 'edit_user' type => 'TemplateToolkit' add_include_paths => '.', ); $template->param('foo' => 'bar'); $template->output; See also below under "CHANGING THE NAME OF THE 'template' METHOD". METHODS config Initialize the "AnyTemplate" system and provide the default configuration. $self->template->config( default_type => 'HTMLTemplate', ); You can keep multiple configurations handy at the same time by passing a value to "template": $self->template('oldstyle')->config( default_type => 'HTML::Template', ); $self->template('newstyle')->config( default_type => 'HTML::Template::Expr', ); Then in a runmode you can mix and match configurations: $self->template('oldstyle')->load # loads an HTML::Template driver object $self->template('newstyle')->load # loads an HTML::Template::Expr driver object The configuration passed to "config" is divided into three areas: *plugin configuration*, *driver configuration*, and *native configuration*: Config Type What it Configures ----------- ------------------ Plugin Config AnyTemplate itself Driver Config AnyTemplate Driver (e.g. HTMLTemplate) Native Config Actual template module (e.g. HTML::Template) These are described in more detail below. Plugin Configuration These configuration params are specific to the "CGI::Application::Plugin::AnyTemplate" itself. They are included at the top level of the configuration hash passed to "config". For instance: $self->template->config( default_type => 'HTMLTemplate', auto_add_template_extension => 0, ); The *plugin configuration* parameters and their defaults are as follows: default_type type The default type of template for this named configuration. Should be the name of a driver in the "CGI::Application::Plugin::AnyTemplate::Driver" namespace: Type Driver ---- ------ HTMLTemplate CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate HTMLTemplateExpr CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr TemplateToolkit CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit Petal CGI::Application::Plugin::AnyTemplate::Driver::Petal include_paths Include Paths (sometimes called search paths) are used by the various template backends to find filenames that aren't fully qualified by an absolute path. Each directory is searched in turn until the template file is found. Can be a single string or a reference to a list. auto_add_template_extension Add a template-system specific extension to template filenames. So, if this feature is enabled and you provide the filename "myfile", then the actual filename will depend on the current template driver: Driver Template ------ -------- HTMLTemplate myfile.html HTMLTemplateExpr myfile.html TemplateToolkit myfile.tmpl Petal myfile.xhtml The per-type extension is controlled by the driver config for each "AnyTemplate" driver (see below under "Driver and Native Configuration" for how to set this). The "auto_add_template_extension" feature is on by default. To disable it, pass a value of zero: $self->template->config( auto_add_template_extension => 0, ); The automatic extension feature is not just there to save typing - it's actually there so you can have templates of different types sitting in the same directory. sub my_runmode { my $self = shift; $self->template->fill; } Then in your template path you can have three files: my_runmode.html my_runmode.tmpl my_runmode.xhtml Then you can change which templates is used by changing the value of "type" that you pass to "$self->template->config". For applications that want to dynamically choose their template system without changing app code, it's a cleaner solution to use the extensions than trying to swap template paths at runtime. Even if you keep each type of template in its own directory, it's simpler to include all the directories all the time and use different extensions for different template types. template_filename_generator If you don't pass a filename to "load", one will be generated for you based on the current run mode. If you want to customize this process, you can pass a reference to a subroutine to do the translation. This subroutine will be passed a reference to the CGI::Application $self object. Here is a subroutine that emulates the built-in behaviour of "AnyTemplate": $self->template->config( template_filename_generator => sub { my ($self, $calling_method_name) = @_; return $self->get_current_runmode; } } ); Here is an example of using a template filename generator to make full templates with full paths based on the module name as well as the current run mode (this is similar to how CGI::Application::Plugin::TT generates its template filenames): package My::WebApp; use File::Spec; sub cgiapp_init { my $self = shift; $self->template->config( template_filename_generator => sub { my $self = shift; my $run_mode = $self->get_current_runmode; my $module = ref $self; my @segments = split /::/, $module; return File::Spec->catfile(@segments, $run_mode); } ); } sub run_mode { my $self = shift; $self->template->load; # loads My/WebApp/run_mode.html } sub other_run_mode { my $self = shift; $self->template->load; # loads My/WebApp/other_run_mode.html } Note that if the "auto_add_template_extension" option is on (which it is by default), then the extension will be added to your generated filename after you return it. If you do not want this to happen, then set "auto_add_template_extension" to a false value. component_handler_class Normally, component embedding is handled by CGI::Application::Plugin::AnyTemplate::ComponentHandler. If you want to use a different class for this purpose, specify the class name as the value of this paramter. It still has to provide the same interface as CGI::Application::Plugin::AnyTemplate::ComponentHandler. See the source code of that module for details. return_references When true (the default), "output" will return a reference to a string rather than a copy. Normally this won't matter. For instance, "CGI::Application" doesn't care whether you return a string or a reference to a string from your run modes. However, if you want to manipulate the output of the $html returned from the template, you may find it convenient to make "output" return a string instead of a reference. Especially if you are converting old code based on HTML::Template which expects "output" to return a string. Driver and Native Configuration You can configure all the drivers at once with a single call to "config", by including subsections for each driver type: $self->template->config( default_type => 'HTMLTemplate', HTMLTemplate => { cache => 1, global_vars => 1, die_on_bad_params => 0, template_extension => '.html', }, HTMLTemplateExpr => { cache => 1, global_vars => 1, die_on_bad_params => 0, template_extension => '.html', }, HTMLTemplatePluggable => { cache => 1, global_vars => 1, die_on_bad_params => 0, template_extension => '.html', }, TemplateToolkit => { POST_CHOMP => 1, template_extension => '.tmpl', }, Petal => { error_on_undef => 0, template_extension => '.xhtml', }, ); Each driver knows how to separate its own configuration from the configuration belonging to the underlying template system. For instance in the example above, the "HTMLTemplate" driver knows that "template_extension" is a driver config parameter, but "cache_global_vars" and "die_on_bad_params" are all HTML::Template configuration parameters. Similarly, The "TemplateToolkit" driver knows that template_extension is a driver config parameter, but "POST_CHOMP" is a "Template::Toolkit" configuration parameter. For details on driver configuration, see the docs for the individual drivers: CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit CGI::Application::Plugin::AnyTemplate::Driver::Petal Copying Query data into Templates This feature is now deprecated and will be removed in a future release. When you enable this feature all data in "$self->query" are copied into the template object before the template is processed. For the "HTMLTemplate", "HTMLTemplateExpr" and "HTMLTemplatePluggable" drivers this is done with the "associate" feature of HTML::Template and HTML::Template::Expr, respectively: my $template = HTML::Template->new( associate => $self->query, ); For the other systems, this feature is emulated, by copying the query params into the template params before the template is processed. To enable this feature, pass a true value to "associate_query" or "emulate_associate_query" (depending on the template system): $self->template->config( default_type => 'HTMLTemplate', HTMLTemplate => { associate_query => 1, }, HTMLTemplateExpr => { associate_query => 1, }, HTMLTemplatePluggable => { associate_query => 1, }, TemplateToolkit => { emulate_associate_query => 1, }, Petal => { emulate_associate_query => 1, }, ); The reason this feature is now disabled by default is that it poses a potential XSS (Cross Site Scripting) security risk. The reason this feature is now deprecated is that in an ideal world developers shouldn't have to flatten objects and hashes in order to make them available to their templates. They should be able to pass the query object (or another object such as a config object) directly into the template: $template->param( 'query' => $self->query, 'cfg' => $self->cfg, 'ENV' => $ENV, ); And in the template retrieve parameters directly: your username: [% query.param('username') %] administrator: [% cfg.admin %] hostname: [% ENV.SERVER_NAME %] This approach works with Template::Toolkit, Petal, and HTML::Template::Pluggable (via the HTML::Template::Plugin::Dot plugin). Note that "associate" and "associate_query" are not compatible. So if you want to associate the query and an additional object, pass a list to "associate": $template->config( HTMLTemplate => { associate => [$self->query, $self->conf] } ); load Create a new template object and configure it. This can be as simple (and magical) as: my $template = $self->template->load; When you call "load" with no parameters, it uses the default template type, the default template configuration, and it determines the name of the template based on the name of the current run mode. It determines the current run mode by calling "$self->get_current_runmode". If you want to have the current runmode updated when you pass control to another runmode, use the CGI::Application::Plugin::Forward module: use CGI::Application::Plugin::Forward; sub first_runmode { my $self = shift; return $self->forward('second_runmode'); } sub second_runmode { my $self = shift; my $template = $self->template->load; # loads 'second_runmode.html' } If instead you call "$self->other_method" directly, the value of "$self->get_current_runmode" will not be updated: sub first_runmode { my $self = shift; return $self->other_method; } sub other_method { my $self = shift; my $template = $self->template->load; # loads 'first_runmode.html' } If you want to override the way the default template filename is generated, you can do so with the "template_filename_generator" configuration parameter. If you call "load" with one paramter, it is taken to be either the filename or a reference to a string containing the template text: my $template = $self->template->load('somefile'); my $template = $self->template->load(\$some_text); If the parameter "auto_add_template_exension" is true, then the appropriate extension will be added for this template type. If you call "load" with more than one parameter, then you can specify filename and configuration paramters directly: my $template = $self->template->load( file => 'some_file.tmpl', type => 'HTMLTemplate', auto_add_template_extension => 0, add_include_paths => '..', HTMLTemplate => { die_on_bad_params => 1, }, ); To initialize the template from a string rather than a file, use: my $template = $self->template->load( string => \$some_text, ); The configuration parameters you pass to "load" are merged with the configuration that was passed to "config". You can include any of the configuration parameters that you can pass to config, plus the following extra parameters: file If you are loading the template from a file, then the "file" parameter contains the template's filename. string If you are loading the template from a string, then the "string" parameter contains the text of the template. It can be either a scalar or a reference to a scalar. Both of the following will work: # passing a string my $template = $self->template->load( string => $some_text, ); # passing a reference to a string my $template = $self->template->load( string => \$some_text, ); add_include_paths Additional include paths. These will be merged with "include_paths" before being passed to the template driver. The "load" method returns a template driver object. See below under "DRIVER METHODS", for how to use this object. fill Fill is a convenience method which in a single step creates the template, fills it with the template paramters and returns its output. You can call it with or without a filename (or string ref). The code: $self->template->fill('filename', \%params); is equivalent to: my $template = $self->template->load('filename'); $template->output(\%params); And the code: $self->template->fill(\$some_text, \%params); is equivalent to: my $template = $self->template->load(\$some_text); $template->output(\%params); And the code: $self->template->fill(\%params); is equivalent to: my $template = $self->template->load; $template->output(\%params); And the code: $self->template->fill('filename'); is equivalent to: my $template = $self->template->load('filename'); $template->output; And the code: $self->template->fill(\$some_text); is equivalent to: my $template = $self->template->load(\$some_text); $template->output; And the code: $self->template->fill; is equivalent to: my $template = $self->template->load; $template->output; process "process" is an alias for "fill". APPLICATION METHODS These methods are called directly on your application's $self object. load_tmpl This is an emulation of CGI::Application's built-in "load_tmpl" method. For instance: $self->load_tmpl('some_template.html'); It is not exported by default. To enable it, use: use CGI::Application::Plugin::AnyTemplate qw/:load_tmpl/; You can call it the same way as documented in "CGI::Application" and it will have the same effect. However, it will respect the current template "type", so you can still use it to fill templates of different backends. The idea is that you can take an existing CGI::Application-based webapp which uses "HTML::Template" templates, and add the following code to it: use CGI::Application::Plugin::AnyTemplate qw/:load_tmpl/; sub setup { my $self = shift; $self->template->config(type => TemplateToolkit); } This will change all existing calls to load_tmpl within your application to use Template::Toolkit based templates. Calling: my $template = $self->load_tmpl('some_template.html'); It is the equivalent of calling: my $template = $self->template->load( file => 'some_template.html', auto_add_template_extension => 0, ); If you add extra options to "load_tmpl", these will be assumed to be HTML::Template specific options, with the exception of the "path" option, which will be extracted and used as 'add_include_paths': my $template = $self->load_tmpl('some_template.html', cache => 0, path => '/path/to/templates', ); This will get translated into: my $template = $self->template->load( file => 'some_template.html', auto_add_template_extension => 0, add_include_paths => '/path/to/templates', HTMLTemplate => { cache => 0, } ); Note that if you specify any HTML::Template-specific options here, they will completely overwrite any options that you passed to config. Some notes and caveats about using the "load_tmpl" method: * This method only works for the default template configuration (i.e. "$self->template()"). If you set up a named configuration (e.g. "$self->template('myconfig')") there is no way to access it with "load_tmpl". Since plugins should be using named configurations, this means that the "load_tmpl" method should not be used by plugins. See "NOTES FOR AUTHORS OF PLUGINS AND REUSABLE APPLICATIONS", below. * The "load_tmpl" method does not automatically add an extension to the filename you pass to it, even if you have "auto_add_template_extension" set to a true value in your call to "$self->template->config". * The "load_tmpl" method ignores always returns a string, not a reference to a string. It ignores the setting of the "returns_references" option. tmpl_path You can set the template "include_paths" by calling "$self->tmpl_path('/path/to/templates')". You can also do so by passing a value to the "TMPL_PATH" parameter to your application's "new" method: my $webapp = App->new( TMPL_PATH => '/path/to/templates', ); Paths that you set via "tmpl_path"/"TMPL_PATH" will be put last in the list of include paths, after "add_include_paths" and "include_paths". DRIVER METHODS These are the most commonly used methods of the "AnyTemplate" driver object. The driver is what you get back from calling "$self->template->load". param The "param" method gets and sets values within the template. my $template = $self->template->load; my @param_names = $template->param(); my $value = $template->param('name'); $template->param('name' => 'value'); $template->param( 'name1' => 'value1', 'name2' => 'value2' ); It is designed to behave similarly to the "param" method in other modules like CGI and HTML::Template. get_param_hash Returns the template variables as a hash of names and values. my %params = $self->template->get_param_hash; In a scalar context, returns a reference to the hash used internally to contain the values: my $params_ref = $self->template->get_param_hash; $params_ref->{'foo'} = 'bar'; # directly change parameter 'foo' output Returns the template with all the values filled in. return $template->output; You can also supply names and values to the template at this stage: return $template->output('name' => 'value', 'name2' => 'value2'); If "return_references" option is set to true, then the return value of "output" will be a reference to a string. If the "return_references" option is false, then a copy of the string will be returned. By default "return_references" is true. When you call the "output" method, any components embedded in the template are run. See "EMBEDDED COMPONENTS", below. PRE- AND POST- PROCESS There are several ways to customize the template process. You can modify the template parameters before the template is filled, and you can modify the output of the template after it has been filled. Multiple applications and plugins can hook into the template process pipeline, each making changes to the template input and output. For instance, it will be possible to make a general-purpose "CGI::Application" plugin that adds arbitrary data to each new template (such as query parameters or configuration data). Note that the API has changed for version 0.10 in a non-backwards-compatible way in order to use the new hook system provided by recent versions of "CGI::Application". The load_tmpl hook The "load_tmpl" hook is designed to be compatible with the "load_tmpl" hook defined by "CGI::Application" itself. The "load_tmpl" hook is called before the template object is created. Any callbacks that you register to this hook will be called before each template is loaded. Register a "load_tmpl" callback with: $self->add_callback('load_tmpl',\&my_load_tmpl); When the "load_tmpl" callback is executed it will be passed three arguments (*adapted from the* CGI::Application *docs*): 1. A hash reference of the extra params passed into C (ignored by AnyTemplate with the exception of 'path') 2. Followed by a hash reference to template parameters. You can modify this hash by reference to affect values that are actually passed to the param() method of the template object. 3. The name of the template file. Here's an example stub for a load_tmpl() callback: sub my_load_tmpl_callback { my ($self, $ht_params, $tmpl_params, $tmpl_file) = @_; # modify $tmpl_params by reference... } Currently, of all the params in $ht_params, all but 'path' are ignored, because these are specific to "HTML::Template". If you want to write a generic callback that needs to be able to access or modify "HTML::Template" parameters then let me know, or add a feature request on . The "path" param of $ht_params is initially set to the value of "add_include_paths" (if set). Your callback can modify the "path" param, and "add_include_param" will be set to the result. Plugin authors who want to provide template processing features are encouraged to use the 'load_tmpl' hook when possible, since it will work both with AnyTemplate and with CGI::Application's built-in "load_tmpl". The template_pre_process and template_post_process hooks Before the template output is generated, the "template_pre_process" hook is called. Any callbacks that you register to this hook will be called before each template is processed. Register a "template_pre_process" callback as follows: $self->add_callback('template_pre_process', \&my_tmpl_pre_process); Pre-process callbacks will be passed a reference to the $template object, and can can modify the parameters passed into the template by using the "param" method: sub my_tmpl_pre_process { my ($self, $template) = @_; # Change the internal template parameters by reference my $params = $template->get_param_hash; foreach my $key (keys %$params) { $params{$key} = to_piglatin($params{$key}); } # Can also set values using the param method $template->param('foo', 'bar'); } After the template output is generated, the "template_post_process" hook is called. You can register a "template_post_process" callback as follows: $self->add_callback('template_post_process', \&my_tmpl_post_process); Any callbacks that you register to this hook will be called after each template is processed, and will be passed both a reference to the template object and a reference to the output generated by the template. This allows you to modify the output of the template: sub my_tmpl_post_process { my ($self, $template, $output_ref) = @_; $$output_ref =~ s/foo/bar/; } EMBEDDED COMPONENTS Introduction "CGI::Application::Plugin::AnyTemplate" allows you to include application components within your templates. For instance, you might include a *header* component a the top of every page and a *footer* component at the bottom of every page. These componenets are actually first-class run modes. When the template engine finds a special tag marking an embedded component, it passes control to the run mode of that name. That run mode can then do whatever a normal run mode could do. But typically it will load its own template and return the template's output. This output returned from the embedded run mode is inserted into the containing template. The syntax for embed components is specific to each type of template driver. Syntax HTML::Template syntax: HTML::Template::Expr syntax: HTML::Template::Pluggable syntax: Template::Toolkit syntax: [% CGIAPP.embed("some_run_mode") %] Petal syntax: this text gets replaced by the output of some_run_mode Getting Template Variables from the Containing Template The component run mode is passed a reference to the template object that contained the component. The component run mode can use this object to access the params that were passed to the containing template. For instance: sub header { my ($self, $containing_template, @other_params) = @_; my %tmplvars = ( 'title' => 'My glorious home page', ); my $template = $self->template->load; $template->param(%tmplvars, $containing_template->get_param_hash); return $template->output; } In this example, the template values of the enclosing template would override any values set by the embedded component. Passing Parameters The template can pass parameters to the target run mode. These are passed in after the reference to the containing template object. Parameters can either be literal strings, specified within the template text, or they can be keys that will be looked up in the template's params. Literal strings are enclosed in double or single quotes. Param keys are barewords. HTML::Template syntax: *Note that HTML::Template doesn't support this type of callback natively* *and that this behaviour is emulated by the HTMLTemplate driver* *see the docs to* CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate *for limitations to the emulation*. HTML::Template::Expr syntax: HTML::Template::Pluggable syntax: Template::Toolkit syntax: [% CGIAPP.embed("some_run_mode", param1, 'literal string2' ) %] Petal syntax: this text gets replaced by the output of some_run_mode NOTES FOR AUTHORS OF PLUGINS AND REUSABLE APPLICATIONS If you are writing a CGI::Application plugin module, or you are writing a "CGI::Application" program that will be distributed to other people (e.g. on CPAN), then it's important to take steps to prevent your application's use of CGI::Application::Plugin::AnyTemplate from conflicting with other plugins or with your end users. When a plugin that uses CGI::Application::Plugin::AnyTemplate calls: $self->template->config(...) It overwrites any existing template configuration with the new settings. So if two plugins do that, they probably clobber each other. However, CGI::Application::Plugin::AnyTemplate has the feature of named independent configs: $self->template('your_module')->config(...) $self->template('my_plugin')->config(...) These configs remain separate from each other. However, you have to keep using these names throughout your module, even when you load and fill the template. For instance: sub my_runmode { my $self = shift; my $template = $self->template('my_plugin')->load; $template->output; } sub your_runmode { my $self = shift; my %params; $self->template('your_module')->fill(\%params); } It's uglier and more verbose, but it also prevents plugins from stepping on each other's toes. CGI::Application plugins that use CGI::Application::Plugin::AnyTemplate should default to using their own package name for the AnyTemplate config name: $self->template(__PACKAGE__)->config(...); $self->template(__PACKAGE__)->fill(...); CHANGING THE NAME OF THE 'template' METHOD If you want to access the features of this module using a method other than "template", you can do so via Anno Siegel's Exporter::Renaming module (available on CPAN). For instance, to use syntax similar to CGI::Application::Plugin::TT: use Exporter::Renaming; use CGI::Application::Plugin::AnyTemplate Renaming => [ template => tt]; sub cgiapp_init { my $self = shift; my %params = ( ... ); # Set config file and other options $self->tt->config( default_type => 'TemplateToolkit', ); } sub my_runmode { my $self = shift; $self->tt->process('file', \%params); } And to use syntax similar to CGI::Application's "load_tmpl" mechanism: use Exporter::Renaming; use CGI::Application::Plugin::AnyTemplate Renaming => [ template => tmpl]; sub cgiapp_init { my $self = shift; # Set config file and other options $self->tmpl->config( default_type => 'HTMLTemplate', ); } sub my_runmode { my $self = shift; my %params = ( ... ); my $template = $self->tmpl->load('file'); $template->param(\%params); $template->output; } AUTHOR Michael Graham, "" ACKNOWLEDGEMENTS I originally wrote this to be a subsystem in Richard Dice's CGI::Application-based framework, before I moved it into its own module. Various ideas taken from CGI::Application (Jesse Erlbaum), CGI::Application::Plugin::TT (Cees Hek) and "Text::Boilerplate" (Stephen Nelson). "Template::Toolkit" singleton support code stolen from CGI::Application::Plugin::TT. BUGS Please report any bugs or feature requests to "bug-cgi-application-plugin-anytemplate@rt.cpan.org", or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. SOURCE The source code repository for this module can be found at http://github.com/mgraham/CAP-AnyTemplate/ SEE ALSO CGI::Application::Plugin::AnyTemplate::Base CGI::Application::Plugin::AnyTemplate::ComponentHandler CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit CGI::Application::Plugin::AnyTemplate::Driver::Petal CGI::Application Template::Toolkit HTML::Template HTML::Template::Pluggable HTML::Template::Plugin::Dot Petal Exporter::Renaming CGI::Application::Plugin::TT COPYRIGHT & LICENSE Copyright 2005 Michael Graham, All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. MANIFEST000444001750001750 725611266661317 21403 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18Build.PL Changes lib/CGI/Application/Plugin/AnyTemplate.pm lib/CGI/Application/Plugin/AnyTemplate/Base.pm lib/CGI/Application/Plugin/AnyTemplate/ComponentHandler.pm lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplate.pm lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplateExpr.pm lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplatePluggable.pm lib/CGI/Application/Plugin/AnyTemplate/Driver/Petal.pm lib/CGI/Application/Plugin/AnyTemplate/Driver/TemplateToolkit.pm Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml misc/dist misc/makedocs.pl misc/module-starter-opts.txt misc/prove-prereqs.pl misc/style.css README t/00.load.t t/01-simple.t t/02-explicit_filename.t t/03-named-configs.t t/04-fill_process.t t/05-fill_process_string.t t/06-embed.t t/07-dispatch_embed.t t/08-custom_component_handler_class.t t/09-embed_error.t t/10-associate.t t/11-pre_post_process_hooks.t t/12-load_tmpl_hook.t t/13-tt_obj_caching.t t/14-tt_obj_caching_include_paths.t t/15-template_string.t t/16-non-clobbering-config.t t/17-load_default_to_crm.t t/18-load_after_forward.t t/19-load_tmpl.t t/20-tmpl_path.t t/21-ht-dot.t t/22-return_references.t t/23-filename_generator.t t/24-tt_opts.t t/30-driver_errors.t t/31-exporter_renaming.t t/pod-coverage.t t/pod.t t/prereq_scenarios/missing_clone/Clone.pm t/prereq_scenarios/missing_clone_pp/Clone/PP.pm t/prereq_scenarios/old_cap_forward/CGI/Application/Plugin/Forward.pm t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTML/Template.pm t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTML/Template/Expr.pm t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTML/Template/Pluggable.pm t/prereq_scenarios/skip_ht+hte+htp+petal+template/Petal.pm t/prereq_scenarios/skip_ht+hte+htp+petal+template/Template.pm t/prereq_scenarios/skip_ht/HTML/Template.pm t/prereq_scenarios/skip_hte+htp+petal+tt/HTML/Template/Expr.pm t/prereq_scenarios/skip_hte+htp+petal+tt/HTML/Template/Pluggable.pm t/prereq_scenarios/skip_hte+htp+petal+tt/Petal.pm t/prereq_scenarios/skip_hte+htp+petal+tt/Template.pm t/prereq_scenarios/skip_hte/HTML/Template/Expr.pm t/prereq_scenarios/skip_htp/HTML/Template/Pluggable.pm t/prereq_scenarios/skip_petal/Petal.pm t/prereq_scenarios/skip_tt/Template.pm t/tlib/CGI/Application/Plugin/AnyTemplate/Driver/MyCAPATDriver1.pm t/tlib/CGI/Application/Plugin/AnyTemplate/Driver/MyCAPATDriver2.pm t/tmpl/blank.html t/tmpl/blank.tmpl t/tmpl/blank.xhtml t/tmpl/cache_incl_paths_outer.tmpl t/tmpl/dispatch_outer.html t/tmpl/dispatch_outer.html_expr t/tmpl/dispatch_outer.html_pluggable t/tmpl/dispatch_outer.tmpl t/tmpl/dispatch_outer.xhtml t/tmpl/embed_error1.html t/tmpl/embed_error2.html t/tmpl/embed_outer.html t/tmpl/embed_outer.html_expr t/tmpl/embed_outer.html_pluggable t/tmpl/embed_outer.tmpl t/tmpl/embed_outer.xhtml t/tmpl/htdot.html t/tmpl/My/Sample/WebApp/start.html t/tmpl/My/Sample/WebApp/start.tmpl t/tmpl/My/Sample/WebApp/start.xhtml t/tmpl/simple.html t/tmpl/simple.tmpl t/tmpl/simple.xhtml t/tmpl/some_old_nonsense.html t/tmpl/some_old_nonsense.tmpl t/tmpl/some_old_nonsense.xhtml t/tmpl/test.ext_HTMLTemplate t/tmpl/test.ext_Petal t/tmpl/test.ext_TemplateToolkit t/tmpl/test_template t/tmpl/wrapper.tmpl t/tmpl_include/cache_incl_paths_inner.tmpl t/tmpl_include/embed_inner1.html t/tmpl_include/embed_inner1.html_expr t/tmpl_include/embed_inner1.html_pluggable t/tmpl_include/embed_inner1.tmpl t/tmpl_include/embed_inner1.xhtml t/tmpl_include/embed_inner2.html t/tmpl_include/embed_inner2.html_expr t/tmpl_include/embed_inner2.html_pluggable t/tmpl_include/embed_inner2.tmpl t/tmpl_include/embed_inner2.xhtml t/tmpl_include/simple_elsewhere.html t/tmpl_include/simple_elsewhere.tmpl t/tmpl_include/simple_elsewhere.xhtml t/tmpl_include2/cache_incl_paths_inner.tmpl TODO Changes000555001750001750 2705411266661317 21566 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18Revision history for CGI-Application-Plugin-AnyTemplate 0.18 Oct 18, 2009 - Can now use Clone::PP if Clone is not installed. Thanks to Bianka Martinovic (RT #37999). Note that there doesn't appear to be a way to indicate to Module::Build that the module can use either Clone or Clone::PP - that it requires one (but not both) of them. So for now, Clone is still listed as a prerequisite. - updated Template::Toolkit driver docs to indicate how to use different encodings. Thanks to Shmuel Fomberg (RT #34791). - removed spurious call to $template->error on Petal templates. Thanks to William McKee (RT #20221). - Component handler now weakens reference to containing_template, in an attempt to avoid crazy memory usage. Thanks to Dan Horne (RT #18157). - Changes of interest to module maintainers only: - t/prereqs-scenarios is now included in the distribution. This is how I simulate the absense of specific modules when running the test suite. For instance, the user may have HTML::Template::Expr installed, but not HTML::Template::Pluggable. Or they may have Clone::PP installed, but not Clone. To test the various prerequisite scenarios, use the included prove-prereqs.pl script: ./misc/prove-prereqs.pl t/prereq_scenarios -Ilib t/ This runs the test suite several times. Each time it simulates a different set of unavailable modules. Adapted from the Perl Hacks book. - fixed the makedocs script to work with more recent pod2html - changed noindex to no_index in META.yml 0.17 Nov 07, 2005 - fixed storage of TT objects so that objects with different named configs don't trample each other (discovered by RA Jones) 0.16 Nov 03, 2005 - fixed fill() so that when it is called without parameters, it does not set the filename to undef. - changed skip_libs to prereq_scenarios (and removed the scenarios from the distribution) - added new scenario for old CAP::Forward 0.15 Oct 03, 2005 - include fix to work with old version of CAP::Forward that doesn't always install its hooks properly. 0.14 Sep 25, 2005 - added template_filename_generator - minor doc fix 0.13 Sep 14, 2005 - fixd bug where clear_params didn't work (Wojciech Pietron) - fixed typos in docs regarding include_paths and add_include_paths (Wojciech Pietron) - minor doc fix 0.12 Sep 13, 2005 - added return_references option, defaulting to true. - changed load_tmpl to always return a string, rather than a reference - added documentation indicating that output returns a reference by default 0.11 Sep 08, 2005 - fixed a bug fill/process when called with a single non-hashref argument. The following used to be broken; now they DWIM: $self->template->fill('filename'); $self->template->fill(\$template); - fixed a bug in template_post_process that has been there since the beginning. The callback was being called as: template_post_process($self, \$output) # wrong! But it was documented as: template_post_process($self, $template, \$output) # right! It's been fixed to match the documentation. 0.10 Aug 17, 2005 - This is a major new release with a lot of new features and some incompatible API changes. The new features are: * new driver (HTMLTemplatePluggable) has support for HTML::Template::Pluggable and HTML::Template::Plugin::Dot * AnyTemplate can now optionally provide a load_tmpl method like the one built into CGI::Application, so that old code can get the benefit of AnyTemplate. * added support for the load_tmpl hook * test suite should be less fragile for users who don't have all of the templating modules installed The incompatibilities are: * associate_query off by default * associate_query now deprecated * CAP::Forward now required * default template names determined from $self->current_runmode, not from the name of the calling sub * template_pre_process and template_post_process now need to be explicitly registered with $self->add_callback() * tmpl_path is respected - for more info on these changes see the changelog below for the developer versions released since 0.08 0.10_06 Aug 17, 2005 [**DEVELOPER RELEASE**] [unreleased] - added an explit test to see if HTML::Template::Plugin::Dot works 0.10_05 Aug 13, 2005 [**DEVELOPER RELEASE**] - fixed a bug in the tests for testing module prerequisites - it is now possible to run the test suite while simulating the absense of specific templating modules. To run the test suite multiple times (each with a different selection of absent modules), run: $ perl misc/prove_without_modules.pl t/*.t To customize this process, see the instructions at the top of misc/prove_without_modules.pl 0.10_04 Aug 13, 2005 [**DEVELOPER RELEASE**] - new driver HTMLTemplatePluggable has support for HTML::Template::Pluggable and HTML::Template::Plugin::Dot (thanks to Mark Stosberg for starting the driver) 0.10_03 July 27, 2005 [**DEVELOPER RELEASE**] - moved 'forward' to its own module: CGI::Application::Plugin::Forward - changed instances of 'use base' to use... and @ISA to be kinder to old Perls - made hook-based tests skip if installed CGI::Application doesn't support hooks 0.10_02 July 25, 2005 [**DEVELOPER RELEASE**] - wrapped usage of CGI::Application's callback system in if ($webapp->can('call_hook')) { ... } ...or equivalent, so CGI::Application 4.x is not required. 0.10_01 July 25, 2005 [**DEVELOPER RELEASE**] - this version has several API changes that are not backwards compatible: - template names used to be automatically determined from the name of the calling subroutine: sub my_runmode { my $self = shift; $self->other_method; } sub other_method { my $self = shift; $self->template->fill; # loads 'other_method.html' } There were two problems with this method: 1. Not every subroutine or method is a run mode 2. Under debuggers, the name of the calling subroutine is often not available, so code that uses automatic template names can't be run under a debugger. So now AnyTemplate has been changed to get the template name from $self->get_current_runmode: sub my_runmode { my $self = shift; $self->other_method; } sub other_method { my $self = shift; $self->template->fill; # loads 'my_runmode.html' } If you want to pass control to another runmode and you want $self->get_current_runmode to be updated, then you use the new 'forward' method: sub my_runmode { my $self = shift; return $self->forward('other_runmode'); } sub other_runmode { my $self = shift; $self->template->fill; # loads 'other_runmode.html' } - template_pre_process and template_post_process are no longer called automatically. Instead you must register them as hooks. $self->add_callback('template_pre_process', \&template_pre_process); $self->add_callback('template_post_process', \&template_post_process); - associate_query and emulate_associate_query have now been disabled by default. Having this feature enabled by default was a potential XSS (Cross Site Scripting) security risk. The use of this feature is now deprecated. The feature will be removed in the future - other changes: - added option to override load_tmpl. It is enabled by: use CGI::Application::Plugin::AnyTemplate qw(load_tmpl); When this feature is enabled, you can do the following: $self->load_tmpl('somefile.txt', path => '/path/to/templates', %other_options ); And this is translated into: $self->template->load('somefile.txt', add_include_path => '/path/to/templates', HTMLTemplate => \%other_options, auto_add_template_extension => 0, ); - added support for the load_tmpl hook, compatible with the one built into CGI::Application - $self->tmpl_path is now merged into 'include_path' - documentation for authors of plugins and re-usable applications - documentation for why the automatic extension mechanism is there - re-numbered some test scripts 0.08 July 20, 2005 - fixed bug where keys of configuration hashref were clobbered, so if you used the same config repeatedly (e.g. under mod_perl), onlyt the first call would work. (thanks to R.A. Jones) 0.07 July 10, 2005 - templates can also be created from strings via fill: return $self->template->fill(\$some_text, \%params); 0.06 July 10, 2005 - allowed templates to be created from strings (works in all drivers except Petal): $self->template->load(string => \$some_text); $self->template->load(\$some_text); 0.05 Jun 15, 2005 - changed embedded components from 'dispatch' to 'embed' to avoid confusion with CGI::Application::Dispatch This is an incompatible API change, which hopefully won't actually affect anybody since I don't think there are any users of AnyTemplate yet. The default syntax has changed from: CGIAPP_dispatch, CGIAPP.dispatch, CGIAPP/dispatch, etc. to: CGIAPP_embed, CGIAPP.embed, CGIAPP/embed, etc. The old syntax still works to embed components in TT and Petal (but is undocumented). Users of HTML::Template and HTML::Template::Expr can return to the old syntax by setting embed_tag_name to 'cgiapp_dispatch' Related API changes: - CAP:AnyTemplate::Dispatcher has been renamed to CAP:AnyTemplate::ComponentHandler - the dispatcher_class option has been renamed to component_handler class - the dispatch_tag_name driver config key has been renamed to embed_tag_name 0.04 May 19, 2005 - fixed Pod links and other minor doc issues 0.03 May 19, 2005 - Fixed one More POD NAME error 0.02 May 19, 2005 - Fixed NAME sections in driver POD 0.01 May 18, 2005 - Initial Release META.yml000444001750001750 316511266661317 21516 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18--- name: CGI-Application-Plugin-AnyTemplate version: 0.18 author: - 'Michael Graham ' abstract: Use any templating system from within CGI::Application using a unified interface license: perl resources: license: http://dev.perl.org/licenses/ requires: CGI::Application: 0 CGI::Application::Plugin::Forward: 0 Clone: 0 Scalar::Util: 0 Test::More: 0 configure_requires: Module::Build: 0.35 provides: CGI::Application::Plugin::AnyTemplate: file: lib/CGI/Application/Plugin/AnyTemplate.pm version: 0.18 CGI::Application::Plugin::AnyTemplate::Base: file: lib/CGI/Application/Plugin/AnyTemplate/Base.pm CGI::Application::Plugin::AnyTemplate::ComponentHandler: file: lib/CGI/Application/Plugin/AnyTemplate/ComponentHandler.pm CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate: file: lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplate.pm CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr: file: lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplateExpr.pm CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable: file: lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplatePluggable.pm CGI::Application::Plugin::AnyTemplate::Driver::Petal: file: lib/CGI/Application/Plugin/AnyTemplate/Driver/Petal.pm CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit: file: lib/CGI/Application/Plugin/AnyTemplate/Driver/TemplateToolkit.pm generated_by: Module::Build version 0.35 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 no_index: directory: - misc - t misc000755001750001750 011266661317 21036 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18style.css000555001750001750 1136711266661317 23100 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/miscBODY, .logo { background: white; } BODY { color: black; font-family: arial,sans-serif; margin: 0; padding: 1ex; } TABLE { border-collapse: collapse; border-spacing: 0; border-width: 0; color: inherit; } IMG { border: 0; } FORM { margin: 0; } input { margin: 2px; } .logo { float: left; width: 264px; height: 77px; } .front .logo { float: none; display:block; } .front .searchbox { margin: 2ex auto; text-align: center; } .front .menubar { text-align: center; } .menubar { background: #006699; margin: 1ex 0; padding: 1px; } .menubar A { padding: 0.8ex; font: bold 10pt Arial,Helvetica,sans-serif; } .menubar A:link, .menubar A:visited { color: white; text-decoration: none; } .menubar A:hover { color: #ff6600; text-decoration: underline; } A:link, A:visited { background: transparent; color: #006699; } A[href="#POD_ERRORS"] { background: transparent; color: #FF0000; } TD { margin: 0; padding: 0; } DIV { border-width: 0; } DT { margin-top: 1em; } .credits TD { padding: 0.5ex 2ex; } .huge { font-size: 32pt; } .s { background: #dddddd; color: inherit; } .s TD, .r TD { padding: 0.2ex 1ex; vertical-align: baseline; } TH { background: #bbbbbb; color: inherit; padding: 0.4ex 1ex; text-align: left; } TH A:link, TH A:visited { background: transparent; color: black; } .box { border: 1px solid #006699; margin: 1ex 0; padding: 0; } .distfiles TD { padding: 0 2ex 0 0; vertical-align: baseline; } .manifest TD { padding: 0 1ex; vertical-align: top; } .l1 { font-weight: bold; } .l2 { font-weight: normal; } .t1, .t2, .t3, .t4 { background: #006699; color: white; } .t4 { padding: 0.2ex 0.4ex; } .t1, .t2, .t3 { padding: 0.5ex 1ex; } /* IE does not support .box>.t1 Grrr */ .box .t1, .box .t2, .box .t3 { margin: 0; } .t1 { font-size: 1.4em; font-weight: bold; text-align: center; } .t2 { font-size: 1.0em; font-weight: bold; text-align: left; } .t3 { font-size: 1.0em; font-weight: normal; text-align: left; } /* width: 100%; border: 0.1px solid #FFFFFF; */ /* NN4 hack */ .datecell { text-align: center; width: 17em; } .cell { padding: 0.2ex 1ex; text-align: left; } .label { background: #aaaaaa; color: black; font-weight: bold; padding: 0.2ex 1ex; text-align: right; white-space: nowrap; vertical-align: baseline; } .categories { border-bottom: 3px double #006699; margin-bottom: 1ex; padding-bottom: 1ex; } .categories TABLE { margin: auto; } .categories TD { padding: 0.5ex 1ex; vertical-align: baseline; } .path A { background: transparent; color: #006699; font-weight: bold; } .pages { background: #dddddd; color: #006699; padding: 0.2ex 0.4ex; } .path { background: #dddddd; border-bottom: 1px solid #006699; color: #006699; /* font-size: 1.4em;*/ margin: 1ex 0; padding: 0.5ex 1ex; } .menubar TD { background: #006699; color: white; } .menubar { background: #006699; color: white; margin: 1ex 0; padding: 1px; } .menubar .links { background: transparent; color: white; padding: 0.2ex; text-align: left; } .menubar .searchbar { background: black; color: black; margin: 0px; padding: 2px; text-align: right; } A.m:link, A.m:visited { background: #006699; color: white; font: bold 10pt Arial,Helvetica,sans-serif; text-decoration: none; } A.o:link, A.o:visited { background: #006699; color: #ccffcc; font: bold 10pt Arial,Helvetica,sans-serif; text-decoration: none; } A.o:hover { background: transparent; color: #ff6600; text-decoration: underline; } A.m:hover { background: transparent; color: #ff6600; text-decoration: underline; } table.dlsip { background: #dddddd; border: 0.4ex solid #dddddd; } .pod PRE { background: #eeeeee; border: 1px solid #888888; color: black; padding: 1em; white-space: pre; } .pod H1 { background: transparent; color: #006699; font-size: large; } .pod H2 { background: transparent; color: #006699; font-size: medium; } .pod IMG { vertical-align: top; } .pod .toc A { text-decoration: none; } .pod .toc LI { line-height: 1.2em; list-style-type: none; } .faq DT { font-size: 1.4em; font-weight: bold; } .chmenu { background: black; color: red; font: bold 1.1em Arial,Helvetica,sans-serif; margin: 1ex auto; padding: 0.5ex; } .chmenu TD { padding: 0.2ex 1ex; } .chmenu A:link, .chmenu A:visited { background: transparent; color: white; text-decoration: none; } .chmenu A:hover { background: transparent; color: #ff6600; text-decoration: underline; } .column { padding: 0.5ex 1ex; vertical-align: top; } .datebar { margin: auto; width: 14em; } .date { background: transparent; color: #008000; } module-starter-opts.txt000555001750001750 21011266661317 25642 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/misc $ module-starter --mb --module=CGI::Application::Plugin::AnyTemplate --author="Michael Graham" --email=mag-perl@occamstoothbrush.com makedocs.pl000555001750001750 510311266661317 23320 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/misc#!/usr/bin/perl # This is a Quick and dirty script to generate docs. # # It can do three things: # 1) make HTML docs that look like those on search.cpan.org # 2) make text docs # 3) copy files # # Run this from the main module directory with: # $ misc/makedocs.pl # my $StyleSheet = "misc/style.css"; my %HTML = ( 'CAP-AnyTemplate.html' => 'lib/CGI/Application/Plugin/AnyTemplate.pm', 'CAP-AnyTemplate-ComponentHandler.html' => 'lib/CGI/Application/Plugin/AnyTemplate/ComponentHandler.pm', 'CAP-AnyTemplate-Base.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Base.pm', 'CAP-AnyTemplate-Driver-HTMLTemplate.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplate.pm', 'CAP-AnyTemplate-Driver-HTMLTemplateExpr.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplateExpr.pm', 'CAP-AnyTemplate-Driver-HTMLTemplatePluggable.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Driver/HTMLTemplatePluggable.pm', 'CAP-AnyTemplate-Driver-TemplateToolkit.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Driver/TemplateToolkit.pm', 'CAP-AnyTemplate-Driver-Petal.html' => 'lib/CGI/Application/Plugin/AnyTemplate/Driver/Petal.pm', ); my %TEXT = ( 'README' => 'lib/CGI/Application/Plugin/AnyTemplate.pm', ); my %COPY = ( 'changes.txt' => 'Changes', 'readme.txt' => 'README', ); my @Tempfiles = qw( pod2htmd.tmp pod2htmd.x~~ pod2htmi.tmp pod2htmi.x~~ ); use strict; use File::Copy; local $/; foreach my $target (keys %TEXT) { my $source = $TEXT{$target}; system("pod2text $source $target"); } foreach my $target (keys %HTML) { my $source = $HTML{$target}; system("pod2html --css=$StyleSheet --infile=$source --outfile=$target"); open my $fh, $target or die "can't read $target: $!\n"; my $text = <$fh>; close $fh; # Add
...
$text =~ s/(]*>)/$1
/i; $text =~ s/(<\/body>)/<\/div>$1/i; # remove redundant
 sequences (only necessary in old pod2html)
    # $text =~ s/<\/pre>(\s*)
/$1/imsg;

    # remove redundant 
 tags (only necessary in old pod2html)
    # $text =~ s/<\/pre>(\s*)<\/dd>\s*
\s*
/$1/imsg;


    open my $fh, '>', $target or die "can't clobber $target: $!\n";
    print $fh $text;
    close $fh;

    foreach my $tempfile (@Tempfiles) {
        unlink $tempfile;
    }
}

foreach my $target (keys %COPY) {
    my $source = $COPY{$target};
    copy($source, $target);
}

dist000555001750001750        21511266661317 22042 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/misc#!/bin/sh

perl Build.PL
rm MANIFEST
misc/makedocs.pl
perl ./Build.PL
perl ./Build
perl ./Build manifest
perl ./Build test
perl ./Build dist
prove-prereqs.pl000555001750001750       543511266661317 24354 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/misc#!/usr/bin/perl

=pod

This script allows you to run the test suite, simulating the absense of
a particular set of Perl modules, even if they are installed on your
system.

To run the test suite multiple times in a row (each with a different 
selection of absent modules), run:

    $ perl misc/prove_prereqs.pl t/prereq_scenarios -Ilib t/

To add a new set of absent modules, make a subdir under t/prereq_scenarios, 
and add a dummy perl module for every module you want to skip.  This file
should be empty.  For instance if you wanted to simulate the absense of
Text::Template and Text::TagTemplate, you would do the following:

    $ mkdir t/prereq_scenarios/skip_tt+ttt
    $ mkdir t/prereq_scenarios/skip_tt+ttt/Text
    $ touch t/prereq_scenarios/skip_tt+ttt/Text/Template.pm
    $ touch t/prereq_scenarios/skip_tt+ttt/Text/TagTemplate.pm

Note that this technique only works because of how AnyTemplate and its
test suite are written.  The AnyTemplate drivers each provide a method
returning the list of modules they depend on.  Each test script gets the
list of modules and attempts to load them:

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

If any of the modules fail to load, then the test script skips the tests
associated with that module.

=cut

use strict;
use warnings;

use File::Find;

unless (@ARGV > 1) {
    die "Usage: $0 [prereq_scenarios_dir] [args to prove]\n";
}

my $scenarios_dir = shift;

my %scenario_modules;
my $errors;

my @scenarios = grep { -d } <$scenarios_dir/*>;
foreach my $lib_dir (@scenarios) {
    if (!-d $lib_dir) {
        $errors = 1;
        warn "lib dir does not exist: $lib_dir\n";
        next;
    }
    my @modules;
    find(sub {
        return unless -f;
        my $dir = "$File::Find::dir/$_";
        $dir =~ s/^\Q$lib_dir\E//;
        $dir =~ s/\.pm$//;
        $dir =~ s{^/}{};
        $dir =~ s{/}{::}g;
        push @modules, $dir;
    }, $lib_dir);
    $scenario_modules{$lib_dir} = \@modules;
}
die "Terminating." if $errors;

foreach my $lib_dir (@scenarios) {
    my $modules = join ', ', sort @{ $scenario_modules{$lib_dir} };
    $modules ||= 'none';
    print "\n##############################################################\n";
    print "Running tests.  Old (or absent) modules in this scenario:\n";
    print "$modules\n";
    my @prove_command = ('prove', '-Ilib', "-I$lib_dir", @ARGV);
    system(@prove_command) && do {
        die < 1;

BEGIN {
use_ok( 'CGI::Application::Plugin::AnyTemplate' );
}

diag( "Testing CGI::Application::Plugin::AnyTemplate $CGI::Application::Plugin::AnyTemplate::VERSION" );
04-fill_process.t000555001750001750      1233611266661317 23625 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 3;

my %Expected_Output;

$Expected_Output{'one'}{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'one'}{'Petal'} =
qq|

$Expected_Output{'one'}{'__Default__'}
|;

$Expected_Output{'three'}{'__Default__'} = <<'EOF';
--begin--
this space intentionally left blank
b1:
--end--
EOF

$Expected_Output{'three'}{'Petal'} =
qq|

$Expected_Output{'three'}{'__Default__'}
|;

$Expected_Output{'four'}{'__Default__'} = <<'EOF';
--begin--
var1:
var2:
var3:
--end--
EOF

$Expected_Output{'four'}{'Petal'} =
qq|

$Expected_Output{'four'}{'__Default__'}
|;


{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('one')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('two')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('three')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('four')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');

        # named config 'one'
        my $expected_output = $Expected_Output{'one'}{$driver}
                           || $Expected_Output{'one'}{'__Default__'};

        my $output = $self->template('one')->fill({
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "(one) Got expected output for driver: $driver");

        # named config 'two' - same settings
        $output = $self->template('one')->process('simple', {
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "(two) Got expected output for driver: $driver");

        # named config 'three' - same settings, but we don't pass params

        $expected_output = $Expected_Output{'three'}{$driver}
                        || $Expected_Output{'three'}{'__Default__'};

        $output = $self->template('three')->fill('blank');
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "(three) Got expected output for driver: $driver");

        # named config 'four' - but this time we call fill without any args
        $expected_output = $Expected_Output{'four'}{$driver}
                        || $Expected_Output{'four'}{'__Default__'};

        $output = $self->template('four')->fill;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "(four) Got expected output for driver: $driver");

        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
20-tmpl_path.t000555001750001750      1416311266661317 23127 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 10;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

my %Extension = (
    HTMLTemplate          => '.html',
    HTMLTemplateExpr      => '.html',
    HTMLTemplatePluggable => '.html',
    TemplateToolkit       => '.tmpl',
    Petal                 => '.xhtml',
);

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate qw/:load_tmpl/;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple_elsewhere');
        $self->run_modes([qw/simple_elsewhere/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple_elsewhere {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $extension = $Extension{$driver};

        unless ($self->param('path_added_via_new')) {;
            $self->tmpl_path('t/tmpl_include');
        }

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';


        is($output, $expected_output, "Got expected output for driver: $driver");

        ok($extension, "extension for driver: $driver");

        $template = $self->load_tmpl(
            'simple' . $extension
        );

        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        $object = $template->object;

        $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");


        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
            path_added_via_new    => 1,
        },
        TMPL_PATH             => 't/tmpl_include',
        )->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
            path_added_via_new    => 1,
        },
        TMPL_PATH             => 't/tmpl_include',
        )->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
            path_added_via_new    => 1,
        },
        TMPL_PATH             => 't/tmpl_include',
        )->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
            path_added_via_new    => 1,
        },
        TMPL_PATH             => 't/tmpl_include',
        )->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
16-non-clobbering-config.t000555001750001750       273511266661317 25267 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %AT_Config = (
    default_type                => 'TemplateToolkit',
    include_paths               => 't/tmpl',
    auto_add_template_extension => 0,
);

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');

    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('test_template');
        $self->run_modes([qw/test_template/]);
        $self->template->config(\%AT_Config);
    }

    sub test_template {
        my $self = shift;

        my $template;
        $template = $self->template->load;
        ok(!$@, "template loaded okay") or die "error loading template: $@\n";

        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate') and test_driver_prereqs('TemplateToolkit')) {
        WebApp->new->run;
        WebApp->new->run;
    }
    else {
        skip "HTML::Template or Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
22-return_references.t000555001750001750      1136411266661317 24661 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 6;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        is(ref $output, 'SCALAR', "output returns reference by default");
        is($$output, $expected_output, "Got expected output for driver: $driver");


        # Now turning off return_references
        $template = $self->template->load('return_references' => undef);
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        $object = $template->object;

        $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        $output = $template->output;
        ok(!ref $output, "return_references off: output returns string");
        is($output, $expected_output, "return_references off: Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}

SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
03-named-configs.t000555001750001750      1260211266661317 23646 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'one'}{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'one'}{'Petal'} =
qq|

$Expected_Output{'one'}{'__Default__'}
|;

$Expected_Output{'two'}{'__Default__'} = <<'EOF';
--begin--
b1:bork1
b2:bork2
b3:bork3
--end--
EOF

$Expected_Output{'two'}{'Petal'} =
qq|

$Expected_Output{'two'}{'__Default__'}
|;

my %Template = (
    HTMLTemplateExpr      => 'simple.html',
    HTMLTemplate          => 'simple.html',
    HTMLTemplatePluggable => 'simple.html',
    Petal                 => 'simple.xhtml',
    TemplateToolkit       => 'simple.tmpl',
);



{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('runmode');
        $self->run_modes([qw/runmode/]);

        $self->template('one')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            auto_add_template_extension => 0,
        );
        $self->template('two')->config(
            include_paths => 't/tmpl',
            auto_add_template_extension => 1,
            TemplateToolkit => {
                template_extension => '.bork',
            },
            HTMLTemplate => {
                template_extension => '.bork',
            },
            HTMLTemplatePluggable => {
                template_extension => '.bork',
            },
            HTMLTemplateExpr => {
                template_extension => '.ext_HTMLTemplate',
            },
            Petal => {
                template_extension => '.bork',
            },
        );
    }

    sub runmode {
        my $self = shift;

        my $driver = $self->param('template_driver');

        # named config 'one'
        my $expected_output = $Expected_Output{'one'}{$driver}
                           || $Expected_Output{'one'}{'__Default__'};

        my $template = $self->template('one')->load($Template{$driver});

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");

        # named config 'two'
        $expected_output = $Expected_Output{'two'}{$driver}
                           || $Expected_Output{'two'}{'__Default__'};

        $template = $self->template('two')->load(
            type => $self->param('template_driver'),
            file => 'test',
            TemplateToolkit => {
                template_extension => '.ext_TemplateToolkit',
            },
            HTMLTemplate => {
                template_extension => '.ext_HTMLTemplate',
            },
            HTMLTemplateExpr => {
            },
            HTMLTemplatePluggable => {
                template_extension => '.ext_HTMLTemplate',
            },
            Petal => {
                template_extension => '.ext_Petal',
            },

        );

        $template->param(
            'var1' => 'bork1',
            'var2' => 'bork2',
            'var3' => 'bork3',
        );

        $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");

        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
13-tt_obj_caching.t000555001750001750      2303711266661317 24076 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Objects;

{
    package MyProject;
    use CGI::Application;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('project')->config(      # defaults to storage in MyProject
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );

        $self->template('cgiapp')->config(
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
            TemplateToolkit => {
                storage_class => 'CGI::Application',
            },
        );
        $self->template('none')->config(
            type           => 'TemplateToolkit',
            TemplateToolkit => {
                object_caching => 0,
            },
            include_paths  => 't/tmpl',
        );
    }
}
{
    package OtherProject;
    use CGI::Application;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('project')->config(      # defaults to storage in MyProject
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );
        $self->template('cgiapp')->config(
            type          => 'TemplateToolkit',
            TemplateToolkit => {
                storage_class => 'CGI::Application',
            },
            include_paths => 't/tmpl',
        );
        $self->template('none')->config(
            type           => 'TemplateToolkit',
            TemplateToolkit => {
                object_caching => 0,
            },
            include_paths  => 't/tmpl',
        );
    }
}

{
    package WebApp1;

    use vars '@ISA';
    @ISA = ('MyProject');

    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {
        my $self = shift;
        $self->SUPER::setup(@_);
        $self->template('app')->config(           # defaults to storage in WebApp1
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );

        $self->template('alpha')->config(         # defaults to storage in WebApp1
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );
        $self->template('beta')->config(          # defaults to storage in WebApp1
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );

    }

    sub simple {
        my $self = shift;

        my ($template, $obj1, $obj2);

        $template = $self->template('app')->load;
        $Objects{WebApp1}{'app_obj'} = $template->object;

        $template = $self->template('project')->load;
        $Objects{WebApp1}{'project_obj'} = $template->object;

        $template = $self->template('cgiapp')->load;
        $Objects{WebApp1}{'cgiapp_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{WebApp1}{'none1_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{WebApp1}{'none2_obj'} = $template->object;

        $template = $self->template('alpha')->load;
        $Objects{WebApp1}{'alpha'} = $template->object;

        $template = $self->template('beta')->load;
        $Objects{WebApp1}{'beta'} = $template->object;

        '';
    }
}

{
    package WebApp2;

    use vars '@ISA';
    @ISA = ('MyProject');

    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {                                  # defaults to storage in WebApp2
        my $self = shift;
        $self->SUPER::setup(@_);
        $self->template('app')->config(
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );
    }
    sub simple {
        my $self = shift;

        my ($template, $obj1, $obj2);

        $template = $self->template('app')->load;
        $Objects{WebApp2}{'app_obj'} = $template->object;

        $template = $self->template('project')->load;
        $Objects{WebApp2}{'project_obj'} = $template->object;

        $template = $self->template('cgiapp')->load;
        $Objects{WebApp2}{'cgiapp_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{WebApp2}{'none1_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{WebApp2}{'none2_obj'} = $template->object;

        '';
    }
}

{
    package OthApp;

    use vars '@ISA';
    @ISA = ('OtherProject');

    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('app')->config(          # defaults to storage in OthApp
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );
        $self->template('project')->config(
            type          => 'TemplateToolkit',
            TemplateToolkit => {
                storage_class => 'OtherProject',
            },
            include_paths => 't/tmpl',
        );
        $self->template('cgiapp')->config(
            type          => 'TemplateToolkit',
            TemplateToolkit => {
                storage_class => 'CGI::Application',
            },
            include_paths => 't/tmpl',
        );
        $self->template('none')->config(
            type           => 'TemplateToolkit',
            TemplateToolkit => {
                object_caching => 0,
            },
            include_paths  => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my ($template, $obj1, $obj2);

        $template = $self->template('app')->load;
        $Objects{OthApp}{'app_obj'} = $template->object;

        $template = $self->template('project')->load;
        $Objects{OthApp}{'project_obj'} = $template->object;

        $template = $self->template('cgiapp')->load;
        $Objects{OthApp}{'cgiapp_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{OthApp}{'none1_obj'} = $template->object;

        $template = $self->template('none')->load;
        $Objects{OthApp}{'none2_obj'} = $template->object;

        '';
    }
}


# Currently, you are not prevented from storing in a class you aren't a descendent of.
# Is this a bad idea?
# {
#     package BadApp;
#     use base 'OtherProject';
#     use Test::More;
#     use CGI::Application::Plugin::AnyTemplate;
#
#     sub setup {
#         my $self = shift;
#         $self->header_type('none');
#         $self->start_mode('simple');
#         $self->run_modes([qw/simple/]);
#
#         $self->template('project')->config(
#             type          => 'TemplateToolkit',
#             TemplateToolkit => {
#                 storage_class => 'BadBadBad',
#             },
#             include_paths => 't/tmpl',
#         );
#     }
# }

SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp1->new->run;
        WebApp2->new->run;
        OthApp->new->run;

        # When app is used for storage, all objects should be different
        isnt($Objects{'WebApp1'}{'app_obj'}, $Objects{'WebApp2'}{'app_obj'}, "[app obj] WebApp1 != WebApp2");
        isnt($Objects{'OthApp'}{'app_obj'},  $Objects{'WebApp1'}{'app_obj'}, "[app obj] OthApp  != WebApp1");

        # When project is used for storage, objects for classes derived from MyProject should be identical
        is($Objects{'WebApp1'}{'project_obj'},  $Objects{'WebApp2'}{'project_obj'}, "[project obj] WebApp1 == WebApp2");
        isnt($Objects{'OthApp'}{'project_obj'}, $Objects{'WebApp1'}{'project_obj'}, "[project obj] OthApp  != WebApp1");

        # When cgiapp is used for storage, all objects should be identical
        is($Objects{'WebApp1'}{'cgiapp_obj'},  $Objects{'WebApp2'}{'cgiapp_obj'}, "[cgiapp obj] WebApp1 == WebApp2");
        is($Objects{'OthApp'}{'cgiapp_obj'},   $Objects{'WebApp1'}{'cgiapp_obj'}, "[cgiapp obj] OthApp  == WebApp1");

        # When no storage is used, all objects should be different, even those loaded by the same app
        isnt($Objects{'WebApp1'}{'none1_obj'},  $Objects{'WebApp1'}{'none2_obj'}, "[none obj] WebApp1 (none1) != WebApp1 (none2)");
        isnt($Objects{'WebApp1'}{'none1_obj'},  $Objects{'WebApp2'}{'none1_obj'}, "[none obj] WebApp1 (none1) != WebApp2 (none1)");
        isnt($Objects{'WebApp2'}{'none1_obj'},  $Objects{'WebApp2'}{'none2_obj'}, "[none obj] WebApp2 (none1) != WebApp2 (none2)");
        isnt($Objects{'OthApp'}{'none1_obj'},   $Objects{'WebApp2'}{'none2_obj'}, "[none obj] OthApp (none1)  != WebApp2 (none2)");
        isnt($Objects{'OthApp'}{'none1_obj'},   $Objects{'OthApp'}{'none2_obj'},  "[none obj] OthApp (none1)  != OthApp (none2)");

        # Two template objects using the same storage class, but different
        # names should be different objects
        isnt($Objects{'WebApp1'}{'alpha'},  $Objects{'WebApp1'}{'beta'}, "WebApp1 (alpha) != WebApp1 (beta)");


    }
    else {
        skip "Template::Toolkit not installed", 11;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
30-driver_errors.t000555001750001750       306711266661317 24010 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tuse strict;
use Test::More 'no_plan';

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;
    use lib 't/tlib';

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('non_existent')->config(
            default_type  => '___NON_EXISTENT__',
        );
        $self->template('poorly_implemented1')->config(
            default_type  => 'MyCAPATDriver1',
        );
        $self->template('poorly_implemented2')->config(
            default_type  => 'MyCAPATDriver2',
        );
        $self->template('poorly_implemented3')->config(
            default_type  => 'MyCAPATDriver3',
        );
        $self->template('poorly_implemented4')->config(
            default_type  => 'MyCAPATDriver4',
        );
    }

    sub simple {
        my $self = shift;

        my $template;
        eval {
            $template = $self->template('non_existent')->load;
        };
        ok($@, 'non existent driver');
        eval {
            $template = $self->template('poorly_implemented1')->load;
        };
        ok($@, 'poorly implemented driver: missing init');

        $template = $self->template('poorly_implemented2')->load;
        eval {
            $template->output;
        };
        like($@, qr/render_template.*virtual/, 'poorly implemented driver - does not provide render_template method');
        '';
    }
}

WebApp->new->run;
12-load_tmpl_hook.t000555001750001750      1110511266661317 24124 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More;

use CGI::Application;

# The load_tmpl hook changed in CGI::Application between versions 4.0 and 4.01
if (CGI::Application->can('new_hook') and $CGI::Application::VERSION > 4.0) {
    plan 'no_plan';
}
else {
    plan skip_all => 'installed version of CGI::Application does not support the latest load_tmpl hook';
}

my $Per_Template_Driver_Tests = 5;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:porkpiehat1
var2:porkpiehat2
var3:porkpiehat3
--end--
EOF

my %Extension = (
    HTMLTemplate          => '.html',
    HTMLTemplateExpr      => '.html',
    HTMLTemplatePluggable => '.html',
    TemplateToolkit       => '.tmpl',
    Petal                 => '.xhtml',
);


$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple_elsewhere');
        $self->run_modes([qw/simple_elsewhere/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            add_include_paths => 'really_bad_path',
        );
        $self->add_callback('load_tmpl', \&my_load_tmpl1);
        $self->add_callback('load_tmpl', \&my_load_tmpl2);
    }

    sub simple_elsewhere {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load;
        $template->param('var3' => 'porkpiehat3');

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }

    sub my_load_tmpl1 {
        my ($self, $ht_params, $tmpl_params, $tmpl_file) = @_;

        my $driver = $self->param('template_driver');
        my $extension = $Extension{$driver};

        is($ht_params->{'path'}, 'really_bad_path', '[my_load_tmpl1] path]');

        $ht_params->{'path'} = 'badpath';

        is($tmpl_file, 'simple_elsewhere' . $extension, '[my_load_tmpl1] filename]');

        $tmpl_params->{'var1'} = 'porkpiehat1';

    }
    sub my_load_tmpl2 {
        my ($self, $ht_params, $tmpl_params, $tmpl_file) = @_;

        my $driver = $self->param('template_driver');
        my $extension = $Extension{$driver};

        is($ht_params->{'path'}, 'badpath', '[my_load_tmpl2] path]');

        $ht_params->{'path'} = 't/tmpl_include';

        is($tmpl_file, 'simple_elsewhere' . $extension, '[my_load_tmpl2] filename]');

        $tmpl_params->{'var2'} = 'porkpiehat2';

    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
19-load_tmpl.t000555001750001750      1214311266661317 23116 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 6;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

my %Extension = (
    HTMLTemplate          => '.html',
    HTMLTemplateExpr      => '.html',
    HTMLTemplatePluggable => '.html',
    TemplateToolkit       => '.tmpl',
    Petal                 => '.xhtml',
);

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate qw/:load_tmpl/;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $extension = $Extension{$driver};

        ok($extension, "extension for driver: $driver");

        my $template = $self->load_tmpl(
            'simple' . $extension
        );

        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");


        # use include path
        $template = $self->load_tmpl(
            'simple_elsewhere' . $extension,
            path => 't/tmpl_include',
        );

        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        $object = $template->object;

        $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        $output = $template->output;
        ok(!ref $output, "load_tmpl returns string, not reference");
        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
pod-coverage.t000555001750001750       425611266661317 23255 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t#!perl -T

use Test::More;
eval "use Test::Pod::Coverage 1.04";
if ($@) {
    plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage";
}
else {
    plan 'no_plan';
}

# The 'template' sub is not documented separately.  Instead it's documented in
# the calling syntax of every other sub.
pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate",
        { also_private => [ qr/^(template)$/ ], },
        "CAP::AnyTemplate, POD coverage, but marking the 'template' sub as private",
);

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::ComponentHandler",
        { also_private => [ qr/^(dispatch)|(dispatch_direct)$/ ], },
        "CAP::AnyTemplate::Base POD coverage",
);
pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Base",
        {},
        "CAP::AnyTemplate::Base POD coverage",
);


# In the driver modules, default_driver_config and driver_config_keys
# are documented in the CONFIGURATION section

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplate",
        { also_private => [ qr/^(default_driver_config)|(driver_config_keys)|(clear_params)$/ ], },
        "CAP::AnyTemplate::Driver::HTMLTemplate POD coverage",
);

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplateExpr",
        { also_private => [ qr/^(default_driver_config)|(driver_config_keys)|(clear_params)$/ ], },
        "CAP::AnyTemplate::Driver::HTMLTemplate POD coverage",
);

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Driver::HTMLTemplatePluggable",
        { also_private => [ qr/^(default_driver_config)|(driver_config_keys)|(clear_params)$/ ], },
        "CAP::AnyTemplate::Driver::HTMLTemplate POD coverage",
);

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Driver::TemplateToolkit",
        { also_private => [ qr/^(default_driver_config)|(driver_config_keys)$/ ], },
        "CAP::AnyTemplate::Driver::TemplateToolkit POD coverage",
);

pod_coverage_ok(
        "CGI::Application::Plugin::AnyTemplate::Driver::Petal",
        { also_private => [ qr/^(default_driver_config)|(driver_config_keys)$/ ], },
        "CAP::AnyTemplate::Driver::Petal POD coverage",
);


10-associate.t000555001750001750      1132211266661317 23103 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'associate'}{'__Default__'} = <<'EOF';
--begin--
var1:query_value1
var2:value2
var3:query_value3
--end--
EOF

$Expected_Output{'associate'}{'Petal'} =
qq|

$Expected_Output{'associate'}{'__Default__'}
|;

$Expected_Output{'non_associate'}{'__Default__'} = <<'EOF';
--begin--
var1:
var2:value2
var3:
--end--
EOF

$Expected_Output{'non_associate'}{'Petal'} =
qq|

$Expected_Output{'non_associate'}{'__Default__'}
|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template('associate')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',

            HTMLTemplate => {
                associate_query => 1,
            },
            HTMLTemplateExpr => {
                associate_query => 1,
            },
            HTMLTemplatePluggable => {
                associate_query => 1,
            },
            TemplateToolkit => {
                emulate_associate_query => 1,
            },
            Petal => {
                emulate_associate_query => 1,
            },
        );
        $self->template('non_associate')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');

        my $expected_output_associate = $Expected_Output{'associate'}{$driver}
                           || $Expected_Output{'associate'}{'__Default__'};

        my $expected_output_non_associate = $Expected_Output{'non_associate'}{$driver}
                           || $Expected_Output{'non_associate'}{'__Default__'};


        $self->query->param('var1' => 'query_value1');
        $self->query->param('var2' => 'query_value2');
        $self->query->param('var3' => 'query_value3');

        my $template = $self->template('associate')->load;

        $template->param(
            'var2' => 'value2',
        );

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output_associate, "Got expected output (using associated query) for driver: $driver");

        $template = $self->template('non_associate')->load;

        $template->param(
            'var2' => 'value2',
        );

        $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output_non_associate, "Got expected output (not associated with query) for driver: $driver");

        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
pod.t000444001750001750        21411266661317 21427 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t#!perl -T

use Test::More;
eval "use Test::Pod 1.14";
plan skip_all => "Test::Pod 1.14 required for testing POD" if $@;
all_pod_files_ok();
31-exporter_renaming.t000555001750001750       344011266661317 24645 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More;

eval { require Exporter::Renaming; };

if ($@) {
    plan 'skip_all' => "Exporter::Renaming not installed"
}
else {
    plan 'no_plan';
}


eval <<'TEST';
my $Expected_Output = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');

    use Exporter::Renaming;
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate Renaming => [ 'template' => 'xxxx' ];

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->xxxx->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $expected_output = $Expected_Output;

        my $template = $self->xxxx->load;
        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );
        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", 1;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    eval "require $_;" for @required_modules;

    if ($@) {
        return;
    }
    return 1;
}
TEST

07-dispatch_embed.t000555001750001750      1541411266661317 24077 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
outer_var1:outer_value1
--begin inner1--
one:none
two:none
three:none
four:none
outer_var1:outer_value1
zzz:p1a
zzz:p2a
zzz:p1b
zzz:p2b
--begin inner2--
one:p1a
two:literal1a
three:p2a
four:literal2a
outer_var1:outer_value1
outer_var2:outer_value2
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
inner2_var1:inner2_value1
inner2_var2:inner2_value2
inner2_var3:inner2_value3
--end inner2--
outer_var2:outer_value2
--begin inner2--
one:p1b
two:literal1b
three:p2b
four:literal2b
outer_var1:outer_value1
outer_var2:outer_value2
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
inner2_var1:inner2_value1
inner2_var2:inner2_value2
inner2_var3:inner2_value3
--end inner2--
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
--end inner1--
outer_var2:outer_value2
outer_var3:outer_value3
--end--
EOF

$Expected_Output{'Petal'}
    = qq|\n$Expected_Output{'__Default__'}|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('dispatch_outer');
        $self->run_modes([qw/
            dispatch_outer
            embed_inner1
            embed_inner2
        /]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params  => 0,
                template_extension => '.html_expr',
            },
            HTMLTemplatePluggable => {
                die_on_bad_params  => 0,
                template_extension => '.html_pluggable',
            },
        );
    }

    sub dispatch_outer {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            add_include_paths => 't/tmpl_include',
            HTMLTemplate => {
                embed_tag_name => 'cgiapp_dispatch',
            },
            HTMLTemplateExpr => {
                embed_tag_name => 'CGIAPP_dispatch',
            }
        );
        $template->param(
            'outer_var1'    => 'outer_value1',
            'outer_var2'    => 'outer_value2',
            'outer_var3'    => 'outer_value3',
        );
        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        # Remove span tags and spurious newlines from Petal output
        if ($self->param('template_driver') eq 'Petal') {
            $output =~ s|\n?||g;
        }

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }

    sub embed_inner1 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            add_include_paths => 't/tmpl_include',
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'param1a'     => 'p1a',
            'param1b'     => 'p1b',
            'param2a'     => 'p2a',
            'param2b'     => 'p2b',
            'inner1_var1' => 'inner1_value1',
            'inner1_var2' => 'inner1_value2',
            'inner1_var3' => 'inner1_value3',
        );
        return $template->output;
    }
    sub embed_inner2 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            include_paths => 't/tmpl_include',
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'inner2_var1' => 'inner2_value1',
            'inner2_var2' => 'inner2_value2',
            'inner2_var3' => 'inner2_value3',
        );
        return $template->output;
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}

17-load_default_to_crm.t000555001750001750      1023611266661317 25130 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 3;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:some_param
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes(
            'simple'       => 'simple_meth',
        );
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple_meth {
        my $self = shift;
        $self->other_meth('some_param');
        '';
    }
    sub other_meth {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};


        # Even though we are in 'other_meth', the current run mode is still 'simple'
        is($self->get_current_runmode, 'simple', '[other_meth] current runmode is simple');

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => $_[0],
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
18-load_after_forward.t000555001750001750      1045511266661317 24772 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More;

use Test::More 'tests' => 15;

my $Per_Template_Driver_Tests = 3;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:some_param
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;
    use CGI::Application::Plugin::Forward;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('start_action');
        $self->run_modes(
            'start_action' => 'start_meth',
            'simple'       => 'simple_meth',
        );
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub start_meth {
        my $self   = shift;
        my $driver = $self->param('template_driver');

        eval {
            $self->simple_meth('some_param');
        };

        ok($@, "non-forward jump to new rm fails correctly for driver: $driver");
        $self->forward('simple', 'some_param');
    }
    sub simple_meth {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );
        $template->clear_params;

        $template->param(
            'var1' => $_[0],
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $object = $template->object;


        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
06-embed.t000555001750001750      1507411266661317 22221 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
outer_var1:outer_value1
--begin inner1--
one:none
two:none
three:none
four:none
outer_var1:outer_value1
zzz:p1a
zzz:p2a
zzz:p1b
zzz:p2b
--begin inner2--
one:p1a
two:literal1a
three:p2a
four:literal2a
outer_var1:outer_value1
outer_var2:outer_value2
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
inner2_var1:inner2_value1
inner2_var2:inner2_value2
inner2_var3:inner2_value3
--end inner2--
outer_var2:outer_value2
--begin inner2--
one:p1b
two:literal1b
three:p2b
four:literal2b
outer_var1:outer_value1
outer_var2:outer_value2
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
inner2_var1:inner2_value1
inner2_var2:inner2_value2
inner2_var3:inner2_value3
--end inner2--
outer_var3:outer_value3
inner1_var1:inner1_value1
inner1_var2:inner1_value2
inner1_var3:inner1_value3
--end inner1--
outer_var2:outer_value2
outer_var3:outer_value3
--end--
EOF

$Expected_Output{'Petal'}
    = qq|\n$Expected_Output{'__Default__'}|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('embed_outer');
        $self->run_modes([qw/
            embed_outer
            embed_inner1
            embed_inner2
        /]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params  => 0,
                template_extension => '.html_expr',
            },
            HTMLTemplatePluggable => {
                die_on_bad_params  => 0,
                template_extension => '.html_pluggable',
            },
        );
    }

    sub embed_outer {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            add_include_paths => 't/tmpl_include',
        );
        $template->param(
            'outer_var1'    => 'outer_value1',
            'outer_var2'    => 'outer_value2',
            'outer_var3'    => 'outer_value3',
        );
        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        # Remove span tags and spurious newlines from Petal output
        if ($self->param('template_driver') eq 'Petal') {
            $output =~ s|\n?||g;
        }

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }

    sub embed_inner1 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            add_include_paths => 't/tmpl_include',
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'inner1_var1' => 'inner1_value1',
            'inner1_var2' => 'inner1_value2',
            'inner1_var3' => 'inner1_value3',
            'param1a'     => 'p1a',
            'param1b'     => 'p1b',
            'param2a'     => 'p2a',
            'param2b'     => 'p2b',
        );
        return $template->output;
    }
    sub embed_inner2 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            include_paths => 't/tmpl_include',
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'inner2_var1' => 'inner2_value1',
            'inner2_var2' => 'inner2_value2',
            'inner2_var3' => 'inner2_value3',
        );
        return $template->output;
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}

23-filename_generator.t000555001750001750      1446411266661317 24774 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';
use File::Spec;

my $Per_Template_Driver_Tests = 4;

my %Expected_Output;

$Expected_Output{'one'}{'__Default__'} = <<'EOF';
--begin--
gvar1:value1
gvar2:
gvar3:value3
--end--
EOF

$Expected_Output{'one'}{'Petal'} =
qq|

$Expected_Output{'one'}{'__Default__'}
|;

$Expected_Output{'two'}{'__Default__'} = <<'EOF';
--begin--
path_gvar1:value1
path_gvar2:
path_gvar3:value3
--end--
EOF

$Expected_Output{'two'}{'Petal'} =
qq|

$Expected_Output{'two'}{'__Default__'}
|;


{
    package My::Sample::WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('start');
        $self->run_modes([qw/start/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            template_filename_generator => sub {
                return 'some_old_nonsense',
            },
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplatePluggable => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params => 0,
            },
        );
        $self->template('path_example')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            template_filename_generator => sub {
                my $self     = shift;
                my $run_mode = $self->get_current_runmode;
                my $module   = ref $self;

                my @segments = split /::/, $module;

                return File::Spec->catfile(@segments, $run_mode);
            },
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplatePluggable => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params => 0,
            },
        );
    }

    sub start {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{'one'}{$driver}
                           || $Expected_Output{'one'}{'__Default__'};

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );

        $template->output;
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");

        # Example with generator that returns a full path
        $expected_output = $Expected_Output{'two'}{$driver}
                        || $Expected_Output{'two'}{'__Default__'};

        $template = $self->template('path_example')->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );

        $template->output;
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var3' => 'value3',
        );

        $object = $template->object;

        $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "[path] template object ref: $ref");

        $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "[path] Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        My::Sample::WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        My::Sample::WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        My::Sample::WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        My::Sample::WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}

SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        My::Sample::WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}

15-template_string.t000555001750001750      1203211266661317 24335 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 4;

my %Expected_Output;
my %Template_String;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
string_var1:value1
string_var2:value2
string_var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

$Template_String{'HTMLTemplatePluggable'} = $Template_String{'HTMLTemplate'} = $Template_String{'HTMLTemplateExpr'} = <
string_var2:
string_var3:
--end--
EOF

$Template_String{'TemplateToolkit'} = <

--begin--
string_var1:var1
string_var2:var2
string_var3:var3
--end--

EOF


{
    package WebApp;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');

    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $string = $Template_String{$driver};

        my %params = (
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );

        my $template = $self->template->load(
            string   =>   \$string,
        );
        $template->param(%params);

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "[load(string => \\\$string)] Got expected output for driver: $driver");

        $template = $self->template->load(\$string);
        $template->param(%params);

        $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "[load(\\\$string)] Got expected output for driver: $driver");

        $output = $self->template->fill(\$string, \%params);

        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "[fill(\\\$string, \\%params)] Got expected output for driver: $driver");


        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    skip "Petal doesn't support loading templates from strings", $Per_Template_Driver_Tests;
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver            => 'Petal',
            template_engine_class      => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
02-explicit_filename.t000555001750001750       665311266661317 24605 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;


my %Template = (
    HTMLTemplateExpr      => 'simple.html',
    HTMLTemplate          => 'simple.html',
    HTMLTemplatePluggable => 'simple.html',
    Petal                 => 'simple.xhtml',
    TemplateToolkit       => 'simple.tmpl',
);



{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('runmode');
        $self->run_modes([qw/runmode/]);
        $self->template->config(
            type                        => $self->param('template_driver'),
            include_paths               => 't/tmpl',
            auto_add_template_extension => 0,
        );
    }

    sub runmode {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load($Template{$driver});
        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );
        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
21-ht-dot.t000555001750001750       476511266661317 22326 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:here(-arg1-)
var2:here(-arg2-)
var3:here(-arg3-)
--end--
EOF

{
    package Something;
    sub new { return bless {} }
    sub somehow {
        my $self = shift;
        return "here(-@_-)";
    }
}


{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        require HTML::Template::Pluggable;
        import HTML::Template::Pluggable;
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }


    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load('htdot');
        my $sumptin  = Something->new;

        $template->param(
            'sumptin' => $sumptin,
        );
        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate') and test_driver_prereqs('HTMLTemplatePluggable')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template or HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
09-embed_error.t000555001750001750       465511266661317 23420 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 4;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('embed_start');
        $self->run_modes([qw/
            embed_start
            embed_non_existent_runmode_sub
        /]);
        $self->template->config(
            # default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params  => 0,
                template_extension => '.html_expr',
            },
        );
    }

    sub embed_start {
        my $self = shift;

        my $driver = $self->param('template_driver');

        my $template = $self->template->load(
            'embed_error1',
        );

        my $output;


        eval {
            $output = $template->output;
        };

        ok($@, "Caught embed to non existent runmode");
        # like($@, qr/embed_non_existent_runmode.*listed/, "Caught embed to non existent runmode (error message ok)");
        # Changed because we currently can't trap and report errors in embed_direct
        like($@, qr/embed_non_existent_runmode/, "Caught embed to non existent runmode (error message ok)");

        $template = $self->template->load(
            'embed_error2',
        );

        eval {
            $output = $template->output;
        };

        ok($@, "Caught embed to non existent runmode sub ");
        like($@, qr/embed_non_existent_runmode.*sub/, "Caught embed to non existent runmode sub (error message ok)");


        '';
    }

}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}

24-tt_opts.t000555001750001750       475311266661317 22623 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'wrapper'} = qq{wrapper-begin
--begin--
var1:value1
var2:value2
var3:value3
--end--

wrapper-end};

$Expected_Output{'no_wrapper'} = <<'EOF';
--begin--
var1:value1
var2:value2
var3:value3
--end--
EOF


{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;

        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('no_wrapper')->config( # for templates not requiring wrapper
          type          => 'TemplateToolkit',
          include_paths => 't/tmpl',
        );

        $self->template('wrapper')->config( # default AnyTemplate config
          type => 'TemplateToolkit',
          include_paths   => 't/tmpl',
          TemplateToolkit => {
            WRAPPER => 'wrapper.tmpl',
          },
        );
    }

    sub simple {
        my $self = shift;

        # named config 'wrapper'
        my $expected_output = $Expected_Output{'wrapper'};

        my $output = $self->template('wrapper')->fill({
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';
        is($output, $expected_output, "(wrapper) Got expected output");


        # named config 'no_wrapper'
        $expected_output = $Expected_Output{'no_wrapper'};

        $output = $self->template('no_wrapper')->fill({
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        });
        $output = $$output if ref $output eq 'SCALAR';
        is($output, $expected_output, "(no_wrapper) Got expected output");
        '';
    }
}

SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
14-tt_obj_caching_include_paths.t000555001750001750      1177011266661317 27002 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my %Expected_Output;

$Expected_Output{'path1'} = <<'EOF';
--begin--
outer_var1:outer_value1
--begin inner--
inner_var1:inner_value1
inner_var2:inner_value2
inner_var3:inner_value3
--end inner--
outer_var2:outer_value2
--end--
EOF

$Expected_Output{'path2'} = <<'EOF';
--begin--
outer_var1:outer_value1
--begin inner_path2--
inner_path2_var1:inner_value1
inner_path2_var2:inner_value2
inner_path2_var3:inner_value3
--end inner_path2--
outer_var2:outer_value2
--end--
EOF


my %Objects;

{
    package MyProject;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/
            simple
            cache_incl_paths_inner
        /]);

        $self->template('project')->config(      # defaults to storage in MyProject
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
        );
    }
}
{
    package OtherProject;
    use CGI::Application;
    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/
            simple
            cache_incl_paths_inner
        /]);

        $self->template('project')->config(      # defaults to storage in MyProject
            type          => 'TemplateToolkit',
            include_paths => 't/tmpl',
            TemplateToolkit => {
                object_caching => 0,
            },
        );
    }
}

{
    package WebApp;
    use vars '@ISA';
    @ISA = ('MyProject');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub simple {
        my $self = shift;

        my $template = $self->template('project')->load(
            file              => 'cache_incl_paths_outer',
        );

        $template->param(
            'outer_var1' => 'outer_value1',
            'outer_var2' => 'outer_value2',
            'inner_var1' => 'inner_value1',
            'inner_var2' => 'inner_value2',
            'inner_var3' => 'inner_value3',
        );

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $Expected_Output{'path1'}, 'include files (path 1)');

        '';
    }
    sub cache_incl_paths_inner {
        my ($self, $parent_template) = @_;

        my $template = $self->template('project')->load(
            file              => 'cache_incl_paths_inner',
            add_include_paths => 't/tmpl_include',
        );
        $template->param($parent_template->get_param_hash);
        return $template->output;
    }
}

{
    package OthApp;
    use vars '@ISA';
    @ISA = ('OtherProject');
    use Test::More;
    use CGI::Application::Plugin::AnyTemplate;

    sub simple {
        my $self = shift;

        my $template = $self->template('project')->load(
            file          => 'cache_incl_paths_outer',
        );
        $template->param(
            'outer_var1' => 'outer_value1',
            'outer_var2' => 'outer_value2',
            'inner_var1' => 'inner_value1',
            'inner_var2' => 'inner_value2',
            'inner_var3' => 'inner_value3',
        );

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $Expected_Output{'path2'}, 'include files (path 2)');
        '';
    }
    sub cache_incl_paths_inner {
        my ($self, $parent_template) = @_;

        my $template = $self->template('project')->load(
            file              => 'cache_incl_paths_inner',
            include_paths => [ 't/tmpl', 't/tmpl_include2' ],
        );
        $template->param($parent_template->get_param_hash);
        return $template->output;
    }
}


# Currently, you are not prevented from storing in a class you aren't a descendent of.
# Is this a bad idea?
# {
#     package BadApp;
#     use base 'OtherProject';
#     use Test::More;
#     use CGI::Application::Plugin::AnyTemplate;
#
#     sub setup {
#         my $self = shift;
#         $self->header_type('none');
#         $self->start_mode('simple');
#         $self->run_modes([qw/simple/]);
#
#         $self->template('project')->config(
#             type          => 'TemplateToolkit',
#             TemplateToolkit => {
#                 storage_class => 'BadBadBad',
#             },
#             include_paths => 't/tmpl',
#         );
#     }
# }

SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new->run;
        OthApp->new->run;
    }
    else {
        skip "Template::Toolkit not installed", 2;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
11-pre_post_process_hooks.t000555001750001750      1152411266661317 25731 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More;

use CGI::Application;

if (CGI::Application->can('new_hook')) {
    plan 'no_plan';
}
else {
    plan skip_all => 'installed version of CGI::Application does not support hooks';
}


my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
fish1----alueVay1
fish2----alueVay2
fish3----alueVay3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params => 0,
            },
            HTMLTemplatePluggable => {
                die_on_bad_params => 0,
            },
        );
        $self->add_callback('template_pre_process', \&my_tmpl_pre1);
        $self->add_callback('template_pre_process', \&my_tmpl_pre2);
        $self->add_callback('template_post_process', \&my_tmpl_post1);
        $self->add_callback('template_post_process', \&my_tmpl_post2);
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1',
            'var2' => 'value2',
            'var3' => 'value3',
        );
        $template->param('replacement1' => 'fish');
        $template->param('replacement2' => '----');

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }

    sub my_tmpl_pre1 {
        my ($self, $template) = @_;
        my $params = $template->get_param_hash;
        foreach my $param (keys %$params) {
            my $value = $template->param($param);
            $value =~ s/value/aluevay/g;

            $template->param($param, $value);
        }

    }
    sub my_tmpl_pre2 {
        my ($self, $template) = @_;
        my $params = $template->get_param_hash;
        foreach my $param (keys %$params) {
            my $value = $template->param($param);
            $value =~ s/v/V/g;

            $template->param($param, $value);
        }

    }

    sub my_tmpl_post1 {
        my ($self, $template, $text) = @_;
        my $replacement = $template->param('replacement1');
        $$text =~ s/var/$replacement/g;
    }
    sub my_tmpl_post2 {
        my ($self, $template, $text) = @_;
        my $replacement = $template->param('replacement2');
        $$text =~ s/:/$replacement/g;
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
01-simple.t000555001750001750      1012611266661317 22422 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 2;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
var1:value1
var2:
var3:value3
--end--
EOF

$Expected_Output{'Petal'} =
qq|

$Expected_Output{'__Default__'}
|;

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);
        $self->template->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplatePluggable => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params => 0,
            },
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load;
        $template->param(
            'var1' => 'value1_xxx',
            'var2' => 'value2_xxx',
            'var3' => 'value3_xxx',
            'var4' => 'value4_xxx',
            'var5' => 'value5_xxx',
            'var6' => 'value6_xxx',
        );

        $template->output;
        $template->clear_params;

        $template->param(
            'var1' => 'value1',
            'var3' => 'value3',
        );

        my $object = $template->object;

        my $ref = $self->param('template_engine_class');
        is(ref $object, $ref, "template object ref: $ref");

        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplate',
            template_engine_class => 'HTML::Template',
        })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplateExpr',
            template_engine_class => 'HTML::Template::Expr',
        })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => {
            template_driver       => 'TemplateToolkit',
            template_engine_class => 'Template',
        })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => {
            template_driver       => 'Petal',
            template_engine_class => 'Petal',
        })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}

SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
08-custom_component_handler_class.t000555001750001750      1617411266661317 27427 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'__Default__'} = <<'EOF';
--begin--
outer_var1:outer_value1
--begin inner1--
one:none
two:none
three:none
four:none
outer_var1:outer_fish1
zzz:p1a
zzz:p2a
zzz:p1b
zzz:p2b
--begin inner2--
one:p1a
two:literal1a
three:p2a
four:literal2a
outer_var1:outer_fish1
outer_var2:outer_fish2
outer_var3:outer_fish3
inner1_var1:inner1_fish1
inner1_var2:inner1_fish2
inner1_var3:inner1_fish3
inner2_var1:inner2_fish1
inner2_var2:inner2_fish2
inner2_var3:inner2_fish3
--end inner2--
outer_var2:outer_fish2
--begin inner2--
one:p1b
two:literal1b
three:p2b
four:literal2b
outer_var1:outer_fish1
outer_var2:outer_fish2
outer_var3:outer_fish3
inner1_var1:inner1_fish1
inner1_var2:inner1_fish2
inner1_var3:inner1_fish3
inner2_var1:inner2_fish1
inner2_var2:inner2_fish2
inner2_var3:inner2_fish3
--end inner2--
outer_var3:outer_fish3
inner1_var1:inner1_fish1
inner1_var2:inner1_fish2
inner1_var3:inner1_fish3
--end inner1--
outer_var2:outer_value2
outer_var3:outer_value3
--end--
EOF

$Expected_Output{'Petal'}
    = qq|\n$Expected_Output{'__Default__'}|;

{
    package MyComponentHandler;
    use base 'CGI::Application::Plugin::AnyTemplate::ComponentHandler';

    sub embed {
        my $self = shift;
        my $output = $self->SUPER::embed(@_);
        $output =~ s/value/fish/g;
        return $output;
    }
    sub embed_direct {
        my $self = shift;
        my $output = $self->SUPER::embed_direct(@_);
        if (ref $output) {
            $$output =~ s/value/fish/g;
        }
        else {
            $output =~ s/value/fish/g;
        }
        return $output;
    }

}

{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('embed_outer');
        $self->run_modes([qw/
            embed_outer
            embed_inner1
            embed_inner2
        /]);
        $self->template->config(
            default_type            => $self->param('template_driver'),
            component_handler_class => 'MyComponentHandler',

            HTMLTemplate => {
                die_on_bad_params => 0,
            },
            HTMLTemplateExpr => {
                die_on_bad_params  => 0,
                template_extension => '.html_expr',
            },
            HTMLTemplatePluggable => {
                die_on_bad_params  => 0,
                template_extension => '.html_pluggable',
            },
        );
    }

    sub embed_outer {
        my $self = shift;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            include_paths    => ['t/tmpl', 't/tmpl_include'],
        );
        $template->param(
            'outer_var1'    => 'outer_value1',
            'outer_var2'    => 'outer_value2',
            'outer_var3'    => 'outer_value3',
        );
        my $output = $template->output;
        $output = $$output if ref $output eq 'SCALAR';

        # Remove span tags and spurious newlines from Petal output
        if ($self->param('template_driver') eq 'Petal') {
            $output =~ s|\n?||g;
        }

        is($output, $expected_output, "Got expected output for driver: $driver");
        '';
    }

    sub embed_inner1 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            add_include_paths    => ['t/tmpl', 't/tmpl_include'],
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'param1a'     => 'p1a',
            'param1b'     => 'p1b',
            'param2a'     => 'p2a',
            'param2b'     => 'p2b',
            'inner1_var1' => 'inner1_value1',
            'inner1_var2' => 'inner1_value2',
            'inner1_var3' => 'inner1_value3',
        );
        return $template->output;
    }
    sub embed_inner2 {
        my $self            = shift;
        my $parent_template = shift;
        my @params          = @_;

        my $driver = $self->param('template_driver');
        my $expected_output = $Expected_Output{$driver}
                           || $Expected_Output{'__Default__'};

        my $template = $self->template->load(
            include_paths    => ['t/tmpl_include'],
        );
        $template->param(
            $parent_template->get_param_hash,
            'one'         => ($params[0] || 'none'),
            'two'         => ($params[1] || 'none'),
            'three'       => ($params[2] || 'none'),
            'four'        => ($params[3] || 'none'),
            'inner2_var1' => 'inner2_value1',
            'inner2_var2' => 'inner2_value2',
            'inner2_var3' => 'inner2_value3',
        );
        return $template->output;
    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
05-fill_process_string.t000555001750001750       726611266661317 25202 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t
use strict;
use Test::More 'no_plan';

my $Per_Template_Driver_Tests = 1;

my %Expected_Output;

$Expected_Output{'four'}{'__Default__'} = <<'EOF';
--begin--
this space unintentionally left sober
s1:
--end--
EOF

$Expected_Output{'four'}{'Petal'} =
qq|

$Expected_Output{'four'}{'__Default__'}
|;


{
    package WebApp;
    use Test::More;
    use CGI::Application;
    use CGI::Application::Plugin::AnyTemplate;

    use vars '@ISA';
    @ISA = ('CGI::Application');

    sub setup {
        my $self = shift;
        $self->header_type('none');
        $self->start_mode('simple');
        $self->run_modes([qw/simple/]);

        $self->template('one')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('two')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('three')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
        $self->template('four')->config(
            default_type  => $self->param('template_driver'),
            include_paths => 't/tmpl',
        );
    }

    sub simple {
        my $self = shift;

        my $driver = $self->param('template_driver');


        # named config 'four' - same settings, but we pass ref to template

        my $expected_output = $Expected_Output{'four'}{$driver}
                        || $Expected_Output{'four'}{'__Default__'};

        my $template_text = $Expected_Output{'four'}{'__Default__'};
        my $output = $self->template('four')->fill(\$template_text);
        $output = $$output if ref $output eq 'SCALAR';

        is($output, $expected_output, "(four) Got expected output for driver: $driver");
        '';

    }
}


SKIP: {
    if (test_driver_prereqs('HTMLTemplate')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplate' })->run;
    }
    else {
        skip "HTML::Template not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplateExpr')) {
        WebApp->new(PARAMS => { template_driver => 'HTMLTemplateExpr' })->run;
    }
    else {
        skip "HTML::Template::Expr not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('TemplateToolkit')) {
        WebApp->new(PARAMS => { template_driver => 'TemplateToolkit' })->run;
    }
    else {
        skip "Template::Toolkit not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    skip "Petal doesn't support loading templates from strings", $Per_Template_Driver_Tests;
    if (test_driver_prereqs('Petal')) {
        WebApp->new(PARAMS => { template_driver => 'Petal' })->run;
    }
    else {
        skip "Petal not installed", $Per_Template_Driver_Tests;
    }
}
SKIP: {
    if (test_driver_prereqs('HTMLTemplatePluggable')) {
        require HTML::Template::Plugin::Dot;
        import HTML::Template::Plugin::Dot;
        WebApp->new(PARAMS => {
            template_driver       => 'HTMLTemplatePluggable',
            template_engine_class => 'HTML::Template::Pluggable',
        })->run;
    }
    else {
        skip "HTML::Template::Pluggable not installed", $Per_Template_Driver_Tests;
    }
}

sub test_driver_prereqs {
    my $driver = shift;
    my $driver_module = 'CGI::Application::Plugin::AnyTemplate::Driver::' . $driver;
    eval "require $driver_module;";
    die $@ if $@;

    my @required_modules = $driver_module->required_modules;

    foreach (@required_modules) {
        eval "require $_;";
        if ($@) {
            return;
        }
    }
    return 1;

}
prereq_scenarios000755001750001750          011266661317 23712 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tskip_petal000755001750001750          011266661317 26045 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosPetal.pm000555001750001750          011266661317 27516 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_petalskip_tt000755001750001750          011266661317 25367 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosTemplate.pm000555001750001750          011266661317 27546 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ttskip_htp000755001750001750          011266661317 25533 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosHTML000755001750001750          011266661317 26277 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_htpTemplate000755001750001750          011266661317 30052 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_htp/HTMLPluggable.pm000555001750001750          011266661317 32360 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_htp/HTML/Templateskip_hte+htp+petal+tt000755001750001750          011266661317 30033 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosPetal.pm000555001750001750          011266661317 31504 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+ttTemplate.pm000555001750001750          011266661317 32212 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+ttHTML000755001750001750          011266661317 30577 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+ttTemplate000755001750001750          011266661317 32352 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+tt/HTMLPluggable.pm000555001750001750          011266661317 34660 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+tt/HTML/TemplateExpr.pm000555001750001750          011266661317 33674 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte+htp+petal+tt/HTML/Templateskip_hte000755001750001750          011266661317 25520 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosHTML000755001750001750          011266661317 26264 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hteTemplate000755001750001750          011266661317 30037 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte/HTMLExpr.pm000555001750001750          011266661317 31361 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_hte/HTML/Templatemissing_clone000755001750001750          011266661317 26543 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosClone.pm000444001750001750          011266661317 30204 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/missing_cloneskip_ht000755001750001750          011266661317 25353 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosHTML000755001750001750          011266661317 26117 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_htTemplate.pm000555001750001750          011266661317 30276 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht/HTMLmissing_clone_pp000755001750001750          011266661317 27242 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosClone000755001750001750          011266661317 30302 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/missing_clone_ppPP.pm000444001750001750          011266661317 31222 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/missing_clone_pp/Cloneskip_ht+hte+htp+petal+template000755001750001750          011266661317 31626 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosPetal.pm000555001750001750          011266661317 33277 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+templateTemplate.pm000555001750001750          011266661317 34005 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+templateHTML000755001750001750          011266661317 32372 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+templateTemplate.pm000555001750001750          011266661317 34551 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTMLTemplate000755001750001750          011266661317 34145 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTMLPluggable.pm000555001750001750          011266661317 36453 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTML/TemplateExpr.pm000555001750001750          011266661317 35467 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/skip_ht+hte+htp+petal+template/HTML/Templateold_cap_forward000755001750001750          011266661317 27037 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenariosCGI000755001750001750          011266661317 27441 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/old_cap_forwardApplication000755001750001750          011266661317 31704 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/old_cap_forward/CGIPlugin000755001750001750          011266661317 33142 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/old_cap_forward/CGI/ApplicationForward.pm000555001750001750      1457311266661317 35276 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/prereq_scenarios/old_cap_forward/CGI/Application/Pluginpackage CGI::Application::Plugin::Forward;

use warnings;
use strict;
use Carp;
use vars qw(@ISA @EXPORT);
@ISA = ('Exporter');

@EXPORT = ('forward');

=head1 NAME

CGI::Application::Plugin::Forward - Pass control from one run mode to another

=head1 VERSION

Version 1.04

=cut

our $VERSION = '1.04';

if (CGI::Application->can('new_hook')) {
    CGI::Application->new_hook('forward_prerun');
}

=head1 SYNOPSIS

    use base 'CGI::Application';
    use CGI::Application::Plugin::Forward;

    sub setup {
        my $self = shift;
        $self->run_modes([qw(
            start
            second_runmode
        )]);
    }
    sub start {
        my $self = shift;
        return $self->forward('second_runmode');
    }
    sub second_runmode {
        my $self = shift;

        my $rm = $self->get_current_runmode;  # 'second_runmode'

    }

=head1 DESCRIPTION

The forward method passes control to another run mode and returns its
output.  This is equivalent to calling C<< $self->$other_runmode >>,
except that L's internal value of the current run mode
is updated.

This means that calling C<< $self->get_current_runmode >> after calling
C will return the name of the new run mode.  This is useful for
modules that depend on the name of the current run mode such as
L.

For example, here's how to pass control to a run mode named C
from C while updating the value of C:

    sub setup {
        my $self = shift;
        $self->run_modes({
            start         => 'start',
            other_action  => 'other_method',
        });
    }
    sub start {
        my $self = shift;
        return $self->forward('other_action');
    }
    sub other_method {
        my $self = shift;

        my $rm = $self->get_current_runmode;  # 'other_action'
    }

Note that forward accepts the I of the run mode (in this case
I<'other_action'>), which might not be the same as the name of the
method that handles the run mode (in this case I<'other_method'>)


You can still call C<< $self->other_method >> directly, but
C will not be updated:

    sub setup {
        my $self = shift;
        $self->run_modes({
            start         => 'start',
            other_action  => 'other_method',
        });
    }
    sub start {
        my $self = shift;
        return $self->other_method;
    }
    sub other_method {
        my $self = shift;

        my $rm = $self->get_current_runmode;  # 'start'
    }


Forward will work with coderef-based runmodes as well:

    sub setup {
        my $self = shift;
        $self->run_modes({
            start         => 'start',
            anon_action   => sub {
                my $self = shift;
                my $rm = $self->get_current_runmode;  # 'anon_action'
            },
        });
    }
    sub start {
        my $self = shift;
        return $self->forward('anon_action');
    }


=head1 METHODS

=head2 forward

Runs another run mode passing any parameters you supply.  Returns the
output of the new run mode.

    return $self->forward('run_mode_name', @run_mode_params);

=cut

sub forward {
    my $self     = shift;
    my $run_mode = shift;

    if ($CGI::Application::Plugin::AutoRunmode::VERSION) {
        if (CGI::Application::Plugin::AutoRunmode->can('is_auto_runmode')) {
            if (CGI::Application::Plugin::AutoRunmode::is_auto_runmode($self, $run_mode)) {
                $self->run_modes( $run_mode => $run_mode);
            }
        }
    }

    my %rm_map = $self->run_modes;
    if (not exists $rm_map{$run_mode}) {
        croak "CAP::Forward: run mode $run_mode does not exist";
    }
    my $method = $rm_map{$run_mode};

    if ($self->can($method) or ref $method eq 'CODE') {
        $self->{__CURRENT_RUNMODE} = $run_mode;
        $self->call_hook('forward_prerun');
        return $self->$method(@_);
    }
    else {
        croak "CAP::Forward: target method $method of run mode $run_mode does not exist";
    }
}


=head1 HOOKS

Before the forwarded run mode is called, the C hook is called.
You can use this hook to do any prep work that you want to do before any
new run mode gains control.

This is similar to L's built in C
method, but it is called each time you call L; not just the
when your application starts.

    sub setup {
        my $self = shift;
        $self->add_callback('forward_prerun' => \&prepare_rm_stuff);
    }

    sub prepare_rm_stuff {
        my $self = shift;
        # do any necessary prep work here....
    }

Note that your hooked method will only be called when you call
L.  If you never call C, the hook will not be called.
In particuar, the hook will not be called for your application's
C.  For that, you still use C.

If you want to have a method run for every run mode I the C,
then you can call the hook directly from C.

    sub setup {
        my $self = shift;
        $self->add_callback('forward_prerun' => \&prepare_rm_stuff);
    }
    sub cgiapp_prerun {
        my $self = shift;
        $self->prepare_rm_stuff;
    }

    sub prepare_rm_stuff {
        my $self = shift;
        # do any necessary prep work here....
    }

Alternately, you can hook C to the C
hook:

    sub setup {
        my $self = shift;
        $self->add_callback('forward_prerun' => \&cgiapp_prerun);
    }
    sub cgiapp_prerun {
        my $self = shift;
        # do any necessary prep work here....
    }

This is a less flexible solution, since certain things that can be done
in C (like setting C) won't work when the
method is called from the C hook.

=head1 AUTHOR

Michael Graham, C<<  >>

=head1 BUGS

Please report any bugs or feature requests to
C, or through the web interface at
L.  I will be notified, and then you'll automatically
be notified of progress on your bug as I make changes.

=head1 ACKNOWLEDGEMENTS

Thanks to Mark Stosberg for the idea and...well...the implementation as
well.

=head1 COPYRIGHT & LICENSE

Copyright 2005 Michael Graham, All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut

1; # End of CGI::Application::Plugin::Forwardtmpl_include2000755001750001750          011266661317 23107 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tcache_incl_paths_inner.tmpl000555001750001750        22011266661317 30561 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include2--begin inner_path2--
inner_path2_var1:[% inner_var1 %]
inner_path2_var2:[% inner_var2 %]
inner_path2_var3:[% inner_var3 %]
--end inner_path2--
tlib000755001750001750          011266661317 21300 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tCGI000755001750001750          011266661317 21702 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlibApplication000755001750001750          011266661317 24145 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGIPlugin000755001750001750          011266661317 25403 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGI/ApplicationAnyTemplate000755001750001750          011266661317 27626 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGI/Application/PluginDriver000755001750001750          011266661317 31061 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGI/Application/Plugin/AnyTemplateMyCAPATDriver1.pm000555001750001750        20411266661317 34126 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGI/Application/Plugin/AnyTemplate/Driver
package CGI::Application::Plugin::AnyTemplate::Driver::MyCAPATDriver1;
use base 'CGI::Application::Plugin::AnyTemplate::Base';

1;
MyCAPATDriver2.pm000555001750001750        23711266661317 34135 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tlib/CGI/Application/Plugin/AnyTemplate/Driver
package CGI::Application::Plugin::AnyTemplate::Driver::MyCAPATDriver2;
use base 'CGI::Application::Plugin::AnyTemplate::Base';

sub initialize {
    1;
}

1;
tmpl_include000755001750001750          011266661317 23025 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tembed_inner2.xhtml000555001750001750       145611266661317 26602 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include

--begin inner2--
one:one
two:two
three:three
four:four
outer_var1:var1
outer_var2:var2
outer_var3:var3
inner1_var1:var1
inner1_var2:var2
inner1_var3:var3
inner2_var1:var1
inner2_var2:var2
inner2_var3:var3
--end inner2--


embed_inner1.html000555001750001750       137411266661317 26410 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner1--
one:
two:
three:
four:
outer_var1:
zzz:
zzz:
zzz:
zzz:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
--end inner1--
embed_inner1.html_pluggable000555001750001750       140411266661317 30424 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner1--
one:
two:
three:
four:
outer_var1:
zzz:
zzz:
zzz:
zzz:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
--end inner1--
cache_incl_paths_inner.tmpl000555001750001750        16211266661317 30504 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner--
inner_var1:[% inner_var1 %]
inner_var2:[% inner_var2 %]
inner_var3:[% inner_var3 %]
--end inner--
embed_inner2.html000555001750001750       110311266661317 26377 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner2--
one:
two:
three:
four:
outer_var1:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
inner2_var1:
inner2_var2:
inner2_var3:
--end inner2--
embed_inner1.tmpl000555001750001750        75011266661317 26375 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner1--
one:[% one %]
two:[% two %]
three:[% three %]
four:[% four %]
outer_var1:[% outer_var1 %]
zzz:[% param1a %]
zzz:[% param2a %]
zzz:[% param1b %]
zzz:[% param2b %]
[% CGIAPP.embed('embed_inner2',param1a,'literal1a',param2a,'literal2a') %]outer_var2:[% outer_var2 %]
[% CGIAPP.embed('embed_inner2',param1b,'literal1b',param2b,'literal2b') %]outer_var3:[% outer_var3 %]
inner1_var1:[% inner1_var1 %]
inner1_var2:[% inner1_var2 %]
inner1_var3:[% inner1_var3 %]
--end inner1--
simple_elsewhere.xhtml000555001750001750        40711266661317 27560 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include

--begin--
var1:var1
var2:var2
var3:var3
--end--


simple_elsewhere.html000555001750001750        16511266661317 27371 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin--
var1:
var2:
var3:
--end--
embed_inner2.tmpl000555001750001750        54611266661317 26401 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner2--
one:[% one %]
two:[% two %]
three:[% three %]
four:[% four %]
outer_var1:[% outer_var1 %]
outer_var2:[% outer_var2 %]
outer_var3:[% outer_var3 %]
inner1_var1:[% inner1_var1 %]
inner1_var2:[% inner1_var2 %]
inner1_var3:[% inner1_var3 %]
inner2_var1:[% inner2_var1 %]
inner2_var2:[% inner2_var2 %]
inner2_var3:[% inner2_var3 %]
--end inner2--
simple_elsewhere.tmpl000555001750001750        10211266661317 27370 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin--
var1:[% var1 %]
var2:[% var2 %]
var3:[% var3 %]
--end--
embed_inner2.html_pluggable000555001750001750       110311266661317 30421 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner2--
one:
two:
three:
four:
outer_var1:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
inner2_var1:
inner2_var2:
inner2_var3:
--end inner2--
embed_inner1.html_expr000555001750001750       137411266661317 27446 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner1--
one:
two:
three:
four:
outer_var1:
zzz:
zzz:
zzz:
zzz:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
--end inner1--
embed_inner2.html_expr000555001750001750       110311266661317 27435 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include--begin inner2--
one:
two:
three:
four:
outer_var1:
outer_var2:
outer_var3:
inner1_var1:
inner1_var2:
inner1_var3:
inner2_var1:
inner2_var2:
inner2_var3:
--end inner2--
embed_inner1.xhtml000555001750001750       210611266661317 26572 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl_include

--begin inner1--
one:one
two:two
three:three
four:four
outer_var1:var1
zzz:param1a
zzz:param2a
zzz:param1b
zzz:param2b
inner component goes hereouter_var2:var2
inner component goes hereouter_var3:var3
inner1_var1:var1
inner1_var2:var1
inner1_var3:var1
--end inner1--


tmpl000755001750001750          011266661317 21322 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/tembed_outer.tmpl000555001750001750        21011266661317 24623 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:[% outer_var1 %]
[% CGIAPP.embed('embed_inner1') %]outer_var2:[% outer_var2 %]
outer_var3:[% outer_var3 %]
--end--
embed_outer.html_pluggable000555001750001750        31611266661317 26644 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
embed_outer.xhtml000555001750001750        60511266661317 25013 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
outer_var1:var1
inner component goes hereouter_var2:var2
outer_var3:var3
--end--


test.ext_TemplateToolkit000555001750001750         7411266661317 26325 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
b1:[% var1 %]
b2:[% var2 %]
b3:[% var3 %]
--end--
blank.tmpl000555001750001750        10411266661317 23422 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
this space intentionally left blank
b1:[% var1 %]
--end--
dispatch_outer.tmpl000555001750001750        21311266661317 25351 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:[% outer_var1 %]
[% CGIAPP.dispatch('embed_inner1') %]outer_var2:[% outer_var2 %]
outer_var3:[% outer_var3 %]
--end--
blank.html000555001750001750        12511266661317 23415 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
this space intentionally left blank
b1:
--end--
some_old_nonsense.tmpl000555001750001750        10511266661317 26045 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
gvar1:[% var1 %]
gvar2:[% var2 %]
gvar3:[% var3 %]
--end--
cache_incl_paths_outer.tmpl000555001750001750        16611266661317 27030 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:[% outer_var1 %]
[% CGIAPP.embed('cache_incl_paths_inner') %]outer_var2:[% outer_var2 %]
--end--
wrapper.tmpl000555001750001750         4711266661317 24001 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmplwrapper-begin
[% content %]
wrapper-endembed_error1.html000555001750001750        33511266661317 24677 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:

outer_var2:
outer_var3:
--end--
htdot.html000555001750001750        26411266661317 23454 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
var1:
var2:
var3:
--end--
simple.xhtml000555001750001750        40711266661317 24012 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
var1:var1
var2:var2
var3:var3
--end--


embed_error2.html000555001750001750        34111266661317 24675 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:

outer_var2:
outer_var3:
--end--
test.ext_Petal000555001750001750        40111266661317 24263 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
b1:var1
b2:var2
b3:var3
--end--


blank.xhtml000555001750001750        32511266661317 23607 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
this space intentionally left blank
b1:var1
--end--


some_old_nonsense.html000555001750001750        17011266661317 26037 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
gvar1:
gvar2:
gvar3:
--end--
dispatch_outer.html_pluggable000555001750001750        32111266661317 27363 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
embed_outer.html_expr000555001750001750        31611266661317 25660 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
test.ext_HTMLTemplate000555001750001750        15711266661317 25466 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
b1:
b2:
b3:
--end--
simple.tmpl000555001750001750        10211266661317 23622 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
var1:[% var1 %]
var2:[% var2 %]
var3:[% var3 %]
--end--
dispatch_outer.html000555001750001750        32111266661317 25341 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
simple.html000555001750001750        16511266661317 23623 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
var1:
var2:
var3:
--end--
embed_outer.html000555001750001750        31611266661317 24622 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
test_template000555001750001750        16511266661317 24241 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
var1:
var2:
var3:
--end--
some_old_nonsense.xhtml000555001750001750        41211266661317 26226 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
gvar1:var1
gvar2:var2
gvar3:var3
--end--


dispatch_outer.html_expr000555001750001750        32111266661317 26377 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl--begin--
outer_var1:
outer_var2:
outer_var3:
--end--
dispatch_outer.xhtml000555001750001750        61011266661317 25532 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl

--begin--
outer_var1:var1
inner component goes hereouter_var2:var2
outer_var3:var3
--end--


My000755001750001750          011266661317 21707 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmplSample000755001750001750          011266661317 23130 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl/MyWebApp000755001750001750          011266661317 24306 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl/My/Samplestart.html000555001750001750        20711266661317 26450 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl/My/Sample/WebApp--begin--
path_gvar1:
path_gvar2:
path_gvar3:
--end--
start.tmpl000555001750001750        12411266661317 26456 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl/My/Sample/WebApp--begin--
path_gvar1:[% var1 %]
path_gvar2:[% var2 %]
path_gvar3:[% var3 %]
--end--
start.xhtml000555001750001750        43111266661317 26637 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/t/tmpl/My/Sample/WebApp

--begin--
path_gvar1:var1
path_gvar2:var2
path_gvar3:var3
--end--


lib000755001750001750          011266661317 20651 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18CGI000755001750001750          011266661317 21253 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/libApplication000755001750001750          011266661317 23516 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/lib/CGIPlugin000755001750001750          011266661317 24754 5ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/lib/CGI/ApplicationAnyTemplate.pm000555001750001750     14200411266661317 27736 0ustar00michaelmichael000000000000CGI-Application-Plugin-AnyTemplate-0.18/lib/CGI/Application/Plugin
package CGI::Application::Plugin::AnyTemplate;

=head1 NAME

CGI::Application::Plugin::AnyTemplate - Use any templating system from within CGI::Application using a unified interface

=head1 VERSION

Version 0.18

=cut

our $VERSION = '0.18';

=head1 SYNOPSIS

In your CGI::Application-based webapp:

    use base 'CGI::Application';
    use CGI::Application::Plugin::AnyTemplate;

    sub cgiapp_init {
        my $self = shift;

        # Set template options
        $self->template->config(
            default_type => 'TemplateToolkit',
        );
    }


Later on, in a runmode:

    sub my_runmode {
        my $self = shift;

        my %template_params = (
            name     => 'Winston Churchill',
            age      => 7,
        );

        $self->template->fill('some_template', \%template_params);
    }

=head1 DESCRIPTION

=head2 Template-Independence

C allows you to use any
supported Perl templating system using a single consistent interface.

Currently supported templating systems include L,
L, L,
L and L.

You can access any of these templating systems using the same interface.
In this way, you can use the same code and switch templating systems on
the fly.

This approach has many uses.  For instance, it can be useful in
migrating your application from one templating system to another.

=head2 Embedded Components

In addition to template abstraction, C also provides a
I.  For instance, you might include a
I
component at the top of every page and a I