line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::GoKGS::Scraper; |
2
|
9
|
|
|
9
|
|
8693
|
use strict; |
|
9
|
|
|
|
|
22
|
|
|
9
|
|
|
|
|
315
|
|
3
|
9
|
|
|
9
|
|
49
|
use warnings; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
256
|
|
4
|
9
|
|
|
9
|
|
51
|
use Carp qw/croak/; |
|
9
|
|
|
|
|
16
|
|
|
9
|
|
|
|
|
605
|
|
5
|
9
|
|
|
9
|
|
867
|
use URI; |
|
9
|
|
|
|
|
5000
|
|
|
9
|
|
|
|
|
5207
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub base_uri { |
8
|
0
|
|
|
0
|
1
|
0
|
croak 'call to abstract method ', __PACKAGE__, '::base_uri'; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub build_uri { |
12
|
70
|
|
|
70
|
1
|
200
|
my ( $class, @query ) = @_; |
13
|
70
|
|
|
|
|
381
|
my $uri = URI->new( $class->base_uri ); |
14
|
70
|
50
|
|
|
|
132140
|
$uri->query_form( @query ) if @query; |
15
|
70
|
|
|
|
|
316
|
$uri; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
7
|
|
|
7
|
1
|
8
|
my $class = shift; |
20
|
7
|
50
|
|
|
|
25
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
21
|
7
|
|
|
|
|
15
|
my $self = bless {}, $class; |
22
|
|
|
|
|
|
|
|
23
|
7
|
|
|
|
|
34
|
$self->init( \%args ); |
24
|
|
|
|
|
|
|
|
25
|
7
|
|
|
|
|
41
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub init { |
29
|
7
|
|
|
7
|
0
|
9
|
my ( $self, $args ) = @_; |
30
|
|
|
|
|
|
|
|
31
|
7
|
|
|
|
|
9
|
for my $method (qw/user_agent _tree_builder_class/) { |
32
|
14
|
50
|
|
|
|
190
|
$self->$method( $args->{$method} ) if exists $args->{$method}; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
7
|
|
|
|
|
11
|
return; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _scraper { |
39
|
14
|
|
|
14
|
|
17
|
my $self = shift; |
40
|
14
|
|
66
|
|
|
96
|
$self->{_scraper} ||= $self->__build_scraper; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub __build_scraper { |
44
|
0
|
|
|
0
|
|
0
|
croak 'call to abstract method ', __PACKAGE__, '::__build_scraper'; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub _tree_builder_class { |
48
|
7
|
|
|
7
|
|
12
|
my ( $self, @args ) = @_; |
49
|
7
|
|
|
|
|
12
|
$self->_scraper->_tree_builder_class( @args ); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub user_agent { |
53
|
7
|
|
|
7
|
1
|
12
|
my ( $self, @args ) = @_; |
54
|
7
|
|
|
|
|
36
|
$self->_scraper->user_agent( @args ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub scrape { |
58
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
59
|
0
|
|
|
|
|
|
$self->_scraper->scrape( @args ); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub query { |
63
|
0
|
|
|
0
|
1
|
|
my ( $self, @query ) = @_; |
64
|
0
|
|
|
|
|
|
$self->scrape( ref($self)->build_uri(@query) ); |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
__END__ |