File Coverage

blib/lib/WWW/Google/CustomSearch/Page.pm
Criterion Covered Total %
statement 11 14 78.5
branch n/a
condition n/a
subroutine 4 5 80.0
pod 1 1 100.0
total 16 20 80.0


line stmt bran cond sub pod time code
1             package WWW::Google::CustomSearch::Page;
2              
3             $WWW::Google::CustomSearch::Page::VERSION = '0.39';
4             $WWW::Google::CustomSearch::Page::AUTHORITY = 'cpan:MANWAR';
5              
6             =head1 NAME
7              
8             WWW::Google::CustomSearch::Page - Placeholder for Google JSON/Atom Custom Search Page.
9              
10             =head1 VERSION
11              
12             Version 0.39
13              
14             =cut
15              
16 5     5   93 use 5.006;
  5         19  
17 5     5   27 use Data::Dumper;
  5         9  
  5         232  
18              
19 5     5   29 use Moo;
  5         9  
  5         34  
20 5     5   1576 use namespace::autoclean;
  5         23  
  5         41  
21              
22             has [qw(api_key cx searchTerms inputEncoding title totalResults outputEncoding)] => (is => 'ro', required => 1);
23             has 'count' => (is => 'ro');
24             has 'safe' => (is => 'ro', default => sub { return 'off' });
25             has 'startIndex' => (is => 'ro', default => sub { return 1 });
26              
27             =head1 DESCRIPTION
28              
29             Provides the interface to the individual search page based on the search criteria.
30              
31             =head1 METHODS
32              
33             =head2 safe()
34              
35             Returns the safety level of the search.
36              
37             use strict; use warnings;
38             use WWW::Google::CustomSearch;
39              
40             my $api_key = 'Your_API_Key';
41             my $cx = 'Search_Engine_Identifier';
42             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
43             my $result = $engine->search("Google");
44             my $page = $result->nextPage;
45             print "Safety Level: ", $page->safe, "\n";
46              
47             =head2 count()
48              
49             Returns the 'count' attribute of the search.
50              
51             use strict; use warnings;
52             use WWW::Google::CustomSearch;
53              
54             my $api_key = 'Your_API_Key';
55             my $cx = 'Search_Engine_Identifier';
56             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
57             my $result = $engine->search("Google");
58             my $page = $result->nextPage;
59             print "Page count: ", $page->count, "\n";
60              
61             =head2 searchTerms()
62              
63             Returns the 'searchTerms' attribute of the search.
64              
65             use strict; use warnings;
66             use WWW::Google::CustomSearch;
67              
68             my $api_key = 'Your_API_Key';
69             my $cx = 'Search_Engine_Identifier';
70             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
71             my $result = $engine->search("Google");
72             my $page = $result->nextPage;
73             print "Search Terms: ", $page->searchTerms, "\n";
74              
75             =head2 startIndex()
76              
77             Returns the 'startIndex' attribute of the search.
78              
79             use strict; use warnings;
80             use WWW::Google::CustomSearch;
81              
82             my $api_key = 'Your_API_Key';
83             my $cx = 'Search_Engine_Identifier';
84             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
85             my $result = $engine->search("Google");
86             my $page = $result->nextPage;
87             print "Start Index: ", $page->startIndex, "\n";
88              
89             =head2 title()
90              
91             Returns the 'title' attribute of the search.
92              
93             use strict; use warnings;
94             use WWW::Google::CustomSearch;
95              
96             my $api_key = 'Your_API_Key';
97             my $cx = 'Search_Engine_Identifier';
98             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
99             my $result = $engine->search("Google");
100             my $page = $result->nextPage;
101             print "Title: ", $page->title, "\n";
102              
103             =head2 totalResults()
104              
105             Returns the 'totalResults' attribute of the search.
106              
107             use strict; use warnings;
108             use WWW::Google::CustomSearch;
109              
110             my $api_key = 'Your_API_Key';
111             my $cx = 'Search_Engine_Identifier';
112             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
113             my $result = $engine->search("Google");
114             my $page = $result->nextPage;
115             print "Total Results: ", $page->totalResults, "\n";
116              
117             =head2 inputEncoding()
118              
119             Returns the 'inputEncoding' attribute of the search.
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             my $page = $result->nextPage;
129             print "Input Encoding: ", $page->inputEncoding, "\n";
130              
131             =head2 outputEncoding()
132              
133             Returns the 'outputEncoding' attribute of the search.
134              
135             use strict; use warnings;
136             use WWW::Google::CustomSearch;
137              
138             my $api_key = 'Your_API_Key';
139             my $cx = 'Search_Engine_Identifier';
140             my $engine = WWW::Google::CustomSearch->new(api_key => $api_key, cx => $cx);
141             my $result = $engine->search("Google");
142             my $page = $result->nextPage;
143             print "Output Encoding: ", $page->outputEncoding, "\n";
144              
145             =head2 fetch()
146              
147             Perform a fresh search based on the previous input data and returns L
148             object.
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             my $page = $result->nextPage;
158             my $nextResult = $page->fetch;
159              
160             =cut
161              
162             sub fetch {
163 0     0 1   my ($self) = @_;
164              
165 0           my $engine = WWW::Google::CustomSearch->new({ api_key => $self->api_key, cx => $self->cx, start => $self->startIndex });
166 0           return $engine->search($self->searchTerms);
167             }
168              
169             =head1 AUTHOR
170              
171             Mohammad S Anwar, C<< >>
172              
173             =head1 REPOSITORY
174              
175             L
176              
177             =head1 CONTRIBUTORS
178              
179             David Kitcher-Jones (m4ddav3)
180              
181             =head1 BUGS
182              
183             Please report any bugs or feature requests to C
184             rt.cpan.org>, or through the web interface at L.
185             I will be notified, and then you'll automatically be notified of progress on your
186             bug as I make changes.
187              
188             =head1 SUPPORT
189              
190             You can find documentation for this module with the perldoc command.
191              
192             perldoc WWW::Google::CustomSearch::Page
193              
194             You can also look for information at:
195              
196             =over 4
197              
198             =item * RT: CPAN's request tracker (report bugs here)
199              
200             L
201              
202             =item * AnnoCPAN: Annotated CPAN documentation
203              
204             L
205              
206             =item * CPAN Ratings
207              
208             L
209              
210             =item * Search CPAN
211              
212             L
213              
214             =back
215              
216             =head1 LICENSE AND COPYRIGHT
217              
218             Copyright (C) 2011 - 2015 Mohammad S Anwar.
219              
220             This program is free software; you can redistribute it and / or modify it under
221             the terms of the the Artistic License (2.0). You may obtain a copy of the full
222             license at:
223              
224             L
225              
226             Any use, modification, and distribution of the Standard or Modified Versions is
227             governed by this Artistic License.By using, modifying or distributing the Package,
228             you accept this license. Do not use, modify, or distribute the Package, if you do
229             not accept this license.
230              
231             If your Modified Version has been derived from a Modified Version made by someone
232             other than you,you are nevertheless required to ensure that your Modified Version
233             complies with the requirements of this license.
234              
235             This license does not grant you the right to use any trademark, service mark,
236             tradename, or logo of the Copyright Holder.
237              
238             This license includes the non-exclusive, worldwide, free-of-charge patent license
239             to make, have made, use, offer to sell, sell, import and otherwise transfer the
240             Package with respect to any patent claims licensable by the Copyright Holder that
241             are necessarily infringed by the Package. If you institute patent litigation
242             (including a cross-claim or counterclaim) against any party alleging that the
243             Package constitutes direct or contributory patent infringement,then this Artistic
244             License to you shall terminate on the date that such litigation is filed.
245              
246             Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
247             CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
248             WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
249             NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
250             REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
251             INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
252             OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
253              
254             =cut
255              
256             1; # End of WWW::Google::CustomSearch::Page