| 1 | package Net::PortTest; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.014002; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||||||||||||||||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # This allows declaration use Net::PortTest ':all'; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||||||||||||||||||||||||||||||||||||||||||
| 17 | # will save memory. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our %EXPORT_TAGS = ( 'all' => [ qw( | |||||||||||||||||||||||||||||||||||||||||
| 19 | ok alias run_tests | ||||||||||||||||||||||||||||||||||||||||||
| 20 | ) ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | |||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 1 | our @EXPORT = qw( | |||||||||||||||||||||||||||||||||||||||||
| 25 | ok alias run_tests | ||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | our $VERSION = '0.01_02'; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $portmap = {}; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | sub on { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $port = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
on: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | my $sub = shift; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | carp 'Not a valid port' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$port =~ /^\d+$/u and ($port < 56000 and $port > 0)
$port < 56000 and $port > 0
MC/DC0%0/3
$port =~ /^\d+$/u and ($port < 56000 and $port > 0)
$port =~ /^\d+$/u
$port < 56000
$port > 0
Truth table0%0/4
A and B and C
A= $port =~ /^\d+$/uB= $port < 56000C= $port > 0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | unless( $port =~ /^\d+$/ and ( $port < 56000 and $port > 0 ) ); | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | carp 'You must provide a function reference' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | unless( ref( $sub ) eq 'CODE' ); | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # Register the handler with the port | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | $portmap->{$port} = $sub; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | sub alias { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my @vars = reverse @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alias: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $port = shift @vars; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my @aliases = reverse @vars; | |||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | if( ref \@aliases eq 'ARRAY' ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | for my $a ( @aliases ){ | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if( defined $portmap->{$port} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | on $a => $portmap->{$port}; | |||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | carp "Can't create alias: target port $port not defined\n"; | |||||||||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | sub run_tests { | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | my $hostname = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
run_tests: not called CC=4 SCAR=26.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | my @ports = @_; | |||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $result_map = {}; | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | use Time::HiRes qw/ time sleep /; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | for my $port ( @ports ){ | |||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | if( defined $portmap->{$port} ){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | print "Port testing port $port against $hostname\n"; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $fnref = $portmap->{$port}; | |||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $sock = IO::Socket::INET->new( | |||||||||||||||||||||||||||||||||||||||||
| 80 | PeerAddr => $hostname, | ||||||||||||||||||||||||||||||||||||||||||
| 81 | PeerPort => $port, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | Proto => 'tcp' | ||||||||||||||||||||||||||||||||||||||||||
| 83 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | carp 'Could not create socket' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | unless $sock; | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | my $start = time; | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my ($rc,$res) = &$fnref( $sock ); | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $end = time; | |||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | # Return the time deltas, plus whatever is returned | ||||||||||||||||||||||||||||||||||||||||||
| 93 | # by the handler | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | $result_map->{$port} = { | |||||||||||||||||||||||||||||||||||||||||
| 95 | delta => ( $end - $start ), | ||||||||||||||||||||||||||||||||||||||||||
| 96 | res => $res, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | rc => $rc, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | warn "No handler for port $port defined\n"; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return $result_map; | |||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | sub import { | ||||||||||||||||||||||||||||||||||||||||||
| 108 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 1 | ▶ | my ( $package, $file, $line ) = caller; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | 1 | for( qw(on alias run_tests)){ | |||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | *{$package . "::$_"} = \&$_; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | __END__ | ||||||||||||||||||||||||||||||||||||||||||