Google/Cache.pm

filter: Statementstmt 58.0% 18 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 71.4% 5 / 7 Podpod 75.0% 3 / 4 totaltotal 50.9% 26 / 51 CC 5 SCAR 13.8
CC
5
Cov
46%
init
7.2
url
6.0
new
2.5
CRAP 4.0
« Google/Service.pm ↑ Summary Google.pm »
1 {
2  
3 1 =head1 NAME
4  
5 Net::Google::Cache - simple OOP-ish interface to the Google SOAP API for
6 cached documents
7  
8 =head1 SYNOPSIS
9  
10 use Net::Google::Cache;
11 my $cache = Net::Google::Cache(\%args);
12  
13 $cache->url("http://aaronland.net);
14 print $cache->get();
15  
16 =head1 DESCRIPTION
17  
18 Provides a simple OOP-ish interface to the Google SOAP API for cached
19 documents.
20  
21 This package is used by I<Net::Google>.
22  
23 =cut
24  
25 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 package Net::Google::Cache;
27 1 ▶use base qw (Net::Google::tool);
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 $Net::Google::Cache::VERSION = '1.0';
32  
33 =head1 PACKAGE METHODS
34  
35 =cut
36  
37 =head2 __PACKAGE__->new(\%args)
38  
39 Valid arguments are :
40  
41 =over 4
42  
43 =item *
44  
45 B<key>
46  
47 I<string>. A Google API key.
48  
49 If none is provided then the key passed to the parent I<Net::Google>
50 object will be used.
51  
52 =item *
53  
54 B<url>
55  
56 I<string>.
57  
58 =item *
59  
60 B<http_proxy>
61  
62 I<url>.
63  
64 Get/set the URL for proxy-ing HTTP request.
65  
66 Returns a string.
67  
68 =item *
69  
70 B<debug>
71  
72 Valid options are:
73  
74 =over 4
75  
76 =item *
77  
78 I<boolean>
79  
80 If true prints debugging information returned by SOAP::Lite
81 to STDERR
82  
83 =item *
84  
85 I<coderef>.
86  
87 Your own subroutine for munging the debugging information
88 returned by SOAP::Lite.
89  
90 =back
91  
92 =back
93  
94 The object constructor in Net::Google 0.53, and earlier, expected
95 a I<GoogleSearchService> object as its first argument followed by
96 a hash reference of argument. Versions 0.6 and higher are backwards
97 compatible.
98  
99 Returns an object. Woot!
100  
101 =cut
102  
103 1 ▶sub new {
Subroutine new: called CC=2 SCAR=9.2
Pod documented
104 1 my $pkg = shift;
105  
106 1 my $self = {};
107 1 bless $self,$pkg;
108  
109 1 ▶ if (! $self->init(@_)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->init(@_)) 0 0 0
110 0 return undef;
111 }
112  
113 0 return $self;
114 }
115  
116 1 ▶sub init {
Subroutine init: called CC=3 SCAR=19.8
Pod undocumented
117 1 my $self = shift;
118  
119 1 ▶ my $args = $self->SUPER::init("cache",@_)
Condition0%0/2
$self->SUPER::init('cache', @_) || (return 0)
l!l
00
MC/DC0%0/1
$self->SUPER::init('cache', @_) || (return 0)
$self->SUPER::init('cache', @_)
Truth table0%0/2
A
A= $self->SUPER::init('cache', @_)
Aresult
11
00
120 || return 0;
121  
122 #
123  
124 0 ▶ if ($args->{'url'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args->{"url"}) 0 0 0
125 0 $self->url($args->{'url'});
126 }
127  
128 0 return 1;
129 }
130  
131 =head1 OBJECT METHODS
132  
133 =cut
134  
135 =head2 $obj->key($string)
136  
137 Get/set the Google API key for this object.
138  
139 =cut
140  
141 # Defined in Net::Google::tool
142  
143 =head2 $obj->http_proxy($url)
144  
145 Get/set the HTTP proxy for this object.
146  
147 Returns a string.
148  
149 =cut
150  
151 # Defined in Net::Google::tool
152  
153 =head2 $pkg->url($url)
154  
155 Set the cached URL to fetch from the Google servers.
156  
157 Returns a string. Returns an undef if there was an error.
158  
159 =cut
160  
161 0 ▶sub url {
Subroutine url: not called CC=2 SCAR=17.9
Pod documented
162 0 my $self = shift;
163 0 my $url = shift;
164  
165 0 ▶ if (defined($url)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $url) 0 0 0
166 0 $self->{'_url'} = $url;
167 }
168  
169 0 return $self->{'_url'};
170 }
171  
172 =head2 $pkg->get()
173  
174 Fetch the requested URL from the Google servers.
175  
176 Returns a string. Returns undef if there was an error.
177  
178 =cut
179  
180 0 ▶sub get {
Subroutine get: not called CC=1 SCAR=6.9
Pod documented
181 0 my $self = shift;
182  
183 0 $self->_queries(1);
184  
185 0 return $self->{'_service'}->doGetCachedPage(
186 $self->key(),
187 $self->url(),
188 );
189 }
190  
191 =head2 $obj->queries_exhausted()
192  
193 Returns true or false depending on whether or not the current in-memory
194 B<session> has exhausted the Google API 1000 query limit.
195  
196 =cut
197  
198 # Defined in Net::Google::tool
199  
200 =head1 VERSION
201  
202 1.0
203  
204 =head1 DATE
205  
206 $Date: 2005/03/26 20:49:03 $
207  
208 =head1 AUTHOR
209  
210 Aaron Straup Cope
211  
212 =head1 TO DO
213  
214 =over 4
215  
216 =item *
217  
218 Add hooks to I<get> method to strip out Google headers and footers from cached pages.
219  
220 =back
221  
222 =head1 SEE ALSO
223  
224 L<Net::Google>
225  
226 =head1 LICENSE
227  
228 Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved.
229  
230 This is free software, you may use it and distribute it under the same terms as Perl itself.
231  
232 =cut
233  
234 1 return 1;
235  
236 }
« Google/Service.pm ↑ Summary Google.pm »