line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Google::Code::Role::Fetchable; |
2
|
12
|
|
|
12
|
|
9490
|
use Any::Moose 'Role'; |
|
12
|
|
|
|
|
28
|
|
|
12
|
|
|
|
|
86
|
|
3
|
12
|
|
|
12
|
|
37649
|
use Params::Validate ':all'; |
|
12
|
|
|
|
|
71161
|
|
|
12
|
|
|
|
|
3107
|
|
4
|
12
|
|
|
12
|
|
28709
|
use WWW::Mechanize; |
|
12
|
|
|
|
|
2418717
|
|
|
12
|
|
|
|
|
2808
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $MECH; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub mech { |
9
|
11
|
100
|
|
11
|
1
|
58
|
if (!$MECH) { |
10
|
4
|
|
|
|
|
50
|
$MECH = WWW::Mechanize->new( |
11
|
|
|
|
|
|
|
agent => 'Net-Google-Code', |
12
|
|
|
|
|
|
|
keep_alive => 4, |
13
|
|
|
|
|
|
|
cookie_jar => {}, |
14
|
|
|
|
|
|
|
stack_depth => 1, |
15
|
|
|
|
|
|
|
timeout => 60, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
} |
18
|
11
|
|
|
|
|
94785
|
return $MECH ; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub fetch { |
22
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
23
|
1
|
|
|
|
|
24
|
my ($url) = validate_pos( @_, { type => SCALAR } ); |
24
|
1
|
|
|
|
|
7
|
$self->mech->get($url); |
25
|
1
|
50
|
|
|
|
6
|
if ( !$self->mech->response->is_success ) { |
26
|
0
|
|
|
|
|
0
|
die "Server threw an error " |
27
|
|
|
|
|
|
|
. $self->mech->response->status_line . " for " |
28
|
|
|
|
|
|
|
. $url; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
else { |
31
|
1
|
|
|
|
|
78
|
my $content = $self->mech->content; |
32
|
|
|
|
|
|
|
# auto decode the content to erase HTML::Parser's utf8 warning like this: |
33
|
|
|
|
|
|
|
# Parsing of undecoded UTF-8 will give garbage when decoding entities |
34
|
1
|
|
|
|
|
8
|
utf8::downgrade( $content, 1 ); |
35
|
1
|
|
|
|
|
5
|
return $content; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
12
|
|
|
12
|
|
151
|
no Any::Moose; |
|
12
|
|
|
|
|
48
|
|
|
12
|
|
|
|
|
138
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__END__ |