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 |
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 |
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 |
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 $template> (for
|
144
|
|
|
|
|
|
|
backward compatibility).
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub new {
|
149
|
10
|
|
|
10
|
1
|
1396
|
my $class = shift;
|
150
|
10
|
|
|
|
|
19
|
my $self = {};
|
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# Parse the arguments.
|
153
|
10
|
|
|
|
|
13
|
my($template_file, $output_file, $utf8, @common, $arg);
|
154
|
10
|
|
|
|
|
30
|
while(@_) {
|
155
|
20
|
|
|
|
|
27
|
$arg = shift;
|
156
|
20
|
100
|
|
|
|
136
|
if($arg =~ /^(template|filename)$/o) {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
157
|
2
|
|
|
|
|
6
|
$template_file = shift;
|
158
|
|
|
|
|
|
|
} elsif($arg eq 'output') {
|
159
|
1
|
|
|
|
|
4
|
$output_file = shift;
|
160
|
|
|
|
|
|
|
} elsif($arg eq '-utf8') {
|
161
|
1
|
|
|
|
|
4
|
$utf8 = 1;
|
162
|
|
|
|
|
|
|
} elsif($arg =~ /^-/o) {
|
163
|
1
|
|
|
|
|
2
|
push @common, $arg, @_;
|
164
|
1
|
|
|
|
|
2
|
last;
|
165
|
|
|
|
|
|
|
} elsif(!defined($template_file)) {
|
166
|
8
|
|
|
|
|
24
|
$template_file = $arg;
|
167
|
|
|
|
|
|
|
} elsif(!defined($output_file)) {
|
168
|
7
|
|
|
|
|
18
|
$output_file = $arg;
|
169
|
|
|
|
|
|
|
}
|
170
|
|
|
|
|
|
|
}
|
171
|
10
|
50
|
|
|
|
24
|
return undef unless(defined($template_file));
|
172
|
10
|
100
|
|
|
|
21
|
$output_file = '-' unless(defined($output_file));
|
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
# Open the .htx file.
|
175
|
10
|
|
|
|
|
13
|
my($file, $close_file);
|
176
|
10
|
100
|
|
|
|
19
|
if(!ref($template_file)) {
|
177
|
1
|
|
|
|
|
13
|
$file = new FileHandle "<$template_file";
|
178
|
1
|
50
|
|
|
|
168
|
return undef unless(defined($file));
|
179
|
1
|
|
|
|
|
3
|
$close_file = 1;
|
180
|
|
|
|
|
|
|
} else {
|
181
|
9
|
|
|
|
|
12
|
$file = $template_file;
|
182
|
9
|
|
|
|
|
12
|
$close_file = '';
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
# Disable UTF-8 coding for Perl 5.8+.
|
185
|
10
|
100
|
66
|
|
|
67
|
binmode($file, ':bytes') if(($] >= 5.008) and (ref($file) ne 'SCALAR'));
|
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
# Open the file used for output (usually STDOUT).
|
188
|
10
|
|
|
|
|
14
|
my($output, $close_output);
|
189
|
10
|
100
|
|
|
|
25
|
if(!ref($output_file)) {
|
190
|
3
|
|
|
|
|
17
|
$output = new FileHandle ">$output_file";
|
191
|
3
|
50
|
|
|
|
124
|
if(!defined($output)) {
|
192
|
0
|
|
|
|
|
0
|
CORE::close($file);
|
193
|
0
|
|
|
|
|
0
|
return undef;
|
194
|
|
|
|
|
|
|
}
|
195
|
3
|
|
|
|
|
5
|
$close_output = 1;
|
196
|
|
|
|
|
|
|
} else {
|
197
|
7
|
100
|
100
|
|
|
39
|
$$output_file = '' if((ref($output_file) eq 'SCALAR') and (!defined($$output_file)));
|
198
|
7
|
|
|
|
|
9
|
$output = $output_file;
|
199
|
7
|
|
|
|
|
8
|
$close_output = '';
|
200
|
|
|
|
|
|
|
}
|
201
|
|
|
|
|
|
|
# Disable UTF-8 coding for Perl 5.8+.
|
202
|
10
|
100
|
66
|
|
|
65
|
binmode($output, ':bytes') if(($] >= 5.008) and (ref($output) ne 'SCALAR'));
|
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Save and initialize some values for later.
|
205
|
10
|
|
|
|
|
24
|
$self->{_file} = $file;
|
206
|
10
|
|
|
|
|
19
|
$self->{_close_file} = $close_file;
|
207
|
10
|
|
|
|
|
19
|
$self->{_output} = $output;
|
208
|
10
|
|
|
|
|
13
|
$self->{_close_output} = $close_output;
|
209
|
10
|
|
|
|
|
19
|
$self->{_closed} = '';
|
210
|
10
|
|
|
|
|
16
|
$self->{_section} = '';
|
211
|
10
|
|
|
|
|
25
|
$self->{_detail} = undef;
|
212
|
10
|
|
|
|
|
25
|
$self->{_rest} = undef;
|
213
|
10
|
|
|
|
|
15
|
$self->{_condition} = 1;
|
214
|
10
|
|
|
|
|
15
|
$self->{_if_count} = 0;
|
215
|
10
|
100
|
|
|
|
22
|
$self->{_utf8} = $utf8 ? 1 : '';
|
216
|
10
|
|
|
|
|
17
|
$self->{_stats} = '';
|
217
|
10
|
|
|
|
|
20
|
$self->{_param} = {};
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
# Bless me, father.
|
220
|
10
|
|
|
|
|
22
|
bless $self, $class;
|
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# Optionally init the common parameters.
|
223
|
10
|
100
|
|
|
|
33
|
$self->common_params(@common) if(@common);
|
224
|
|
|
|
|
|
|
|
225
|
10
|
|
|
|
|
110
|
return $self;
|
226
|
|
|
|
|
|
|
}
|
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=item C<$htx-Eparam($name =E $value,>
|
230
|
|
|
|
|
|
|
[C<$name =E $value>...]C<)>
|
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=item C<$value = $htx-Eparam($name)>
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=item C<@names = $htx-Eparam()>
|
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 method returns a list of names of
|
242
|
|
|
|
|
|
|
all defined variables.
|
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
I, and the>
|
245
|
|
|
|
|
|
|
I method.>
|
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
=cut
|
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
sub param {
|
250
|
|
|
|
|
|
|
# If there are no arguments, then return a list of variable names.
|
251
|
60
|
100
|
|
60
|
1
|
1088
|
return (keys %{$_[0]->{_param}}) if($#_ == 0);
|
|
1
|
|
|
|
|
10
|
|
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
# If there's only one argument, then return the value of that variable.
|
254
|
59
|
100
|
|
|
|
232
|
return $_[0]->{_param}{$_[1]} if($#_ == 1);
|
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
# If there's two arguments, then one name/value pair is specified.
|
257
|
22
|
100
|
|
|
|
45
|
if($#_ == 2) {
|
258
|
3
|
|
|
|
|
14
|
$_[0]->{_param}{$_[1]} = $_[2];
|
259
|
3
|
|
|
|
|
6
|
return;
|
260
|
|
|
|
|
|
|
}
|
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
# Apparently two or more name/value pairs are specified.
|
263
|
19
|
|
|
|
|
21
|
my $n = 1;
|
264
|
19
|
|
|
|
|
37
|
while($n <= $#_) {
|
265
|
|
|
|
|
|
|
# Set the variable to the specified value.
|
266
|
43
|
|
|
|
|
100
|
$_[0]->{_param}{$_[$n]} = $_[$n+1];
|
267
|
43
|
|
|
|
|
102
|
$n += 2;
|
268
|
|
|
|
|
|
|
}
|
269
|
|
|
|
|
|
|
}
|
270
|
|
|
|
|
|
|
|
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=item C<$htx-Eprint_header(>[C<$http_header>] [C<-nph>]C<)>
|
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Reads, parses and outputs the template file up to
|
275
|
|
|
|
|
|
|
C%begindetail%E>, and only reads what's between
|
276
|
|
|
|
|
|
|
C%begindetail%E> and C%enddetail%E>, but does not parse
|
277
|
|
|
|
|
|
|
and output this section yet. If no C%begindetail%E> was found,
|
278
|
|
|
|
|
|
|
then simply reads, parses and outputs the entire file. In this last case
|
279
|
|
|
|
|
|
|
C 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 method).
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
If this is the very first call to C 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-Eprint_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 with a false value, e.g. C<$htx-Eprint_header('')> (or
|
296
|
|
|
|
|
|
|
even just C<$htx-Eprint_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 function of the CGI module, e.g.
|
306
|
|
|
|
|
|
|
C<$htx-Eprint_header(header(-nph =E 1))>.
|
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
=cut
|
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
sub print_header {
|
311
|
16
|
|
|
16
|
1
|
167
|
my $self = $_[0];
|
312
|
16
|
|
|
|
|
19
|
local $_;
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
# Is this the first ever call to print_header?
|
315
|
16
|
|
|
|
|
18
|
my $first_time;
|
316
|
16
|
100
|
|
|
|
51
|
if(!defined($self->{_rest})) {
|
317
|
6
|
|
|
|
|
8
|
$first_time = 1;
|
318
|
|
|
|
|
|
|
# Output the specified HTTP header.
|
319
|
6
|
100
|
100
|
|
|
46
|
if(defined($_[1]) and ($_[1] =~ /\n/o)) {
|
|
|
100
|
|
|
|
|
|
320
|
1
|
|
|
|
|
4
|
_print($self, \$_[1]);
|
321
|
|
|
|
|
|
|
# Construct and output a (partial) HTTP header.
|
322
|
|
|
|
|
|
|
} elsif($_[1]) {
|
323
|
4
|
|
|
|
|
49
|
my $content_type = $_[1];
|
324
|
4
|
100
|
|
|
|
15
|
if($content_type !~ m#/#o) {
|
325
|
3
|
|
|
|
|
4
|
$content_type = 'text/html';
|
326
|
3
|
100
|
|
|
|
13
|
$content_type .= '; charset=utf-8' if($self->{_utf8});
|
327
|
|
|
|
|
|
|
}
|
328
|
4
|
|
|
|
|
9
|
$content_type = "Content-Type: $content_type\n\n";
|
329
|
4
|
|
|
|
|
11
|
_print($self, \$content_type);
|
330
|
|
|
|
|
|
|
}
|
331
|
6
|
|
|
|
|
13
|
$self->{_rest} = '';
|
332
|
|
|
|
|
|
|
} else {
|
333
|
10
|
|
|
|
|
13
|
$first_time = '';
|
334
|
|
|
|
|
|
|
}
|
335
|
|
|
|
|
|
|
|
336
|
|
|
|
|
|
|
# Optionally update the automated counters (NUMBER).
|
337
|
16
|
100
|
100
|
|
|
70
|
_stats($self, -1) if((!$first_time) and $self->{_stats});
|
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
# Read, parse and output everything up to <%begindetail%>.
|
340
|
16
|
|
|
|
|
27
|
$self->{_section} = '';
|
341
|
16
|
|
|
|
|
18
|
my $found;
|
342
|
16
|
|
|
|
|
25
|
my $file = $self->{_file};
|
343
|
16
|
|
|
|
|
36
|
my $is_scalar = ref($file) eq 'SCALAR';
|
344
|
|
|
|
|
|
|
# Start with whatever is left of that which followed <%enddetail%> last
|
345
|
|
|
|
|
|
|
# time.
|
346
|
16
|
100
|
|
|
|
41
|
if($self->{_rest} ne '') {
|
|
|
50
|
|
|
|
|
|
347
|
9
|
|
|
|
|
16
|
$_ = $self->{_rest};
|
348
|
9
|
|
|
|
|
15
|
$self->{_rest} = '';
|
349
|
|
|
|
|
|
|
} elsif(!$is_scalar) {
|
350
|
0
|
|
|
|
|
0
|
$_ = <$file>;
|
351
|
|
|
|
|
|
|
} else {
|
352
|
7
|
100
|
|
|
|
23
|
$_ = $first_time ? $$file : undef;
|
353
|
|
|
|
|
|
|
}
|
354
|
16
|
|
|
|
|
36
|
while(defined($_)) {
|
355
|
|
|
|
|
|
|
# Check for <%begindetail%>.
|
356
|
15
|
100
|
|
|
|
82
|
if($found = /<%begindetail%>/io) {
|
357
|
|
|
|
|
|
|
# Output and parse only that which came before <%begindetail%>.
|
358
|
12
|
50
|
|
|
|
47
|
_print($self, $`) if($` ne '');
|
359
|
|
|
|
|
|
|
# Start the detail section with whatever followed <%begindetail%>.
|
360
|
12
|
|
|
|
|
61
|
$self->{_rest} = $';
|
361
|
12
|
|
|
|
|
20
|
last;
|
362
|
|
|
|
|
|
|
} else {
|
363
|
|
|
|
|
|
|
# Simply parse and output the entire line.
|
364
|
3
|
|
|
|
|
8
|
_print($self, $_);
|
365
|
|
|
|
|
|
|
}
|
366
|
|
|
|
|
|
|
# Next, please!
|
367
|
3
|
50
|
|
|
|
7
|
last if($is_scalar);
|
368
|
0
|
|
|
|
|
0
|
$_ = <$file>;
|
369
|
|
|
|
|
|
|
}
|
370
|
16
|
100
|
|
|
|
45
|
$found or return '';
|
371
|
|
|
|
|
|
|
|
372
|
|
|
|
|
|
|
# Optionally init the automated counters (NUMBER and COUNT).
|
373
|
12
|
100
|
|
|
|
38
|
_stats($self, 0, 0) if($self->{_stats});
|
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
# Read and store everything between <%begindetail%> and <%enddetail%>.
|
376
|
12
|
|
|
|
|
18
|
$self->{_detail} = '';
|
377
|
|
|
|
|
|
|
# Start with the remainder of the last line that was read...
|
378
|
12
|
50
|
|
|
|
26
|
if($self->{_rest} ne '') {
|
379
|
12
|
|
|
|
|
20
|
$_ = $self->{_rest};
|
380
|
12
|
|
|
|
|
16
|
$self->{_rest} = '';
|
381
|
|
|
|
|
|
|
# ... or read a line.
|
382
|
|
|
|
|
|
|
} else {
|
383
|
0
|
0
|
|
|
|
0
|
$_ = $is_scalar ? undef : <$file>;
|
384
|
|
|
|
|
|
|
}
|
385
|
12
|
|
|
|
|
26
|
while(defined($_)) {
|
386
|
|
|
|
|
|
|
# Check for <%enddetail%>.
|
387
|
12
|
50
|
|
|
|
48
|
if($found = /<%enddetail%>/io) {
|
388
|
|
|
|
|
|
|
# Store only that which came before <%enddetail%>.
|
389
|
12
|
50
|
|
|
|
46
|
$self->{_detail} .= $` if($` ne '');
|
390
|
|
|
|
|
|
|
# Save whatever followed <%enddetail%> for later.
|
391
|
12
|
|
|
|
|
32
|
$self->{_rest} = $';
|
392
|
12
|
|
|
|
|
17
|
last;
|
393
|
|
|
|
|
|
|
} else {
|
394
|
|
|
|
|
|
|
# Simply store the entire line.
|
395
|
0
|
|
|
|
|
0
|
$self->{_detail} .= $_;
|
396
|
|
|
|
|
|
|
}
|
397
|
|
|
|
|
|
|
# Next, please!
|
398
|
0
|
0
|
|
|
|
0
|
last if($is_scalar);
|
399
|
0
|
|
|
|
|
0
|
$_ = <$file>;
|
400
|
|
|
|
|
|
|
}
|
401
|
|
|
|
|
|
|
|
402
|
|
|
|
|
|
|
# Return whether a (valid) detail section was found.
|
403
|
12
|
50
|
|
|
|
24
|
return '' unless($found);
|
404
|
12
|
|
|
|
|
21
|
$found = $self->{_section};;
|
405
|
12
|
100
|
|
|
|
23
|
$found = 1 unless($found);
|
406
|
12
|
|
|
|
|
61
|
return $found;
|
407
|
|
|
|
|
|
|
}
|
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
=item C<$htx-Eprint_detail>
|
411
|
|
|
|
|
|
|
|
412
|
|
|
|
|
|
|
Parses and outputs the detail section that was read by the C
|
413
|
|
|
|
|
|
|
method. The method C method is usually called from a loop to
|
414
|
|
|
|
|
|
|
output each subsequent record.
|
415
|
|
|
|
|
|
|
|
416
|
|
|
|
|
|
|
=cut
|
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub print_detail {
|
419
|
|
|
|
|
|
|
# Optionally update the automated counters (COUNT and TOTAL).
|
420
|
15
|
100
|
|
15
|
1
|
49
|
_stats($_[0], undef, 1, 1) if($_[0]->{_stats});
|
421
|
|
|
|
|
|
|
|
422
|
|
|
|
|
|
|
# Parse and output the detail section.
|
423
|
15
|
50
|
|
|
|
31
|
if(_print($_[0], $_[0]->{_detail})) {
|
424
|
15
|
100
|
|
|
|
45
|
_stats($_[0], 1) if($_[0]->{_stats}); # (NUMBER)
|
425
|
|
|
|
|
|
|
}
|
426
|
|
|
|
|
|
|
}
|
427
|
|
|
|
|
|
|
|
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
=item C<$htx-Eprint_footer(>[C<$http_header>] [C<-nph>]C<)>
|
430
|
|
|
|
|
|
|
|
431
|
|
|
|
|
|
|
Reads, parses and outputs the rest of the template file, skipping any
|
432
|
|
|
|
|
|
|
C%begindetail%E>..C%enddetail%E> sections it might
|
433
|
|
|
|
|
|
|
encounter. For the optional arguments, see the C method.
|
434
|
|
|
|
|
|
|
|
435
|
|
|
|
|
|
|
A script that uses a template file without a detail section could call this
|
436
|
|
|
|
|
|
|
method immediately after Cnew> (without calling
|
437
|
|
|
|
|
|
|
C). This is because this method actually does subsequent calls
|
438
|
|
|
|
|
|
|
to the C method until the end of the file is reached.
|
439
|
|
|
|
|
|
|
|
440
|
|
|
|
|
|
|
=cut
|
441
|
|
|
|
|
|
|
|
442
|
|
|
|
|
|
|
sub print_footer {
|
443
|
1
|
|
|
1
|
1
|
3
|
my $self = shift;
|
444
|
1
|
|
|
|
|
4
|
while($self->print_header(@_)) {}
|
445
|
1
|
|
|
|
|
3
|
return '';
|
446
|
|
|
|
|
|
|
}
|
447
|
|
|
|
|
|
|
|
448
|
|
|
|
|
|
|
|
449
|
|
|
|
|
|
|
=item C<$htx-Eclose>
|
450
|
|
|
|
|
|
|
|
451
|
|
|
|
|
|
|
Closes the template and output files. This is usually done directly after
|
452
|
|
|
|
|
|
|
the C method. When a HTML::Template::HTX object is destroyed
|
453
|
|
|
|
|
|
|
the files will be closed automatically, so you don't I to call
|
454
|
|
|
|
|
|
|
C (but I think it's very rude not to call C!). ;-)
|
455
|
|
|
|
|
|
|
|
456
|
|
|
|
|
|
|
=cut
|
457
|
|
|
|
|
|
|
|
458
|
|
|
|
|
|
|
sub close {
|
459
|
10
|
|
|
10
|
1
|
16
|
my $self = $_[0];
|
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
# Close the file used for output.
|
462
|
10
|
|
|
|
|
13
|
my($closed_output, $output);
|
463
|
10
|
|
|
|
|
19
|
$output = $self->{_output};
|
464
|
10
|
100
|
66
|
|
|
53
|
if(defined($output) and $self->{_close_output}) {
|
465
|
3
|
|
|
|
|
12
|
$closed_output = CORE::close($output);
|
466
|
|
|
|
|
|
|
} else {
|
467
|
7
|
|
|
|
|
13
|
$closed_output = 1;
|
468
|
|
|
|
|
|
|
}
|
469
|
|
|
|
|
|
|
|
470
|
|
|
|
|
|
|
# Close the .htx template file.
|
471
|
10
|
|
|
|
|
32
|
my($closed_file, $file);
|
472
|
10
|
|
|
|
|
17
|
$file = $self->{_file};
|
473
|
10
|
100
|
66
|
|
|
49
|
if(defined($file) and $self->{_close_file}) {
|
474
|
1
|
|
|
|
|
14
|
$closed_file = CORE::close($file);
|
475
|
|
|
|
|
|
|
} else {
|
476
|
9
|
|
|
|
|
14
|
$closed_file = 1;
|
477
|
|
|
|
|
|
|
}
|
478
|
|
|
|
|
|
|
|
479
|
10
|
50
|
33
|
|
|
44
|
return '' unless($closed_output and $closed_file);
|
480
|
10
|
|
|
|
|
66
|
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 the HTML::Template::HTX
|
492
|
|
|
|
|
|
|
object, or you can use the C method to define them later on.
|
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=over 4
|
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
=item C<$htx-Ecommon_params(>[I]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 $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%COUNT%E> - The number of times C was called within
|
519
|
|
|
|
|
|
|
the current detail section.
|
520
|
|
|
|
|
|
|
|
521
|
|
|
|
|
|
|
=item *
|
522
|
|
|
|
|
|
|
|
523
|
|
|
|
|
|
|
C%NUMBER%E> - The number of times C was called within
|
524
|
|
|
|
|
|
|
the current detail section, I (thus not an empty
|
525
|
|
|
|
|
|
|
string).
|
526
|
|
|
|
|
|
|
|
527
|
|
|
|
|
|
|
=item *
|
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
C%TOTAL%E> - The number of times C was called
|
530
|
|
|
|
|
|
|
within I detail section.
|
531
|
|
|
|
|
|
|
|
532
|
|
|
|
|
|
|
=item *
|
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
C%SECTION%E> - The name of the current detail section.
|
535
|
|
|
|
|
|
|
|
536
|
|
|
|
|
|
|
=back
|
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
C%NUMBER%E>, C%COUNT%E> and C%TOTAL%E> can be
|
539
|
|
|
|
|
|
|
followed by a question mark to get its value modules 2, e.g.
|
540
|
|
|
|
|
|
|
C%NUMBER?%E>.
|
541
|
|
|
|
|
|
|
|
542
|
|
|
|
|
|
|
You should always enable automated counters when L 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, and
|
547
|
|
|
|
|
|
|
I calling C. This means you can still query them in
|
548
|
|
|
|
|
|
|
C (or the next C, if you're using
|
549
|
|
|
|
|
|
|
L).
|
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=item C<-date> [C<=E $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%YEAR%E> - The year as a 4-digit number.
|
563
|
|
|
|
|
|
|
|
564
|
|
|
|
|
|
|
=item *
|
565
|
|
|
|
|
|
|
|
566
|
|
|
|
|
|
|
C%MONTH%E> - The month as a 2-digit number (01..12).
|
567
|
|
|
|
|
|
|
|
568
|
|
|
|
|
|
|
=item *
|
569
|
|
|
|
|
|
|
|
570
|
|
|
|
|
|
|
C%MONTH$%E> - The month as a 3-character string (in English).
|
571
|
|
|
|
|
|
|
|
572
|
|
|
|
|
|
|
=item *
|
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
C%DAY%E> - The day as a 2-digit number (01..31).
|
575
|
|
|
|
|
|
|
|
576
|
|
|
|
|
|
|
=item *
|
577
|
|
|
|
|
|
|
|
578
|
|
|
|
|
|
|
C%DATE%E> - The date ("dd mmm yyyy").
|
579
|
|
|
|
|
|
|
|
580
|
|
|
|
|
|
|
=item *
|
581
|
|
|
|
|
|
|
|
582
|
|
|
|
|
|
|
C%WEEKDAY%E> - The weekday as a 1-digit number (1..7; 1 = Sun, 2 =
|
583
|
|
|
|
|
|
|
Mon ... 7 = Sat).
|
584
|
|
|
|
|
|
|
|
585
|
|
|
|
|
|
|
=item *
|
586
|
|
|
|
|
|
|
|
587
|
|
|
|
|
|
|
C%WEEKDAY$%E> - The weekday as a 3-character string (in English).
|
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=item *
|
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
C%HOUR%E> - The hour of the day as a 2-digit number (00..23).
|
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=item *
|
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
C%MINUTE%E> - The minutes part of time time as a 2-digit number
|
596
|
|
|
|
|
|
|
(00..59).
|
597
|
|
|
|
|
|
|
|
598
|
|
|
|
|
|
|
=item *
|
599
|
|
|
|
|
|
|
|
600
|
|
|
|
|
|
|
C%TIME%E> - The time ("hh:mm").
|
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=item *
|
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
C%SECOND%E> - The seconds part of time time a 2-digit number
|
605
|
|
|
|
|
|
|
(00..59).
|
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
=item *
|
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
C%TIME_ZONE%E> - The timezone (e.g. "+0100" or "GMT").
|
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
=item *
|
612
|
|
|
|
|
|
|
|
613
|
|
|
|
|
|
|
C%DATE_TIME%E> - 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%GMT_DATE_TIME%E>, C%GMT_TIME_ZONE%E> (which naturally
|
620
|
|
|
|
|
|
|
always is "GMT") etc.
|
621
|
|
|
|
|
|
|
|
622
|
|
|
|
|
|
|
=back
|
623
|
|
|
|
|
|
|
|
624
|
|
|
|
|
|
|
=cut
|
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
sub common_params {
|
627
|
5
|
|
|
5
|
1
|
7
|
my $self = shift;
|
628
|
5
|
50
|
|
|
|
11
|
@_ = (-count, -date) unless(@_);
|
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
# Parse the options one by one.
|
631
|
5
|
|
|
|
|
5
|
my($option, $arg);
|
632
|
5
|
|
|
|
|
11
|
while(@_) {
|
633
|
6
|
|
|
|
|
13
|
$option = shift;
|
634
|
6
|
100
|
100
|
|
|
25
|
$arg = (defined($_[0]) and ($_[0] !~ /^-/o)) ? shift : undef;
|
635
|
|
|
|
|
|
|
|
636
|
|
|
|
|
|
|
# Enable or disable the automated counters.
|
637
|
6
|
100
|
|
|
|
12
|
if($option eq '-count') {
|
638
|
3
|
100
|
|
|
|
8
|
$arg = 1 unless(defined($arg));
|
639
|
3
|
100
|
|
|
|
5
|
if($arg) {
|
640
|
2
|
50
|
|
|
|
5
|
if(!$self->{_stats}) {
|
641
|
2
|
|
|
|
|
3
|
$self->{_stats} = 1;
|
642
|
2
|
|
|
|
|
6
|
_stats($self, 0, 0, 0, $self->{_section});
|
643
|
|
|
|
|
|
|
}
|
644
|
|
|
|
|
|
|
} else {
|
645
|
1
|
|
|
|
|
2
|
$self->{_stats} = '';
|
646
|
|
|
|
|
|
|
}
|
647
|
3
|
|
|
|
|
8
|
next;
|
648
|
|
|
|
|
|
|
}
|
649
|
|
|
|
|
|
|
|
650
|
|
|
|
|
|
|
# Set date and time variables.
|
651
|
3
|
50
|
|
|
|
7
|
if($option eq '-date') {
|
652
|
3
|
100
|
|
|
|
11
|
$arg = time unless(defined($arg));
|
653
|
3
|
|
|
|
|
7
|
_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 (header of 1st detail section)
|
672
|
|
|
|
|
|
|
|
673
|
|
|
|
|
|
|
=item 2
|
674
|
|
|
|
|
|
|
|
675
|
|
|
|
|
|
|
CC< foreach(0..>IC<)> (1st detail section)
|
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=item 3
|
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
C (footer of 1st and header of 2nd detail section)
|
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=item 4
|
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
CC< foreach(0..>IC<)> (2nd detail section)
|
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
=item 5
|
686
|
|
|
|
|
|
|
|
687
|
|
|
|
|
|
|
C (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 method and the C%detailsection >IC<%E>
|
699
|
|
|
|
|
|
|
F<.htx> command come in. :-)
|
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
=over 4
|
702
|
|
|
|
|
|
|
|
703
|
|
|
|
|
|
|
=item C<$name = $htx-Edetail_section>
|
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
=item C<$htx-Edetail_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%detailsection >IC<%E> command in your
|
716
|
|
|
|
|
|
|
template file. Normally you do not even have to retrieve the section name
|
717
|
|
|
|
|
|
|
using this method, because the C 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 example file:
|
743
|
|
|
|
|
|
|
|
744
|
|
|
|
|
|
|
Sample results
|
745
|
|
|
|
|
|
|
|
746
|
|
|
|
|
|
|
<%detailsection ADS%>
|
747
|
|
|
|
|
|
|
<%begindetail%>
|
748
|
|
|
|
|
|
|
>
|
749
|
|
|
|
|
|
|
<%enddetail%>
|
750
|
|
|
|
|
|
|
|
751
|
|
|
|
|
|
|
<%detailsection LINKS%>
|
752
|
|
|
|
|
|
|
Links to Perly websites
|
753
|
|
|
|
|
|
|
<%begindetail%>
|
754
|
|
|
|
|
|
|
755
|
|
|
|
|
|
|
<%enddetail%>
|
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
=cut
|
760
|
|
|
|
|
|
|
|
761
|
|
|
|
|
|
|
sub detail_section {
|
762
|
|
|
|
|
|
|
# Return the current section name.
|
763
|
8
|
100
|
|
8
|
1
|
65
|
return $_[0]->{_section} if(!defined($_[1]));
|
764
|
|
|
|
|
|
|
|
765
|
|
|
|
|
|
|
# Set the current section name.
|
766
|
2
|
|
|
|
|
18
|
$_[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 method lets you control
|
778
|
|
|
|
|
|
|
whether your output will be UTF-8 coded or not.
|
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
=over 4
|
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
=item C<$htx-Eutf8(>[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 the
|
792
|
|
|
|
|
|
|
HTML::Template::HTX object or right after. You should B change the
|
793
|
|
|
|
|
|
|
UTF-8 flag later on.
|
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
You can always use UTF-8 characters inside user defined variables,
|
796
|
|
|
|
|
|
|
I. 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
|
|
|
|
|
|
|
sub utf8 {
|
808
|
7
|
|
|
7
|
1
|
21
|
my($self, $enable) = @_;
|
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
# Enable or disable UTF-8 encoding.
|
811
|
7
|
100
|
|
|
|
17
|
if(defined($enable)) {
|
812
|
5
|
100
|
|
|
|
10
|
$enable = $enable ? 1 : '';
|
813
|
|
|
|
|
|
|
} else {
|
814
|
2
|
|
|
|
|
4
|
$enable = 1;
|
815
|
|
|
|
|
|
|
}
|
816
|
7
|
100
|
|
|
|
22
|
return unless($self->{_utf8} ne $enable);
|
817
|
5
|
|
|
|
|
12
|
$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
|
|
|
1
|
|
8
|
use vars qw(%_operator $_is_number);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
96
|
|
829
|
|
|
|
|
|
|
|
830
|
|
|
|
|
|
|
sub BEGIN {
|
831
|
|
|
|
|
|
|
# The operators that can be used in an <%if%> statement, and their
|
832
|
|
|
|
|
|
|
# numerical counterparts.
|
833
|
1
|
|
|
1
|
|
5
|
%_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
|
|
|
|
|
5127
|
$_is_number = '-?\d*[.]?\d*';
|
844
|
|
|
|
|
|
|
}
|
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
# Closes the file handles before destroying the object.
|
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
sub DESTROY {
|
850
|
|
|
|
|
|
|
# Call the close method to close the template and output files.
|
851
|
9
|
100
|
|
9
|
|
187
|
$_[0]->close unless($_[0]->{_closed});
|
852
|
|
|
|
|
|
|
}
|
853
|
|
|
|
|
|
|
|
854
|
|
|
|
|
|
|
|
855
|
|
|
|
|
|
|
# Reads an include file.
|
856
|
|
|
|
|
|
|
#
|
857
|
|
|
|
|
|
|
# _include($self, 'include.htx', \$htx_code_fragment, \$prematch,
|
858
|
|
|
|
|
|
|
# \$postmatch) or die;
|
859
|
|
|
|
|
|
|
|
860
|
|
|
|
|
|
|
sub _include {
|
861
|
1
|
|
|
1
|
|
4
|
my($self, $include_file, $htx, $prematch, $postmatch) = @_;
|
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
# Open the include file.
|
864
|
1
|
|
|
|
|
12
|
my $file = new FileHandle "<$include_file";
|
865
|
1
|
50
|
|
|
|
92
|
if(defined($file)) {
|
866
|
|
|
|
|
|
|
# Disable UTF-8 coding for Perl 5.8+.
|
867
|
1
|
50
|
|
|
|
9
|
binmode($file, ':bytes') if($] >= 5.008);
|
868
|
|
|
|
|
|
|
# Read and insert the entire include file at once.
|
869
|
1
|
|
|
|
|
54
|
$$htx = $$prematch.join('', <$file>).$$postmatch;
|
870
|
1
|
|
|
|
|
20
|
CORE::close($file);
|
871
|
1
|
|
|
|
|
10
|
return 1;
|
872
|
|
|
|
|
|
|
}
|
873
|
|
|
|
|
|
|
|
874
|
|
|
|
|
|
|
# Reading the file failed, so simply remove the <%include%> tag.
|
875
|
0
|
|
|
|
|
0
|
$$htx = $$prematch.$$postmatch;
|
876
|
0
|
|
|
|
|
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
|
|
|
|
|
|
|
sub _express {
|
890
|
|
|
|
|
|
|
# Check if the expresion is enclosed by "".
|
891
|
107
|
100
|
|
107
|
|
266
|
if($_[1] =~ /^"(.*)"$/o) {
|
892
|
|
|
|
|
|
|
# Treat it as a literal, but remove the "".
|
893
|
15
|
|
|
|
|
55
|
return $1;
|
894
|
|
|
|
|
|
|
}
|
895
|
|
|
|
|
|
|
|
896
|
|
|
|
|
|
|
# Check if the expression could be a user defined variable.
|
897
|
92
|
|
|
|
|
85
|
my $value;
|
898
|
92
|
100
|
|
|
|
246
|
if(exists $_[0]->{_param}{$_[1]}) {
|
|
|
100
|
|
|
|
|
|
899
|
|
|
|
|
|
|
# Return the value of the variable.
|
900
|
66
|
|
|
|
|
117
|
$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
|
|
|
|
|
2
|
$value = $ENV{$_[1]};
|
905
|
|
|
|
|
|
|
}
|
906
|
92
|
100
|
|
|
|
159
|
if(defined($value)) {
|
907
|
|
|
|
|
|
|
# Make sure Perl 5.6+ does UTF-8 coding.
|
908
|
67
|
50
|
|
|
|
128
|
if($] >= 5.006) {
|
909
|
67
|
50
|
|
|
|
92
|
if($] < 5.008) {
|
910
|
|
|
|
|
|
|
# Make sure it's UTF-8.
|
911
|
0
|
|
|
|
|
0
|
$value .= "\x{A9}";
|
912
|
0
|
|
|
|
|
0
|
chop($value);
|
913
|
|
|
|
|
|
|
# Optionally convert UTF-8 back to octets.
|
914
|
0
|
0
|
|
|
|
0
|
$value = pack("U0C*", unpack("U*", $value)) unless($_[0]->{_utf8});
|
915
|
|
|
|
|
|
|
} else {
|
916
|
|
|
|
|
|
|
# With Perl 5.8+ in :bytes mode we'll need UTF-8 code ourselves.
|
917
|
67
|
100
|
|
|
|
169
|
utf8::encode($value) if($_[0]->{_utf8});
|
918
|
|
|
|
|
|
|
}
|
919
|
|
|
|
|
|
|
}
|
920
|
67
|
|
|
|
|
147
|
return $value;
|
921
|
|
|
|
|
|
|
}
|
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
# Check if the expression is a numerical expression.
|
924
|
25
|
100
|
66
|
|
|
204
|
if(($_[1] ne '') and ($_[1] =~ /^$_is_number$/o)) {
|
925
|
|
|
|
|
|
|
# Return the numerical value.
|
926
|
|
|
|
|
|
|
#no warnings 'numeric'; # Warnings are enabled only during development
|
927
|
12
|
|
|
|
|
41
|
return 1*$_[1];
|
928
|
|
|
|
|
|
|
}
|
929
|
|
|
|
|
|
|
|
930
|
|
|
|
|
|
|
# None of the above, so return an empty string.
|
931
|
13
|
|
|
|
|
45
|
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
|
|
|
|
|
|
|
sub _evaluate {
|
940
|
26
|
|
|
26
|
|
34
|
local $_;
|
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
# Break up the condition into three parts (value1, operator, value2).
|
943
|
26
|
|
|
|
|
26
|
my($value1, $value2, $operator);
|
944
|
26
|
50
|
|
|
|
199
|
$_[1] =~ /^(.+?)\s+(.+?)(\s+(.+?))?$/o or return '';
|
945
|
26
|
|
|
|
|
45
|
$value1 = $1;
|
946
|
26
|
|
|
|
|
41
|
$operator = lc($2);
|
947
|
26
|
|
|
|
|
49
|
$value2 = $4;
|
948
|
|
|
|
|
|
|
|
949
|
|
|
|
|
|
|
# Is this the istypeeq operator?
|
950
|
26
|
100
|
|
|
|
83
|
if($operator eq 'istypeeq') {
|
951
|
|
|
|
|
|
|
# Return true (just included for compatibility).
|
952
|
1
|
|
|
|
|
5
|
return 1;
|
953
|
|
|
|
|
|
|
}
|
954
|
|
|
|
|
|
|
|
955
|
|
|
|
|
|
|
# Parse both expressions.
|
956
|
25
|
|
|
|
|
29
|
my $string_compare = '';
|
957
|
25
|
|
|
|
|
50
|
foreach(\$value1, \$value2) {
|
958
|
50
|
100
|
|
|
|
93
|
if(defined($$_)) {
|
959
|
40
|
|
|
|
|
87
|
$$_ = _express($_[0], $$_);
|
960
|
40
|
100
|
100
|
|
|
311
|
$string_compare = 1 unless(($$_ ne '') and ($$_ =~ /^$_is_number$/o));
|
961
|
|
|
|
|
|
|
} else {
|
962
|
10
|
|
|
|
|
16
|
$$_ = '';
|
963
|
10
|
|
|
|
|
24
|
$string_compare = 1;
|
964
|
|
|
|
|
|
|
}
|
965
|
|
|
|
|
|
|
}
|
966
|
|
|
|
|
|
|
|
967
|
|
|
|
|
|
|
# Is this the isempty operator?
|
968
|
25
|
100
|
|
|
|
61
|
if($operator eq 'isempty') {
|
969
|
|
|
|
|
|
|
# Return whether the string value1 is empty.
|
970
|
10
|
|
|
|
|
32
|
return $value1 eq '';
|
971
|
|
|
|
|
|
|
}
|
972
|
|
|
|
|
|
|
|
973
|
|
|
|
|
|
|
# Compare the strings case-insensitive.
|
974
|
15
|
100
|
|
|
|
28
|
if($string_compare) {
|
975
|
4
|
|
|
|
|
8
|
$value1 = lc($value1);
|
976
|
4
|
|
|
|
|
6
|
$value2 = lc($value2);
|
977
|
|
|
|
|
|
|
}
|
978
|
|
|
|
|
|
|
|
979
|
|
|
|
|
|
|
# Is this the contains operator?
|
980
|
15
|
100
|
|
|
|
29
|
if($operator eq 'contains') {
|
981
|
|
|
|
|
|
|
# Return whether the string value1 contains the string value2.
|
982
|
1
|
|
|
|
|
19
|
return $value1 =~ /$value2/;
|
983
|
|
|
|
|
|
|
}
|
984
|
|
|
|
|
|
|
|
985
|
|
|
|
|
|
|
# If it's not one of the comparison operators, then return false.
|
986
|
14
|
50
|
|
|
|
32
|
return '' unless(exists $_operator{$operator});
|
987
|
|
|
|
|
|
|
|
988
|
|
|
|
|
|
|
# Construct a Perl eval expression.
|
989
|
14
|
|
|
|
|
13
|
my $eval;
|
990
|
14
|
100
|
|
|
|
21
|
if($string_compare) {
|
991
|
3
|
|
|
|
|
7
|
$value1 =~ s/'/\\'/go;
|
992
|
3
|
|
|
|
|
4
|
$value2 =~ s/'/\\'/go;
|
993
|
3
|
|
|
|
|
10
|
$eval = "'$value1' $operator '$value2'";
|
994
|
|
|
|
|
|
|
} else {
|
995
|
11
|
|
|
|
|
30
|
$eval = "$value1 $_operator{$operator} $value2";
|
996
|
|
|
|
|
|
|
}
|
997
|
|
|
|
|
|
|
# Let Perl evaluate the expression.
|
998
|
14
|
|
|
|
|
784
|
$eval = eval($eval);
|
999
|
14
|
50
|
|
|
|
46
|
return '' if($@);
|
1000
|
14
|
|
|
|
|
47
|
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
|
|
|
|
|
|
|
sub _encode {
|
1013
|
|
|
|
|
|
|
# Parse the expression.
|
1014
|
60
|
|
|
60
|
|
225
|
my $value = _express(@_[0, 1]);
|
1015
|
|
|
|
|
|
|
|
1016
|
|
|
|
|
|
|
# Encode as HTML entities.
|
1017
|
60
|
|
|
|
|
88
|
my $encoding = lc($_[2]); # lc converts undef to ''
|
1018
|
60
|
100
|
|
|
|
167
|
return encode_entities($value) if($encoding eq 'html');
|
1019
|
|
|
|
|
|
|
|
1020
|
|
|
|
|
|
|
# Encode using URL escape codes.
|
1021
|
18
|
100
|
|
|
|
41
|
return uri_escape($value) if($encoding eq 'url');
|
1022
|
|
|
|
|
|
|
|
1023
|
|
|
|
|
|
|
# Encode for use in JavaScript strings (double-quoted).
|
1024
|
16
|
100
|
|
|
|
25
|
if($encoding eq 'js') {
|
1025
|
2
|
|
|
|
|
17
|
$value =~ s/[\\"]/\\$&/go; # Backslash, double quote
|
1026
|
2
|
|
|
|
|
5
|
$value =~ s/\x08/\\b/go; # Backspace
|
1027
|
2
|
|
|
|
|
5
|
$value =~ s/\f/\\f/go; # Form feed
|
1028
|
2
|
|
|
|
|
8
|
$value =~ s/\n/\\n/go; # New line
|
1029
|
2
|
|
|
|
|
6
|
$value =~ s/\r/\\r/go; # Carriage return
|
1030
|
2
|
|
|
|
|
4
|
$value =~ s/\t/\\t/go; # Tab
|
1031
|
2
|
|
|
|
|
32
|
return $value;
|
1032
|
|
|
|
|
|
|
}
|
1033
|
|
|
|
|
|
|
|
1034
|
|
|
|
|
|
|
# Encode and scramble for use in JavaScript strings (double-quoted).
|
1035
|
14
|
100
|
|
|
|
30
|
if($encoding eq 'scramble') {
|
1036
|
2
|
|
|
|
|
3
|
my($scramble, $method, $previous, $n, $c);
|
1037
|
2
|
|
|
|
|
4
|
$scramble = '';
|
1038
|
2
|
|
|
|
|
3
|
$previous = -1;
|
1039
|
2
|
|
|
|
|
6
|
foreach $n (0..length($value)-1) {
|
1040
|
|
|
|
|
|
|
# Select a method (raw, octal or hex).
|
1041
|
39
|
|
|
|
|
43
|
$c = substr($value, $n, 1);
|
1042
|
39
|
|
|
|
|
38
|
$method = -1;
|
1043
|
39
|
100
|
|
|
|
138
|
if($c =~ /^[\x00-\x1F"\\\@\x7F-\xFF]$/o) {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1044
|
5
|
|
|
|
|
59
|
$method = int(rand(2));
|
1045
|
|
|
|
|
|
|
} elsif($previous == 0) {
|
1046
|
6
|
100
|
|
|
|
20
|
$method = int(rand(2)) if($c =~ /^[0-9A-Za-z]$/o);
|
1047
|
|
|
|
|
|
|
} elsif($previous == 1) {
|
1048
|
13
|
50
|
|
|
|
31
|
$method = int(rand(2)) if($c =~ /^[0-7]$/o);
|
1049
|
|
|
|
|
|
|
}
|
1050
|
39
|
100
|
|
|
|
69
|
$method = int(rand(5)) if($method == -1);
|
1051
|
|
|
|
|
|
|
# Encode scrambled using the selected method.
|
1052
|
39
|
100
|
|
|
|
71
|
if($method == 0) {
|
|
|
100
|
|
|
|
|
|
1053
|
9
|
|
|
|
|
17
|
$scramble .= sprintf("\\x%X", ord($c));
|
1054
|
|
|
|
|
|
|
} elsif($method == 1) {
|
1055
|
15
|
|
|
|
|
28
|
$scramble .= sprintf("\\%o", ord($c));
|
1056
|
|
|
|
|
|
|
} else {
|
1057
|
15
|
|
|
|
|
16
|
$scramble .= $c;
|
1058
|
|
|
|
|
|
|
}
|
1059
|
39
|
|
|
|
|
46
|
$previous = $method;
|
1060
|
|
|
|
|
|
|
}
|
1061
|
2
|
|
|
|
|
13
|
return $scramble;
|
1062
|
|
|
|
|
|
|
}
|
1063
|
|
|
|
|
|
|
|
1064
|
|
|
|
|
|
|
# Do not encode, instead leave the raw data in tact.
|
1065
|
12
|
|
|
|
|
67
|
return $value;
|
1066
|
|
|
|
|
|
|
}
|
1067
|
|
|
|
|
|
|
|
1068
|
|
|
|
|
|
|
|
1069
|
|
|
|
|
|
|
# Parse (part of) the HTML template file.
|
1070
|
|
|
|
|
|
|
#
|
1071
|
|
|
|
|
|
|
# _parse($self, \$htx_code_fragment);
|
1072
|
|
|
|
|
|
|
|
1073
|
|
|
|
|
|
|
sub _parse {
|
1074
|
51
|
|
|
51
|
|
81
|
my($self, $htx) = @_;
|
1075
|
|
|
|
|
|
|
|
1076
|
|
|
|
|
|
|
# Fetch our current condition.
|
1077
|
51
|
|
|
|
|
75
|
my $condition = $self->{_condition};
|
1078
|
51
|
|
|
|
|
63
|
my $if_count = $self->{_if_count};
|
1079
|
51
|
|
|
|
|
42
|
my $if_offset = 0;
|
1080
|
|
|
|
|
|
|
|
1081
|
|
|
|
|
|
|
# Find the next statement (between "<%" and "%>").
|
1082
|
51
|
|
|
|
|
46
|
my($expr, $statement, $arg);
|
1083
|
51
|
|
|
|
|
352
|
while($$htx =~ /<%(.+?)(\s+(.+?))?%>/os) {
|
1084
|
120
|
|
|
|
|
564
|
$expr = $1;
|
1085
|
120
|
|
|
|
|
188
|
$statement = lc($1);
|
1086
|
120
|
|
|
|
|
138
|
$arg = $3;
|
1087
|
|
|
|
|
|
|
|
1088
|
|
|
|
|
|
|
# Are we currently processing an <%if%> that turned out false?
|
1089
|
120
|
100
|
|
|
|
521
|
if(!$condition) {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1090
|
|
|
|
|
|
|
# Cut off everything before the current statement (and also cut off
|
1091
|
|
|
|
|
|
|
# the statement itself).
|
1092
|
25
|
|
|
|
|
73
|
$$htx = substr($`, 0, $if_offset).$';
|
1093
|
|
|
|
|
|
|
# Is this a nested <%if%> statement?
|
1094
|
25
|
50
|
|
|
|
156
|
if($statement eq 'if') {
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
1095
|
0
|
|
|
|
|
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
|
50
|
|
|
|
16
|
$condition = 1 if($if_count == 0);
|
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
|
50
|
|
|
|
23
|
if($if_count > 0) {
|
1104
|
0
|
|
|
|
|
0
|
$if_count--;
|
1105
|
|
|
|
|
|
|
} else {
|
1106
|
15
|
|
|
|
|
107
|
$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
|
|
|
|
|
19
|
$$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
|
|
|
|
|
34
|
$$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
|
|
|
|
|
3
|
$$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
|
|
|
|
|
4
|
$$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
|
|
|
|
|
3
|
$$htx = $`._encode($self, $arg, 'scramble').$';
|
1134
|
|
|
|
|
|
|
|
1135
|
|
|
|
|
|
|
# Is this the <%include%> statement?
|
1136
|
|
|
|
|
|
|
} elsif($statement eq 'include') {
|
1137
|
|
|
|
|
|
|
# Insert the include file.
|
1138
|
0
|
|
|
|
|
0
|
_include($self, $arg, $htx, \$`, \$');
|
1139
|
|
|
|
|
|
|
|
1140
|
|
|
|
|
|
|
# Is this the <%if%> statement?
|
1141
|
|
|
|
|
|
|
} elsif($statement eq 'if') {
|
1142
|
|
|
|
|
|
|
# Evaluate the condition.
|
1143
|
13
|
|
|
|
|
30
|
$condition = _evaluate($self, $arg);
|
1144
|
|
|
|
|
|
|
# Continue after the current statement.
|
1145
|
31
|
|
|
|
|
82
|
_IF_:
|
1146
|
|
|
|
|
|
|
$$htx = $`.$';
|
1147
|
31
|
|
|
|
|
190
|
$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
|
|
|
|
|
18
|
$condition = '';
|
1153
|
14
|
|
|
|
|
151
|
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
|
|
|
|
|
42
|
goto _IF_;
|
1159
|
|
|
|
|
|
|
|
1160
|
|
|
|
|
|
|
# Is this the <%detailsection%> statement?
|
1161
|
|
|
|
|
|
|
} elsif($statement eq 'detailsection') {
|
1162
|
|
|
|
|
|
|
# Set the current section name.
|
1163
|
9
|
|
|
|
|
22
|
$self->{_section} = $arg;
|
1164
|
9
|
100
|
|
|
|
25
|
_stats($self, undef, undef, undef, $arg) if($self->{_stats});
|
1165
|
9
|
|
|
|
|
40
|
$$htx = $`.$';
|
1166
|
|
|
|
|
|
|
|
1167
|
|
|
|
|
|
|
# The statement was not recognized, so it must an expression.
|
1168
|
|
|
|
|
|
|
} else {
|
1169
|
|
|
|
|
|
|
# Encode the expression using HTML encoding.
|
1170
|
23
|
|
|
|
|
44
|
$$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
|
100
|
|
|
|
361
|
$$htx = substr($$htx, 0, $if_offset) if(!$condition);
|
1177
|
|
|
|
|
|
|
|
1178
|
|
|
|
|
|
|
# Save some values for later.
|
1179
|
51
|
|
|
|
|
68
|
$self->{_condition} = $condition;
|
1180
|
51
|
|
|
|
|
60
|
$self->{_if_count} = $if_count;
|
1181
|
|
|
|
|
|
|
|
1182
|
51
|
100
|
|
|
|
84
|
return '' if(!$condition);
|
1183
|
50
|
|
|
|
|
121
|
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
|
|
|
|
|
|
|
sub _print {
|
1193
|
37
|
|
|
37
|
|
115
|
my($self, $scalar) = @_;
|
1194
|
|
|
|
|
|
|
|
1195
|
|
|
|
|
|
|
# Optionally parse the scalar.
|
1196
|
37
|
|
|
|
|
39
|
my $ref;
|
1197
|
37
|
100
|
|
|
|
67
|
if(!ref($scalar)) {
|
1198
|
31
|
|
|
|
|
59
|
_parse($self, $ref = \$scalar);
|
1199
|
|
|
|
|
|
|
} else {
|
1200
|
6
|
|
|
|
|
8
|
$ref = $scalar;
|
1201
|
|
|
|
|
|
|
}
|
1202
|
|
|
|
|
|
|
|
1203
|
|
|
|
|
|
|
# Output the scalar.
|
1204
|
37
|
50
|
|
|
|
90
|
if(ref($self->{_output}) eq 'SCALAR') {
|
|
|
0
|
|
|
|
|
|
1205
|
37
|
50
|
|
|
|
79
|
${$self->{_output}} .= $$ref if($$ref ne '');
|
|
37
|
|
|
|
|
99
|
|
1206
|
|
|
|
|
|
|
} elsif($$ref ne '') {
|
1207
|
0
|
0
|
|
|
|
0
|
(print {$self->{_output}} $$ref) or return undef;
|
|
0
|
|
|
|
|
0
|
|
1208
|
|
|
|
|
|
|
}
|
1209
|
37
|
|
|
|
|
82
|
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
|
|
|
|
|
|
|
sub _stats {
|
1222
|
35
|
|
|
35
|
|
70
|
my($self, $number, $count, $total, $section) = @_;
|
1223
|
35
|
|
|
|
|
31
|
local $_;
|
1224
|
|
|
|
|
|
|
|
1225
|
35
|
100
|
|
|
|
62
|
if(defined($number)) {
|
1226
|
20
|
100
|
|
|
|
38
|
$number ? ($number = $self->{_param}{'NUMBER'}+$number) : ($number = 1);
|
1227
|
20
|
|
|
|
|
25
|
$self->{_param}{'NUMBER'} = $number;
|
1228
|
20
|
|
|
|
|
33
|
$self->{_param}{'NUMBER?'} = $number%2;
|
1229
|
|
|
|
|
|
|
}
|
1230
|
|
|
|
|
|
|
|
1231
|
35
|
100
|
|
|
|
57
|
if(defined($count)) {
|
1232
|
18
|
100
|
|
|
|
30
|
$count ? ($count = $self->{_param}{'COUNT'}+$count) : ($count = 0);
|
1233
|
18
|
|
|
|
|
23
|
$self->{_param}{'COUNT'} = $count;
|
1234
|
18
|
|
|
|
|
27
|
$self->{_param}{'COUNT?'} = $count%2;
|
1235
|
|
|
|
|
|
|
}
|
1236
|
|
|
|
|
|
|
|
1237
|
35
|
100
|
|
|
|
58
|
if(defined($total)) {
|
1238
|
15
|
100
|
|
|
|
29
|
$total ? ($total = $self->{_param}{'TOTAL'}+$total) : ($total = 0);
|
1239
|
15
|
|
|
|
|
22
|
$self->{_param}{'TOTAL'} = $total;
|
1240
|
15
|
|
|
|
|
22
|
$self->{_param}{'TOTAL?'} = $total%2;
|
1241
|
|
|
|
|
|
|
}
|
1242
|
|
|
|
|
|
|
|
1243
|
35
|
100
|
|
|
|
80
|
$self->{_param}{'SECTION'} = $section if(defined($section));
|
1244
|
|
|
|
|
|
|
}
|
1245
|
|
|
|
|
|
|
|
1246
|
|
|
|
|
|
|
|
1247
|
|
|
|
|
|
|
# Sets the common date and time parameters.
|
1248
|
|
|
|
|
|
|
#
|
1249
|
|
|
|
|
|
|
# _date($self, $epoch_time);
|
1250
|
|
|
|
|
|
|
|
1251
|
|
|
|
|
|
|
sub _date {
|
1252
|
3
|
|
|
3
|
|
4
|
my($self, $epoch_time) = @_;
|
1253
|
3
|
50
|
|
|
|
6
|
$epoch_time = time unless(defined($epoch_time));
|
1254
|
|
|
|
|
|
|
|
1255
|
|
|
|
|
|
|
# Calculate the local time zone.
|
1256
|
3
|
|
|
|
|
76
|
my @ltm = localtime($epoch_time);
|
1257
|
3
|
|
|
|
|
9
|
my @gmt = gmtime($epoch_time);
|
1258
|
3
|
|
|
|
|
6
|
my $zone = ($ltm[2]*60+$ltm[1])-($gmt[2]*60+$gmt[1]);
|
1259
|
3
|
50
|
33
|
|
|
32
|
if(($ltm[5] > $gmt[5]) or (($ltm[5] == $gmt[5]) and ($ltm[7] > $gmt[7]))) {
|
|
|
50
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
33
|
|
|
|
|
1260
|
0
|
|
|
|
|
0
|
$zone += 24*60;
|
1261
|
|
|
|
|
|
|
} elsif(($ltm[5] < $gmt[5]) or (($ltm[5] == $gmt[5]) and ($ltm[7] < $gmt[7]))) {
|
1262
|
0
|
|
|
|
|
0
|
$zone -= 24*60;
|
1263
|
|
|
|
|
|
|
}
|
1264
|
3
|
|
|
|
|
6
|
my $hour = int($zone/60);
|
1265
|
3
|
|
|
|
|
9
|
$zone = sprintf("%+03d%02d", $hour, abs($zone-$hour*60));
|
1266
|
|
|
|
|
|
|
|
1267
|
|
|
|
|
|
|
# Set the parameters for both the local time and GMT.
|
1268
|
3
|
|
|
|
|
9
|
my($date, $tm, $prefix);
|
1269
|
3
|
|
|
|
|
52
|
$date = localtime($epoch_time);
|
1270
|
3
|
|
|
|
|
6
|
$tm = \@ltm;
|
1271
|
3
|
|
|
|
|
5
|
foreach $prefix ('', 'GMT_') {
|
1272
|
|
|
|
|
|
|
# Construct a full date/time string.
|
1273
|
6
|
|
|
|
|
21
|
$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
|
|
|
|
|
16
|
$self->{_param}{$prefix.'YEAR'} = substr($date, 12, 4);
|
1284
|
6
|
|
|
|
|
16
|
$self->{_param}{$prefix.'MONTH'} = sprintf("%02d", $$tm[4]+1);
|
1285
|
6
|
|
|
|
|
15
|
$self->{_param}{$prefix.'MONTH$'} = substr($date, 8, 3);
|
1286
|
6
|
|
|
|
|
9
|
$self->{_param}{$prefix.'DAY'} = substr($date, 5, 2);
|
1287
|
6
|
|
|
|
|
13
|
$self->{_param}{$prefix.'DATE'} = substr($date, 5, 11);
|
1288
|
6
|
|
|
|
|
18
|
$self->{_param}{$prefix.'WEEKDAY'} = $$tm[6]+1;
|
1289
|
6
|
|
|
|
|
11
|
$self->{_param}{$prefix.'WEEKDAY$'} = substr($date, 0, 3);
|
1290
|
6
|
|
|
|
|
11
|
$self->{_param}{$prefix.'HOUR'} = substr($date, 17, 2);
|
1291
|
6
|
|
|
|
|
10
|
$self->{_param}{$prefix.'MINUTE'} = substr($date, 20, 2);
|
1292
|
6
|
|
|
|
|
12
|
$self->{_param}{$prefix.'TIME'} = substr($date, 17, 5);
|
1293
|
6
|
|
|
|
|
12
|
$self->{_param}{$prefix.'SECOND'} = substr($date, 23, 2);
|
1294
|
6
|
|
|
|
|
35
|
$self->{_param}{$prefix.'TIME_ZONE'} = $zone;
|
1295
|
6
|
|
|
|
|
12
|
$self->{_param}{$prefix.'DATE_TIME'} = $date;
|
1296
|
|
|
|
|
|
|
|
1297
|
|
|
|
|
|
|
# Next, please!
|
1298
|
6
|
|
|
|
|
23
|
$date = gmtime($epoch_time);
|
1299
|
6
|
|
|
|
|
16
|
$tm = \@gmt;
|
1300
|
6
|
|
|
|
|
26
|
$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%> and C<%E> (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%>IC<%E>
|
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 method.
|
1321
|
|
|
|
|
|
|
This is typically done before a call to the C method, but
|
1322
|
|
|
|
|
|
|
also before calling the C and C methods.
|
1323
|
|
|
|
|
|
|
|
1324
|
|
|
|
|
|
|
=item C%EscapeRaw >IC<%E>
|
1325
|
|
|
|
|
|
|
|
1326
|
|
|
|
|
|
|
=item C%EscapeHTML >IC<%E>
|
1327
|
|
|
|
|
|
|
|
1328
|
|
|
|
|
|
|
=item C%EscapeURL >IC<%E>
|
1329
|
|
|
|
|
|
|
|
1330
|
|
|
|
|
|
|
=item C%EscapeJS >IC<%E>
|
1331
|
|
|
|
|
|
|
|
1332
|
|
|
|
|
|
|
=item C%EscapeScramble >IC<%E>
|
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%EscapeJS Variable%E");>. Scrambled JavaScript
|
1339
|
|
|
|
|
|
|
encoding comes in handy when you want to "hide" e-mail addresses from
|
1340
|
|
|
|
|
|
|
spambots, e.g. C%EscapeScramble Email%E");>.
|
1341
|
|
|
|
|
|
|
|
1342
|
|
|
|
|
|
|
=item C%begindetail%E>
|
1343
|
|
|
|
|
|
|
|
1344
|
|
|
|
|
|
|
Repeats what comes next for each record, until C%enddetail%E> or
|
1345
|
|
|
|
|
|
|
the end of the file is reached. This is the section that is printed by the
|
1346
|
|
|
|
|
|
|
C method.
|
1347
|
|
|
|
|
|
|
|
1348
|
|
|
|
|
|
|
=item C%enddetail%E>
|
1349
|
|
|
|
|
|
|
|
1350
|
|
|
|
|
|
|
See C%begindetail%E>.
|
1351
|
|
|
|
|
|
|
|
1352
|
|
|
|
|
|
|
=item C%detailsection >IC<%E>
|
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 method.
|
1357
|
|
|
|
|
|
|
|
1358
|
|
|
|
|
|
|
=item C%if >IC<%E>
|
1359
|
|
|
|
|
|
|
|
1360
|
|
|
|
|
|
|
Only output what comes next if I is true. The I has
|
1361
|
|
|
|
|
|
|
the following syntax:
|
1362
|
|
|
|
|
|
|
|
1363
|
|
|
|
|
|
|
I I [I]
|
1364
|
|
|
|
|
|
|
|
1365
|
|
|
|
|
|
|
I and I 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 can be one of the following operators:
|
1371
|
|
|
|
|
|
|
|
1372
|
|
|
|
|
|
|
=over 4
|
1373
|
|
|
|
|
|
|
|
1374
|
|
|
|
|
|
|
=item *
|
1375
|
|
|
|
|
|
|
|
1376
|
|
|
|
|
|
|
C - I and I are identical.
|
1377
|
|
|
|
|
|
|
|
1378
|
|
|
|
|
|
|
=item *
|
1379
|
|
|
|
|
|
|
|
1380
|
|
|
|
|
|
|
C - I and I are not identical.
|
1381
|
|
|
|
|
|
|
|
1382
|
|
|
|
|
|
|
=item *
|
1383
|
|
|
|
|
|
|
|
1384
|
|
|
|
|
|
|
C - I is less than I.
|
1385
|
|
|
|
|
|
|
|
1386
|
|
|
|
|
|
|
=item *
|
1387
|
|
|
|
|
|
|
|
1388
|
|
|
|
|
|
|
C - I is less than or equal to I.
|
1389
|
|
|
|
|
|
|
|
1390
|
|
|
|
|
|
|
=item *
|
1391
|
|
|
|
|
|
|
|
1392
|
|
|
|
|
|
|
C - I is greater than I.
|
1393
|
|
|
|
|
|
|
|
1394
|
|
|
|
|
|
|
=item *
|
1395
|
|
|
|
|
|
|
|
1396
|
|
|
|
|
|
|
C - I is greater than or equal to I.
|
1397
|
|
|
|
|
|
|
|
1398
|
|
|
|
|
|
|
=item *
|
1399
|
|
|
|
|
|
|
|
1400
|
|
|
|
|
|
|
C - I contains I.
|
1401
|
|
|
|
|
|
|
|
1402
|
|
|
|
|
|
|
=item *
|
1403
|
|
|
|
|
|
|
|
1404
|
|
|
|
|
|
|
C - This is always true; it's included for compatibility.
|
1405
|
|
|
|
|
|
|
|
1406
|
|
|
|
|
|
|
=item *
|
1407
|
|
|
|
|
|
|
|
1408
|
|
|
|
|
|
|
C - I equals an empty string (or zero in a numerical
|
1409
|
|
|
|
|
|
|
context). I should be ommited when you use the C
|
1410
|
|
|
|
|
|
|
operator.
|
1411
|
|
|
|
|
|
|
|
1412
|
|
|
|
|
|
|
=back
|
1413
|
|
|
|
|
|
|
|
1414
|
|
|
|
|
|
|
=item C%else%E>
|
1415
|
|
|
|
|
|
|
|
1416
|
|
|
|
|
|
|
Only output what comes next if the I of an earlier
|
1417
|
|
|
|
|
|
|
C%if%E> was false.
|
1418
|
|
|
|
|
|
|
|
1419
|
|
|
|
|
|
|
=item C%endif%E>
|
1420
|
|
|
|
|
|
|
|
1421
|
|
|
|
|
|
|
Ends a conditional block and returns to its earlier conditional state. Yes,
|
1422
|
|
|
|
|
|
|
this means that you can nest
|
1423
|
|
|
|
|
|
|
C%if%E>..C%else%E>..C%endif%E> blocks. :-)
|
1424
|
|
|
|
|
|
|
|
1425
|
|
|
|
|
|
|
=item C%include >IC<%E>
|
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%include%E> tag for that matter. However, the use of
|
1430
|
|
|
|
|
|
|
C%include%E> inside an include file is not recommended, because it
|
1431
|
|
|
|
|
|
|
may lead to recursive inclusion. You should also be careful with using
|
1432
|
|
|
|
|
|
|
C%begindetail%E>..C%enddetail%E> inside an include file,
|
1433
|
|
|
|
|
|
|
because I.
|
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%if%E>, C%else%E> and C%endif%E>
|
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%else%E>..C%endif%E> around it
|
1448
|
|
|
|
|
|
|
(without C%if%E>!).
|
1449
|
|
|
|
|
|
|
|
1450
|
|
|
|
|
|
|
The use of multiple C%begindetail%E>..C%enddetail%E>
|
1451
|
|
|
|
|
|
|
sections is not documented for Microsoft's Index Server, but is supported
|
1452
|
|
|
|
|
|
|
very elegantly by this module (see the C method).
|
1453
|
|
|
|
|
|
|
|
1454
|
|
|
|
|
|
|
=head1 MODIFICATION HISTORY
|
1455
|
|
|
|
|
|
|
|
1456
|
|
|
|
|
|
|
=over 4
|
1457
|
|
|
|
|
|
|
|
1458
|
|
|
|
|
|
|
=item Version 0.07
|
1459
|
|
|
|
|
|
|
|
1460
|
|
|
|
|
|
|
[I] 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 are now much easier to
|
1464
|
|
|
|
|
|
|
handle. Two new encoding types have been added: C%EscapeJS%E> and
|
1465
|
|
|
|
|
|
|
C%EscapeScramble%E>. The L
|
1466
|
|
|
|
|
|
|
feature has been added. The tests in F 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] 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] Added the option for output to a scalar instead of a
|
1481
|
|
|
|
|
|
|
file.
|
1482
|
|
|
|
|
|
|
|
1483
|
|
|
|
|
|
|
=item Version 0.04
|
1484
|
|
|
|
|
|
|
|
1485
|
|
|
|
|
|
|
[I] Fixed a minor bug concerning multi-line
|
1486
|
|
|
|
|
|
|
C%if%E>'s.
|
1487
|
|
|
|
|
|
|
|
1488
|
|
|
|
|
|
|
=item Version 0.03
|
1489
|
|
|
|
|
|
|
|
1490
|
|
|
|
|
|
|
[I] Fixed a bug in the C<_evaluate> sub, that resulted in
|
1491
|
|
|
|
|
|
|
warnings about uninitialized multiplications when using the C
|
1492
|
|
|
|
|
|
|
operator.
|
1493
|
|
|
|
|
|
|
|
1494
|
|
|
|
|
|
|
=item Version 0.02
|
1495
|
|
|
|
|
|
|
|
1496
|
|
|
|
|
|
|
[I] Fixed a few minor bugs concerning nested
|
1497
|
|
|
|
|
|
|
C%if%E>'s, the C operator, and the use of HTTP headers.
|
1498
|
|
|
|
|
|
|
|
1499
|
|
|
|
|
|
|
=item Version 0.01
|
1500
|
|
|
|
|
|
|
|
1501
|
|
|
|
|
|
|
[I] Created the module. :-)
|
1502
|
|
|
|
|
|
|
|
1503
|
|
|
|
|
|
|
=back
|
1504
|
|
|
|
|
|
|
|
1505
|
|
|
|
|
|
|
=head1 AUTHOR INFORMATION
|
1506
|
|
|
|
|
|
|
|
1507
|
|
|
|
|
|
|
Theo Niessink , http://www.taletn.com/
|
1508
|
|
|
|
|
|
|
|
1509
|
|
|
|
|
|
|
I<(The "I used to care but Things Have Changed" used in the
|
1510
|
|
|
|
|
|
|
L was written by Bob Dylan.)> :-)
|
1511
|
|
|
|
|
|
|
|
1512
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
1513
|
|
|
|
|
|
|
|
1514
|
|
|
|
|
|
|
E 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;
|