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