line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package FileMetadata::Miner::HTML; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require HTML::Parser; |
4
|
|
|
|
|
|
|
@ISA = qw(HTML::Parser); |
5
|
1
|
|
|
1
|
|
1518
|
use HTML::Entities (); |
|
1
|
|
|
|
|
15207
|
|
|
1
|
|
|
|
|
155
|
|
6
|
1
|
|
|
1
|
|
14
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
7
|
1
|
|
|
1
|
|
1737
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
7
|
|
8
|
|
|
|
|
|
|
our $VERSION = '1.0'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
1
|
16
|
my $class = shift; |
13
|
1
|
|
|
|
|
15
|
my $self = $class->SUPER::new(); # Inheriting |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# Set handlers |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
103
|
$self->handler (text => 'text', "self, text"); |
18
|
1
|
|
|
|
|
7
|
$self->handler (start => 'start', 'self, tagname, attr'); |
19
|
1
|
|
|
|
|
6
|
$self->handler (end => 'end', 'self, tagname'); |
20
|
|
|
|
|
|
|
|
21
|
1
|
|
|
|
|
3
|
return $self; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub mine { |
26
|
|
|
|
|
|
|
|
27
|
2
|
|
|
2
|
1
|
11
|
my ($self, $path, $meta) = @_; |
28
|
2
|
|
|
|
|
10
|
$self->{data} = $meta; |
29
|
2
|
100
|
|
|
|
12
|
return 0 unless defined $self->parse_file ($path); |
30
|
1
|
|
|
|
|
27
|
return 1; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# |
35
|
|
|
|
|
|
|
# This method handles text by appending it to the title key of |
36
|
|
|
|
|
|
|
# $self->{'data'} when the tag is title. We are not interested in |
37
|
|
|
|
|
|
|
# any other text |
38
|
|
|
|
|
|
|
# |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub text { |
41
|
|
|
|
|
|
|
|
42
|
6
|
|
|
6
|
1
|
11
|
my ($self, $text) = @_; |
43
|
6
|
100
|
|
|
|
47
|
$self->{'data'}->{ref ($self)."::".'title'} .= $text |
44
|
|
|
|
|
|
|
if defined $self->{'tag-title'}; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# This method handles start tags. It ignores all but meta and title tags |
50
|
|
|
|
|
|
|
# |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub start { |
53
|
|
|
|
|
|
|
|
54
|
5
|
|
|
5
|
1
|
149
|
my($self, $tag, $attr) = @_; |
55
|
|
|
|
|
|
|
|
56
|
5
|
100
|
66
|
|
|
41
|
if ($tag eq 'meta' && defined $attr->{'name'}) { |
|
|
100
|
|
|
|
|
|
57
|
2
|
|
|
|
|
13
|
$self->{'data'}->{ref ($self)."::".$attr->{'name'}} = $attr->{'content'}; |
58
|
|
|
|
|
|
|
} elsif ($tag eq 'title') { |
59
|
|
|
|
|
|
|
# Flag this |
60
|
1
|
|
|
|
|
7
|
$self->{'tag-title'} = ''; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub end { |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
2
|
1
|
4
|
my($self, $tag) = @_; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Stop processing |
70
|
2
|
100
|
|
|
|
19
|
$self->eof() if ($tag eq 'head'); |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Unflag |
73
|
2
|
|
|
|
|
9
|
delete $self->{'tag-title'}; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
1; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
__END__ |