blib/lib/HTML/Template/HTX.pm

filter: Statementstmt 94.5% 344 / 364 Branchbran 83.5% 224 / 268 Conditioncond 66.6% 30 / 45 MC/DCmcdc 53.5% 15 / 28 Subroutinesub 100% 25 / 25 Podpod 100% 9 / 9 totaltotal 87.5% 647 / 739 CC 153 SCAR 27.1
CC
153
Cov
88%
print_header
29.5
new
22.3
_parse
21.3
CRAP 15.1
↑ Summary
1 package HTML::Template::HTX;
2
3 1 $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 1 require 5.006;
12 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 <HTML><HEAD><TITLE>Sample results</TITLE>
42
43 </HEAD><BODY>
44
45 <H2>Sample results:</H2>
46
47 <%begindetail%>
48 <%counter%>. <%Name%><BR>
49 <%enddetail%>
50
51 </BODY></HTML>
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 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 #use warnings; # Enable warnings only during development
71
72 1 ▶use FileHandle;
Subroutine BEGIN: called CC=1 SCAR=0.0
73 1 ▶use HTML::Entities qw(encode_entities);
Subroutine BEGIN: called CC=1 SCAR=0.0
74 1 ▶use URI::Escape qw(uri_escape);
Subroutine BEGIN: called CC=1 SCAR=0.0
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<new> HTML::Template::HTX object.
87
88 =item 2
89
90 Optionally define some L<parameters|param>, and output the
91 L<header|print_header> of the template.
92
93 =item 3
94
95 Optionally change or define some L<parameters|param>, and output the
96 L<detail section|print_detail>. 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<parameters|param>, and output the
102 L<footer|print_footer> of the template.
103
104 =item 5
105
106 L<Close|close> 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<print_footer> 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<detail_section> method).
114
115 =head2 Basic methods
116
117 =over 4
118
119 =item C<$htx = HTML::Template::HTX-E<gt>new($template,> [C<$output>]C<,>
120 [C<-utf8>]C<,> [I<common parameters>]C<)>
121
122 =item C<$htx = HTML::Template::HTX-E<gt>new(template =E<gt> $template,>
123 [C<output =E<gt> $output>]C<,> [C<-utf8>]C<,> [I<common parameters>]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<appended> 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<utf8> 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<common_params> method.
141
142 When using the named parameters interface, you can also use
143 C<filename =E<gt> $template> instead of C<template =E<gt> $template> (for
144 backward compatibility).
145
146 =cut
147
148 10 ▶sub new {
Subroutine new: called CC=22 SCAR=31.0
Pod documented
149 10 my $class = shift;
150 10 my $self = {};
151
152 # Parse the arguments.
153 10 my($template_file, $output_file, $utf8, @common, $arg);
154 10 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 20 9 29
155 20 $arg = shift;
156 20 ▶ if($arg =~ /^(template|filename)$/o) {
Branch: 6 branches
BranchTrueFalseTotal
if ($arg =~ /^(template|filename)$/o) { } 2 18 20
elsif ($arg eq 'output') { } 1 17 18
elsif ($arg eq '-utf8') { } 1 16 17
elsif ($arg =~ /^-/o) { } 1 15 16
elsif (not defined $template_file) { } 8 7 15
elsif (not defined $output_file) { } 7 0 7
157 2 $template_file = shift;
158 } elsif($arg eq 'output') {
159 1 $output_file = shift;
160 } elsif($arg eq '-utf8') {
161 1 $utf8 = 1;
162 } elsif($arg =~ /^-/o) {
163 1 push @common, $arg, @_;
164 1 last;
165 } elsif(!defined($template_file)) {
166 8 $template_file = $arg;
167 } elsif(!defined($output_file)) {
168 7 $output_file = $arg;
169 }
170 }
171 10 ▶ return undef unless(defined($template_file));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $template_file 0 10 10
172 10 ▶ $output_file = '-' unless(defined($output_file));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $output_file 2 8 10
173
174 # Open the .htx file.
175 10 my($file, $close_file);
176 10 ▶ if(!ref($template_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $template_file) { } 1 9 10
177 1 $file = new FileHandle "<$template_file";
178 1 ▶ return undef unless(defined($file));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $file 0 1 1
179 1 $close_file = 1;
180 } else {
181 9 $file = $template_file;
182 9 $close_file = '';
183 }
184 # Disable UTF-8 coding for Perl 5.8+.
185 10 ▶ binmode($file, ':bytes') if(($] >= 5.008) and (ref($file) ne 'SCALAR'));
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" and ref $file ne "SCALAR" 2 8 10
Condition66%2/3
$] >= "5.008" and ref $file ne "SCALAR"
!ll&&!rl&&r
082
MC/DC50%1/2
$] >= "5.008" and ref $file ne "SCALAR"
$] >= "5.008" ref $file ne "SCALAR"
Truth table66%2/3
A and B
A= $] >= "5.008"B= ref $file ne "SCALAR"
ABresult
0X0
100
111
186
187 # Open the file used for output (usually STDOUT).
188 10 my($output, $close_output);
189 10 ▶ if(!ref($output_file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $output_file) { } 3 7 10
190 3 $output = new FileHandle ">$output_file";
191 3 ▶ if(!defined($output)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $output) 0 3 3
192 0 CORE::close($file);
193 0 return undef;
194 }
195 3 $close_output = 1;
196 } else {
197 7 ▶ $$output_file = '' if((ref($output_file) eq 'SCALAR') and (!defined($$output_file)));
Branch: 1 branch
BranchTrueFalseTotal
if ref $output_file eq "SCALAR" and not defined $$output_file 2 5 7
Condition100%3/3
ref $output_file eq "SCALAR" and not defined $$output_file
!ll&&!rl&&r
142
MC/DC100%2/2
ref $output_file eq "SCALAR" and not defined $$output_file
ref $output_file eq "SCALAR" not defined $$output_file
Truth table100%3/3
A and not(B)
A= ref $output_file eq "SCALAR"B= not defined $$output_file
ABresult
0X0
100
111
198 7 $output = $output_file;
199 7 $close_output = '';
200 }
201 # Disable UTF-8 coding for Perl 5.8+.
202 10 ▶ binmode($output, ':bytes') if(($] >= 5.008) and (ref($output) ne 'SCALAR'));
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" and ref $output ne "SCALAR" 4 6 10
Condition66%2/3
$] >= "5.008" and ref $output ne "SCALAR"
!ll&&!rl&&r
064
MC/DC50%1/2
$] >= "5.008" and ref $output ne "SCALAR"
$] >= "5.008" ref $output ne "SCALAR"
Truth table66%2/3
A and B
A= $] >= "5.008"B= ref $output ne "SCALAR"
ABresult
0X0
100
111
203
204 # Save and initialize some values for later.
205 10 $self->{_file} = $file;
206 10 $self->{_close_file} = $close_file;
207 10 $self->{_output} = $output;
208 10 $self->{_close_output} = $close_output;
209 10 $self->{_closed} = '';
210 10 $self->{_section} = '';
211 10 $self->{_detail} = undef;
212 10 $self->{_rest} = undef;
213 10 $self->{_condition} = 1;
214 10 $self->{_if_count} = 0;
215 10 ▶ $self->{_utf8} = $utf8 ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$utf8 ? : 1 9 10
216 10 $self->{_stats} = '';
217 10 $self->{_param} = {};
218
219 # Bless me, father.
220 10 bless $self, $class;
221
222 # Optionally init the common parameters.
223 10 ▶ $self->common_params(@common) if(@common);
Branch: 1 branch
BranchTrueFalseTotal
if @common 1 9 10
224
225 10 return $self;
226 }
227
228
229 =item C<$htx-E<gt>param($name =E<gt> $value,>
230 [C<$name =E<gt> $value>...]C<)>
231
232 =item C<$value = $htx-E<gt>param($name)>
233
234 =item C<@names = $htx-E<gt>param()>
235
236 Sets or retrieves a user defined variable, or a list of variables. If one or
237 more name and value pairs are specified, then these variables will be set to
238 the specified values.
239
240 If only one argument is specified, than the value of that variable is
241 returned. Without arguments the C<param> method returns a list of names of
242 all defined variables.
243
244 I<See also L<The .htx file format|"THE .HTX FILE FORMAT">, and the>
245 I<C<common_params> method.>
246
247 =cut
248
249 60 ▶sub param {
Subroutine param: called CC=5 SCAR=16.1
Pod documented
250 # If there are no arguments, then return a list of variable names.
251 60 ▶ return (keys %{$_[0]->{_param}}) if($#_ == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $#_ == 0 1 59 60
252
253 # If there's only one argument, then return the value of that variable.
254 59 ▶ return $_[0]->{_param}{$_[1]} if($#_ == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $#_ == 1 37 22 59
255
256 # If there's two arguments, then one name/value pair is specified.
257 22 ▶ if($#_ == 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == 2) 3 19 22
258 3 $_[0]->{_param}{$_[1]} = $_[2];
259 3 return;
260 }
261
262 # Apparently two or more name/value pairs are specified.
263 19 my $n = 1;
264 19 ▶ while($n <= $#_) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n <= $#_) 43 19 62
265 # Set the variable to the specified value.
266 43 $_[0]->{_param}{$_[$n]} = $_[$n+1];
267 43 $n += 2;
268 }
269 }
270
271
272 =item C<$htx-E<gt>print_header(>[C<$http_header>] [C<-nph>]C<)>
273
274 Reads, parses and outputs the template file up to
275 C<E<lt>%begindetail%E<gt>>, and only reads what's between
276 C<E<lt>%begindetail%E<gt>> and C<E<lt>%enddetail%E<gt>>, but does not parse
277 and output this section yet. If no C<E<lt>%begindetail%E<gt>> was found,
278 then simply reads, parses and outputs the entire file. In this last case
279 C<print_header> returns a false value, else it returns a true value. If a
280 section name was specified inside the template file, then this true value is
281 actually the specified section name. This make life very easy for F<.htx>
282 files with multiple detail sections (see also the C<detail_section> method).
283
284 If this is the very first call to C<print_header> and only a content type is
285 specified in C<$http_header> (usually this should be C<'text/html'>), then
286 the following simplified HTTP header is printed before anything else:
287
288 Content-Type: $http_header
289
290 If C<$http_header> is not a valid content type (i.e. there's no '/' in it)
291 but its value is true, then the default content type of C<'text/html'> is
292 used. This is very useful, because you can thus simply do
293 C<$htx-E<gt>print_header(1)> to get a valid HTTP header with the
294 C<'text/html'> content type. If you don't want any header, then simply do a
295 C<print_header> with a false value, e.g. C<$htx-E<gt>print_header('')> (or
296 even just C<$htx-E<gt>print_header>).
297
298 If a full HTTP header is specified in C<$http_header> (i.e. if
299 C<$http_header> contains one or more "\n" characters), then that header
300 printed before anything else. Beware that a valid HTTP header should include
301 a trailing empty line.
302
303 The C<-nph> option is ignored, but still included for backward(s) ;-)
304 compatibility. If you need to print a full HTTP header, you could simply
305 pass the C<header> function of the CGI module, e.g.
306 C<$htx-E<gt>print_header(header(-nph =E<gt> 1))>.
307
308 =cut
309
310 16 ▶sub print_header {
Subroutine print_header: called CC=26 SCAR=33.8
Pod documented
311 16 my $self = $_[0];
312 16 local $_;
313
314 # Is this the first ever call to print_header?
315 16 my $first_time;
316 16 ▶ if(!defined($self->{_rest})) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_rest'}) { } 6 10 16
317 6 $first_time = 1;
318 # Output the specified HTTP header.
319 6 ▶ if(defined($_[1]) and ($_[1] =~ /\n/o)) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $_[1] and $_[1] =~ /\n/o) { } 1 5 6
elsif ($_[1]) { } 4 1 5
Condition100%3/3
defined $_[1] and $_[1] =~ /\n/o
!ll&&!rl&&r
141
MC/DC100%2/2
defined $_[1] and $_[1] =~ /\n/o
defined $_[1] $_[1] =~ /\n/o
Truth table100%3/3
A and B
A= defined $_[1]B= $_[1] =~ /\n/o
ABresult
0X0
100
111
320 1 _print($self, \$_[1]);
321 # Construct and output a (partial) HTTP header.
322 } elsif($_[1]) {
323 4 my $content_type = $_[1];
324 4 ▶ if($content_type !~ m#/#o) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($content_type =~ m[/]o) 3 1 4
325 3 $content_type = 'text/html';
326 3 ▶ $content_type .= '; charset=utf-8' if($self->{_utf8});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_utf8"} 1 2 3
327 }
328 4 $content_type = "Content-Type: $content_type\n\n";
329 4 _print($self, \$content_type);
330 }
331 6 $self->{_rest} = '';
332 } else {
333 10 $first_time = '';
334 }
335
336 # Optionally update the automated counters (NUMBER).
337 16 ▶ _stats($self, -1) if((!$first_time) and $self->{_stats});
Branch: 1 branch
BranchTrueFalseTotal
if not $first_time and $self->{"_stats"} 2 14 16
Condition100%3/3
not $first_time and $self->{"_stats"}
!ll&&!rl&&r
682
MC/DC100%2/2
not $first_time and $self->{"_stats"}
not $first_time $self->{"_stats"}
Truth table100%3/3
not(A) and B
A= not $first_timeB= $self->{"_stats"}
ABresult
0X0
100
111
338
339 # Read, parse and output everything up to <%begindetail%>.
340 16 $self->{_section} = '';
341 16 my $found;
342 16 my $file = $self->{_file};
343 16 my $is_scalar = ref($file) eq 'SCALAR';
344 # Start with whatever is left of that which followed <%enddetail%> last
345 # time.
346 16 ▶ if($self->{_rest} ne '') {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_rest'} ne '') { } 9 7 16
elsif (not $is_scalar) { } 0 7 7
347 9 $_ = $self->{_rest};
348 9 $self->{_rest} = '';
349 } elsif(!$is_scalar) {
350 0 $_ = <$file>;
351 } else {
352 7 ▶ $_ = $first_time ? $$file : undef;
Branch: 1 branch
BranchTrueFalseTotal
$first_time ? : 6 1 7
353 }
354 16 ▶ while(defined($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 15 1 16
355 # Check for <%begindetail%>.
356 15 ▶ if($found = /<%begindetail%>/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found = /<%begindetail%>/io) { } 12 3 15
357 # Output and parse only that which came before <%begindetail%>.
358 12 ▶ _print($self, $`) if($` ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $` ne "" 12 0 12
359 # Start the detail section with whatever followed <%begindetail%>.
360 12 $self->{_rest} = $';
361 12 last;
362 } else {
363 # Simply parse and output the entire line.
364 3 _print($self, $_);
365 }
366 # Next, please!
367 3 ▶ last if($is_scalar);
Branch: 1 branch
BranchTrueFalseTotal
if $is_scalar 3 0 3
368 0 $_ = <$file>;
369 }
370 16 ▶ $found or return '';
Branch: 1 branch
BranchTrueFalseTotal
$found or return "" 12 4 16
371
372 # Optionally init the automated counters (NUMBER and COUNT).
373 12 ▶ _stats($self, 0, 0) if($self->{_stats});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_stats"} 3 9 12
374
375 # Read and store everything between <%begindetail%> and <%enddetail%>.
376 12 $self->{_detail} = '';
377 # Start with the remainder of the last line that was read...
378 12 ▶ if($self->{_rest} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_rest'} ne '') { } 12 0 12
379 12 $_ = $self->{_rest};
380 12 $self->{_rest} = '';
381 # ... or read a line.
382 } else {
383 0 ▶ $_ = $is_scalar ? undef : <$file>;
Branch: 1 branch
BranchTrueFalseTotal
$is_scalar ? : 0 0 0
384 }
385 12 ▶ while(defined($_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $_) 12 0 12
386 # Check for <%enddetail%>.
387 12 ▶ if($found = /<%enddetail%>/io) {
Branch: 1 branch
BranchTrueFalseTotal
if ($found = /<%enddetail%>/io) { } 12 0 12
388 # Store only that which came before <%enddetail%>.
389 12 ▶ $self->{_detail} .= $` if($` ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $` ne "" 12 0 12
390 # Save whatever followed <%enddetail%> for later.
391 12 $self->{_rest} = $';
392 12 last;
393 } else {
394 # Simply store the entire line.
395 0 $self->{_detail} .= $_;
396 }
397 # Next, please!
398 0 ▶ last if($is_scalar);
Branch: 1 branch
BranchTrueFalseTotal
if $is_scalar 0 0 0
399 0 $_ = <$file>;
400 }
401
402 # Return whether a (valid) detail section was found.
403 12 ▶ return '' unless($found);
Branch: 1 branch
BranchTrueFalseTotal
unless $found 0 12 12
404 12 $found = $self->{_section};;
405 12 ▶ $found = 1 unless($found);
Branch: 1 branch
BranchTrueFalseTotal
unless $found 3 9 12
406 12 return $found;
407 }
408
409
410 =item C<$htx-E<gt>print_detail>
411
412 Parses and outputs the detail section that was read by the C<print_header>
413 method. The method C<print_detail> method is usually called from a loop to
414 output each subsequent record.
415
416 =cut
417
418 15 ▶sub print_detail {
Subroutine print_detail: called CC=4 SCAR=13.9
Pod documented
419 # Optionally update the automated counters (COUNT and TOTAL).
420 15 ▶ _stats($_[0], undef, 1, 1) if($_[0]->{_stats});
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_stats"} 13 2 15
421
422 # Parse and output the detail section.
423 15 ▶ if(_print($_[0], $_[0]->{_detail})) {
Branch: 1 branch
BranchTrueFalseTotal
if (_print($_[0], $_[0]{"_detail"})) 15 0 15
424 15 ▶ _stats($_[0], 1) if($_[0]->{_stats}); # (NUMBER)
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_stats"} 13 2 15
425 }
426 }
427
428
429 =item C<$htx-E<gt>print_footer(>[C<$http_header>] [C<-nph>]C<)>
430
431 Reads, parses and outputs the rest of the template file, skipping any
432 C<E<lt>%begindetail%E<gt>>..C<E<lt>%enddetail%E<gt>> sections it might
433 encounter. For the optional arguments, see the C<print_header> method.
434
435 A script that uses a template file without a detail section could call this
436 method immediately after C<HTML::Template::HTX-E<gt>new> (without calling
437 C<print_header>). This is because this method actually does subsequent calls
438 to the C<print_header> method until the end of the file is reached.
439
440 =cut
441
442 1 ▶sub print_footer {
Subroutine print_footer: called CC=2 SCAR=6.9
Pod documented
443 1 my $self = shift;
444 1 ▶ while($self->print_header(@_)) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->print_header(@_)) 3 1 4
445 1 return '';
446 }
447
448
449 =item C<$htx-E<gt>close>
450
451 Closes the template and output files. This is usually done directly after
452 the C<print_footer> method. When a HTML::Template::HTX object is destroyed
453 the files will be closed automatically, so you don't I<need> to call
454 C<close> (but I think it's very rude not to call C<close>!). ;-)
455
456 =cut
457
458 10 ▶sub close {
Subroutine close: called CC=7 SCAR=19.8
Pod documented
459 10 my $self = $_[0];
460
461 # Close the file used for output.
462 10 my($closed_output, $output);
463 10 $output = $self->{_output};
464 10 ▶ if(defined($output) and $self->{_close_output}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $output and $self->{'_close_output'}) { } 3 7 10
Condition66%2/3
defined $output and $self->{"_close_output"}
!ll&&!rl&&r
073
MC/DC50%1/2
defined $output and $self->{"_close_output"}
defined $output $self->{"_close_output"}
Truth table66%2/3
A and B
A= defined $outputB= $self->{"_close_output"}
ABresult
0X0
100
111
465 3 $closed_output = CORE::close($output);
466 } else {
467 7 $closed_output = 1;
468 }
469
470 # Close the .htx template file.
471 10 my($closed_file, $file);
472 10 $file = $self->{_file};
473 10 ▶ if(defined($file) and $self->{_close_file}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file and $self->{'_close_file'}) { } 1 9 10
Condition66%2/3
defined $file and $self->{"_close_file"}
!ll&&!rl&&r
091
MC/DC50%1/2
defined $file and $self->{"_close_file"}
defined $file $self->{"_close_file"}
Truth table66%2/3
A and B
A= defined $fileB= $self->{"_close_file"}
ABresult
0X0
100
111
474 1 $closed_file = CORE::close($file);
475 } else {
476 9 $closed_file = 1;
477 }
478
479 10 ▶ return '' unless($closed_output and $closed_file);
Branch: 1 branch
BranchTrueFalseTotal
unless $closed_output and $closed_file 0 10 10
Condition33%1/3
$closed_output and $closed_file
!ll&&!rl&&r
0010
MC/DC0%0/2
$closed_output and $closed_file
$closed_output $closed_file
Truth table33%1/3
A and B
A= $closed_outputB= $closed_file
ABresult
0X0
100
111
480 10 return $self->{_closed} = 1;
481 }
482
483
484 =back
485
486 =head2 Common parameters
487
488 Common parameters are a sets of parameters that are automatically defined
489 and maintained so you won't have to worry about them, but which can be used
490 inside a template just like any parameters you've defined yourself. You can
491 specify common parameters while L<creating|new> the HTML::Template::HTX
492 object, or you can use the C<common_params> method to define them later on.
493
494 =over 4
495
496 =item C<$htx-E<gt>common_params(>[I<options>]C<)>
497
498 Automatically defines and sets certain frequently used parameters. You can
499 specify one or more options, or nothing if you want to use the default set
500 of options (which is C<-count> and C<-date>).
501
502 The following options are currently supported:
503
504 =over 4
505
506 =item C<-count> [C<=E<gt> $enable>]
507
508 Enables or disables the use of automated counters. When called with no
509 argument or a true value, automated counters will be enabled. When called
510 with a false value, automated counters will be disabled.
511
512 The following HTX counter parameters are defined and maintained:
513
514 =over 4
515
516 =item *
517
518 C<E<lt>%COUNT%E<gt>> - The number of times C<print_detail> was called within
519 the current detail section.
520
521 =item *
522
523 C<E<lt>%NUMBER%E<gt>> - The number of times C<print_detail> was called within
524 the current detail section, I<and actually produced data> (thus not an empty
525 string).
526
527 =item *
528
529 C<E<lt>%TOTAL%E<gt>> - The number of times C<print_detail> was called
530 within I<all> detail section.
531
532 =item *
533
534 C<E<lt>%SECTION%E<gt>> - The name of the current detail section.
535
536 =back
537
538 C<E<lt>%NUMBER%E<gt>>, C<E<lt>%COUNT%E<gt>> and C<E<lt>%TOTAL%E<gt>> can be
539 followed by a question mark to get its value modules 2, e.g.
540 C<E<lt>%NUMBER?%E<gt>>.
541
542 You should always enable automated counters when L<creating|new> the
543 HTML::Template::HTX object or right after. You can disable them again
544 whenever you feel like it.
545
546 The automated counters only change when calling C<print_detail>, and
547 I<after> calling C<print_header>. This means you can still query them in
548 C<print_footer> (or the next C<print_header>, if you're using
549 L<multiple detail sections|detail_section>).
550
551 =item C<-date> [C<=E<gt> $epoch_time>]
552
553 Defines a set of date and time parameters for the given epoch date/time, or
554 the current date and time if no epoch date/time is specified.
555
556 The following HTX date and time parameters are defined and set:
557
558 =over 4
559
560 =item *
561
562 C<E<lt>%YEAR%E<gt>> - The year as a 4-digit number.
563
564 =item *
565
566 C<E<lt>%MONTH%E<gt>> - The month as a 2-digit number (01..12).
567
568 =item *
569
570 C<E<lt>%MONTH$%E<gt>> - The month as a 3-character string (in English).
571
572 =item *
573
574 C<E<lt>%DAY%E<gt>> - The day as a 2-digit number (01..31).
575
576 =item *
577
578 C<E<lt>%DATE%E<gt>> - The date ("dd mmm yyyy").
579
580 =item *
581
582 C<E<lt>%WEEKDAY%E<gt>> - The weekday as a 1-digit number (1..7; 1 = Sun, 2 =
583 Mon ... 7 = Sat).
584
585 =item *
586
587 C<E<lt>%WEEKDAY$%E<gt>> - The weekday as a 3-character string (in English).
588
589 =item *
590
591 C<E<lt>%HOUR%E<gt>> - The hour of the day as a 2-digit number (00..23).
592
593 =item *
594
595 C<E<lt>%MINUTE%E<gt>> - The minutes part of time time as a 2-digit number
596 (00..59).
597
598 =item *
599
600 C<E<lt>%TIME%E<gt>> - The time ("hh:mm").
601
602 =item *
603
604 C<E<lt>%SECOND%E<gt>> - The seconds part of time time a 2-digit number
605 (00..59).
606
607 =item *
608
609 C<E<lt>%TIME_ZONE%E<gt>> - The timezone (e.g. "+0100" or "GMT").
610
611 =item *
612
613 C<E<lt>%DATE_TIME%E<gt>> - The date and time (e.g. "Thu, 30 Oct 1975
614 17:10:00 +0100").
615
616 =back
617
618 Each of these variables is also available in GMT, e.g.
619 C<E<lt>%GMT_DATE_TIME%E<gt>>, C<E<lt>%GMT_TIME_ZONE%E<gt>> (which naturally
620 always is "GMT") etc.
621
622 =back
623
624 =cut
625
626 5 ▶sub common_params {
Subroutine common_params: called CC=11 SCAR=24.0
Pod documented
627 5 my $self = shift;
628 5 ▶ @_ = (-count, -date) unless(@_);
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 5 5
629
630 # Parse the options one by one.
631 5 my($option, $arg);
632 5 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 6 5 11
633 6 $option = shift;
634 6 ▶ $arg = (defined($_[0]) and ($_[0] !~ /^-/o)) ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] && !($_[0] =~ /^-/o) ? : 2 4 6
Condition100%3/3
defined $_[0] and not $_[0] =~ /^-/o
!ll&&!rl&&r
312
MC/DC100%2/2
defined $_[0] and not $_[0] =~ /^-/o
defined $_[0] not $_[0] =~ /^-/o
Truth table100%3/3
A and not(B)
A= defined $_[0]B= not $_[0] =~ /^-/o
ABresult
0X0
100
111
635
636 # Enable or disable the automated counters.
637 6 ▶ if($option eq '-count') {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq "-count") 3 3 6
638 3 ▶ $arg = 1 unless(defined($arg));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 2 1 3
639 3 ▶ if($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) { } 2 1 3
640 2 ▶ if(!$self->{_stats}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_stats"}) 2 0 2
641 2 $self->{_stats} = 1;
642 2 _stats($self, 0, 0, 0, $self->{_section});
643 }
644 } else {
645 1 $self->{_stats} = '';
646 }
647 3 next;
648 }
649
650 # Set date and time variables.
651 3 ▶ if($option eq '-date') {
Branch: 1 branch
BranchTrueFalseTotal
if ($option eq "-date") 3 0 3
652 3 ▶ $arg = time unless(defined($arg));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg 2 1 3
653 3 _date($self, $arg);
654 }
655 }
656
657 }
658
659
660 =back
661
662 =head2 Multiple detail sections
663
664 If you have multiple sets of repeated data which you want to pass to a
665 single F<.htx> template, you could simply do:
666
667 =over 4
668
669 =item 1
670
671 C<print_header> (header of 1st detail section)
672
673 =item 2
674
675 C<print_detail>C< foreach(0..>I<n>C<)> (1st detail section)
676
677 =item 3
678
679 C<print_header> (footer of 1st and header of 2nd detail section)
680
681 =item 4
682
683 C<print_detail>C< foreach(0..>I<n>C<)> (2nd detail section)
684
685 =item 5
686
687 C<print_footer> (footer of 2nd detail section)
688
689 =back
690
691 Steps 3 and 4 could be repeated a number of times before continuing to step
692 5, depending on the number of detail sections in both your Perl script and
693 your F<.htx> template.
694
695 But what if you'd change the order in which the detail sections appear
696 inside the template? You would also have to change the order in which the
697 data is processed inside your Perl script. :-( This is where the
698 C<detail_section> method and the C<E<lt>%detailsection >I<name>C<%E<gt>>
699 F<.htx> command come in. :-)
700
701 =over 4
702
703 =item C<$name = $htx-E<gt>detail_section>
704
705 =item C<$htx-E<gt>detail_section($name)>
706
707 Retrieves (or sets) the name of the current detail section. You can define a
708 logical name for the next detail section inside a template file (which sort
709 of announces the next detail section), and your Perl script that passes data
710 to the template can check this section name and pass the data belonging to
711 that specific section. This comes in handy if your template contains
712 multiple detail sections.
713
714 Normally you should never set the section name from your Perl script, but
715 rather use the C<E<lt>%detailsection >I<name>C<%E<gt>> command in your
716 template file. Normally you do not even have to retrieve the section name
717 using this method, because the C<print_header> method already returns the
718 current section name.
719
720 Consider this Perl example:
721
722 $htx = HTML::Template::HTX->new('template.htx');
723 ...
724 while($section = $htx->print_header(1)) {
725 if($section eq 'LINKS') {
726 foreach(@url) {
727 ...
728 print_detail;
729 }
730 next;
731 }
732 if($section eq 'ADS') {
733 while(<$ads>) {
734 ...
735 print_detail;
736 }
737 next;
738 }
739 }
740 $htx->close;
741
742 And the corresponding C<template.htx> example file:
743
744 <HTML><HEAD><TITLE>Sample results</TITLE></HEAD><BODY>
745
746 <%detailsection ADS%>
747 <%begindetail%>
748 <A HREF="<%EscapeRaw URL%><IMG SRC="<%EscapeURL Image%>></A>
749 <%enddetail%>
750
751 <%detailsection LINKS%>
752 <H2>Links to Perly websites</H2>
753 <%begindetail%>
754 <A HREF="<%EscapeRaw URL%><%URL%></A><BR>
755 <%enddetail%>
756
757 </BODY></HTML>
758
759 =cut
760
761 8 ▶sub detail_section {
Subroutine detail_section: called CC=2 SCAR=6.9
Pod documented
762 # Return the current section name.
763 8 ▶ return $_[0]->{_section} if(!defined($_[1]));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[1] 6 2 8
764
765 # Set the current section name.
766 2 $_[0]->{_section} = $_[1];
767 }
768
769
770 =back
771
772 =head2 UTF-8 support
773
774 The transparent UTF-8 support in Perl is very useful when reading data from
775 different sources, but it's not very useful when returning data to client
776 software (e.g. an internet browser) that almost certainly won't have
777 transparent UTP-8 support. That's why the C<utf8> method lets you control
778 whether your output will be UTF-8 coded or not.
779
780 =over 4
781
782 =item C<$htx-E<gt>utf8(>[C<$enable>]C<)>
783
784 Enables or disables UTF-8 coding for the output of user defined or
785 "environmental" :-) variables. When called with no argument (thus undef) or
786 a true value, UTF-8 coding will be enabled. When called with a false value,
787 UTF-8 coding will be disabled. For UTF-8 coding Perl 5.6 or newer is
788 required. You may also need versions of the HTML::Entities and URI::Escape
789 modules that understand UTF-8.
790
791 You should always enable or disable UTF-8 coding when L<creating|new> the
792 HTML::Template::HTX object or right after. You should B<never> change the
793 UTF-8 flag later on.
794
795 You can always use UTF-8 characters inside user defined variables,
796 I<regardless of the state of the UTF-8 flag>. With UTF-8 coding disabled,
797 all UTF-8 characters that are found inside variable values will be converted
798 to their 8-bit counterparts (where possible). With UTF-8 coding enabled, all
799 8-bit non-UTF-8 characters will be converted to their UTF-8 counterparts.
800
801 Note that enabling the UTF-8 flag will only UTF-8 code variables, not the
802 rest of the template file, which is parsed "as is". So when enabling UTF-8,
803 make sure your template is also UTF-8 coded.
804
805 =cut
806
807 7 ▶sub utf8 {
Subroutine utf8: called CC=4 SCAR=13.9
Pod documented
808 7 my($self, $enable) = @_;
809
810 # Enable or disable UTF-8 encoding.
811 7 ▶ if(defined($enable)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $enable) { } 5 2 7
812 5 ▶ $enable = $enable ? 1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$enable ? : 2 3 5
813 } else {
814 2 $enable = 1;
815 }
816 7 ▶ return unless($self->{_utf8} ne $enable);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_utf8"} ne $enable 2 5 7
817 5 $self->{_utf8} = $enable;
818 }
819
820
821 # Here ends the "documented" part of this module, and so "things should
822 # start to get interesting right about now"("Mississippi", Bob Dylan).
823
824 =back
825
826 =cut
827
828 1 ▶use vars qw(%_operator $_is_number);
Subroutine BEGIN: called CC=1 SCAR=0.0
829
830 1 ▶sub BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
831 # The operators that can be used in an <%if%> statement, and their
832 # numerical counterparts.
833 1 %_operator = (
834 'eq' => '==',
835 'ne' => '!=',
836 'lt' => '<',
837 'le' => '<=',
838 'gt' => '>',
839 'ge' => '>=',
840 );
841
842 # The regular expression that matches a (simple) numerical value.
843 1 $_is_number = '-?\d*[.]?\d*';
844 }
845
846
847 # Closes the file handles before destroying the object.
848
849 9 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=6.9
850 # Call the close method to close the template and output files.
851 9 ▶ $_[0]->close unless($_[0]->{_closed});
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"_closed"} 6 3 9
852 }
853
854
855 # Reads an include file.
856 #
857 # _include($self, 'include.htx', \$htx_code_fragment, \$prematch,
858 # \$postmatch) or die;
859
860 1 ▶sub _include {
Subroutine _include: called CC=3 SCAR=11.8
861 1 my($self, $include_file, $htx, $prematch, $postmatch) = @_;
862
863 # Open the include file.
864 1 my $file = new FileHandle "<$include_file";
865 1 ▶ if(defined($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $file) 1 0 1
866 # Disable UTF-8 coding for Perl 5.8+.
867 1 ▶ binmode($file, ':bytes') if($] >= 5.008);
Branch: 1 branch
BranchTrueFalseTotal
if $] >= "5.008" 1 0 1
868 # Read and insert the entire include file at once.
869 1 $$htx = $$prematch.join('', <$file>).$$postmatch;
870 1 CORE::close($file);
871 1 return 1;
872 }
873
874 # Reading the file failed, so simply remove the <%include%> tag.
875 0 $$htx = $$prematch.$$postmatch;
876 0 return '';
877 }
878
879
880 # Parse an expression by retrieving the value of a variable, or by leaving
881 # it almost unchanged if it's a literal expression (that may be unclosed by
882 # "").
883 #
884 # $string = _express($self, '"Text"');
885 # $value = _express($self, 'HtxVariableName');
886 # $host = _express($self, 'HTTP_HOST');
887 # $number = _express($self, '123.45');
888
889 107 ▶sub _express {
Subroutine _express: called CC=11 SCAR=25.0
890 # Check if the expresion is enclosed by "".
891 107 ▶ if($_[1] =~ /^"(.*)"$/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] =~ /^"(.*)"$/o) 15 92 107
892 # Treat it as a literal, but remove the "".
893 15 return $1;
894 }
895
896 # Check if the expression could be a user defined variable.
897 92 my $value;
898 92 ▶ if(exists $_[0]->{_param}{$_[1]}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $_[0]{'_param'}{$_[1]}) { } 66 26 92
elsif (exists $ENV{$_[1]}) { } 1 25 26
899 # Return the value of the variable.
900 66 $value = $_[0]->{_param}{$_[1]};
901 # Check if the expression is a (CGI) environment variable.
902 } elsif(exists $ENV{$_[1]}) {
903 # Return the value of the environment variable.
904 1 $value = $ENV{$_[1]};
905 }
906 92 ▶ if(defined($value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) 67 25 92
907 # Make sure Perl 5.6+ does UTF-8 coding.
908 67 ▶ if($] >= 5.006) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= "5.006") 67 0 67
909 67 ▶ if($] < 5.008) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] < 5.008) { } 0 67 67
910 # Make sure it's UTF-8.
911 0 $value .= "\x{A9}";
912 0 chop($value);
913 # Optionally convert UTF-8 back to octets.
914 0 ▶ $value = pack("U0C*", unpack("U*", $value)) unless($_[0]->{_utf8});
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]{"_utf8"} 0 0 0
915 } else {
916 # With Perl 5.8+ in :bytes mode we'll need UTF-8 code ourselves.
917 67 ▶ utf8::encode($value) if($_[0]->{_utf8});
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_utf8"} 27 40 67
918 }
919 }
920 67 return $value;
921 }
922
923 # Check if the expression is a numerical expression.
924 25 ▶ if(($_[1] ne '') and ($_[1] =~ /^$_is_number$/o)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1] ne "" and $_[1] =~ /^$HTML::Template::HTX::_is_number$/o) 12 13 25
Condition66%2/3
$_[1] ne "" and $_[1] =~ /^$HTML::Template::HTX::_is_number$/o
!ll&&!rl&&r
01312
MC/DC50%1/2
$_[1] ne "" and $_[1] =~ /^$HTML::Template::HTX::_is_number$/o
$_[1] ne "" $_[1] =~ /^$HTML::Template::HTX::_is_number$/o
Truth table66%2/3
A and B
A= $_[1] ne ""B= $_[1] =~ /^$HTML::Template::HTX::_is_number$/o
ABresult
0X0
100
111
925 # Return the numerical value.
926 #no warnings 'numeric'; # Warnings are enabled only during development
927 12 return 1*$_[1];
928 }
929
930 # None of the above, so return an empty string.
931 13 return '';
932 }
933
934
935 # Evaluate a condition from an <%if%> statement.
936 #
937 # _evaluate($self, 'Count gt 10') and print "More than 10!";
938
939 26 ▶sub _evaluate {
Subroutine _evaluate: called CC=13 SCAR=25.7
940 26 local $_;
941
942 # Break up the condition into three parts (value1, operator, value2).
943 26 my($value1, $value2, $operator);
944 26 ▶ $_[1] =~ /^(.+?)\s+(.+?)(\s+(.+?))?$/o or return '';
Branch: 1 branch
BranchTrueFalseTotal
$_[1] =~ /^(.+?)\s+(.+?)(\s+(.+?))?$/o or return "" 26 0 26
945 26 $value1 = $1;
946 26 $operator = lc($2);
947 26 $value2 = $4;
948
949 # Is this the istypeeq operator?
950 26 ▶ if($operator eq 'istypeeq') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "istypeeq") 1 25 26
951 # Return true (just included for compatibility).
952 1 return 1;
953 }
954
955 # Parse both expressions.
956 25 my $string_compare = '';
957 25 foreach(\$value1, \$value2) {
958 50 ▶ if(defined($$_)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$_) { } 40 10 50
959 40 $$_ = _express($_[0], $$_);
960 40 ▶ $string_compare = 1 unless(($$_ ne '') and ($$_ =~ /^$_is_number$/o));
Branch: 1 branch
BranchTrueFalseTotal
unless $$_ ne "" and $$_ =~ /^$HTML::Template::HTX::_is_number$/o 17 23 40
Condition100%3/3
$$_ ne "" and $$_ =~ /^$HTML::Template::HTX::_is_number$/o
!ll&&!rl&&r
8923
MC/DC100%2/2
$$_ ne "" and $$_ =~ /^$HTML::Template::HTX::_is_number$/o
$$_ ne "" $$_ =~ /^$HTML::Template::HTX::_is_number$/o
Truth table100%3/3
A and B
A= $$_ ne ""B= $$_ =~ /^$HTML::Template::HTX::_is_number$/o
ABresult
0X0
100
111
961 } else {
962 10 $$_ = '';
963 10 $string_compare = 1;
964 }
965 }
966
967 # Is this the isempty operator?
968 25 ▶ if($operator eq 'isempty') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "isempty") 10 15 25
969 # Return whether the string value1 is empty.
970 10 return $value1 eq '';
971 }
972
973 # Compare the strings case-insensitive.
974 15 ▶ if($string_compare) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string_compare) 4 11 15
975 4 $value1 = lc($value1);
976 4 $value2 = lc($value2);
977 }
978
979 # Is this the contains operator?
980 15 ▶ if($operator eq 'contains') {
Branch: 1 branch
BranchTrueFalseTotal
if ($operator eq "contains") 1 14 15
981 # Return whether the string value1 contains the string value2.
982 1 return $value1 =~ /$value2/;
983 }
984
985 # If it's not one of the comparison operators, then return false.
986 14 ▶ return '' unless(exists $_operator{$operator});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $HTML::Template::HTX::_operator{$operator} 0 14 14
987
988 # Construct a Perl eval expression.
989 14 my $eval;
990 14 ▶ if($string_compare) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string_compare) { } 3 11 14
991 3 $value1 =~ s/'/\\'/go;
992 3 $value2 =~ s/'/\\'/go;
993 3 $eval = "'$value1' $operator '$value2'";
994 } else {
995 11 $eval = "$value1 $_operator{$operator} $value2";
996 }
997 # Let Perl evaluate the expression.
998 14 $eval = eval($eval);
999 14 ▶ return '' if($@);
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 14 14
1000 14 return $eval;
1001 }
1002
1003
1004 # Encode a variable or value using a certain encoding.
1005 #
1006 # _encode($self, 'SomeHtxVariable', 'html');
1007 # _encode($self, 'SomeHtxVariable', 'url');
1008 # _encode($self, 'SomeHtxVariable', 'js');
1009 # _encode($self, 'SomeHtxVariable', 'scramble');
1010 # _encode($self, 'SomeHtxVariable'); # Raw ("as is")
1011
1012 60 ▶sub _encode {
Subroutine _encode: called CC=14 SCAR=26.4
1013 # Parse the expression.
1014 60 my $value = _express(@_[0, 1]);
1015
1016 # Encode as HTML entities.
1017 60 my $encoding = lc($_[2]); # lc converts undef to ''
1018 60 ▶ return encode_entities($value) if($encoding eq 'html');
Branch: 1 branch
BranchTrueFalseTotal
if $encoding eq "html" 42 18 60
1019
1020 # Encode using URL escape codes.
1021 18 ▶ return uri_escape($value) if($encoding eq 'url');
Branch: 1 branch
BranchTrueFalseTotal
if $encoding eq "url" 2 16 18
1022
1023 # Encode for use in JavaScript strings (double-quoted).
1024 16 ▶ if($encoding eq 'js') {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq "js") 2 14 16
1025 2 $value =~ s/[\\"]/\\$&/go; # Backslash, double quote
1026 2 $value =~ s/\x08/\\b/go; # Backspace
1027 2 $value =~ s/\f/\\f/go; # Form feed
1028 2 $value =~ s/\n/\\n/go; # New line
1029 2 $value =~ s/\r/\\r/go; # Carriage return
1030 2 $value =~ s/\t/\\t/go; # Tab
1031 2 return $value;
1032 }
1033
1034 # Encode and scramble for use in JavaScript strings (double-quoted).
1035 14 ▶ if($encoding eq 'scramble') {
Branch: 1 branch
BranchTrueFalseTotal
if ($encoding eq "scramble") 2 12 14
1036 2 my($scramble, $method, $previous, $n, $c);
1037 2 $scramble = '';
1038 2 $previous = -1;
1039 2 foreach $n (0..length($value)-1) {
1040 # Select a method (raw, octal or hex).
1041 39 $c = substr($value, $n, 1);
1042 39 $method = -1;
1043 39 ▶ if($c =~ /^[\x00-\x1F"\\\@\x7F-\xFF]$/o) {
Branch: 3 branches
BranchTrueFalseTotal
if ($c =~ /^[\x00-\x1F"\\\@\x7F-\xFF]$/o) { } 5 34 39
elsif ($previous == 0) { } 9 25 34
elsif ($previous == 1) { } 6 19 25
1044 5 $method = int(rand(2));
1045 } elsif($previous == 0) {
1046 9 ▶ $method = int(rand(2)) if($c =~ /^[0-9A-Za-z]$/o);
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /^[0-9A-Za-z]$/o 8 1 9
1047 } elsif($previous == 1) {
1048 6 ▶ $method = int(rand(2)) if($c =~ /^[0-7]$/o);
Branch: 1 branch
BranchTrueFalseTotal
if $c =~ /^[0-7]$/o 0 6 6
1049 }
1050 39 ▶ $method = int(rand(5)) if($method == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $method == -1 26 13 39
1051 # Encode scrambled using the selected method.
1052 39 ▶ if($method == 0) {
Branch: 2 branches
BranchTrueFalseTotal
if ($method == 0) { } 10 29 39
elsif ($method == 1) { } 8 21 29
1053 10 $scramble .= sprintf("\\x%X", ord($c));
1054 } elsif($method == 1) {
1055 8 $scramble .= sprintf("\\%o", ord($c));
1056 } else {
1057 21 $scramble .= $c;
1058 }
1059 39 $previous = $method;
1060 }
1061 2 return $scramble;
1062 }
1063
1064 # Do not encode, instead leave the raw data in tact.
1065 12 return $value;
1066 }
1067
1068
1069 # Parse (part of) the HTML template file.
1070 #
1071 # _parse($self, \$htx_code_fragment);
1072
1073 51 ▶sub _parse {
Subroutine _parse: called CC=21 SCAR=30.6
1074 51 my($self, $htx) = @_;
1075
1076 # Fetch our current condition.
1077 51 my $condition = $self->{_condition};
1078 51 my $if_count = $self->{_if_count};
1079 51 my $if_offset = 0;
1080
1081 # Find the next statement (between "<%" and "%>").
1082 51 my($expr, $statement, $arg);
1083 51 ▶ while($$htx =~ /<%(.+?)(\s+(.+?))?%>/os) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$htx =~ /<%(.+?)(\s+(.+?))?%>/so) 120 51 171
1084 120 $expr = $1;
1085 120 $statement = lc($1);
1086 120 $arg = $3;
1087
1088 # Are we currently processing an <%if%> that turned out false?
1089 120 ▶ if(!$condition) {
Branch: 11 branches
BranchTrueFalseTotal
if (not $condition) { } 25 95 120
elsif ($statement eq 'escaperaw') { } 11 84 95
elsif ($statement eq 'escapehtml') { } 18 66 84
elsif ($statement eq 'escapeurl') { } 1 65 66
elsif ($statement eq 'escapejs') { } 1 64 65
elsif ($statement eq 'escapescramble') { } 1 63 64
elsif ($statement eq 'include') { } 0 63 63
elsif ($statement eq 'if') { } 13 50 63
elsif ($statement eq 'else') { } 14 36 50
elsif ($statement eq 'endif') { } 4 32 36
elsif ($statement eq 'detailsection') { } 9 23 32
1090 # Cut off everything before the current statement (and also cut off
1091 # the statement itself).
1092 25 $$htx = substr($`, 0, $if_offset).$';
1093 # Is this a nested <%if%> statement?
1094 25 ▶ if($statement eq 'if') {
Branch: 3 branches
BranchTrueFalseTotal
if ($statement eq 'if') { } 0 25 25
elsif ($statement eq 'else') { } 2 23 25
elsif ($statement eq 'endif') { } 15 8 23
1095 0 $if_count++;
1096 # Is this an <%else%> statement?
1097 } elsif($statement eq 'else') {
1098 # Reset the current condition state to true if we're not nested.
1099 2 ▶ $condition = 1 if($if_count == 0);
Branch: 1 branch
BranchTrueFalseTotal
if $if_count == 0 2 0 2
1100 # Is this an <%endif%> statement?
1101 } elsif($statement eq 'endif') {
1102 # Reset the current condition state to true if we're not nested.
1103 15 ▶ if($if_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($if_count > 0) { } 0 15 15
1104 0 $if_count--;
1105 } else {
1106 15 $condition = 1;
1107 }
1108 }
1109
1110 # Is this the <%EscapeRaw%> statement?
1111 } elsif($statement eq 'escaperaw') {
1112 # Parse the expression using no encoding.
1113 11 $$htx = $`._encode($self, $arg).$';
1114
1115 # Is this the <%EscapeHTML%> statement?
1116 } elsif($statement eq 'escapehtml') {
1117 # Parse the expression using HTML encoding.
1118 18 $$htx = $`._encode($self, $arg, 'html').$';
1119
1120 # Is this the <%EscapeURL%> statement?
1121 } elsif($statement eq 'escapeurl') {
1122 # Parse the expression using URL encoding.
1123 1 $$htx = $`._encode($self, $arg, 'url').$';
1124
1125 # Is this the <%EscapeJS%> statement?
1126 } elsif($statement eq 'escapejs') {
1127 # Parse the expression using JavaScript encoding.
1128 1 $$htx = $`._encode($self, $arg, 'js').$';
1129
1130 # Is this the <%EscapeScramble%> statement?
1131 } elsif($statement eq 'escapescramble') {
1132 # Parse the expression using JavaScript encoding.
1133 1 $$htx = $`._encode($self, $arg, 'scramble').$';
1134
1135 # Is this the <%include%> statement?
1136 } elsif($statement eq 'include') {
1137 # Insert the include file.
1138 0 _include($self, $arg, $htx, \$`, \$');
1139
1140 # Is this the <%if%> statement?
1141 } elsif($statement eq 'if') {
1142 # Evaluate the condition.
1143 13 $condition = _evaluate($self, $arg);
1144 # Continue after the current statement.
1145 31 _IF_:
1146 $$htx = $`.$';
1147 31 $if_offset = length($`);
1148
1149 # Is this the <%else%> statement?
1150 } elsif($statement eq 'else') {
1151 # Set the current condition state to false.
1152 14 $condition = '';
1153 14 goto _IF_;
1154
1155 # Is this the <%endif%> statement?
1156 } elsif($statement eq 'endif') {
1157 # Do the same as you would for an <%if%> that turned out true.
1158 4 goto _IF_;
1159
1160 # Is this the <%detailsection%> statement?
1161 } elsif($statement eq 'detailsection') {
1162 # Set the current section name.
1163 9 $self->{_section} = $arg;
1164 9 ▶ _stats($self, undef, undef, undef, $arg) if($self->{_stats});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_stats"} 2 7 9
1165 9 $$htx = $`.$';
1166
1167 # The statement was not recognized, so it must an expression.
1168 } else {
1169 # Encode the expression using HTML encoding.
1170 23 $$htx = $`._encode($self, $expr, 'html').$';
1171 }
1172 }
1173
1174 # If the condition is false, then keep only everything up to the last
1175 # point where the condition was true.
1176 51 ▶ $$htx = substr($$htx, 0, $if_offset) if(!$condition);
Branch: 1 branch
BranchTrueFalseTotal
unless $condition 1 50 51
1177
1178 # Save some values for later.
1179 51 $self->{_condition} = $condition;
1180 51 $self->{_if_count} = $if_count;
1181
1182 51 ▶ return '' if(!$condition);
Branch: 1 branch
BranchTrueFalseTotal
unless $condition 1 50 51
1183 50 return 1;
1184 }
1185
1186
1187 # Parses (optional) and outputs a scalar.
1188 #
1189 # defined(_print($self, $scalar)) or die; # Parse and output
1190 # (_print($self, \$scalar) > 0) or print "Void"; # Output only
1191
1192 37 ▶sub _print {
Subroutine _print: called CC=6 SCAR=20.8
1193 37 my($self, $scalar) = @_;
1194
1195 # Optionally parse the scalar.
1196 37 my $ref;
1197 37 ▶ if(!ref($scalar)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not ref $scalar) { } 31 6 37
1198 31 _parse($self, $ref = \$scalar);
1199 } else {
1200 6 $ref = $scalar;
1201 }
1202
1203 # Output the scalar.
1204 37 ▶ if(ref($self->{_output}) eq 'SCALAR') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $self->{'_output'} eq 'SCALAR') { } 37 0 37
elsif ($$ref ne '') { } 0 0 0
1205 37 ▶ ${$self->{_output}} .= $$ref if($$ref ne '');
Branch: 1 branch
BranchTrueFalseTotal
if $$ref ne "" 37 0 37
1206 } elsif($$ref ne '') {
1207 0 ▶ (print {$self->{_output}} $$ref) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
print {$self->{"_output"};} $$ref or return undef 0 0 0
1208 }
1209 37 return length($$ref);
1210 }
1211
1212
1213 # Sets the common parameters for automated counters.
1214 #
1215 # _stats($self, 0, 0); # Reset NUMBER and COUNT
1216 # _stats($self, 1); # Add 1 to NUMBER
1217 # _stats($self, 1); # Substract 1 from NUMBER
1218 # _stats($self, undef, 1, 1); # Add 1 to COUNT and to TOTAL
1219 # _stats($self, undef, undef, undef, $section); # Only set SECTION
1220
1221 35 ▶sub _stats {
Subroutine _stats: called CC=8 SCAR=20.8
1222 35 my($self, $number, $count, $total, $section) = @_;
1223 35 local $_;
1224
1225 35 ▶ if(defined($number)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $number) 20 15 35
1226 20 ▶ $number ? ($number = $self->{_param}{'NUMBER'}+$number) : ($number = 1);
Branch: 1 branch
BranchTrueFalseTotal
$number ? : 15 5 20
1227 20 $self->{_param}{'NUMBER'} = $number;
1228 20 $self->{_param}{'NUMBER?'} = $number%2;
1229 }
1230
1231 35 ▶ if(defined($count)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $count) 18 17 35
1232 18 ▶ $count ? ($count = $self->{_param}{'COUNT'}+$count) : ($count = 0);
Branch: 1 branch
BranchTrueFalseTotal
$count ? : 13 5 18
1233 18 $self->{_param}{'COUNT'} = $count;
1234 18 $self->{_param}{'COUNT?'} = $count%2;
1235 }
1236
1237 35 ▶ if(defined($total)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $total) 15 20 35
1238 15 ▶ $total ? ($total = $self->{_param}{'TOTAL'}+$total) : ($total = 0);
Branch: 1 branch
BranchTrueFalseTotal
$total ? : 13 2 15
1239 15 $self->{_param}{'TOTAL'} = $total;
1240 15 $self->{_param}{'TOTAL?'} = $total%2;
1241 }
1242
1243 35 ▶ $self->{_param}{'SECTION'} = $section if(defined($section));
Branch: 1 branch
BranchTrueFalseTotal
if defined $section 4 31 35
1244 }
1245
1246
1247 # Sets the common date and time parameters.
1248 #
1249 # _date($self, $epoch_time);
1250
1251 3 ▶sub _date {
Subroutine _date: called CC=9 SCAR=23.5
1252 3 my($self, $epoch_time) = @_;
1253 3 ▶ $epoch_time = time unless(defined($epoch_time));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $epoch_time 0 3 3
1254
1255 # Calculate the local time zone.
1256 3 my @ltm = localtime($epoch_time);
1257 3 my @gmt = gmtime($epoch_time);
1258 3 my $zone = ($ltm[2]*60+$ltm[1])-($gmt[2]*60+$gmt[1]);
1259 3 ▶ if(($ltm[5] > $gmt[5]) or (($ltm[5] == $gmt[5]) and ($ltm[7] > $gmt[7]))) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ltm[5] > $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] > $gmt[7]) { } 0 3 3
elsif ($ltm[5] < $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] < $gmt[7]) { } 0 3 3
Condition33%2/6
$ltm[5] > $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] > $gmt[7]
l!l&&r!l&&!r
003
$ltm[5] == $gmt[5] and $ltm[7] > $gmt[7]
!ll&&!rl&&r
030
MC/DC0%0/3
$ltm[5] > $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] > $gmt[7]
$ltm[5] > $gmt[5] $ltm[5] == $gmt[5] $ltm[7] > $gmt[7]
Truth table25%1/4
A or B and C
A= $ltm[5] > $gmt[5]B= $ltm[5] == $gmt[5]C= $ltm[7] > $gmt[7]
ABCresult
1XX1
0111
00X0
0100
1260 0 $zone += 24*60;
1261 ▶ } elsif(($ltm[5] < $gmt[5]) or (($ltm[5] == $gmt[5]) and ($ltm[7] < $gmt[7]))) {
Condition33%2/6
$ltm[5] < $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] < $gmt[7]
l!l&&r!l&&!r
003
$ltm[5] == $gmt[5] and $ltm[7] < $gmt[7]
!ll&&!rl&&r
030
MC/DC0%0/3
$ltm[5] < $gmt[5] or $ltm[5] == $gmt[5] and $ltm[7] < $gmt[7]
$ltm[5] < $gmt[5] $ltm[5] == $gmt[5] $ltm[7] < $gmt[7]
Truth table25%1/4
A or B and C
A= $ltm[5] < $gmt[5]B= $ltm[5] == $gmt[5]C= $ltm[7] < $gmt[7]
ABCresult
1XX1
0111
00X0
0100
1262 0 $zone -= 24*60;
1263 }
1264 3 my $hour = int($zone/60);
1265 3 $zone = sprintf("%+03d%02d", $hour, abs($zone-$hour*60));
1266
1267 # Set the parameters for both the local time and GMT.
1268 3 my($date, $tm, $prefix);
1269 3 $date = localtime($epoch_time);
1270 3 $tm = \@ltm;
1271 3 foreach $prefix ('', 'GMT_') {
1272 # Construct a full date/time string.
1273 6 $date =
1274 substr($date, 0, 3). # Weekday, e.g. "Thu"
1275 ', '.
1276 sprintf("%02d", $$tm[3]). # Day, e.g. "30"
1277 substr($date, 3, 5). # Month, e.g. " Oct "
1278 substr($date, 20, 4). # Year, e.g. "1975"
1279 substr($date, 10, 10). # Time, e.g. " 17:10:00 "
1280 $zone; # Zone, e.g. "+0100"
1281
1282 # Set the date/time parameters.
1283 6 $self->{_param}{$prefix.'YEAR'} = substr($date, 12, 4);
1284 6 $self->{_param}{$prefix.'MONTH'} = sprintf("%02d", $$tm[4]+1);
1285 6 $self->{_param}{$prefix.'MONTH$'} = substr($date, 8, 3);
1286 6 $self->{_param}{$prefix.'DAY'} = substr($date, 5, 2);
1287 6 $self->{_param}{$prefix.'DATE'} = substr($date, 5, 11);
1288 6 $self->{_param}{$prefix.'WEEKDAY'} = $$tm[6]+1;
1289 6 $self->{_param}{$prefix.'WEEKDAY$'} = substr($date, 0, 3);
1290 6 $self->{_param}{$prefix.'HOUR'} = substr($date, 17, 2);
1291 6 $self->{_param}{$prefix.'MINUTE'} = substr($date, 20, 2);
1292 6 $self->{_param}{$prefix.'TIME'} = substr($date, 17, 5);
1293 6 $self->{_param}{$prefix.'SECOND'} = substr($date, 23, 2);
1294 6 $self->{_param}{$prefix.'TIME_ZONE'} = $zone;
1295 6 $self->{_param}{$prefix.'DATE_TIME'} = $date;
1296
1297 # Next, please!
1298 6 $date = gmtime($epoch_time);
1299 6 $tm = \@gmt;
1300 6 $zone = 'GMT';
1301 }
1302 }
1303
1304
1305 =head1 THE .HTX FILE FORMAT
1306
1307 A F<.htx> file is a normal HTML file, but it also contains special tags,
1308 which are handled by this module. These special tags are enclosed by
1309 C<E<lt>%> and C<%E<gt>> (kinda like Microsoft's Active Server Pages), and
1310 may contain variables and simple statements. The following special tags are
1311 supported:
1312
1313 =over 4
1314
1315 =item C<E<lt>%>I<variable>C<%E<gt>>
1316
1317 Outputs the value of the variable in HTML encoding. The variable may be a
1318 user defined variable, but also a CGI environment variable.
1319
1320 User defined variables are defined or modified using the C<param> method.
1321 This is typically done before a call to the C<print_detail> method, but
1322 also before calling the C<print_header> and C<print_footer> methods.
1323
1324 =item C<E<lt>%EscapeRaw >I<expression>C<%E<gt>>
1325
1326 =item C<E<lt>%EscapeHTML >I<expression>C<%E<gt>>
1327
1328 =item C<E<lt>%EscapeURL >I<expression>C<%E<gt>>
1329
1330 =item C<E<lt>%EscapeJS >I<expression>C<%E<gt>>
1331
1332 =item C<E<lt>%EscapeScramble >I<expression>C<%E<gt>>
1333
1334 Outputs the value of a variable or a literal string using HTML, URL,
1335 JavaScript, scrambled JavaScript or "raw" encoding.
1336
1337 JavaScript encoding can be used in JavaScript between double quotes, e.g.
1338 C<document.write("E<lt>%EscapeJS Variable%E<gt>");>. Scrambled JavaScript
1339 encoding comes in handy when you want to "hide" e-mail addresses from
1340 spambots, e.g. C<document.write("E<lt>%EscapeScramble Email%E<gt>");>.
1341
1342 =item C<E<lt>%begindetail%E<gt>>
1343
1344 Repeats what comes next for each record, until C<E<lt>%enddetail%E<gt>> or
1345 the end of the file is reached. This is the section that is printed by the
1346 C<print_detail> method.
1347
1348 =item C<E<lt>%enddetail%E<gt>>
1349
1350 See C<E<lt>%begindetail%E<gt>>.
1351
1352 =item C<E<lt>%detailsection >I<name>C<%E<gt>>
1353
1354 Defines a name for the next detail section, which makes life very easy when
1355 your template file contains multiple detail sections. For more information
1356 see the C<detail_section> method.
1357
1358 =item C<E<lt>%if >I<condition>C<%E<gt>>
1359
1360 Only output what comes next if I<condition> is true. The I<condition> has
1361 the following syntax:
1362
1363 I<expression1> I<operator> [I<expression2>]
1364
1365 I<expression1> and I<expression2> can be any value or variable name. Literal
1366 string values should be enclosed by C<"">. If one of the values is a typical
1367 string value, then both values are treated as strings, otherwise they are
1368 treated as numerical values.
1369
1370 I<operator> can be one of the following operators:
1371
1372 =over 4
1373
1374 =item *
1375
1376 C<eq> - I<expression1> and I<expression2> are identical.
1377
1378 =item *
1379
1380 C<ne> - I<expression1> and I<expression2> are not identical.
1381
1382 =item *
1383
1384 C<lt> - I<expression1> is less than I<expression2>.
1385
1386 =item *
1387
1388 C<le> - I<expression1> is less than or equal to I<expression2>.
1389
1390 =item *
1391
1392 C<gt> - I<expression1> is greater than I<expression2>.
1393
1394 =item *
1395
1396 C<ge> - I<expression1> is greater than or equal to I<expression2>.
1397
1398 =item *
1399
1400 C<contains> - I<expression1> contains I<expression2>.
1401
1402 =item *
1403
1404 C<istypeeq> - This is always true; it's included for compatibility.
1405
1406 =item *
1407
1408 C<isempty> - I<expression1> equals an empty string (or zero in a numerical
1409 context). I<expression2> should be ommited when you use the C<isempty>
1410 operator.
1411
1412 =back
1413
1414 =item C<E<lt>%else%E<gt>>
1415
1416 Only output what comes next if the I<condition> of an earlier
1417 C<E<lt>%if%E<gt>> was false.
1418
1419 =item C<E<lt>%endif%E<gt>>
1420
1421 Ends a conditional block and returns to its earlier conditional state. Yes,
1422 this means that you can nest
1423 C<E<lt>%if%E<gt>>..C<E<lt>%else%E<gt>>..C<E<lt>%endif%E<gt>> blocks. :-)
1424
1425 =item C<E<lt>%include >I<file>C<%E<gt>>
1426
1427 Includes a file as if it were part of the current F<.htx> file. In this
1428 include file you may also again use the special tags, or even the
1429 C<E<lt>%include%E<gt>> tag for that matter. However, the use of
1430 C<E<lt>%include%E<gt>> inside an include file is not recommended, because it
1431 may lead to recursive inclusion. You should also be careful with using
1432 C<E<lt>%begindetail%E<gt>>..C<E<lt>%enddetail%E<gt>> inside an include file,
1433 because I<detail sections cannot be nested>.
1434
1435 =back
1436
1437 =head1 KNOWN ISSUES
1438
1439 Since no syntax checking is performed on F<.htx> files, any unsupported
1440 statements or non-existing variables will simply be ignored. If you misuse
1441 any of the supported statements, you can't be sure of what might happen.
1442
1443 Also, the C<E<lt>%if%E<gt>>, C<E<lt>%else%E<gt>> and C<E<lt>%endif%E<gt>>
1444 statements are not really block statements, as they are in Perl or most
1445 other programming languages, but they rather just change the state of the
1446 internal condition flag. As a side effect you can disable a portion of a
1447 template file by placing C<E<lt>%else%E<gt>>..C<E<lt>%endif%E<gt>> around it
1448 (without C<E<lt>%if%E<gt>>!).
1449
1450 The use of multiple C<E<lt>%begindetail%E<gt>>..C<E<lt>%enddetail%E<gt>>
1451 sections is not documented for Microsoft's Index Server, but is supported
1452 very elegantly by this module (see the C<detail_section> method).
1453
1454 =head1 MODIFICATION HISTORY
1455
1456 =over 4
1457
1458 =item Version 0.07
1459
1460 [I<May 5 - 15, 2005>] Transparent UTF-8 support for both Perl 5.6 and 5.8
1461 was a little buggy (really?), but now it works (really!). The template file
1462 can now also be an open file handle or a scalar in memory. Templates
1463 containing multiple L<detail sections|detail_section> are now much easier to
1464 handle. Two new encoding types have been added: C<E<lt>%EscapeJS%E<gt>> and
1465 C<E<lt>%EscapeScramble%E<gt>>. The L<common parameters|common_params>
1466 feature has been added. The tests in F<test.pl> now don't do just one simple
1467 "live" test anymore, but rather test most of the module. (The coverage of
1468 these tests is probably not 100%, but it's close.)
1469
1470 =item Version 0.06
1471
1472 [I<April 17/18, 2005>] Added transparent UTF-8 support for both Perl 5.6 and
1473 5.8. Also reviewed and partly rewrote all other code. Output to a scalar
1474 doesn't use tying anymore (which worked, but probably produced warnings, and
1475 probably was a bit slower), but it now simply appends the output to the
1476 specified scalar.
1477
1478 =item Version 0.05
1479
1480 [I<November 21, 2004>] Added the option for output to a scalar instead of a
1481 file.
1482
1483 =item Version 0.04
1484
1485 [I<July 30, 2002>] Fixed a minor bug concerning multi-line
1486 C<E<lt>%if%E<gt>>'s.
1487
1488 =item Version 0.03
1489
1490 [I<July 21, 2002>] Fixed a bug in the C<_evaluate> sub, that resulted in
1491 warnings about uninitialized multiplications when using the C<isempty>
1492 operator.
1493
1494 =item Version 0.02
1495
1496 [I<June 21/24, 2002>] Fixed a few minor bugs concerning nested
1497 C<E<lt>%if%E<gt>>'s, the C<isempty> operator, and the use of HTTP headers.
1498
1499 =item Version 0.01
1500
1501 [I<April, 2002>] Created the module. :-)
1502
1503 =back
1504
1505 =head1 AUTHOR INFORMATION
1506
1507 Theo Niessink <niessink@martinic.nl>, http://www.taletn.com/
1508
1509 I<(The "I used to care but Things Have Changed" used in the
1510 L<Synopsis|"SYNOPSIS"> was written by Bob Dylan.)> :-)
1511
1512 =head1 COPYRIGHT
1513
1514 E<copy> MARTINIC Computers 2002-2005. This module is free software; you can
1515 redistribute it and/or modify it under the same terms as Perl itself.
1516
1517 For more information on MARTINIC Computers visit http://www.martinic.nl/
1518
1519 =cut
1520
1521
1522 1 1;
↑ Summary