line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Mechanize::AutoPager; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
711
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
60
|
|
4
|
2
|
|
|
2
|
|
27
|
use 5.8.1; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
2123
|
use HTML::AutoPagerize; |
|
2
|
|
|
|
|
137992
|
|
|
2
|
|
|
|
|
63
|
|
8
|
2
|
|
|
2
|
|
20
|
use Scalar::Util qw( weaken ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
129
|
|
9
|
2
|
|
|
2
|
|
1800
|
use WWW::Mechanize::DecodedContent; |
|
2
|
|
|
|
|
29937
|
|
|
2
|
|
|
|
|
69
|
|
10
|
2
|
|
|
2
|
|
2364
|
use JSON; |
|
2
|
|
|
|
|
44496
|
|
|
2
|
|
|
|
|
13
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub WWW::Mechanize::autopager { |
13
|
0
|
|
|
0
|
0
|
|
my $mech = shift; |
14
|
0
|
|
0
|
|
|
|
$mech->{autopager} ||= WWW::Mechanize::AutoPager->new($mech); |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub WWW::Mechanize::next_link { |
18
|
0
|
|
|
0
|
0
|
|
my $mech = shift; |
19
|
0
|
|
|
|
|
|
$mech->{autopager}->next_link; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub WWW::Mechanize::page_element { |
23
|
0
|
|
|
0
|
0
|
|
my $mech = shift; |
24
|
0
|
|
|
|
|
|
$mech->{autopager}->page_element; |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub new { |
28
|
0
|
|
|
0
|
0
|
|
my($class, $mech) = @_; |
29
|
0
|
|
|
|
|
|
my $self = bless { |
30
|
|
|
|
|
|
|
mech => $mech, |
31
|
|
|
|
|
|
|
autopager => HTML::AutoPagerize->new, |
32
|
|
|
|
|
|
|
}, $class; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
weaken($self->{mech}); # don't make it a circular reference |
35
|
0
|
|
|
|
|
|
$self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub load_siteinfo { |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
0
|
|
|
|
my $url = shift || "http://wedata.net/databases/AutoPagerize/items.json"; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my $res = $self->{mech}->get($url); |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
if (my $content = $self->{mech}->content) { |
45
|
0
|
0
|
|
|
|
|
if ($res->content_type =~ m{text/html}) { # backward compatibility |
46
|
0
|
|
|
|
|
|
while ($content =~ m!!gs) { |
47
|
0
|
|
|
|
|
|
my $site = $self->parse_siteinfo($1); |
48
|
0
|
|
|
|
|
|
$self->{autopager}->add_site(%$site); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
} else { |
51
|
0
|
|
|
|
|
|
for my $row ( @{ from_json( $content ) } ) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$self->{autopager}->add_site(%{ $row->{data} }); |
|
0
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub add_site { |
59
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
60
|
0
|
|
|
|
|
|
$self->{autopager}->add_site(@_); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse_siteinfo { |
64
|
0
|
|
|
0
|
0
|
|
my($self, $config) = @_; |
65
|
0
|
|
|
|
|
|
my $site; |
66
|
0
|
|
|
|
|
|
while ($config =~ /^(\w+):\s+(.*?)\s*$/mg) { |
67
|
0
|
|
|
|
|
|
$site->{$1} = $2; |
68
|
|
|
|
|
|
|
} |
69
|
0
|
|
|
|
|
|
return $site; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub next_link { |
73
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
my $res = $self->{autopager}->handle($self->{mech}->uri, $self->{mech}->decoded_content) |
76
|
|
|
|
|
|
|
or return; |
77
|
|
|
|
|
|
|
|
78
|
0
|
|
|
|
|
|
return $res->{next_link}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub page_element { |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
my $res = $self->{autopager}->handle($self->{mech}->uri, $self->{mech}->decoded_content) |
85
|
|
|
|
|
|
|
or return; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
return $res->{page_element}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |