| 1 | package POE::Component::WWW::Cache::Google; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '2.001002'; # VERSION | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use POE; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use base 'POE::Component::NonBlockingWrapper::Base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use WWW::Cache::Google; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | sub _methods_define { | ||||||||||||||||||||||||||
|
Subroutine
_methods_define: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | return ( cache => '_wheel_entry' ); | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | sub cache { | ||||||||||||||||||||||||||
|
Subroutine
cache: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 18 | 1 | $poe_kernel->post( shift->{session_id} => cache => @_ ); | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub _process_request { | ||||||||||||||||||||||||||
|
Subroutine
_process_request: not called CC=9 SCAR=45.0
| |||||||||||||||||||||||||||||
| 22 | 0 | my ( $self, $in_ref ) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 0 | my $cache = WWW::Cache::Google->new( $in_ref->{uri} ); | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | $in_ref->{cache} = $cache->cache; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | ▶ | if ( $in_ref->{fetch} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | my $ua = LWP::UserAgent->new( | ||||||||||||||||||||||||||||
| 30 | agent => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:21.0) ' | ||||||||||||||||||||||||||||
| 31 | . 'Gecko/20100101 Firefox/21.0', | ||||||||||||||||||||||||||||
| 32 | # trick google into not giving us 403s | ||||||||||||||||||||||||||||
| 33 | timeout => 30, | ||||||||||||||||||||||||||||
| 34 | max_size => $in_ref->{max_size}, | ||||||||||||||||||||||||||||
| 35 | 0 | ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $response = $ua->get( $in_ref->{cache} ); | |||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ( not $response->is_success ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 0 | $in_ref->{error} = $response->status_line; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | if ( $in_ref->{error} eq '404 Not Found' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 0 | $in_ref->{error} = q|Doesn't look like cache exists|; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 0 | return; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | $in_ref->{content} = $response->content; | |||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ( $in_ref->{content} !~ /<base/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | $in_ref->{error} = q|Doesn't look like cache exists|; | |||||||||||||||||||||||||||
| 49 | 0 | return; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | if ( ref $in_ref->{fetch} eq 'SCALAR' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $filename = ${ $in_ref->{fetch} }; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ( -e $filename and not $in_ref->{overwrite} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
-e $filename and not $in_ref->{"overwrite"}
MC/DC0%0/2
-e $filename and not $in_ref->{"overwrite"}
-e $filename
not $in_ref->{"overwrite"}
Truth table0%0/3
A and not(B)
A= -e $filenameB= not $in_ref->{"overwrite"}
| |||||||||||||||||||||||||||||
| 58 | 0 | $in_ref->{error} = "File `$filename` already exists"; | |||||||||||||||||||||||||||
| 59 | 0 | return; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | if ( open my $fh, '>', $filename ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 0 | print $fh delete $in_ref->{content}, "\n"; | |||||||||||||||||||||||||||
| 64 | 0 | close $fh; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | else { | ||||||||||||||||||||||||||||
| 67 | 0 | $in_ref->{error} = "Failed to open `$filename` for writing [$!]"; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | return; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | 1; | |||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||