| 1 | package Net::Google::Code::Role::Fetchable; | ||||||||||
| 2 | 12 | ▶ | use Any::Moose 'Role'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 12 | ▶ | use Params::Validate ':all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 12 | ▶ | use WWW::Mechanize; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 12 | our $MECH; | |||||||||
| 7 | |||||||||||
| 8 | 11 | ▶ | sub mech { | ||||||||
|
Subroutine
mech: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 9 | 11 | ▶ | if (!$MECH) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 10 | 4 | $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 | return $MECH ; | |||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | 1 | ▶ | sub fetch { | ||||||||
|
Subroutine
fetch: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 22 | 1 | my $self = shift; | |||||||||
| 23 | 1 | my ($url) = validate_pos( @_, { type => SCALAR } ); | |||||||||
| 24 | 1 | $self->mech->get($url); | |||||||||
| 25 | 1 | ▶ | if ( !$self->mech->response->is_success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 0 | die "Server threw an error " | |||||||||
| 27 | . $self->mech->response->status_line . " for " | ||||||||||
| 28 | . $url; | ||||||||||
| 29 | } | ||||||||||
| 30 | else { | ||||||||||
| 31 | 1 | 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 | utf8::downgrade( $content, 1 ); | |||||||||
| 35 | 1 | return $content; | |||||||||
| 36 | } | ||||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 12 | ▶ | no Any::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 40 | |||||||||||
| 41 | 12 | 1; | |||||||||
| 42 | |||||||||||
| 43 | __END__ | ||||||||||