WWW/Cache/Google.pm

filter: Statementstmt 45.8% 22 / 48 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 100% 1 / 1 totaltotal 40.2% 31 / 77 CC 9 SCAR 38.7
CC
9
Cov
34%
_process_request
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 48.1
« WebService/Validator/HTML/W3C.pm ↑ Summary Syntax/Highlight/CSS.pm »
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
BranchTrueFalseTotal
if ($in_ref->{"fetch"}) 0 0 0
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
BranchTrueFalseTotal
unless ($response->is_success) 0 0 0
39 0 $in_ref->{error} = $response->status_line;
40 0 ▶ if ( $in_ref->{error} eq '404 Not Found' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($in_ref->{"error"} eq "404 Not Found") 0 0 0
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
BranchTrueFalseTotal
unless ($in_ref->{"content"} =~ /<base/) 0 0 0
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
BranchTrueFalseTotal
if (ref $in_ref->{"fetch"} eq "SCALAR") 0 0 0
54  
55 0 my $filename = ${ $in_ref->{fetch} };
56  
57 0 ▶ if ( -e $filename and not $in_ref->{overwrite} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $filename and not $in_ref->{"overwrite"}) 0 0 0
Condition0%0/3
-e $filename and not $in_ref->{"overwrite"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
58 0 $in_ref->{error} = "File `$filename` already exists";
59 0 return;
60 }
61  
62 0 ▶ if ( open my $fh, '>', $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, '>', $filename) { } 0 0 0
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__
« WebService/Validator/HTML/W3C.pm ↑ Summary Syntax/Highlight/CSS.pm »