File Coverage

blib/lib/HTML/Template/HTX.pm
Criterion Covered Total %
statement 341 361 94.4
branch 211 254 83.0
condition 30 45 66.6
subroutine 25 25 100.0
pod 9 9 100.0
total 616 694 88.7


line stmt bran cond sub pod time code
1             package HTML::Template::HTX;
2            
3             $VERSION = '0.07';
4            
5            
6             # FOR PERL VERSIONS PRIOR TO 5.6
7             #
8             # The next two lines should be disabled for Perl versions prior to 5.6. As
9             # far as I know there is no (simple) way to do this automatically at compile
10             # time, so you will have to do it yourself.
11             require 5.006;
12 1     1   2605 use utf8;
  1         10  
  1         5  
13            
14            
15             =head1 NAME
16            
17             HTML::Template::HTX - Handle HTML Extension template (F<.htx>) files
18            
19             =head1 SYNOPSIS
20            
21             use HTML::Template::HTX;
22            
23             $htx = HTML::Template::HTX->new('template.htx') or die "Oops!";
24            
25             $htx->param('counter' => 0);
26             $htx->print_header(1);
27            
28             foreach(qw(I used to care but Things Have Changed)) {
29             $htx->param(
30             'counter' => $htx->param('counter')+1,
31             'Name' => $_,
32             );
33             $htx->print_detail;
34             }
35            
36             $htx->print_footer;
37             $htx->close;
38            
39             =head2 template.htx
40            
41             Sample results
42            
43            
44            
45            

Sample results:

46            
47             <%begindetail%>
48             <%counter%>. <%Name%>
49             <%enddetail%>
50            
51            
52            
53             =head1 ABSTRACT
54            
55             Reads and outputs HTML Extension template (F<.htx>) files, which enable you
56             to seperate your Perl code from HTML code.
57            
58             The F<.htx> file format was originally used by Microsoft's Index Server and
59             their Internet Database Connector, but may be useful for any server side
60             program that outputs HTML (or even some other ASCII file format), and
61             especially for scripts generating sequential data, such as search engines.
62            
63             Note that this module and its template format are not directly related nor
64             compatible with the popular HTML::Template module.
65            
66             =cut
67            
68            
69 1     1   41 use strict;
  1         3  
  1         36  
70             #use warnings; # Enable warnings only during development
71            
72 1     1   19 use FileHandle;
  1         2  
  1         9  
73 1     1   1394 use HTML::Entities qw(encode_entities);
  1         8160  
  1         209  
74 1     1   880 use URI::Escape qw(uri_escape);
  1         1393  
  1         2101  
75            
76            
77             =head1 DESCRIPTION
78            
79             To use a F<.htx> template file in your Perl script, basically follow these
80             steps:
81            
82             =over 4
83            
84             =item 1
85            
86             Create a L HTML::Template::HTX object.
87            
88             =item 2
89            
90             Optionally define some L, and output the
91             L of the template.
92            
93             =item 3
94            
95             Optionally change or define some L, and output the
96             L. This step is optionally repeated a number of
97             times, depending on the data you're processing.
98            
99             =item 4
100            
101             Optionally change or define some L, and output the
102             L of the template.
103            
104             =item 5
105            
106             L the template file, or destroy the HTML::Template::HTX object.
107            
108             =back
109            
110             If you don't have any repeated data, then you can skip steps 2 and 3, and
111             just use C to output the whole template file at once. If you
112             have multiple sets of repeated data, then you should probably follow a
113             slightly altered schema (see the C method).
114            
115             =head2 Basic methods
116            
117             =over 4
118            
119             =item C<$htx = HTML::Template::HTX-Enew($template,> [C<$output>]C<,>
120             [C<-utf8>]C<,> [I]C<)>
121            
122             =item C<$htx = HTML::Template::HTX-Enew(template =E $template,>
123             [C $output>]C<,> [C<-utf8>]C<,> [I]C<)>
124            
125             Opens the specified F<.htx> template file. If an open file handle is
126             specified instead of a file name, then the template is read from this file
127             handle. If a scalar reference is specified, then the contents of the scalar
128             will be used as the template.
129            
130             If no output file is specified, then the STDOUT is used for output. If an
131             open file handle is specified, then this file handle is used for output. If
132             a scalar reference is specified instead of an output file, then all output
133             will be B to the specified scalar.
134            
135             By default UTF-8 coding will be disabled, but you can specify C<-utf8> to
136             enable it. For more on UTF-8 coding and this module see the C method.
137            
138             When any common parameters are specified, certain frequently used parameters
139             are automatically defined and maintained. For more information see the
140             C method.
141            
142             When using the named parameters interface, you can also use
143             C $template> instead of C