Any-Renderer

 view release on metacpan or  search on metacpan

lib/Any/Renderer/Template.pm  view on Meta::CPAN

#
# Cache management
#

sub _init_cache
{
  $CacheLastPurged = time();
  return new Cache::AgainstFile ( \&_template_from_file, {
    'Method'    => 'Memory',
    'Grace'     => 0, # seconds
    'MaxATime'  => $CacheMaxAtime,
    'MaxItems'  => $CacheMaxItems,
  } );
}

sub _purge_cache
{
  my $cache = shift;
  return unless defined $cache;
  $cache->purge();
  $CacheLastPurged = time();
}


sub TRACE {}
sub DUMP {}

1;

=head1 NAME

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

=head1 SYNOPSIS

  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 );

=head1 DESCRIPTION

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.

=head1 FORMATS

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 B<Any::Template> format is also provided.  This uses the default backend (as specified in the ANY_TEMPLATE_DEFAULT environment variable).

=head1 METHODS

=over 4

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

See L</FORMATS> for a description of valid values for C<$format>.
See L</OPTIONS> for a description of valid C<%options>.

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

The main method.

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

This will be true for these formats.

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

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

=back

=head1 OPTIONS

=over 4

=item Template (aka TemplateFilename)

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

=item TemplateString

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

=item NoCache

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

=item TemplateOptions

A hashref of options for the backend templating engine.  

If C<TemplateOptions> is not explicitly specified, 
all options passed to this module that are not recognised will be passed through
Any::Template (via the C<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 



( run in 0.717 second using v1.01-cache-2.11-cpan-140bd7fdf52 )