line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
{ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Net::Google::Response - simple OOP-ish interface to the Google SOAP |
6
|
|
|
|
|
|
|
API search responses |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $service = Net::Google->new(key=>LOCAL_GOOGLE_KEY); |
11
|
|
|
|
|
|
|
my $session = $service->search(); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$session->query(qw(Perl modules)); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# You are probably better off calling |
16
|
|
|
|
|
|
|
# $session->results() but if you want |
17
|
|
|
|
|
|
|
# the raw response object(s) here ya go : |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $responses = $session->response(); |
20
|
|
|
|
|
|
|
my $count = scalar(@$responses); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# $r is a Net::Google::Response object |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
foreach my $r (@$responses) { |
25
|
|
|
|
|
|
|
print sprintf("%s : %s\n",$r->searchQuery(),$r->estimatedTotalResults()); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Provides a simple OOP-ish interface to the Google SOAP API for |
31
|
|
|
|
|
|
|
searching. This package is used by I. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
The Net::Google::Response object is used to contain response |
34
|
|
|
|
|
|
|
information provided by the Google search service in response to a |
35
|
|
|
|
|
|
|
search query. The Response object allows the client program to easily |
36
|
|
|
|
|
|
|
access the data returned from a search. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
Response data is accessed using methods with identical names to the |
39
|
|
|
|
|
|
|
elements of a search response (as documented in the Google Web APIs |
40
|
|
|
|
|
|
|
Reference, section 3). For instance, the first example in the SYNOPSIS |
41
|
|
|
|
|
|
|
section, above, would return the estimated number of total results for |
42
|
|
|
|
|
|
|
the query. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
Response objects may contain other response objects, where an element |
45
|
|
|
|
|
|
|
would return an array of other elements. For instance, calling |
46
|
|
|
|
|
|
|
C<$response-EresultElements()> will return a reference to an array |
47
|
|
|
|
|
|
|
of Net::Google::Response objects, each one representing one result |
48
|
|
|
|
|
|
|
from the search. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
The Response module will automatically provide methods for the search |
51
|
|
|
|
|
|
|
response, as described by the service WSDL file. The results format |
52
|
|
|
|
|
|
|
is described by the Google APIs documentation, to which you should |
53
|
|
|
|
|
|
|
refer for the most up-to-date information. As of the April 8th, 2002 |
54
|
|
|
|
|
|
|
release of the Google APIs, the methods below are provided for each |
55
|
|
|
|
|
|
|
search result. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package Net::Google::Response; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
4
|
use vars qw ($AUTOLOAD); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
64
|
|
|
|
|
|
|
|
65
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
83
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
$Net::Google::Response::VERSION = '1.0'; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# Note that we handle 'resultElements' separately |
70
|
|
|
|
|
|
|
# Maybe we should doing the same w/ directoryCategories... |
71
|
|
|
|
|
|
|
|
72
|
1
|
|
|
1
|
|
5
|
use constant RESPONSE_FIELDS => qw [ directoryCategories estimateIsExact startIndex searchTime estimatedTotalResultsCount searchTips searchComments searchQuery endIndex documentFiltering ]; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
595
|
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 PACKAGE METHODS |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head2 __PACKAGE__->new(\%args) |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=cut |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub new { |
83
|
0
|
|
|
0
|
1
|
|
my $pkg = shift; |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $self = {}; |
86
|
0
|
|
|
|
|
|
bless $self,$pkg; |
87
|
|
|
|
|
|
|
|
88
|
0
|
0
|
|
|
|
|
if (! $self->init(@_)) { |
89
|
0
|
|
|
|
|
|
return undef; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return $self; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub init { |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
0
|
|
|
|
|
|
my $response = shift; |
98
|
|
|
|
|
|
|
|
99
|
0
|
0
|
|
|
|
|
if (ref($response) ne "GoogleSearchResult") { |
100
|
0
|
|
|
|
|
|
carp "Unknown response object."; |
101
|
0
|
|
|
|
|
|
return 0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
|
|
|
foreach my $el (@{$response->{'resultElements'}}) { |
|
0
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if (my $res = Result->new($el)) { |
106
|
0
|
|
|
|
|
|
push @{$self->{'__resultElements'}},$res; |
|
0
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
map { $self->{'__'.$_} = $response->{$_}; } &RESPONSE_FIELDS; |
|
0
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return 1; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 I OBJECT METHODS |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 $response->documentFiltering() |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Returns 0 if false, 1 if true. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=head2 $response->searchComments() |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
Returns a string. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 $response->estimatedTotalResultsCount() |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Returns an integer. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head2 $response->estimateIsExact() |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Returns 0 if false, 1 if true. |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 $response->resultElements() |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Returns a reference to an array of I objects. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=cut |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
sub resultElements { |
141
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
142
|
|
|
|
|
|
|
|
143
|
0
|
0
|
|
|
|
|
if(ref($self->{'__resultElements'}) eq "ARRAY") { |
144
|
0
|
|
|
|
|
|
return $self->{'__resultElements'}; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
return []; |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=head2 $response->searchQuery() |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
Returns a string. |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 $response->startIndex() |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Returns an integer. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head2 $response->endIndex() |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Returns an integer. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head2 $response->searchTips() |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Returns a string. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
=head2 $response->directoryCategories() |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
Returns a reference to an array of Response objects (one per directory |
169
|
|
|
|
|
|
|
category -- see below). |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 $response->searchTime() |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Returns a float. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=head2 $pkg->to_string() |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=cut |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub to_string { |
180
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
181
|
0
|
|
|
|
|
|
my $string = ''; |
182
|
|
|
|
|
|
|
|
183
|
0
|
|
|
|
|
|
foreach my $key (keys %$self) { |
184
|
0
|
|
|
|
|
|
$string .= "$key: $$self{$key}\n"; |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $string; |
188
|
|
|
|
|
|
|
} |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub DESTROY { |
191
|
0
|
|
|
0
|
|
|
return 1; |
192
|
|
|
|
|
|
|
} |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
sub AUTOLOAD { |
195
|
0
|
|
|
0
|
|
|
my $self = shift; |
196
|
|
|
|
|
|
|
|
197
|
0
|
|
|
|
|
|
$AUTOLOAD =~ s/.*:://; |
198
|
|
|
|
|
|
|
|
199
|
0
|
0
|
|
|
|
|
unless (grep/^($AUTOLOAD)$/,&RESPONSE_FIELDS) { |
200
|
0
|
|
|
|
|
|
carp "Unknown attribute : ".$AUTOLOAD; |
201
|
0
|
|
|
|
|
|
return undef; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
0
|
|
|
|
|
|
return $self->{'__'.$AUTOLOAD}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
package Result; |
208
|
1
|
|
|
1
|
|
41
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
66
|
|
209
|
|
|
|
|
|
|
|
210
|
1
|
|
|
1
|
|
5
|
use vars qw ($AUTOLOAD); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
211
|
|
|
|
|
|
|
|
212
|
1
|
|
|
1
|
|
5
|
use constant RESULT_FIELDS => qw [ title URL snippet cachedSize directoryTitle summary hostName directoryCategory relatedInformationPresent ]; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
287
|
|
213
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
sub new { |
215
|
0
|
|
|
0
|
|
|
my $pkg = shift; |
216
|
|
|
|
|
|
|
|
217
|
0
|
|
|
|
|
|
my $self = {}; |
218
|
0
|
|
|
|
|
|
bless $self,$pkg; |
219
|
|
|
|
|
|
|
|
220
|
0
|
0
|
|
|
|
|
if (! $self->init(@_)) { |
221
|
0
|
|
|
|
|
|
return undef; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return $self; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub init { |
228
|
0
|
|
|
0
|
|
|
my $self = shift; |
229
|
0
|
|
|
|
|
|
my $res = shift; |
230
|
|
|
|
|
|
|
|
231
|
0
|
0
|
|
|
|
|
unless (ref($res) eq "ResultElement") { |
232
|
0
|
|
|
|
|
|
carp "Unknown result object"; |
233
|
0
|
|
|
|
|
|
return 0; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
map { $self->{'__'.$_} = $res->{$_}; } &RESULT_FIELDS; |
|
0
|
|
|
|
|
|
|
237
|
0
|
|
|
|
|
|
return 1; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=head1 I OBJECT METHODS |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=cut |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head2 $result->title() |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Returns a string. |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head2 $result->URL() |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
Returns a string. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head2 $result->snippet() |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
Returns a string, formatted in HTML. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
=head2 $result->cachedSize() |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
Returns a string. |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=head2 $result->directoryTitle() |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
Returns a string. |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head2 $result->summary() |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
Returns a string. |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
=head2 $result->hostName() |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
Returns a string. |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head2 $result->directoryCategory() |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
Returns a hash reference. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=cut |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
sub AUTOLOAD { |
279
|
0
|
|
|
0
|
|
|
my $self = shift; |
280
|
0
|
|
|
|
|
|
$AUTOLOAD =~ s/.*:://; |
281
|
|
|
|
|
|
|
|
282
|
0
|
0
|
|
|
|
|
unless (grep/^($AUTOLOAD)$/,&RESULT_FIELDS) { |
283
|
0
|
|
|
|
|
|
carp "Unknown attribute :".$AUTOLOAD; |
284
|
0
|
|
|
|
|
|
return undef; |
285
|
|
|
|
|
|
|
} |
286
|
|
|
|
|
|
|
|
287
|
0
|
|
|
|
|
|
return $self->{'__'.$AUTOLOAD}; |
288
|
|
|
|
|
|
|
} |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub DESTROY { |
291
|
0
|
|
|
0
|
|
|
return 1; |
292
|
|
|
|
|
|
|
} |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
=head1 VERSION |
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
1.0 |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=head1 DATE |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
$Date: 2005/04/02 21:51:16 $ |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
=head1 AUTHOR |
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
Aaron Straup Cope |
305
|
|
|
|
|
|
|
|
306
|
|
|
|
|
|
|
=head1 CONTRIBUTORS |
307
|
|
|
|
|
|
|
|
308
|
|
|
|
|
|
|
Marc Hedlund |
309
|
|
|
|
|
|
|
|
310
|
|
|
|
|
|
|
=head1 SEE ALSO |
311
|
|
|
|
|
|
|
|
312
|
|
|
|
|
|
|
L |
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
=head1 LICENSE |
315
|
|
|
|
|
|
|
|
316
|
|
|
|
|
|
|
Copyright (c) 2002-2005, Aaron Straup Cope. All Rights Reserved. |
317
|
|
|
|
|
|
|
|
318
|
|
|
|
|
|
|
This is free software, you may use it and distribute it under the |
319
|
|
|
|
|
|
|
same terms as Perl itself. |
320
|
|
|
|
|
|
|
|
321
|
|
|
|
|
|
|
=cut |
322
|
|
|
|
|
|
|
|
323
|
|
|
|
|
|
|
return 1; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
} |