blib/lib/WWW/ipinfo.pm

filter: Statementstmt 100% 27 / 27 Branchbran 75.0% 3 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 84.7% 39 / 46 SCAR 16.2
CC
5
Cov
86%
get_ipinfo
6.4
BEGIN
1.0
BEGIN
1.0
CRAP 5.1
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package WWW::ipinfo;
4 1 $WWW::ipinfo::VERSION = '0.04';
5 1 ▶use HTTP::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # ABSTRACT: Returns your ip address and geolocation data using L<http://ipinfo.io>
10  
11  
12 BEGIN {
13 1 ▶ require Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶ use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 our @EXPORT = 'get_ipinfo';
16 1 our @EXPORT_OK = ();
17 }
18  
19  
20  
21 sub get_ipinfo {
22 2 ▶ my $ip = shift;
Subroutine get_ipinfo: called CC=5 SCAR=18.6
Pod documented
23 2 ▶ my $url = $ip ? "http://ipinfo.io/$ip/json" : "http://ipinfo.io/json";
Branch: 1 branch
BranchTrueFalseTotal
$ip ? : 1 1 2
24 2 my $response = HTTP::Tiny->new->get($url);
25 die join(' ', 'Error fetching ip: ',
26 ($response->{status} or ''),
27 2 ▶ ($response->{reason} or '')) unless $response->{success};
Branch: 1 branch
BranchTrueFalseTotal
unless $response->{"success"} 0 2 2
Condition0%0/4
$response->{'status'} || ''
l!l
00
$response->{'reason'} || ''
l!l
00
MC/DC0%0/1
$response->{'status'} || ''
$response->{'status'}
MC/DC0%0/1
$response->{'reason'} || ''
$response->{'reason'}
Truth table0%0/2
A
A= $response->{'status'}
Aresult
11
00
Truth table0%0/2
A
A= $response->{'reason'}
Aresult
11
00
28 2 decode_json($response->{content});
29 }
30  
31  
32  
33 1 1;
34  
35 __END__
↑ Summary