| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package HTML::RelExtor; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1807
|
use strict; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
118
|
|
|
4
|
3
|
|
|
3
|
|
15
|
use vars qw($VERSION); |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
159
|
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.03'; |
|
6
|
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
2960
|
use HTML::Parser; |
|
|
3
|
|
|
|
|
18596
|
|
|
|
3
|
|
|
|
|
128
|
|
|
8
|
3
|
|
|
3
|
|
4349
|
use URI; |
|
|
3
|
|
|
|
|
18830
|
|
|
|
3
|
|
|
|
|
106
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
32
|
use base qw(HTML::Parser); |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
1170
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
0
|
|
|
0
|
1
|
|
my($class, %args) = @_; |
|
14
|
0
|
|
|
|
|
|
my $self = $class->SUPER::new( |
|
15
|
|
|
|
|
|
|
start_h => [ "_start_tag", "self,tagname,attr" ], |
|
16
|
|
|
|
|
|
|
report_tags => [ qw(a link base) ], |
|
17
|
|
|
|
|
|
|
); |
|
18
|
0
|
0
|
|
|
|
|
if (my $base = delete $args{base}) { |
|
19
|
0
|
|
|
|
|
|
$self->{relextor_base} = $base; |
|
20
|
|
|
|
|
|
|
} |
|
21
|
0
|
|
|
|
|
|
$self; |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _start_tag { |
|
25
|
0
|
|
|
0
|
|
|
my($self, $tag, $attr) = @_; |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# If there's , change the base URL |
|
28
|
0
|
0
|
0
|
|
|
|
if ($tag eq 'base' && exists $attr->{href}) { |
|
29
|
0
|
|
|
|
|
|
$self->{relextor_base} = $attr->{href}; |
|
30
|
0
|
|
|
|
|
|
return; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# no 'rel' nor 'rev' attribute |
|
34
|
0
|
0
|
0
|
|
|
|
return unless exists $attr->{rel} or exists $attr->{rev}; |
|
35
|
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
my $href = $attr->{href} or return; |
|
37
|
0
|
0
|
|
|
|
|
$href = URI->new_abs($href, $self->{relextor_base})->as_string |
|
38
|
|
|
|
|
|
|
if $self->{relextor_base}; |
|
39
|
0
|
|
|
|
|
|
my $link = HTML::RelExtor::Link->new($tag, $href, $attr); |
|
40
|
0
|
0
|
|
|
|
|
if ($tag eq 'a') { |
|
41
|
|
|
|
|
|
|
$self->handler(text => sub { |
|
42
|
0
|
|
|
0
|
|
|
my($self, $text) = @_; |
|
43
|
0
|
|
|
|
|
|
$link->{text} = $text; |
|
44
|
0
|
|
|
|
|
|
$self->handler(text => undef); |
|
45
|
0
|
|
|
|
|
|
}, "self,dtext"); |
|
46
|
|
|
|
|
|
|
} |
|
47
|
0
|
|
|
|
|
|
push @{$self->{links}}, $link; |
|
|
0
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub links { |
|
51
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
52
|
0
|
|
|
|
|
|
my %args = @_; |
|
53
|
0
|
0
|
|
|
|
|
my @links = $self->{links} ? @{$self->{links}} : (); |
|
|
0
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
0
|
|
|
|
if ($args{rel} && $args{rev}) { |
|
56
|
0
|
|
|
|
|
|
Carp::croak("You can't pass both rev and rel to the links()"); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if ($args{rel}) { |
|
|
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
@links = grep $_->has_rel($args{rel}), @links; |
|
61
|
|
|
|
|
|
|
} elsif ($args{rev}) { |
|
62
|
0
|
|
|
|
|
|
@links = grep $_->has_rev($args{rev}), @links; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return @links; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub parse_file { |
|
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
70
|
0
|
|
|
|
|
|
delete $self->{links}; |
|
71
|
0
|
|
|
|
|
|
$self->SUPER::parse_file(@_); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
package HTML::RelExtor::Link; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub new { |
|
77
|
0
|
|
|
0
|
|
|
my($class, $tag, $href, $attr) = @_; |
|
78
|
0
|
|
0
|
|
|
|
my @rel = grep length, split /\s+/, ($attr->{rel} || ''); |
|
79
|
0
|
|
0
|
|
|
|
my @rev = grep length, split /\s+/, ($attr->{rev} || ''); |
|
80
|
0
|
|
|
|
|
|
bless { |
|
81
|
|
|
|
|
|
|
tag => $tag, |
|
82
|
|
|
|
|
|
|
href => $href, |
|
83
|
|
|
|
|
|
|
attr => $attr, |
|
84
|
|
|
|
|
|
|
rel => \@rel, |
|
85
|
|
|
|
|
|
|
rev => \@rev, |
|
86
|
|
|
|
|
|
|
}, $class; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub tag { |
|
90
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
91
|
0
|
|
|
|
|
|
$self->{tag}; |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub href { |
|
95
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
96
|
0
|
|
|
|
|
|
$self->{href}; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub attr { |
|
100
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
101
|
0
|
|
|
|
|
|
$self->{attr}; |
|
102
|
|
|
|
|
|
|
} |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub rel { |
|
105
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
106
|
0
|
|
|
|
|
|
@{$self->{rel}}; |
|
|
0
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub rev { |
|
110
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
111
|
0
|
|
|
|
|
|
@{$self->{rev}}; |
|
|
0
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
} |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub has_rel { |
|
115
|
0
|
|
|
0
|
|
|
my($self, $tag) = @_; |
|
116
|
0
|
|
|
|
|
|
scalar grep { $_ eq $tag } $self->rel; |
|
|
0
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub has_rev { |
|
120
|
0
|
|
|
0
|
|
|
my($self, $tag) = @_; |
|
121
|
0
|
|
|
|
|
|
scalar grep { $_ eq $tag } $self->rev; |
|
|
0
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
} |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub text { |
|
125
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
126
|
0
|
|
|
|
|
|
$self->{text}; |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
1; |
|
130
|
|
|
|
|
|
|
__END__ |