UserAgent.pm

filter: Statementstmt 56.4% 22 / 39 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 2 / 2 totaltotal 51.7% 30 / 58 CC 5 SCAR 18.1
CC
5
Cov
47%
get
12.0
post
12.0
__ANON__
1.1
CRAP 6.1
↑ Summary UserAgent/DataTypes.pm »
1 package WWW::Google::UserAgent;
2  
3 3 $WWW::Google::UserAgent::VERSION = '0.21';
4 3 $WWW::Google::UserAgent::AUTHORITY = 'cpan:MANWAR';
5  
6 =head1 NAME
7  
8 WWW::Google::UserAgent - Low-level HTTP request handler for Google API.
9  
10 =head1 VERSION
11  
12 Version 0.21
13  
14 =cut
15  
16 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 3 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 3 ▶use WWW::Google::UserAgent::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 has 'api_key' => ( is => 'ro', required => 1 );
26 0 ▶has 'ua' => ( is => 'rw', default => sub { HTTP::Tiny->new(agent => "WWW-Google/0.01"); } );
Subroutine __ANON__: not called CC=1 SCAR=1.2
27  
28 =head1 DESCRIPTION
29  
30 It provides common useragent library for Google API services.
31  
32 =head1 METHODS
33  
34 =head2 get($url)
35  
36 It expects one parameter i.e. URL and returns the standard response. On error
37 throws exception of type L<WWW::Google::UserAgent::Exception>.
38  
39 =cut
40  
41 sub get {
42 0 ▶ my ($self, $url) = @_;
Subroutine get: not called CC=3 SCAR=24.8
Pod documented
43  
44 0 my $ua = $self->ua;
45 0 my $response = $ua->request('GET', $url);
46 0 my @caller = caller(1);
47 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
48  
49 0 ▶ unless ($response->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"success"}) 0 0 0
50 WWW::Google::UserAgent::Exception->throw({
51 method => $caller[3],
52 code => $response->{status},
53 message => $response->{reason},
54 0 filename => $caller[1],
55 line_number => $caller[2] });
56 }
57  
58 0 return $response;
59 }
60  
61 =head2 post($url, \%headers, $content)
62  
63 It expects three parameters i.e. URL, Headers and Content in the same order and
64 returns the standard response. The c<$content> should be JSON formatted. On error
65 throws exception of type L<WWW::Google::UserAgent::Exception>.
66  
67 =cut
68  
69 sub post {
70 0 ▶ my ($self, $url, $headers, $content) = @_;
Subroutine post: not called CC=3 SCAR=24.8
Pod documented
71  
72 0 my $ua = $self->ua;
73 0 my $response = $ua->request('POST', $url, { headers => $headers, content => $content });
74 0 my @caller = caller(1);
75 0 ▶ @caller = caller(2) if $caller[3] eq '(eval)';
Branch: 1 branch
BranchTrueFalseTotal
if $caller[3] eq "(eval)" 0 0 0
76  
77 0 ▶ unless ($response->{success}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($response->{"success"}) 0 0 0
78 WWW::Google::UserAgent::Exception->throw({
79 method => $caller[3],
80 code => $response->{status},
81 message => $response->{reason},
82 0 filename => $caller[1],
83 line_number => $caller[2] });
84 }
85  
86 0 return $response;
87 }
88  
89 =head1 AUTHOR
90  
91 Mohammad S Anwar, C<< <mohammad.anwar at yahoo.com> >>
92  
93 =head1 REPOSITORY
94  
95 L<https://github.com/manwar/WWW-Google-UserAgent>
96  
97 =head1 SEE ALSO
98  
99 =over 4
100  
101 =item * L<WWW::Google::CustomSearch>
102  
103 =item * L<WWW::Google::Places>
104  
105 =item * L<WWW::Google::APIDiscovery>
106  
107 =item * L<WWW::Google::DistanceMatrix>
108  
109 =item * L<WWW::Google::URLShortener>
110  
111 =item * L<WWW::Google::PageSpeedOnline>
112  
113 =back
114  
115 =head1 BUGS
116  
117 Please report any bugs or feature requests to C<bug-www-google-useragent at rt.cpan.org>,
118 or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-UserAgent>.
119 I will be notified, and then you'll automatically be notified of progress on your
120 bug as I make changes.
121  
122 =head1 SUPPORT
123  
124 You can find documentation for this module with the perldoc command.
125  
126 perldoc WWW::Google::UserAgent
127  
128 You can also look for information at:
129  
130 =over 4
131  
132 =item * RT: CPAN's request tracker (report bugs here)
133  
134 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=WWW-Google-UserAgent>
135  
136 =item * AnnoCPAN: Annotated CPAN documentation
137  
138 L<http://annocpan.org/dist/WWW-Google-UserAgent>
139  
140 =item * CPAN Ratings
141  
142 L<http://cpanratings.perl.org/d/WWW-Google-UserAgent>
143  
144 =item * Search CPAN
145  
146 L<http://search.cpan.org/dist/WWW-Google-UserAgent/>
147  
148 =back
149  
150 =head1 LICENSE AND COPYRIGHT
151  
152 Copyright (C) 2014 - 2015 Mohammad S Anwar.
153  
154 This program is free software; you can redistribute it and/or modify it under
155 the terms of the the Artistic License (2.0). You may obtain a copy of the full
156 license at:
157  
158 L<http://www.perlfoundation.org/artistic_license_2_0>
159  
160 Any use, modification, and distribution of the Standard or Modified Versions is
161 governed by this Artistic License.By using, modifying or distributing the Package,
162 you accept this license. Do not use, modify, or distribute the Package, if you do
163 not accept this license.
164  
165 If your Modified Version has been derived from a Modified Version made by someone
166 other than you,you are nevertheless required to ensure that your Modified Version
167 complies with the requirements of this license.
168  
169 This license does not grant you the right to use any trademark, service mark,
170 tradename, or logo of the Copyright Holder.
171  
172 This license includes the non-exclusive, worldwide, free-of-charge patent license
173 to make, have made, use, offer to sell, sell, import and otherwise transfer the
174 Package with respect to any patent claims licensable by the Copyright Holder that
175 are necessarily infringed by the Package. If you institute patent litigation
176 (including a cross-claim or counterclaim) against any party alleging that the
177 Package constitutes direct or contributory patent infringement,then this Artistic
178 License to you shall terminate on the date that such litigation is filed.
179  
180 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
181 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
182 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
183 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
184 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
185 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
186 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
187  
188 =cut
189  
190 3 1; # End of WWW::Google::UserAgent
↑ Summary UserAgent/DataTypes.pm »