File Coverage

blib/lib/Test2/Require/Internet.pm
Criterion Covered Total %
statement 25 25 100.0
branch 5 6 83.3
condition n/a
subroutine 6 6 100.0
pod 0 1 0.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             package Test2::Require::Internet;
2              
3 2     2   674520 use strict;
  2         3  
  2         71  
4 2     2   9 use warnings;
  2         8  
  2         116  
5 2     2   35 use 5.014;
  2         7  
6 2     2   1081 use IO::Socket::INET;
  2         48761  
  2         15  
7 2     2   1822 use parent qw( Test2::Require );
  2         407  
  2         16  
8              
9             # ABSTRACT: Skip tests if there is no internet access
10             our $VERSION = '0.12'; # VERSION
11              
12              
13             sub skip
14             {
15 3     3 0 286109 my(undef, %args) = @_;
16 3 100       43 return 'NO_NETWORK_TESTING' if $ENV{NO_NETWORK_TESTING};
17              
18 2 50       5 my @pairs = @{ $args{'-tcp'} || [ 'httpbin.org', 80 ] };
  2         14  
19 2         6 while(@pairs)
20             {
21 2         7 my $host = shift @pairs;
22 2         5 my $port = shift @pairs;
23              
24 2         14 my $sock = IO::Socket::INET->new(
25             PeerAddr => $host,
26             PeerPort => $port,
27             Proto => 'tcp',
28             );
29              
30 2 100       1042 return "Unable to connect to $host:$port/tcp" unless $sock;
31              
32 1         9 $sock->close;
33             }
34              
35 1         77 undef;
36             }
37              
38             1;
39              
40             __END__