| 1 | 7 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 2 | 7 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | package Test::RequiresInternet; | ||||||||||||||
| 4 | 7 | $Test::RequiresInternet::VERSION = '0.05'; | |||||||||||||
| 5 | # ABSTRACT: Easily test network connectivity | ||||||||||||||
| 6 | |||||||||||||||
| 7 | |||||||||||||||
| 8 | 7 | ▶ | use Socket; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 6 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=6 SCAR=18.0
| |||||||||||||||
| 11 | 6 | ▶ | skip_all("NO_NETWORK_TESTING") if env("NO_NETWORK_TESTING"); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 12 | |||||||||||||||
| 13 | 5 | my $namespace = shift; | |||||||||||||
| 14 | |||||||||||||||
| 15 | 5 | my $argc = scalar @_; | |||||||||||||
| 16 | 5 | ▶ | if ( $argc == 0 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 17 | 0 | push @_, 'www.google.com', 80; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | elsif ( $argc % 2 != 0 ) { | ||||||||||||||
| 20 | 1 | die "Must supply server and a port pairs. You supplied " . (join ", ", @_) . "\n"; | |||||||||||||
| 21 | } | ||||||||||||||
| 22 | |||||||||||||||
| 23 | 4 | ▶ | while ( @_ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 5 | my $host = shift; | |||||||||||||
| 25 | 5 | my $port = shift; | |||||||||||||
| 26 | |||||||||||||||
| 27 | 5 | local $@; | |||||||||||||
| 28 | |||||||||||||||
| 29 | 5 | eval {make_socket($host, $port)}; | |||||||||||||
| 30 | |||||||||||||||
| 31 | 5 | ▶ | if ( $@ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 3 | skip_all("$@"); | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | } | ||||||||||||||
| 35 | } | ||||||||||||||
| 36 | |||||||||||||||
| 37 | 5 | ▶ | sub make_socket { | ||||||||||||
|
Subroutine
make_socket: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||
| 38 | 5 | my ($host, $port) = @_; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 5 | my $portnum; | |||||||||||||
| 41 | 5 | ▶ | if ($port =~ /\D/) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 42 | 2 | $portnum = getservbyname($port, "tcp"); | |||||||||||||
| 43 | } | ||||||||||||||
| 44 | else { | ||||||||||||||
| 45 | 3 | $portnum = $port; | |||||||||||||
| 46 | } | ||||||||||||||
| 47 | |||||||||||||||
| 48 | 5 | ▶ | die "Could not find a port number for $port\n" if not $portnum; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | |||||||||||||||
| 50 | 3 | ▶ | my $iaddr = inet_aton($host) or die "no host: $host\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 51 | |||||||||||||||
| 52 | 2 | my $paddr = sockaddr_in($portnum, $iaddr); | |||||||||||||
| 53 | 2 | my $proto = getprotobyname("tcp"); | |||||||||||||
| 54 | |||||||||||||||
| 55 | 2 | ▶ | socket(my $sock, PF_INET, SOCK_STREAM, $proto) or die "socket: $!\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 56 | 2 | ▶ | connect($sock, $paddr) or die "connect: $!\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | 2 | ▶ | close ($sock) or die "close: $!\n"; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 58 | |||||||||||||||
| 59 | 2 | 1; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 6 | ▶ | sub env { | ||||||||||||
|
Subroutine
env: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 63 | 6 | ▶ | exists $ENV{$_[0]} && $ENV{$_[0]} eq '1' | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 64 | } | ||||||||||||||
| 65 | |||||||||||||||
| 66 | 4 | ▶ | sub skip_all { | ||||||||||||
|
Subroutine
skip_all: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 67 | 4 | my $reason = shift; | |||||||||||||
| 68 | 4 | print "1..0 # Skipped: $reason"; | |||||||||||||
| 69 | 4 | exit 0; | |||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 7 | 1; | |||||||||||||
| 73 | |||||||||||||||
| 74 | __END__ | ||||||||||||||