#================================================================== # DynamicTemplate.pm package HTML::DynamicTemplate; use strict; use vars qw($VERSION); $VERSION = "0.94"; #================================================================== =head1 NAME HTML::DynamicTemplate - HTML template class. =head1 SYNOPSIS use HTML::DynamicTemplate; my $template = new HTML::DynamicTemplate 'path/to/template'; $template->set_recursion_limit($integer); $template->set(NAME => $value); $template->set(NAME_1 => $value_1, NAME_2 => $value_2, NAME_3 => $value_3); $template->clear(); $template->render(); $template->render(@variables); path/to/template ----------------


This is standard HTML with arbitrary embedded variable references which are substituted with actual values when the template is rendered.

Template variables may be set within the template itself with the special $SET directive. This is useful when setting variables for use by included templates. Example: $SET(PAGE_TITLE, "What's New"). Note: Be sure to escape quotes (") and closing parantheses ()) as HTML entities.

Additionally, templates may be recursively included by specifying a template with the special $INCLUDE directive. Example: $INCLUDE(templates/example.tmpl). Template paths may be variable references as in $INCLUDE($EXAMPLE_FILE). Note: Any variable references found in included templates will be substituted as in the original template.

Usage note: variable and directive names are always specified in uppercase.

=head1 DESCRIPTION The C is a class implementing a HTML template in perl. Significant features include the ability to set template variables from within the template itself, the ability to recursively include other templates, and the ability to selectively render a specified subset of variables. =head1 METHODS =over 4 =cut #================================================================== =item $template = new HTML::DynamicTemplate $template_filename; Constructor for the template. Returns a reference to a HTML::DynamicTemplate object based on the specified template file. =cut sub new { my($class, $template) = @_; my $self = {}; bless $self, $class; $self->{'vars'} = {}; $self->{'source'} = ''; $self->{'recursion_level'} = 0; $self->{'recursion_limit'} = 10; $self->{'template'} = $template; open TEMPLATE, $template or die $!; while(