File Coverage

blib/lib/WWW/Amazon/checkip.pm
Criterion Covered Total %
statement 21 21 100.0
branch 1 2 50.0
condition 0 4 0.0
subroutine 7 7 100.0
pod 1 1 100.0
total 30 35 85.7


line stmt bran cond sub pod time code
1             package WWW::Amazon::checkip;
2              
3 1     1   164686 use 5.008;
  1         3  
4 1     1   5 use strict;
  1         1  
  1         19  
5 1     1   4 use warnings;
  1         2  
  1         44  
6              
7             our $VERSION = '0.01';
8              
9 1     1   617 use HTTP::Tiny;
  1         36722  
  1         35  
10              
11             BEGIN {
12 1     1   6 require Exporter;
13 1     1   7 use base 'Exporter';
  1         2  
  1         96  
14 1         3 our @EXPORT = 'get_ip';
15 1         132 our @EXPORT_OK = ();
16             }
17              
18              
19             sub get_ip {
20 1     1 1 69 my $response = HTTP::Tiny->new->get("http://checkip.amazonaws.com/");
21             die sprintf 'Error fetching ip: %s %s',
22             ($response->{status} || ''),
23 1 50 0     162994 ($response->{reason} || '') unless $response->{success};
      0        
24 1         4 chomp $response->{content};
25 1         12 return $response->{ content };
26             }
27              
28             1;
29              
30             =pod
31              
32             =encoding UTF-8
33              
34             =head1 NAME
35              
36             WWW::Amazon::checkip - Returns your ip address using L
37              
38             =head1 VERSION
39              
40             version 0.01
41              
42             =head1 SYNOPSIS
43              
44             use WWW::Amazon::checkip;
45             my $ip = get_ip();
46              
47             or from the command line
48              
49             perl -MWWW::Amazon::checkip -E 'say get_ip'
50              
51             =head1 EXPORTS
52              
53             Exports the C function.
54              
55             =head1 FUNCTIONS
56              
57             =head2 get_ip
58              
59             Returns your external ipv4 address.
60              
61             =head1 SEE ALSO
62              
63             L - a similar module that returs your up address
64              
65             L - a similar module that returns your ip address and more
66              
67             L - a similar module that returns your ip address
68              
69             L - a wrapper module that uses up to 3 services to retrieve your IP address
70              
71             =head1 AUTHOR
72              
73             Jose Luis Martinez Torres
74              
75             Based on the work by David Farrell for L
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2017 by CAPSiDE
80              
81             This code is distributed under the Apache 2 License. The full text of the
82             license can be found in the LICENSE file included with this module.
83              
84             =cut