File Coverage

blib/lib/WWW/Cache/Google.pm
Criterion Covered Total %
statement 34 38 89.4
branch 1 2 50.0
condition n/a
subroutine 13 15 86.6
pod 4 6 66.6
total 52 61 85.2


line stmt bran cond sub pod time code
1             package WWW::Cache::Google;
2              
3 2     2   110043 use strict;
  2         5  
  2         88  
4 2     2   12 use vars qw($VERSION);
  2         3  
  2         110  
5             $VERSION = 0.04;
6              
7 2     2   2396 use URI;
  2         16581  
  2         73  
8 2     2   21 use URI::Escape;
  2         3  
  2         838  
9              
10             sub cache_base {
11 4     4 0 12 return 'http://www.google.com/search?q=cache:%s';
12             }
13              
14              
15             # ro-accessor
16 16     16 1 627 sub orig { $_[0]->[0] }
17 8     8 1 46 sub cache { $_[0]->[1] }
18              
19             sub new {
20 8     8 1 1821 my($class, $thingy) = @_;
21 8         25 my $uri = _make_uri($thingy);
22 8         20799 my $self = bless [ $uri ], $class;
23 8         31 $self->init;
24 8         508 return $self;
25             }
26              
27             sub _make_uri {
28 8     8   15 my $thingy = shift;
29 8 50       53 return $thingy if UNIVERSAL::isa($thingy => 'URL');
30 8         35 return URI->new($thingy);
31             }
32              
33             sub init {
34 8     8 0 14 my $self = shift;
35 8         28 my $uri = sprintf $self->cache_base, $self->_cache_param;
36 8         454 $self->[1] = URI->new($uri);
37             }
38              
39             sub _cache_param {
40 8     8   13 my $self = shift;
41 8         25 return $self->orig->host . uri_escape($self->orig->path_query, q(\W));
42             }
43              
44             sub fetch {
45 0     0 1 0 require LWP::Simple;
46 0         0 my $self = shift;
47 0         0 return LWP::Simple::get($self->cache->as_string);
48             }
49              
50 0     0   0 sub DESTROY { }
51              
52 2     2   12 use vars qw($AUTOLOAD);
  2         2  
  2         216  
53             sub AUTOLOAD {
54 8     8   86 my $self = shift;
55 8         47 (my $meth = $AUTOLOAD) =~ s/.*://;
56 8         30 $self->cache->$meth(@_);
57             }
58              
59              
60             1;
61             __END__