line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::Parser::TreeWriter::HTP; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
1475
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
59
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
58
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use base qw(HTML::Template::Parser::TreeWriter); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
1103
|
|
7
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw( expr_writer )); |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
17
|
|
|
17
|
1
|
12251
|
my $class = shift; |
11
|
17
|
|
|
|
|
81
|
my $self = $class->SUPER::new(@_); |
12
|
17
|
|
|
|
|
270
|
$self->expr_writer(HTML::Template::Parser::TreeWriter::HTP::Expr->new); |
13
|
17
|
|
|
|
|
241
|
$self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
sub get_type { |
16
|
34
|
|
|
34
|
0
|
42
|
my($self, $node) = @_; |
17
|
34
|
|
|
|
|
231
|
my($type) = (ref($node) =~ /::([^:]+)$/); |
18
|
34
|
|
|
|
|
106
|
$type; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub get_node_children { |
22
|
34
|
|
|
34
|
0
|
45
|
my($self, $node) = @_; |
23
|
34
|
|
|
|
|
41
|
@{$node->children}; |
|
34
|
|
|
|
|
78
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _pre_String { |
27
|
2
|
|
|
2
|
|
3
|
my($self, $node) = @_; |
28
|
|
|
|
|
|
|
|
29
|
2
|
|
|
|
|
7
|
$node->text; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _pre_Var { |
33
|
15
|
|
|
15
|
|
19
|
my($self, $node) = @_; |
34
|
|
|
|
|
|
|
|
35
|
15
|
|
|
|
|
41
|
my $label = uc($node->name_or_expr->[0]); |
36
|
15
|
|
|
|
|
126
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
37
|
15
|
100
|
|
|
|
59
|
my $escape = defined($node->escape) ? (' ESCAPE='.$node->escape) : ''; |
38
|
15
|
100
|
|
|
|
133
|
my $default = defined($node->default) ? (' DEFAULT='.$self->expr_writer->write($node->default)) : ''; |
39
|
15
|
|
|
|
|
127
|
qq{}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub _pre_Include { |
43
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
0
|
my $label = uc($node->name_or_expr->[0]); |
46
|
0
|
|
|
|
|
0
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
47
|
0
|
|
|
|
|
0
|
qq{}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub _pre_If { |
52
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
55
|
0
|
|
|
|
|
0
|
sprintf(q{}, |
56
|
|
|
|
|
|
|
uc($node->name_or_expr->[0]), |
57
|
|
|
|
|
|
|
$name_or_expr); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub _pre_ElsIf { |
61
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
0
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
64
|
0
|
|
|
|
|
0
|
sprintf(q{}, |
65
|
|
|
|
|
|
|
uc($node->name_or_expr->[0]), |
66
|
|
|
|
|
|
|
$name_or_expr); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _pre_Else { |
70
|
0
|
|
|
0
|
|
0
|
q{}; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _pre_IfEnd { |
74
|
0
|
|
|
0
|
|
0
|
q{}; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _pre_Unless { |
78
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
0
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
81
|
0
|
|
|
|
|
0
|
sprintf(q{}, |
82
|
|
|
|
|
|
|
uc($node->name_or_expr->[0]), # @@@ |
83
|
|
|
|
|
|
|
$name_or_expr); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub _pre_UnlessEnd { |
87
|
0
|
|
|
0
|
|
0
|
q{}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _pre_Loop { |
91
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
0
|
my $name_or_expr = $self->expr_writer->write($node->name_or_expr->[1]); |
94
|
0
|
|
|
|
|
0
|
sprintf(q{}, |
95
|
|
|
|
|
|
|
uc($node->name_or_expr->[0]), # @@@ |
96
|
|
|
|
|
|
|
$name_or_expr); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _pre_LoopEnd { |
100
|
0
|
|
|
0
|
|
0
|
q{}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
package HTML::Template::Parser::TreeWriter::HTP::Expr; |
104
|
|
|
|
|
|
|
|
105
|
2
|
|
|
2
|
|
15
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
54
|
|
106
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
62
|
|
107
|
|
|
|
|
|
|
|
108
|
2
|
|
|
2
|
|
10
|
use base qw(HTML::Template::Parser::TreeWriter); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2035
|
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my %op_to_name = ( |
111
|
|
|
|
|
|
|
'not' => 'not_sym', |
112
|
|
|
|
|
|
|
'!' => 'not', |
113
|
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
foreach my $bin_operator (qw(or and || && > >= < <= != == le ge eq ne lt gt + - * / % =~ !~)){ |
116
|
|
|
|
|
|
|
$op_to_name{$bin_operator} = 'binary'; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub get_type { |
120
|
57
|
|
|
57
|
|
75
|
my($self, $node) = @_; |
121
|
|
|
|
|
|
|
|
122
|
57
|
|
|
|
|
128
|
my $type = $node->[0]; # 'op', 'variable', 'function' .... |
123
|
57
|
100
|
|
|
|
160
|
if($node->[0] eq 'op'){ |
124
|
17
|
|
|
|
|
38
|
my $op_name = $op_to_name{$node->[1]}; |
125
|
17
|
50
|
|
|
|
42
|
die "Unknown op_name[$node->[1]]\n" unless $op_name; |
126
|
17
|
|
|
|
|
41
|
$type .= '_' . $op_name; |
127
|
|
|
|
|
|
|
} |
128
|
57
|
|
|
|
|
145
|
$type; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub get_node_children { |
132
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
133
|
|
|
|
|
|
|
# die "internal error\n"; # use custom map function. |
134
|
0
|
|
|
|
|
0
|
(); # @@@ |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
################################################################ |
138
|
|
|
|
|
|
|
# bin_op |
139
|
|
|
|
|
|
|
sub _main_op_binary { |
140
|
17
|
|
|
17
|
|
26
|
my($self, $node) = @_; |
141
|
|
|
|
|
|
|
|
142
|
17
|
|
|
|
|
223
|
'(' . $self->write($node->[2]) . $node->[1] . $self->write($node->[3]) . ')'; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
################################################################ |
146
|
|
|
|
|
|
|
# op_not_sym |
147
|
|
|
|
|
|
|
sub _main_op_not_sym { |
148
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
149
|
|
|
|
|
|
|
|
150
|
0
|
|
|
|
|
0
|
'(' . 'not' . $node->[2] . ')'; |
151
|
|
|
|
|
|
|
} |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
################################################################ |
154
|
|
|
|
|
|
|
# op_not |
155
|
|
|
|
|
|
|
sub _main_op_not { |
156
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
0
|
'(' . '!' . $node->[2] . ')'; |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
################################################################ |
162
|
|
|
|
|
|
|
# function |
163
|
|
|
|
|
|
|
sub _pre_function { |
164
|
5
|
|
|
5
|
|
10
|
my($self, $node) = @_; |
165
|
5
|
|
|
|
|
22
|
$node->[1]->[1]; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _map_function { |
169
|
5
|
|
|
5
|
|
10
|
my($self, $node) = @_; |
170
|
|
|
|
|
|
|
|
171
|
5
|
|
|
|
|
10
|
my @chilren_out; |
172
|
5
|
|
|
|
|
22
|
for(my $i = 2;$i < @$node;$i ++){ # 0:'function', 1:['name', 'function_name'], 2:param1, 3:param2, .... |
173
|
6
|
|
|
|
|
13
|
my $child_node = $node->[$i]; |
174
|
6
|
|
|
|
|
20
|
push(@chilren_out, $self->write($child_node)); |
175
|
|
|
|
|
|
|
} |
176
|
5
|
|
|
|
|
22
|
@chilren_out; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub _join_function { |
180
|
5
|
|
|
5
|
|
9
|
my($self, $node, $chilren_out) = @_; |
181
|
|
|
|
|
|
|
|
182
|
5
|
|
|
|
|
29
|
'(' . join(',', @$chilren_out) . ')'; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
################################################################ |
186
|
|
|
|
|
|
|
# string |
187
|
|
|
|
|
|
|
sub _main_string { |
188
|
0
|
|
|
0
|
|
0
|
my($self, $node) = @_; |
189
|
|
|
|
|
|
|
|
190
|
0
|
|
|
|
|
0
|
qq{'$node->[1]'}; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
################################################################ |
194
|
|
|
|
|
|
|
# variable |
195
|
|
|
|
|
|
|
sub _main_variable { |
196
|
11
|
|
|
11
|
|
29
|
my($self, $node) = @_; |
197
|
|
|
|
|
|
|
|
198
|
11
|
|
|
|
|
36
|
$node->[1]; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
################################################################ |
202
|
|
|
|
|
|
|
# number |
203
|
|
|
|
|
|
|
sub _main_number { |
204
|
21
|
|
|
21
|
|
30
|
my($self, $node) = @_; |
205
|
|
|
|
|
|
|
|
206
|
21
|
|
|
|
|
65
|
$node->[1]; |
207
|
|
|
|
|
|
|
} |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
################################################################ |
210
|
|
|
|
|
|
|
# default |
211
|
|
|
|
|
|
|
sub _main_default { |
212
|
2
|
|
|
2
|
|
4
|
my($self, $node) = @_; |
213
|
|
|
|
|
|
|
|
214
|
2
|
|
|
|
|
6
|
qq{"$node->[1]"}; |
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
################################################################ |
218
|
|
|
|
|
|
|
# regexp |
219
|
|
|
|
|
|
|
sub _main_regexp { |
220
|
1
|
|
|
1
|
|
2
|
my($self, $node) = @_; |
221
|
|
|
|
|
|
|
|
222
|
1
|
|
|
|
|
6
|
$node->[1]; |
223
|
|
|
|
|
|
|
} |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
1; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
|