| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::Template::Pro::Extension; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
10072
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
59
|
|
|
4
|
1
|
|
|
1
|
|
1065
|
use integer; # no floating point math so far! |
|
|
1
|
|
|
|
|
12
|
|
|
|
1
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
29
|
use Carp; |
|
|
1
|
|
|
|
|
7
|
|
|
|
1
|
|
|
|
|
83
|
|
|
7
|
1
|
|
|
1
|
|
1034
|
use HTML::Template::Pro; |
|
|
1
|
|
|
|
|
6397
|
|
|
|
1
|
|
|
|
|
82
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
12
|
use base "HTML::Template::Pro"; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
1345
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$HTML::Template::Pro::Extension::VERSION = "0.11"; |
|
12
|
0
|
|
|
0
|
1
|
0
|
sub Version { $HTML::Template::Pro::Extension::VERSION; } |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my $fields = { |
|
15
|
|
|
|
|
|
|
tmplfile => '', |
|
16
|
|
|
|
|
|
|
source => undef, |
|
17
|
|
|
|
|
|
|
source_orig => undef, |
|
18
|
|
|
|
|
|
|
plugins => [] , |
|
19
|
|
|
|
|
|
|
__plugins => {}, |
|
20
|
|
|
|
|
|
|
__reloadSource => 0, |
|
21
|
|
|
|
|
|
|
__reloadFile => 0, |
|
22
|
|
|
|
|
|
|
}; |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub new { |
|
25
|
2
|
|
|
2
|
1
|
122
|
my $proto = shift; |
|
26
|
2
|
|
33
|
|
|
13
|
my $class = ref($proto) || $proto; |
|
27
|
|
|
|
|
|
|
# valid HTML::Template::Pro parameter |
|
28
|
2
|
|
|
|
|
24
|
my $htpoptions={ |
|
29
|
|
|
|
|
|
|
functions => {}, |
|
30
|
|
|
|
|
|
|
debug => 0, |
|
31
|
|
|
|
|
|
|
max_includes => 10, |
|
32
|
|
|
|
|
|
|
global_vars => 0, |
|
33
|
|
|
|
|
|
|
no_includes => 0, |
|
34
|
|
|
|
|
|
|
search_path_on_include => 0, |
|
35
|
|
|
|
|
|
|
loop_context_vars => 1, |
|
36
|
|
|
|
|
|
|
path => [], |
|
37
|
|
|
|
|
|
|
associate => [], |
|
38
|
|
|
|
|
|
|
case_sensitive => 0, |
|
39
|
|
|
|
|
|
|
strict => 1, |
|
40
|
|
|
|
|
|
|
die_on_bad_params => 0, |
|
41
|
|
|
|
|
|
|
scalarref => '', |
|
42
|
|
|
|
|
|
|
option => 'value' |
|
43
|
|
|
|
|
|
|
}; |
|
44
|
|
|
|
|
|
|
# set the htp options with new parameters |
|
45
|
2
|
|
|
|
|
7
|
my %opt = @_; |
|
46
|
2
|
|
|
|
|
11
|
foreach (keys %$htpoptions) { |
|
47
|
28
|
50
|
|
|
|
52
|
$htpoptions->{$_} = $opt{$_} if (exists $opt{$_}); |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
# carico il modulo HTML::Template::Pro |
|
50
|
2
|
|
|
|
|
9
|
my $self = {%$fields,%{new HTML::Template::Pro(%$htpoptions)}}; |
|
|
2
|
|
|
|
|
16
|
|
|
51
|
2
|
|
|
|
|
148
|
bless $self,$class; |
|
52
|
2
|
|
|
|
|
8
|
$self->_init(@_); |
|
53
|
2
|
|
|
|
|
12
|
return $self; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub _init { |
|
57
|
2
|
|
|
2
|
|
4
|
my $self = shift; |
|
58
|
2
|
|
|
|
|
5
|
my %opts = @_; |
|
59
|
2
|
50
|
|
|
|
10
|
$self->tmplfile($opts{tmplfile}) if ($opts{tmplfile}); |
|
60
|
2
|
|
|
|
|
3
|
foreach (@{$opts{plugins}}) { |
|
|
2
|
|
|
|
|
7
|
|
|
61
|
1
|
|
|
|
|
5
|
$self->plugin_add($_); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
0
|
|
0
|
sub DESTROY {} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub tmplfile { |
|
68
|
17
|
|
|
17
|
1
|
23
|
my $self = shift; |
|
69
|
17
|
50
|
|
|
|
39
|
if (my $tmplfile = shift) { |
|
70
|
17
|
|
|
|
|
27
|
$self->{__reloadFile} = 1; |
|
71
|
17
|
50
|
33
|
|
|
38
|
unless (ref($tmplfile) && $self->{tmplfile}) { |
|
72
|
|
|
|
|
|
|
# sia $tmplfile che $self->{tmplfile} sono stringhe |
|
73
|
17
|
100
|
|
|
|
40
|
if ($tmplfile eq $self->{tmplfile}) { |
|
74
|
|
|
|
|
|
|
# il tmplfile e' lo stesso, niente reload |
|
75
|
6
|
|
|
|
|
7
|
$self->{__reloadFile} = 0; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
} |
|
78
|
17
|
|
|
|
|
22
|
$self->{tmplfile} = $tmplfile; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
17
|
|
|
|
|
25
|
return $self->{tmplfile}; |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub output { |
|
84
|
|
|
|
|
|
|
# redefine standard output function |
|
85
|
18
|
|
|
18
|
1
|
918
|
my $self = shift; |
|
86
|
18
|
|
|
|
|
36
|
my %args = @_; |
|
87
|
18
|
100
|
|
|
|
55
|
$self->_reloadFile if ($self->{__reloadFile}); |
|
88
|
18
|
100
|
|
|
|
56
|
$self = $self->_reloadSource if ($self->{__reloadSource}); |
|
89
|
18
|
100
|
|
|
|
38
|
if (exists $args{as}) { |
|
90
|
|
|
|
|
|
|
# delete old params settings |
|
91
|
|
|
|
|
|
|
# I don't know if this is a bug or a change in H::T::Pro interface |
|
92
|
|
|
|
|
|
|
# however |
|
93
|
15
|
50
|
|
|
|
60
|
if ($self->can('clear_params')) { |
|
94
|
15
|
|
|
|
|
39
|
$self->clear_params(); |
|
95
|
|
|
|
|
|
|
} else { |
|
96
|
0
|
|
|
|
|
0
|
$self->clear_param(); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
15
|
|
|
|
|
74
|
$self->param(%{$args{as}}); |
|
|
15
|
|
|
|
|
53
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
18
|
|
|
|
|
232
|
return $self->SUPER::output(print_to => $args{print_to}); |
|
101
|
|
|
|
|
|
|
} |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub html { |
|
104
|
14
|
|
|
14
|
1
|
703
|
my $self = shift; |
|
105
|
14
|
50
|
|
|
|
26
|
my %args = (defined $_[0]) ? %{$_[0]} : (); |
|
|
14
|
|
|
|
|
43
|
|
|
106
|
14
|
50
|
|
|
|
49
|
$self->tmplfile($_[1]) if (defined $_[1]); |
|
107
|
14
|
|
|
|
|
31
|
return $self->output('as' => \%args); |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub _reloadFile { |
|
111
|
11
|
|
|
11
|
|
12
|
my $self = shift; |
|
112
|
11
|
|
|
|
|
21
|
$self->_loadFile; |
|
113
|
11
|
|
|
|
|
14
|
$self->{__reloadSource} = 1; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub _loadFile { |
|
117
|
11
|
|
|
11
|
|
12
|
my $self = shift; |
|
118
|
11
|
50
|
|
|
|
24
|
if (ref($self->{tmplfile}) eq '') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
119
|
11
|
|
|
|
|
40
|
my $filepath = $self->_find_file($self->{tmplfile}); |
|
120
|
11
|
50
|
|
|
|
390
|
confess("HTML::Template->new() : Cannot open included file $self->{tmplfile} : file not found.") unless defined($filepath); |
|
121
|
|
|
|
|
|
|
# we'll need this for future reference - to call stat() for example. |
|
122
|
|
|
|
|
|
|
# read into scalar |
|
123
|
11
|
50
|
|
|
|
336
|
confess("HTML::Template::Pro::Extension : Cannot open included file $self->{tmplfile} : $!") |
|
124
|
|
|
|
|
|
|
unless defined(open(TEMPLATE, $filepath)); |
|
125
|
11
|
|
|
|
|
37
|
$self->{source_orig} = ""; |
|
126
|
11
|
|
|
|
|
220
|
while (read(TEMPLATE, $self->{source_orig}, 10240, length($self->{source_orig}))) {} |
|
127
|
11
|
|
|
|
|
94
|
close(TEMPLATE); |
|
128
|
|
|
|
|
|
|
} elsif (ref($self->{tmplfile}) eq 'SCALAR') { |
|
129
|
|
|
|
|
|
|
# copy in the template text |
|
130
|
0
|
|
|
|
|
0
|
$self->{source_orig} = ${$self->{tmplfile}}; |
|
|
0
|
|
|
|
|
0
|
|
|
131
|
0
|
|
|
|
|
0
|
delete($self->{tmplfile}); |
|
132
|
|
|
|
|
|
|
} elsif (ref($self->{tmplfile}) eq 'ARRAY') { |
|
133
|
|
|
|
|
|
|
# if we have an array ref, join and store the template text |
|
134
|
0
|
|
|
|
|
0
|
$self->{source_orig} = join("", @{$self->{tmplfile}}); |
|
|
0
|
|
|
|
|
0
|
|
|
135
|
0
|
|
|
|
|
0
|
delete($self->{tmplfile}); |
|
136
|
|
|
|
|
|
|
} elsif (ref($self->{tmplfile}) eq 'GLOB') { |
|
137
|
|
|
|
|
|
|
# just read everything in in one go |
|
138
|
0
|
|
|
|
|
0
|
local $/ = undef; |
|
139
|
0
|
|
|
|
|
0
|
$self->{source_orig} = readline($self->{tmplfile}); |
|
140
|
0
|
|
|
|
|
0
|
delete($self->{tmplfile}); |
|
141
|
|
|
|
|
|
|
} else { |
|
142
|
0
|
|
|
|
|
0
|
confess("HTML::Template::Pro::Extension : Need to set file with a filename, filehandle, scalarref or arrayref parameter specified."); |
|
143
|
|
|
|
|
|
|
} |
|
144
|
11
|
|
|
|
|
23
|
$self->{__reloadFile} = 0; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub _reloadSource { |
|
148
|
14
|
|
|
14
|
|
15
|
my $self = shift; |
|
149
|
14
|
|
|
|
|
23
|
my $src_orig = $self->{source_orig}; |
|
150
|
14
|
|
|
|
|
15
|
foreach my $plugin (values %{$self->{__plugins}}) { |
|
|
14
|
|
|
|
|
34
|
|
|
151
|
29
|
|
|
|
|
30
|
foreach my $filter (@{$plugin->{filter}}) { |
|
|
29
|
|
|
|
|
48
|
|
|
152
|
38
|
50
|
|
|
|
77
|
croak("HTML::Template::Pro::Extension : bad value set for filter parameter - must be a code ref or a hash ref.") unless ref $filter; |
|
153
|
38
|
|
|
|
|
102
|
&$filter(\$src_orig,$self); |
|
154
|
|
|
|
|
|
|
} |
|
155
|
|
|
|
|
|
|
} |
|
156
|
14
|
|
|
|
|
27
|
$self->{source} = $src_orig; |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
# ricarico il modulo HTML::Template::Pro |
|
159
|
14
|
|
|
|
|
23
|
$self->{scalarref} = $src_orig; |
|
160
|
14
|
|
|
|
|
22
|
$self->{options}->{scalarref} = $src_orig; |
|
161
|
14
|
|
|
|
|
33
|
$self->{__reloadSource} = 0; |
|
162
|
14
|
|
|
|
|
30
|
return $self; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub plugin_add { |
|
166
|
10
|
|
|
10
|
0
|
644
|
my $s = shift; |
|
167
|
10
|
|
|
|
|
23
|
my ($module, $module_name) = $s->_module_info(shift); |
|
168
|
|
|
|
|
|
|
# plugin gia caricato |
|
169
|
10
|
50
|
|
|
|
25
|
return if (exists $s->{__plugins}->{$module_name}); |
|
170
|
10
|
|
|
|
|
38
|
$s->{__plugins}->{$module_name}->{obj} = $module; |
|
171
|
|
|
|
|
|
|
# init module |
|
172
|
10
|
|
|
|
|
23
|
$s->_initModule($module); |
|
173
|
|
|
|
|
|
|
# add filter from added module to me |
|
174
|
10
|
|
|
|
|
25
|
$s->_pushModule($module); |
|
175
|
10
|
|
|
|
|
28
|
$s->{__reloadSource} = 1; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub _initModule { |
|
179
|
10
|
|
|
10
|
|
10
|
my $self = shift; |
|
180
|
10
|
|
|
|
|
12
|
my $module = shift; |
|
181
|
10
|
100
|
|
|
|
20
|
if (ref($module) eq '') { |
|
182
|
9
|
|
|
|
|
17
|
$self->_importModule($module); |
|
183
|
1
|
|
|
1
|
|
8
|
no strict "refs"; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
244
|
|
|
184
|
9
|
|
|
|
|
19
|
&{$module . "::init"}($self); |
|
|
9
|
|
|
|
|
56
|
|
|
185
|
|
|
|
|
|
|
} else { |
|
186
|
1
|
|
|
|
|
5
|
$module->init($self); |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub _importModule { |
|
191
|
9
|
|
|
9
|
|
12
|
my $self = shift; |
|
192
|
9
|
|
|
|
|
11
|
my $module_name = shift; |
|
193
|
|
|
|
|
|
|
|
|
194
|
9
|
|
|
|
|
37
|
$module_name =~s/::/\//g; |
|
195
|
9
|
|
|
|
|
4971
|
require $module_name . ".pm"; |
|
196
|
|
|
|
|
|
|
} |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
sub _pushModule { |
|
200
|
10
|
|
|
10
|
|
16
|
my $self = shift; |
|
201
|
10
|
|
|
|
|
22
|
my ($module, $module_name) = $self->_module_info(shift); |
|
202
|
10
|
|
|
|
|
11
|
my @codes; |
|
203
|
10
|
100
|
|
|
|
23
|
if (ref($module) eq '') { |
|
204
|
1
|
|
|
1
|
|
7
|
no strict "refs"; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
347
|
|
|
205
|
9
|
|
|
|
|
10
|
@codes = &{$module . "::get_filter"}($self); |
|
|
9
|
|
|
|
|
39
|
|
|
206
|
|
|
|
|
|
|
} else { |
|
207
|
1
|
|
|
|
|
7
|
@codes = $module->get_filter($self); |
|
208
|
|
|
|
|
|
|
} |
|
209
|
10
|
|
|
|
|
37
|
$self->{__plugins}->{$module_name}->{filter} = \@codes; |
|
210
|
|
|
|
|
|
|
} |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
sub plugin_remove { |
|
213
|
1
|
|
|
1
|
0
|
188
|
my $s = shift; |
|
214
|
1
|
|
|
|
|
2
|
my ($module, $module_name) = $s->_module_info(shift); |
|
215
|
|
|
|
|
|
|
#delete $s->{plugins}->{$module_name}; |
|
216
|
1
|
|
|
|
|
3
|
delete $s->{__plugins}->{$module_name}; |
|
217
|
1
|
|
|
|
|
4
|
$s->{__reloadSource} = 1; |
|
218
|
|
|
|
|
|
|
} |
|
219
|
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
sub plugins_clear { |
|
221
|
3
|
|
|
3
|
0
|
547
|
my $s = shift; |
|
222
|
3
|
|
|
|
|
7
|
$s->{plugins} = []; |
|
223
|
3
|
|
|
|
|
5
|
$s->{__plugins} = {}; |
|
224
|
3
|
|
|
|
|
11
|
$s->{__reloadSource} = 1; |
|
225
|
|
|
|
|
|
|
} |
|
226
|
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub _module_info { |
|
228
|
21
|
|
|
21
|
|
26
|
my $self = shift; |
|
229
|
21
|
|
|
|
|
24
|
my $module = shift; |
|
230
|
21
|
|
|
|
|
19
|
my $module_name; |
|
231
|
21
|
100
|
|
|
|
38
|
if (ref($module)) { |
|
232
|
2
|
|
|
|
|
2
|
$module_name = ref($module); |
|
233
|
|
|
|
|
|
|
} else { |
|
234
|
19
|
100
|
|
|
|
67
|
$module = "HTML::Template::Pro::Extension::$module" |
|
235
|
|
|
|
|
|
|
if ($module!~/::/); |
|
236
|
19
|
|
|
|
|
25
|
$module_name = $module; |
|
237
|
|
|
|
|
|
|
} |
|
238
|
21
|
|
|
|
|
43
|
return ($module,$module_name); |
|
239
|
|
|
|
|
|
|
} |
|
240
|
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
sub AUTOLOAD { |
|
242
|
9
|
|
|
9
|
|
868
|
my $self = shift; |
|
243
|
9
|
|
|
|
|
32
|
my @procs = split(/::/,$HTML::Template::Pro::Extension::AUTOLOAD); |
|
244
|
|
|
|
|
|
|
#confess("Unable to find $HTML::Template::Pro::Extension::AUTOLOAD") if (scalar(@procs)<4); |
|
245
|
9
|
|
|
|
|
13
|
my $proc = $procs[-1]; |
|
246
|
9
|
|
|
|
|
8
|
my $value; |
|
247
|
1
|
|
|
1
|
|
6
|
no strict "refs"; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
147
|
|
|
248
|
9
|
|
|
|
|
8
|
foreach my $module (keys %{$self->{__plugins}}) { |
|
|
9
|
|
|
|
|
23
|
|
|
249
|
27
|
|
|
|
|
23
|
my $ret; |
|
250
|
27
|
|
|
|
|
25
|
$ret= eval { return &{"${module}::$proc"}($self,@_) }; |
|
|
27
|
|
|
|
|
28
|
|
|
|
27
|
|
|
|
|
212
|
|
|
251
|
27
|
100
|
|
|
|
64
|
if (!$@) { return $ret }; |
|
|
9
|
|
|
|
|
44
|
|
|
252
|
|
|
|
|
|
|
}; |
|
253
|
0
|
|
|
|
|
|
confess("Unable to find $HTML::Template::Pro::Extension::AUTOLOAD"); |
|
254
|
|
|
|
|
|
|
} |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
1; |
|
257
|
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# vim: set ts=2: |