File Coverage

blib/lib/WWW/ipinfo.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition 0 4 0.0
subroutine 8 8 100.0
pod 1 1 100.0
total 38 43 88.3


line stmt bran cond sub pod time code
1 1     1   109664 use strict;
  1         2  
  1         50  
2 1     1   6 use warnings;
  1         2  
  1         63  
3             package WWW::ipinfo;
4             $WWW::ipinfo::VERSION = '0.05';
5 1     1   965 use HTTP::Tiny;
  1         39551  
  1         38  
6 1     1   17 use 5.008;
  1         3  
  1         32  
7 1     1   719 use JSON;
  1         11552  
  1         4  
8              
9             # ABSTRACT: Returns your ip address and geolocation data using L
10              
11              
12             BEGIN {
13 1     1   4 require Exporter;
14 1     1   133 use base 'Exporter';
  1         1  
  1         91  
15 1         2 our @EXPORT = 'get_ipinfo';
16 1         93 our @EXPORT_OK = ();
17             }
18              
19              
20              
21             sub get_ipinfo {
22 2     2 1 7 my $ip = shift;
23 2 100       8 my $url = $ip ? "http://ipinfo.io/$ip/json" : "http://ipinfo.io/json";
24 2         14 my $response = HTTP::Tiny->new->get($url);
25 2 50 0     1084800 die join(' ', 'Error fetching ip: ',
      0        
26             ($response->{status} or ''),
27             ($response->{reason} or '')) unless $response->{success};
28 2         55 decode_json($response->{content});
29             }
30              
31              
32              
33             1;
34              
35             __END__