line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::SimpleTemplate; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# (C)1998-2003 Andrew Crawford |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# A quicker (for the programmer!) and simpler template system for |
6
|
|
|
|
|
|
|
# people who like simple things. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or |
9
|
|
|
|
|
|
|
# modify it under the same terms as Perl itself. |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3544
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
74
|
|
13
|
1
|
|
|
1
|
|
721
|
use Symbol; |
|
1
|
|
|
|
|
915
|
|
|
1
|
|
|
|
|
84
|
|
14
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
818
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require Exporter; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
19
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
20
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
21
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# We don't need no stinkin' exports |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = '1.00'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new |
28
|
|
|
|
|
|
|
{ |
29
|
1
|
|
|
1
|
0
|
7069
|
my $type = shift; |
30
|
1
|
|
33
|
|
|
17
|
my $class = ref($type) || $type; |
31
|
1
|
|
|
|
|
3
|
my $filepath=shift; |
32
|
1
|
|
|
|
|
6
|
my $self={"FILEPATH"=>$filepath}; |
33
|
1
|
|
|
|
|
5
|
bless ($self,$class); |
34
|
1
|
|
|
|
|
4
|
return $self; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub Display |
38
|
|
|
|
|
|
|
{ |
39
|
4
|
|
|
4
|
0
|
538
|
my $self = shift; |
40
|
4
|
|
|
|
|
11
|
my $filename = shift; |
41
|
4
|
|
|
|
|
10
|
my @ifstate=(1); |
42
|
4
|
|
|
|
|
18
|
my $fh = Symbol::gensym(); |
43
|
4
|
|
|
|
|
64
|
my $blockelse; |
44
|
|
|
|
|
|
|
|
45
|
4
|
50
|
|
|
|
26
|
if ($self->{FILEPATH}) |
46
|
|
|
|
|
|
|
{ |
47
|
4
|
50
|
|
|
|
220
|
open ($fh,$self->{FILEPATH}."/$filename") || return; |
48
|
|
|
|
|
|
|
} else { |
49
|
0
|
0
|
|
|
|
0
|
open ($fh,"$filename") || return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
4
|
|
|
|
|
9
|
my $bundle = shift; # a reference to the hash with the variables in |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
8
|
${$bundle}{TemplatePath} = $self->{FILEPATH}; |
|
4
|
|
|
|
|
11
|
|
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
87
|
while(<$fh>) # for each line of the template file... |
57
|
|
|
|
|
|
|
{ |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# # some comment not sent to output |
60
|
112
|
100
|
|
|
|
467
|
if (/^\#/) # skip it if it's a comment |
61
|
|
|
|
|
|
|
{ |
62
|
1
|
|
|
|
|
6
|
next; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# ?$ShowImage |
68
|
111
|
100
|
|
|
|
244
|
if (/^\?\$(\S+)/) # Simple if clause |
69
|
|
|
|
|
|
|
{ |
70
|
|
|
|
|
|
|
|
71
|
3
|
50
|
|
|
|
9
|
if (!$ifstate[0]) |
72
|
|
|
|
|
|
|
{ |
73
|
0
|
|
|
|
|
0
|
$blockelse++; |
74
|
0
|
|
|
|
|
0
|
next; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
3
|
100
|
|
|
|
4
|
if (${$bundle}{$1}) |
|
3
|
|
|
|
|
15
|
|
78
|
|
|
|
|
|
|
{ |
79
|
2
|
|
|
|
|
6
|
unshift @ifstate,1; |
80
|
|
|
|
|
|
|
} else { |
81
|
1
|
|
|
|
|
2
|
unshift @ifstate,0; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
3
|
|
|
|
|
10
|
next; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# ?($name=~/Bishop/) |
88
|
108
|
100
|
|
|
|
242
|
if (/^\?\((.+)\)$/) # Complex if clause |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
|
91
|
9
|
100
|
|
|
|
23
|
if (!$ifstate[0]) |
92
|
|
|
|
|
|
|
{ |
93
|
1
|
|
|
|
|
3
|
$blockelse++; |
94
|
1
|
|
|
|
|
4
|
next; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
8
|
|
|
|
|
23
|
my $cond=$1; # the condition |
98
|
|
|
|
|
|
|
|
99
|
8
|
|
|
|
|
36
|
$cond=~s/\$(\w+)/\$\{\$bundle\}\{$1\}/g; |
100
|
|
|
|
|
|
|
# interpolate string |
101
|
|
|
|
|
|
|
|
102
|
8
|
100
|
|
|
|
611
|
if(eval($cond)) |
103
|
|
|
|
|
|
|
{ |
104
|
5
|
|
|
|
|
12
|
unshift @ifstate,1 ; |
105
|
|
|
|
|
|
|
} else { |
106
|
3
|
|
|
|
|
8
|
unshift @ifstate,0 ; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
8
|
|
|
|
|
48
|
next; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# ?!$ShowImage |
113
|
99
|
100
|
|
|
|
240
|
if(/^\?\!\$(\S+)/) # Simple if NOT clause |
114
|
|
|
|
|
|
|
{ |
115
|
2
|
50
|
|
|
|
3
|
if (${$bundle}{$1}) |
|
2
|
|
|
|
|
12
|
|
116
|
|
|
|
|
|
|
{ |
117
|
0
|
|
|
|
|
0
|
unshift @ifstate,0; |
118
|
|
|
|
|
|
|
} else { |
119
|
2
|
|
|
|
|
5
|
unshift @ifstate,1; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
2
|
|
|
|
|
9
|
next; |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# ?else |
126
|
97
|
100
|
|
|
|
321
|
if (/^\?else/) # ELSE command - swap ifstate |
127
|
|
|
|
|
|
|
{ |
128
|
12
|
100
|
|
|
|
29
|
if ($blockelse) |
129
|
|
|
|
|
|
|
{ |
130
|
1
|
|
|
|
|
4
|
next; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
11
|
100
|
|
|
|
26
|
if ($ifstate[0]==0) |
134
|
|
|
|
|
|
|
{ |
135
|
3
|
|
|
|
|
5
|
$ifstate[0]=1; |
136
|
|
|
|
|
|
|
} else { |
137
|
8
|
|
|
|
|
12
|
$ifstate[0]=0; |
138
|
|
|
|
|
|
|
} |
139
|
11
|
|
|
|
|
39
|
next; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
# ?exit |
143
|
85
|
50
|
|
|
|
173
|
if (/^\?exit/) # EXIT command - quit processing |
144
|
|
|
|
|
|
|
{ |
145
|
0
|
0
|
|
|
|
0
|
if ($ifstate[0]) |
146
|
|
|
|
|
|
|
{ |
147
|
0
|
|
|
|
|
0
|
close($fh); |
148
|
0
|
|
|
|
|
0
|
return; |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
85
|
100
|
|
|
|
391
|
if (/^\?end/) # End of an if block |
153
|
|
|
|
|
|
|
{ |
154
|
14
|
100
|
|
|
|
32
|
if ($blockelse) |
155
|
|
|
|
|
|
|
{ |
156
|
1
|
|
|
|
|
2
|
$blockelse--; |
157
|
1
|
|
|
|
|
5
|
next; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
13
|
|
|
|
|
17
|
shift(@ifstate); |
161
|
|
|
|
|
|
|
|
162
|
13
|
50
|
|
|
|
28
|
if (!defined @ifstate) |
163
|
|
|
|
|
|
|
{ |
164
|
|
|
|
|
|
|
# Allow for too many ?ends |
165
|
0
|
|
|
|
|
0
|
@ifstate=(1); |
166
|
|
|
|
|
|
|
} |
167
|
13
|
|
|
|
|
44
|
next; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
# Add callbacks to perl procedures |
173
|
|
|
|
|
|
|
# &SomeFunc($a,3) |
174
|
71
|
50
|
|
|
|
156
|
if (/^\&([^\)]+)\(([^\)]+)/) |
175
|
|
|
|
|
|
|
{ |
176
|
0
|
|
|
|
|
0
|
my $params=$2; |
177
|
0
|
|
|
|
|
0
|
my $command=$1; |
178
|
|
|
|
|
|
|
|
179
|
0
|
|
|
|
|
0
|
$params=~s/\$(\w+)/${$bundle}{$1}/g; |
|
0
|
|
|
|
|
0
|
|
180
|
0
|
|
|
|
|
0
|
$command=~s/\$(\w+)/${$bundle}{$1}/g; |
|
0
|
|
|
|
|
0
|
|
181
|
|
|
|
|
|
|
|
182
|
0
|
|
|
|
|
0
|
$params=~s/\"/\\\"/g; |
183
|
|
|
|
|
|
|
|
184
|
0
|
|
|
|
|
0
|
eval"$command($params);"; |
185
|
0
|
|
|
|
|
0
|
next; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# Substitute template variables where ever found |
190
|
|
|
|
|
|
|
|
191
|
71
|
|
|
|
|
120
|
s/\$(\w+)/${$bundle}{$1}/g; |
|
7
|
|
|
|
|
33
|
|
192
|
71
|
|
|
|
|
88
|
s/\$\{(\w+)\}/${$bundle}{$1}/g; |
|
0
|
|
|
|
|
0
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
# !another.tpl |
195
|
71
|
100
|
|
|
|
143
|
if (/^\!(\S+)/) # Include other tpl file |
196
|
|
|
|
|
|
|
{ |
197
|
1
|
50
|
|
|
|
6
|
if ($ifstate[0]) |
198
|
|
|
|
|
|
|
{ |
199
|
1
|
|
|
|
|
13
|
Display($self,$1,$bundle); |
200
|
1
|
|
|
|
|
9
|
next; |
201
|
|
|
|
|
|
|
} |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
# Print the processed line if appropriate |
205
|
|
|
|
|
|
|
|
206
|
70
|
100
|
|
|
|
179
|
if ($ifstate[0]) |
207
|
|
|
|
|
|
|
{ |
208
|
51
|
|
|
|
|
18694
|
print; |
209
|
|
|
|
|
|
|
} |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
4
|
|
|
|
|
241
|
close($fh); |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# Preloaded methods go here. |
218
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
1; |
221
|
|
|
|
|
|
|
__END__ |