File Coverage

blib/lib/IP/CountryFlag/UserAgent.pm
Criterion Covered Total %
statement 17 25 68.0
branch 0 4 0.0
condition n/a
subroutine 6 7 85.7
pod 1 1 100.0
total 24 37 64.8


line stmt bran cond sub pod time code
1             package IP::CountryFlag::UserAgent;
2              
3             $IP::CountryFlag::UserAgent::VERSION = '0.12';
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.12
13              
14             =cut
15              
16 4     4   79 use 5.006;
  4         16  
17 4     4   25 use Data::Dumper;
  4         11  
  4         201  
18              
19 4     4   1868 use HTTP::Tiny;
  4         148563  
  4         151  
20 4     4   1481 use IP::CountryFlag::UserAgent::Exception;
  4         17  
  4         148  
21              
22 4     4   31 use Moo;
  4         10  
  4         14  
23 4     4   1133 use namespace::clean;
  4         8  
  4         29  
24              
25             has 'ua' => (is => 'rw', default => sub { HTTP::Tiny->new(agent => "IP/CountryFlag/v1"); } );
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.
33              
34             =cut
35              
36             sub get {
37 0     0 1   my ($self, $url) = @_;
38              
39 0           my $ua = $self->ua;
40 0           my $response = $ua->request('GET', $url);
41 0           my @caller = caller(1);
42 0 0         @caller = caller(2) if $caller[3] eq '(eval)';
43              
44 0 0         unless ($response->{success}) {
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<< >>
60              
61             =head1 REPOSITORY
62              
63             L
64              
65             =head1 BUGS
66              
67             Please report any bugs / feature requests to C,
68             or through the web interface at L.
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
85              
86             =item * AnnoCPAN: Annotated CPAN documentation
87              
88             L
89              
90             =item * CPAN Ratings
91              
92             L
93              
94             =item * Search CPAN
95              
96             L
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
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             1; # End of IP::CountryFlag::UserAgent