blib/lib/Zed/Plugin/Exe/Port.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod n/a totaltotal 0.0% 0 / 68 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Zed::Plugin::Exe::Port;
2  
3 use Zed::Plugin;
4 use Zed::Output;
5 use Zed::Config::Env;
6 use Zed::Config::Space;
7  
8 use AnyEvent;
9 use AnyEvent::Socket;
10  
11 use strict;
12 use warnings;
13  
14 use constant MAX_CONN => 20;
15 use constant TIMEOUT => 5;
16  
17 =head1 SYNOPSIS
18  
19 port PORT
20 ex:
21 port 22
22  
23 =cut
24  
25 invoke "port" => sub {
26 my ( $port, $cv, @host) = shift;
27 debug("port: $port");
28 return unless @host = targets();
29  
30 $cv = AE::cv;
31  
32 my($all, @suc, @fail, $sub, $count) = scalar @host;
33  
34 $sub = sub
35 {
36 return unless my $host = shift @host;
37 $cv->begin;
38 tcp_connect $host, $port, sub {
39 $count += 1;
40 if( shift )
41 {
42 push @suc, $host;
43 result("$count/$all", 1, "$host port $port open..");
44 }else{
45 push @fail, $host;
46 result("$count/$all", 0, "$host port $port close..");
47 }
48 $cv->end;
49 $sub->();
50 },sub{ TIMEOUT };
51 };
52  
53 $sub->() for 1..MAX_CONN;
54 $cv->recv;
55  
56 (\@suc, \@fail);
57 };
58  
59 1;