| 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
| |||||||||||||||||||||||||||||||
| 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
Condition0%0/4
$response->{'status'} || ''
$response->{'reason'} || ''
MC/DC0%0/1
$response->{'status'} || ''
$response->{'status'}
MC/DC0%0/1
$response->{'reason'} || ''
$response->{'reason'}
Truth table0%0/2
A
A= $response->{'status'}
Truth table0%0/2
A
A= $response->{'reason'}
| |||||||||||||||||||||||||||||||
| 28 | 2 | decode_json($response->{content}); | |||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 1 | 1; | |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||
| 35 | __END__ | ||||||||||||||||||||||||||||||