File Coverage

blib/lib/HTML/DynamicTemplate.pm
Criterion Covered Total %
statement 61 63 96.8
branch 16 22 72.7
condition 6 6 100.0
subroutine 10 10 100.0
pod 5 5 100.0
total 98 106 92.4


line stmt bran cond sub pod time code
1             #==================================================================
2             # DynamicTemplate.pm
3              
4             package HTML::DynamicTemplate;
5 2     2   14253 use strict;
  2         4  
  2         75  
6              
7 2     2   10 use vars qw($VERSION);
  2         5  
  2         3101  
8             $VERSION = "0.94";
9              
10              
11              
12             #==================================================================
13              
14             =head1 NAME
15              
16             HTML::DynamicTemplate - HTML template class.
17              
18             =head1 SYNOPSIS
19              
20             use HTML::DynamicTemplate;
21             my $template = new HTML::DynamicTemplate 'path/to/template';
22             $template->set_recursion_limit($integer);
23             $template->set(NAME => $value);
24             $template->set(NAME_1 => $value_1,
25             NAME_2 => $value_2,
26             NAME_3 => $value_3);
27              
28             $template->clear();
29             $template->render();
30             $template->render(@variables);
31              
32             path/to/template
33             ----------------
34            
35            
36            

$HEADING

37              
38            

This is standard HTML with

39             arbitrary embedded variable references which are substituted
40             with actual values when the template is rendered.

41              
42            

Template variables may be set within the template itself

43             with the special $SET directive. This is useful when setting
44             variables for use by included templates. Example:
45             $SET(PAGE_TITLE, "What's New"). Note: Be sure to escape
46             quotes (") and closing parantheses ()) as HTML
47             entities.

48              
49            

Additionally, templates may be recursively included by

50             specifying a template with the special $INCLUDE directive.
51             Example: $INCLUDE(templates/example.tmpl). Template paths may
52             be variable references as in $INCLUDE($EXAMPLE_FILE). Note:
53             Any variable references found in included templates will be
54             substituted as in the original template.
55              
56            

Usage note: variable and directive names are always

57             specified in uppercase.

58              
59            
60            
61              
62             =head1 DESCRIPTION
63              
64             The C is a class implementing a HTML
65             template in perl. Significant features include the ability to set
66             template variables from within the template itself, the ability to
67             recursively include other templates, and the ability to selectively
68             render a specified subset of variables.
69              
70             =head1 METHODS
71              
72             =over 4
73              
74             =cut
75              
76             #==================================================================
77              
78             =item $template = new HTML::DynamicTemplate $template_filename;
79              
80             Constructor for the template. Returns a reference to a
81             HTML::DynamicTemplate object based on the specified template file.
82              
83             =cut
84              
85             sub new {
86 2     2 1 58 my($class, $template) = @_;
87              
88 2         6 my $self = {};
89 2         6 bless $self, $class;
90              
91 2         14 $self->{'vars'} = {};
92 2         6 $self->{'source'} = '';
93 2         6 $self->{'recursion_level'} = 0;
94 2         4 $self->{'recursion_limit'} = 10;
95 2         42 $self->{'template'} = $template;
96              
97 2 50       111 open TEMPLATE, $template or die $!;
98 2         48 while(