File Coverage

blib/lib/IP/CountryFlag/UserAgent.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 4 0.0
condition n/a
subroutine 5 6 83.3
pod 1 1 100.0
total 20 33 60.6


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