line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
########################################### |
2
|
|
|
|
|
|
|
# File::Comments::Plugin::HTML |
3
|
|
|
|
|
|
|
# 2005, Mike Schilli |
4
|
|
|
|
|
|
|
########################################### |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
########################################### |
7
|
|
|
|
|
|
|
package File::Comments::Plugin::HTML; |
8
|
|
|
|
|
|
|
########################################### |
9
|
|
|
|
|
|
|
|
10
|
9
|
|
|
9
|
|
19245
|
use strict; |
|
9
|
|
|
|
|
95
|
|
|
9
|
|
|
|
|
328
|
|
11
|
9
|
|
|
9
|
|
52
|
use warnings; |
|
9
|
|
|
|
|
23
|
|
|
9
|
|
|
|
|
305
|
|
12
|
9
|
|
|
9
|
|
2573
|
use File::Comments::Plugin; |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
293
|
|
13
|
9
|
|
|
9
|
|
52
|
use Log::Log4perl qw(:easy); |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
64
|
|
14
|
9
|
|
|
9
|
|
15876
|
use HTML::TokeParser; |
|
9
|
|
|
|
|
124411
|
|
|
9
|
|
|
|
|
4382
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
17
|
|
|
|
|
|
|
our @ISA = qw(File::Comments::Plugin); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
########################################### |
20
|
|
|
|
|
|
|
sub init { |
21
|
|
|
|
|
|
|
########################################### |
22
|
11
|
|
|
11
|
0
|
29
|
my($self) = @_; |
23
|
|
|
|
|
|
|
|
24
|
11
|
|
|
|
|
69
|
$self->register_suffix(".htm"); |
25
|
11
|
|
|
|
|
49
|
$self->register_suffix(".html"); |
26
|
11
|
|
|
|
|
42
|
$self->register_suffix(".HTML"); |
27
|
11
|
|
|
|
|
40
|
$self->register_suffix(".HTM"); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
########################################### |
31
|
|
|
|
|
|
|
sub type { |
32
|
|
|
|
|
|
|
########################################### |
33
|
0
|
|
|
0
|
0
|
0
|
my($self, $target) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
0
|
return "html"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
########################################### |
39
|
|
|
|
|
|
|
sub comments { |
40
|
|
|
|
|
|
|
########################################### |
41
|
1
|
|
|
1
|
0
|
2
|
my($self, $target) = @_; |
42
|
|
|
|
|
|
|
|
43
|
1
|
|
|
|
|
11
|
return $self->extract_html_comments($target); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
########################################### |
47
|
|
|
|
|
|
|
sub stripped { |
48
|
|
|
|
|
|
|
########################################### |
49
|
1
|
|
|
1
|
0
|
3
|
my($self, $target) = @_; |
50
|
|
|
|
|
|
|
|
51
|
1
|
|
|
|
|
5
|
return $self->strip_html_comments($target); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
########################################### |
55
|
|
|
|
|
|
|
sub extract_html_comments { |
56
|
|
|
|
|
|
|
########################################### |
57
|
1
|
|
|
1
|
0
|
2
|
my($self, $target) = @_; |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
|
|
2
|
my @comments = (); |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
10
|
my $stream = HTML::TokeParser->new( |
62
|
|
|
|
|
|
|
\$target->{content}); |
63
|
|
|
|
|
|
|
|
64
|
1
|
|
|
|
|
202
|
while(my $token = $stream->get_token()) { |
65
|
13
|
100
|
|
|
|
218
|
next unless $token->[0] eq "C"; |
66
|
|
|
|
|
|
|
|
67
|
3
|
|
|
|
|
12
|
$token->[1] =~ s/^$//; |
69
|
|
|
|
|
|
|
|
70
|
3
|
|
|
|
|
12
|
push @comments, $token->[1]; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
1
|
|
|
|
|
24
|
return \@comments; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
########################################### |
77
|
|
|
|
|
|
|
sub strip_html_comments { |
78
|
|
|
|
|
|
|
########################################### |
79
|
1
|
|
|
1
|
0
|
2
|
my($self, $target) = @_; |
80
|
|
|
|
|
|
|
|
81
|
1
|
|
|
|
|
1394
|
require HTML::TreeBuilder; |
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
|
|
26142
|
my $root = HTML::TreeBuilder->new(); |
84
|
1
|
|
|
|
|
317
|
$root->parse($target->{content}); |
85
|
1
|
50
|
|
|
|
729
|
if(!$root) { |
86
|
0
|
|
|
|
|
0
|
WARN "Cannot parse $target->{path}"; |
87
|
0
|
|
|
|
|
0
|
return $target->{content}; |
88
|
|
|
|
|
|
|
} |
89
|
1
|
|
|
|
|
9
|
my $stripped_html = $root->as_HTML(); |
90
|
|
|
|
|
|
|
# HTML::Element < 4 appends a newline to the HTML |
91
|
|
|
|
|
|
|
# for no apparent reason (CPAN RT#41739) |
92
|
1
|
|
|
|
|
655
|
$stripped_html =~ s/\n$//; |
93
|
1
|
|
|
|
|
36
|
return $stripped_html; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
1; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
__END__ |