File Coverage

blib/lib/WWW/Google/CustomSearch/Result.pm
Criterion Covered Total %
statement 20 45 44.4
branch 0 4 0.0
condition 0 6 0.0
subroutine 7 8 87.5
pod 0 1 0.0
total 27 64 42.1


line stmt bran cond sub pod time code
1             package WWW::Google::CustomSearch::Result;
2              
3             $WWW::Google::CustomSearch::Result::VERSION = '0.40';
4             $WWW::Google::CustomSearch::Result::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             WWW::Google::CustomSearch::Result - Placeholder for Google JSON/Atom Custom Search Result.
9              
10             =head1 VERSION
11              
12             Version 0.40
13              
14             =cut
15              
16 5     5   134 use 5.006;
  5         19  
17 5     5   34 use Data::Dumper;
  5         12  
  5         403  
18 5     5   11206 use WWW::Google::CustomSearch::Item;
  5         30  
  5         378  
19 5     5   12037 use WWW::Google::CustomSearch::Page;
  5         28  
  5         319  
20 5     5   5109 use WWW::Google::CustomSearch::Request;
  5         28  
  5         316  
21              
22 5     5   50 use Moo;
  5         12  
  5         28  
23 5     5   2694 use namespace::autoclean;
  5         15  
  5         36  
24              
25             has [qw(api_key raw)] => (is => 'ro', required => 1);
26             has [qw(kind formattedTotalResults formattedSearchTime totalResults searchTime url_template url_type request nextPage previousPage items)] => (is => 'ro');
27              
28             sub BUILD {
29 0     0 0   my ($self) = @_;
30              
31 0           my $raw = $self->raw;
32 0           $self->{'kind'} = $raw->{'kind'};
33 0           $self->{'formattedTotalResults'} = $raw->{'searchInformation'}->{'formattedTotalResults'};
34 0           $self->{'formattedSearchTime'} = $raw->{'searchInformation'}->{'formattedSearchTime'};
35 0           $self->{'totalResults'} = $raw->{'searchInformation'}->{'totalResults'};
36 0           $self->{'searchTime'} = $raw->{'searchInformation'}->{'searchTime'};
37              
38 0           $self->{'url_template'} = $raw->{'url'}->{'template'};
39 0           $self->{'url_type'} = $raw->{'url'}->{'type'};
40              
41 0           $raw->{'queries'}->{'request'}->[0]->{'api_key'} = $self->api_key;
42              
43 0           my $request_params = $raw->{'queries'}->{'request'}->[0];
44 0   0       $request_params->{totalResults} = $raw->{searchInformation}->{totalResults} || 0;
45 0           $self->{'request'} = WWW::Google::CustomSearch::Request->new($request_params);
46              
47 0 0 0       if (defined $raw->{'queries'}->{'nextPage'} && (scalar(@{$raw->{'queries'}->{'nextPage'}}))) {
  0            
48 0           $raw->{'queries'}->{'nextPage'}->[0]->{'api_key'} = $self->api_key;
49 0           $self->{'nextPage'} = WWW::Google::CustomSearch::Page->new($raw->{'queries'}->{'nextPage'}->[0]);
50             }
51              
52 0 0 0       if (defined $raw->{'queries'}->{'previousPage'} && (scalar(@{$raw->{'queries'}->{'previousPage'}}))) {
  0            
53 0           $raw->{'queries'}->{'previousPage'}->[0]->{'api_key'} = $self->api_key;
54 0           $self->{'previousPage'} = WWW::Google::CustomSearch::Page->new($raw->{'queries'}->{'previousPage'}->[0]);
55             }
56              
57 0           foreach (@{$raw->{items}}) {
  0            
58 0           push @{$self->{items}}, WWW::Google::CustomSearch::Item->new($_);
  0            
59             }
60             }
61              
62             =head1 DESCRIPTION
63              
64             Provides the interface to the individual search results based on the search criteria.
65              
66             =head1 METHODS
67              
68             =head2 kind()
69              
70             Returns the 'kind' attribute of the search result.
71              
72             use strict; use warnings;
73             use WWW::Google::CustomSearch;
74              
75             my $api_key = 'Your_API_Key';
76             my $cx = 'Search_Engine_Identifier';
77             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
78             my $result = $engine->search("Google");
79             print "Kind: ", $result->kind, "\n";
80              
81             =head2 formattedTotalResults()
82              
83             Returns the 'formattedTotalResults' attribute of the search result.
84              
85             use strict; use warnings;
86             use WWW::Google::CustomSearch;
87              
88             my $api_key = 'Your_API_Key';
89             my $cx = 'Search_Engine_Identifier';
90             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
91             my $result = $engine->search("Google");
92             print "Formatted Total Results: ", $result->formattedTotalResults, "\n";
93              
94             =head2 formattedSearchTime()
95              
96             Returns the 'formattedSearchTime' attribute of the search result.
97              
98             use strict; use warnings;
99             use WWW::Google::CustomSearch;
100              
101             my $api_key = 'Your_API_Key';
102             my $cx = 'Search_Engine_Identifier';
103             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
104             my $result = $engine->search("Google");
105             print "Formatted Search Time: ", $result->formattedSearchTime, "\n";
106              
107             =head2 totalResults()
108              
109             Returns the 'totalResults' attribute of the search result.
110              
111             use strict; use warnings;
112             use WWW::Google::CustomSearch;
113              
114             my $api_key = 'Your_API_Key';
115             my $cx = 'Search_Engine_Identifier';
116             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
117             my $result = $engine->search("Google");
118             print "Total Results: ", $result->totalResults, "\n";
119              
120             =head2 searchTime()
121              
122             Returns the 'searchTime' attribute of the search result.
123              
124             use strict; use warnings;
125             use WWW::Google::CustomSearch;
126              
127             my $api_key = 'Your_API_Key';
128             my $cx = 'Search_Engine_Identifier';
129             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
130             my $result = $engine->search("Google");
131             print "Search Time: ", $result->searchTime, "\n";
132              
133             =head2 url_template()
134              
135             Returns the URL template attribute of the search result.
136              
137             use strict; use warnings;
138             use WWW::Google::CustomSearch;
139              
140             my $api_key = 'Your_API_Key';
141             my $cx = 'Search_Engine_Identifier';
142             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
143             my $result = $engine->search("Google");
144             print "URL Template: ", $result->url_template, "\n";
145              
146             =head2 url_type()
147              
148             Returns the URL Type attribute of the search result.
149              
150             use strict; use warnings;
151             use WWW::Google::CustomSearch;
152              
153             my $api_key = 'Your_API_Key';
154             my $cx = 'Search_Engine_Identifier';
155             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
156             my $result = $engine->search("Google");
157             print "URL Type: ", $result->url_type, "\n";
158              
159             =head2 request()
160              
161             Returns the request L object used in the last
162             search.
163              
164             use strict; use warnings;
165             use WWW::Google::CustomSearch;
166              
167             my $api_key = 'Your_API_Key';
168             my $cx = 'Search_Engine_Identifier';
169             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
170             my $result = $engine->search("Google");
171             my $request = $result->request;
172              
173             =head2 nextPage()
174              
175             Returns the next page L object which can be used
176             to fetch the next page result.
177              
178             use strict; use warnings;
179             use WWW::Google::CustomSearch;
180              
181             my $api_key = 'Your_API_Key';
182             my $cx = 'Search_Engine_Identifier';
183             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
184             my $result = $engine->search("Google");
185             my $page = $result->nextPage;
186              
187             =head2 previousPage()
188              
189             Returns the previous page L object which can be
190             used to fetch the previous page result.
191              
192             use strict; use warnings;
193             use WWW::Google::CustomSearch;
194              
195             my $api_key = 'Your_API_Key';
196             my $cx = 'Search_Engine_Identifier';
197             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx, start => 2);
198             my $result = $engine->search("Google");
199             my $page = $result->previousPage;
200              
201             =head2 items()
202              
203             Returns list of search item L based on the search
204             criteria.
205              
206             use strict; use warnings;
207             use WWW::Google::CustomSearch;
208              
209             my $api_key = 'Your_API_Key';
210             my $cx = 'Search_Engine_Identifier';
211             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
212             my $result = $engine->search("Google");
213             my $items = $result->items;
214              
215             =head1 AUTHOR
216              
217             Mohammad S Anwar, C<< >>
218              
219             =head1 REPOSITORY
220              
221             L
222              
223             =head1 CONTRIBUTORS
224              
225             David Kitcher-Jones (m4ddav3)
226              
227             =head1 BUGS
228              
229             Please report any bugs or feature requests to C
230             rt.cpan.org>, or through the web interface at L.
231             I will be notified, and then you'll automatically be notified of progress on your
232             bug as I make changes.
233              
234             =head1 SUPPORT
235              
236             You can find documentation for this module with the perldoc command.
237              
238             perldoc WWW::Google::CustomSearch::Result
239              
240             You can also look for information at:
241              
242             =over 4
243              
244             =item * RT: CPAN's request tracker (report bugs here)
245              
246             L
247              
248             =item * AnnoCPAN: Annotated CPAN documentation
249              
250             L
251              
252             =item * CPAN Ratings
253              
254             L
255              
256             =item * Search CPAN
257              
258             L
259              
260             =back
261              
262             =head1 LICENSE AND COPYRIGHT
263              
264             Copyright (C) 2011 - 2015 Mohammad S Anwar.
265              
266             This program is free software; you can redistribute it and / or modify it under
267             the terms of the the Artistic License (2.0). You may obtain a copy of the full
268             license at:
269              
270             L
271              
272             Any use, modification, and distribution of the Standard or Modified Versions is
273             governed by this Artistic License.By using, modifying or distributing the Package,
274             you accept this license. Do not use, modify, or distribute the Package, if you do
275             not accept this license.
276              
277             If your Modified Version has been derived from a Modified Version made by someone
278             other than you,you are nevertheless required to ensure that your Modified Version
279             complies with the requirements of this license.
280              
281             This license does not grant you the right to use any trademark, service mark,
282             tradename, or logo of the Copyright Holder.
283              
284             This license includes the non-exclusive, worldwide, free-of-charge patent license
285             to make, have made, use, offer to sell, sell, import and otherwise transfer the
286             Package with respect to any patent claims licensable by the Copyright Holder that
287             are necessarily infringed by the Package. If you institute patent litigation
288             (including a cross-claim or counterclaim) against any party alleging that the
289             Package constitutes direct or contributory patent infringement,then this Artistic
290             License to you shall terminate on the date that such litigation is filed.
291              
292             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
293             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
294             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
295             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
296             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
297             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
298             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
299              
300             =cut
301              
302             1; # End of WWW::Google::CustomSearch::Result