line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::AutoPagerize; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
4086
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
25
|
use 5.8.1; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
114
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
9
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
149
|
|
8
|
2
|
|
|
2
|
|
2103
|
use HTML::TreeBuilder::XPath; |
|
2
|
|
|
|
|
88886
|
|
|
2
|
|
|
|
|
44
|
|
9
|
2
|
|
|
2
|
|
6747
|
use URI; |
|
2
|
|
|
|
|
6181
|
|
|
2
|
|
|
|
|
978
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
13
|
0
|
|
|
|
|
|
bless { sites => [] }, $class; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub sites { |
17
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
18
|
0
|
0
|
|
|
|
|
$self->{sites} = shift if @_; |
19
|
0
|
|
|
|
|
|
$self->{sites}; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub sorted_sites { |
23
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
24
|
0
|
|
|
|
|
|
return [ sort { length $b->{url} <=> length $a->{url} } @{ $self->sites } ]; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub add_site { |
28
|
0
|
|
|
0
|
0
|
|
my($self, %site) = @_; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
for my $key (qw( url nextLink )) { |
31
|
0
|
0
|
|
|
|
|
unless (defined $site{$key}) { |
32
|
0
|
|
|
|
|
|
croak "key '$key' needed for SITEINFO"; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
$site{url} = qr/$site{url}/; # compile the regexp |
37
|
0
|
|
|
|
|
|
push @{$self->{sites}}, \%site; |
|
0
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub handle { |
41
|
0
|
|
|
0
|
0
|
|
my($self, $uri, $html) = @_; |
42
|
|
|
|
|
|
|
|
43
|
0
|
0
|
|
|
|
|
my $siteinfo = $self->site_info_for($uri) or return; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
my $tree = HTML::TreeBuilder::XPath->new; |
46
|
0
|
|
|
|
|
|
$tree->parse($html); |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
|
|
|
|
my $res; |
49
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $next_link = $siteinfo->{nextLink}; |
51
|
0
|
0
|
|
|
|
|
if (my $nodes = $tree->findnodes($next_link)) { |
52
|
0
|
|
|
|
|
|
$res->{next_link} = URI->new_abs($nodes->shift->attr('href'), $uri); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if (my $page_element = $siteinfo->{pageElement}) { |
56
|
0
|
0
|
|
|
|
|
if (my $nodes = $tree->findnodes($page_element)) { |
57
|
0
|
|
|
|
|
|
$res->{page_element} = $nodes; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $res; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub site_info_for { |
65
|
0
|
|
|
0
|
0
|
|
my($self, $uri) = @_; |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
for my $site (@{ $self->sorted_sites }) { |
|
0
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ($uri =~ $site->{url}) { |
69
|
0
|
|
|
|
|
|
return $site; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
1; |
77
|
|
|
|
|
|
|
__END__ |