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