blib/lib/MYDan/Project/Check/Port.pm untested

filter: Statementstmt 0.0% 0 / 21 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 7 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 40 CC 3 SCAR 13.9
CC
3
Cov
0%
new
6.0
check
6.0
BEGIN
2.0
CRAP 4.0
1 package MYDan::Project::Check::Port;
2 use strict;
3 use warnings;
4 use Carp;
5 use IO::Socket::INET;
6  
7 # port: 8080
8 # type: tcp # type: udp default
9 # host: abc.foo.org # host: 127.0.0.1 default
10  
11 sub new
12 {
13 my ( $class, %self ) = @_;
14 confess "port undef.\n" unless defined $self{port};
15
16 $self{host} ||= '127.0.0.1';
17 $self{type} ||= 'tcp';
18  
19 bless \%self, ref $class || $class;
20 }
21  
22 sub check
23 {
24 my $this = shift;
25 my ( $port, $type, $host ) = @$this{qw( port type host )};
26  
27 IO::Socket::INET->new(
28 PeerAddr => "$host:$port", Blocking => 0,
29 Timeout => 10, Type => SOCK_STREAM,
30 Proto => $type
31 )
32 ? print "$type => $host:$port :OK\n"
33 : die "$type => $host:$port :FAIL\n";
34  
35 }
36  
37 1;
38 __END__