| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Google::UserAgent; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$WWW::Google::UserAgent::VERSION = '0.22'; |
|
4
|
|
|
|
|
|
|
$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.22 |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
|
15
|
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
66535
|
use 5.006; |
|
|
3
|
|
|
|
|
23
|
|
|
17
|
3
|
|
|
3
|
|
1867
|
use Data::Dumper; |
|
|
3
|
|
|
|
|
20324
|
|
|
|
3
|
|
|
|
|
206
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
3
|
|
|
3
|
|
2002
|
use HTTP::Tiny; |
|
|
3
|
|
|
|
|
150267
|
|
|
|
3
|
|
|
|
|
126
|
|
|
20
|
3
|
|
|
3
|
|
1572
|
use WWW::Google::UserAgent::Exception; |
|
|
3
|
|
|
|
|
13
|
|
|
|
3
|
|
|
|
|
123
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
3
|
|
|
3
|
|
25
|
use Moo; |
|
|
3
|
|
|
|
|
6
|
|
|
|
3
|
|
|
|
|
13
|
|
|
23
|
3
|
|
|
3
|
|
924
|
use namespace::autoclean; |
|
|
3
|
|
|
|
|
7
|
|
|
|
3
|
|
|
|
|
26
|
|
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
has 'api_key' => ( is => 'ro', required => 1 ); |
|
26
|
|
|
|
|
|
|
has 'ua' => ( is => 'rw', default => sub { HTTP::Tiny->new(agent => "WWW-Google/0.01"); } ); |
|
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. |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub get { |
|
42
|
0
|
|
|
0
|
1
|
|
my ($self, $url) = @_; |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
|
45
|
0
|
|
|
|
|
|
my $response = $ua->request('GET', $url); |
|
46
|
0
|
|
|
|
|
|
my @caller = caller(1); |
|
47
|
0
|
0
|
|
|
|
|
@caller = caller(2) if $caller[3] eq '(eval)'; |
|
48
|
|
|
|
|
|
|
|
|
49
|
0
|
0
|
|
|
|
|
unless ($response->{success}) { |
|
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. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub post { |
|
70
|
0
|
|
|
0
|
1
|
|
my ($self, $url, $headers, $content) = @_; |
|
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
|
0
|
|
|
|
|
@caller = caller(2) if $caller[3] eq '(eval)'; |
|
76
|
|
|
|
|
|
|
|
|
77
|
0
|
0
|
|
|
|
|
unless ($response->{success}) { |
|
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<< >> |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 REPOSITORY |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * L |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * L |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item * L |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * L |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item * L |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * L |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 BUGS |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, |
|
118
|
|
|
|
|
|
|
or through the web interface at L. |
|
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 |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
L |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=item * CPAN Ratings |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
L |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=item * Search CPAN |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
L |
|
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 |
|
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
|
|
|
|
|
|
|
1; # End of WWW::Google::UserAgent |