line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Template::Extension::HEAD_BODY; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = "0.26"; |
4
|
0
|
|
|
0
|
0
|
0
|
sub Version { $VERSION; } |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
84
|
|
7
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
886
|
use HTML::TokeParser; |
|
1
|
|
|
|
|
14365
|
|
|
1
|
|
|
|
|
1143
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my %fields_parent = |
12
|
|
|
|
|
|
|
( |
13
|
|
|
|
|
|
|
autoDeleteHeader => 0, |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub init { |
17
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
18
|
1
|
|
|
|
|
9
|
while (my ($key,$val) = each(%fields_parent)) { |
19
|
1
|
|
33
|
|
|
15
|
$self->{$key} = $self->{$key} || $val; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub push_filter { |
24
|
3
|
|
|
3
|
0
|
6
|
my $self = shift; |
25
|
3
|
|
|
|
|
6
|
push @{$self->{filter_internal}},@{_get_filter($self)}; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
8
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _get_filter { |
29
|
3
|
|
|
3
|
|
8
|
my $self = shift; |
30
|
3
|
|
|
|
|
3
|
my @ret ; |
31
|
3
|
100
|
|
|
|
11
|
if ($self->{autoDeleteHeader}) { |
32
|
|
|
|
|
|
|
push @ret, sub { |
33
|
2
|
|
|
2
|
|
30
|
my $tmpl = shift; |
34
|
2
|
|
|
|
|
3
|
my $header; |
35
|
2
|
50
|
|
|
|
21
|
if ($$tmpl =~s{(^.+?'"]*|".*?"|'.*?')+>)}{}msi) { |
36
|
2
|
|
|
|
|
6
|
$self->{header} = $1; |
37
|
2
|
|
|
|
|
7
|
&tokenizer_header($self); |
38
|
|
|
|
|
|
|
} else { |
39
|
|
|
|
|
|
|
# header doesn't exist |
40
|
0
|
|
|
|
|
0
|
undef $self->{header}; |
41
|
0
|
|
|
|
|
0
|
undef $self->{tokens}; |
42
|
|
|
|
|
|
|
} |
43
|
2
|
|
|
|
|
95
|
$$tmpl =~ s{.+}{}msi; |
44
|
1
|
|
|
|
|
11
|
}; |
45
|
|
|
|
|
|
|
} |
46
|
3
|
|
|
|
|
10
|
return \@ret; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub autoDeleteHeader { |
50
|
5
|
|
|
5
|
0
|
9
|
my $s=shift; |
51
|
5
|
50
|
|
|
|
14
|
if (@_) { |
52
|
5
|
|
|
|
|
64
|
my $newvalue = shift; |
53
|
5
|
100
|
|
|
|
25
|
return if ($newvalue == $s->{autoDeleteHeader}); |
54
|
2
|
|
|
|
|
8
|
$s->{autoDeleteHeader}=$newvalue; |
55
|
|
|
|
|
|
|
# reload local filter |
56
|
2
|
|
|
|
|
11
|
$s->_reloadFilter(); |
57
|
2
|
|
|
|
|
5
|
$s->{_auto_parse} = 1; |
58
|
|
|
|
|
|
|
}; |
59
|
2
|
|
|
|
|
4
|
my $ret = $s->{autoDeleteHeader}; |
60
|
|
|
|
|
|
|
return |
61
|
2
|
|
|
|
|
7
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub tokenizer_header { |
64
|
|
|
|
|
|
|
# prende l'header contenuto in $self->{header} e ne estrae i |
65
|
|
|
|
|
|
|
# token fondamentali inserendoli in $self->{tokens} |
66
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
67
|
2
|
|
|
|
|
4
|
my $header = $self->{header}; |
68
|
2
|
|
|
|
|
10
|
$header =~m|(.*?)|smi; |
69
|
2
|
|
|
|
|
5
|
$header = $1; |
70
|
2
|
|
|
|
|
11
|
my $p = HTML::TokeParser->new(\$header); |
71
|
2
|
|
|
|
|
319
|
$self->{tokens} = {}; |
72
|
2
|
|
|
|
|
10
|
while (my $token = $p->get_tag()) { |
73
|
6
|
|
|
|
|
186
|
my $tag = $token->[0]; |
74
|
6
|
100
|
|
|
|
16
|
my $type = substr($tag,0,1) eq '/' ? 'E' : 'S'; |
75
|
6
|
|
|
|
|
6
|
my $tag_text; |
76
|
6
|
100
|
|
|
|
16
|
if ($type eq 'S') { |
|
|
50
|
|
|
|
|
|
77
|
4
|
|
|
|
|
7
|
$tag_text = $token->[3]; |
78
|
4
|
|
|
|
|
13
|
my $text = $p->get_text(); |
79
|
4
|
|
|
|
|
173
|
my $struct = [$tag_text,$text,undef]; |
80
|
4
|
|
|
|
|
6
|
push @{$self->{tokens}->{$tag}},$struct; |
|
4
|
|
|
|
|
26
|
|
81
|
|
|
|
|
|
|
} elsif ($type eq 'E') { |
82
|
2
|
|
|
|
|
6
|
$tag = substr($tag,1,length($tag)-1); |
83
|
2
|
|
|
|
|
4
|
$tag_text = $token->[1]; |
84
|
2
|
|
|
|
|
3
|
my $last_idx = scalar @{$self->{tokens}->{$tag}}-1; |
|
2
|
|
|
|
|
5
|
|
85
|
2
|
|
|
|
|
9
|
$self->{tokens}->{$tag}->[$last_idx]->[2] = $tag_text; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
2
|
50
|
|
2
|
0
|
3
|
sub header {my $s = shift;return exists($s->{header}) ? $s->{header} : ''}; |
|
2
|
|
|
|
|
10
|
|
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
0
|
0
|
sub js_header { return &header_js(shift); } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub header_js { |
96
|
|
|
|
|
|
|
# ritorna il codice javascript presente nell'header |
97
|
1
|
|
|
1
|
0
|
2
|
my $self = shift; |
98
|
1
|
|
|
|
|
2
|
my $ret; |
99
|
1
|
|
|
|
|
4
|
my $js_token = $self->{tokens}->{script}; |
100
|
1
|
|
|
|
|
1
|
foreach (@{$js_token}) { |
|
1
|
|
|
|
|
3
|
|
101
|
1
|
|
|
|
|
6
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
102
|
|
|
|
|
|
|
} |
103
|
1
|
|
|
|
|
5
|
return $ret; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub header_css { |
107
|
|
|
|
|
|
|
# ritorna i css presenti nell'header |
108
|
|
|
|
|
|
|
# compresi i link a css esterni |
109
|
1
|
|
|
1
|
0
|
4
|
my $self = shift; |
110
|
1
|
|
|
|
|
2
|
my $ret; |
111
|
1
|
|
|
|
|
3
|
my $style_token = $self->{tokens}->{style}; |
112
|
1
|
|
|
|
|
3
|
foreach (@{$style_token}) { |
|
1
|
|
|
|
|
3
|
|
113
|
1
|
|
|
|
|
6
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
114
|
|
|
|
|
|
|
} |
115
|
1
|
|
|
|
|
7
|
my $link_token = $self->{tokens}->{link}; |
116
|
1
|
|
|
|
|
2
|
foreach (@{$link_token}) { |
|
1
|
|
|
|
|
3
|
|
117
|
0
|
0
|
0
|
|
|
0
|
if ($_->[0] =~ /[Rr][Ee][Ll]\s*=\s*"?[Ss][Tt][Yy][Ll][Ee][Ss][Hh][Ee][Ee][Tt]"?/ && |
118
|
|
|
|
|
|
|
$_->[0] =~ /[Tt][Yy][Pp][Ee]\s*=\s*"?[Tt][Te][Xx][Tt]\/[Cc][Ss][Ss]"?/) |
119
|
|
|
|
|
|
|
{ |
120
|
0
|
|
|
|
|
0
|
$ret .= $_->[0] . $_->[1] . $_->[2]; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
} |
123
|
1
|
|
|
|
|
5
|
return $ret; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub body_attributes { |
127
|
|
|
|
|
|
|
# ritorna gli attributi interni al campo body |
128
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
129
|
0
|
|
|
|
|
0
|
my $h = $self->{header}; |
130
|
0
|
|
|
|
|
0
|
my $re_init = q|<\s*body(.*?)>|; |
131
|
0
|
|
|
|
|
0
|
$h=~/$re_init/msxi; |
132
|
0
|
|
|
|
|
0
|
return $1; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub header_tokens { |
136
|
|
|
|
|
|
|
# ritorna un riferimento ad un hash che contiene |
137
|
|
|
|
|
|
|
# come chiavi tutti i tag presenti nell'header ... |
138
|
|
|
|
|
|
|
# ogni elemento dell'hash e' un riferimento ad un array. |
139
|
|
|
|
|
|
|
# Ogni array e' a sua volta un riferimento ad array di tre elementi |
140
|
|
|
|
|
|
|
# tag_init - testo contenuto tra il tag e l'eventuale fine tag o successivo tag - eventuale fine tag o undef |
141
|
1
|
|
|
1
|
0
|
3
|
my $self = shift; |
142
|
1
|
|
|
|
|
5
|
return $self->{tokens}; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |