Kevin McGrath > Any-Renderer > Any::Renderer::Template



Annotate this POD


Open  1
View/Report Bugs
Module Version: 1.021   Source  


Any::Renderer::Template - render data structure using a template


  use Any::Renderer;

  my %options = ( 'Template'  => 'path/to/template.tmpl' );

  my $format = "HTML::Template";
  my $r = new Any::Renderer ( $format, \%options );

  my $data_structure = [...]; # arbitrary structure code
  my $string = $r->render ( $data_structure );

You can get a list of all formats that this module handles using the following syntax:

  my $list_ref = Any::Renderer::Template::available_formats ();

Also, determine whether or not a format requires a template with requires_template:

  my $bool = Any::Renderer::Template::requires_template ( $format );


Any::Renderer::Template renders any Perl data structure passed to it with Any::Template. The Any::Template backend used depends on the 'format' parameter passed to the object constructor.

Templates expressed as filenames are cached using a package-level in-memory cache with Cache::AgainstFile. This will stat the file to validate the cache before using the cached object, so if the template is updated, this will be immediately picked up by all processes holding a cached copy.


All the formats supported by Any::Template. Try this to find out what's available on your system:

  perl -MAny::Renderer::Template -e "print join(qq{\n}, sort @{Any::Renderer::Template::available_formats()})"

An Any::Template format is also provided. This uses the default backend (as specified in the ANY_TEMPLATE_DEFAULT environment variable).


$r = new Any::Renderer::Template($format,\%options)

See "FORMATS" for a description of valid values for $format. See "OPTIONS" for a description of valid %options.

$scalar = $r->render($data_structure)

The main method.

$bool = Any::Renderer::Template::requires_template($format)

This will be true for these formats.

$list_ref = Any::Renderer::Template::available_formats()

This will discover the formats supported by your Any::Template installation.


Template (aka TemplateFilename)

Name of file containing template. Mandatory unless TemplateString is defined.


String containing template. Mandatory unless Template or TemplateFilename is defined.


Suppress in-memory caching of templates loaded from the filesystem.


A hashref of options for the backend templating engine.

If TemplateOptions is not explicitly specified, all options passed to this module that are not recognised will be passed through Any::Template (via the Options constructor option) to the backend templating engine for the rendering process. This flatter options structure may be more convenient but does introduce the risk of a nameclash between an option name in an obscure back-end templating module and an option specific to Any::Render::Template - it's your choice.

Further information on the options for each backend module can be found in the documentation for Any::Template::$backend or the documentation for the backend templating module itself.


The package-level template cache is created on demand the first time it's needed. There are a few global variables which you can tune before it's created (i.e. before you create any objects):


Maximum number of template objects held in the cache. Default is 1000.


Items older than this will be purged from the cache when the next purge() call happens. In Seconds. Default is 6 hours.


How often to purge the cache. In Seconds. Default is 1 hour.


Set the ANY_RENDERER_AT_SAFE environment variable to a true value if you want to check each Any::Template backend compiles before adding it to the list of available formats. This is safer in that modules with missing dependencies are not advertised as available but it incurs a CPU and memory overhead.


Any::Template, Any::Renderer, Cache::AgainstFile


$Revision: 1.21 $ on $Date: 2006/09/04 12:15:53 $ by $Author: johna $


Matt Wilson and John Alden <cpan _at_ bbc _dot_ co _dot_ uk>


(c) BBC 2006. This program is free software; you can redistribute it and/or modify it under the GNU GPL.

See the file COPYING in this distribution, or

syntax highlighting: