CustomSearch/Result.pm

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