11 use Data::Dump qw(dump);
13 use Moose::Util::TypeConstraints;
14 use Regexp::Common qw(net);
18 => where {/^$RE{net}{IPv4}$/}
19 => message { 'invalid IP address'};
21 has 'ip' => ( is => 'rw', isa => 'IPAddr' );
30 return $telnet->{$ip} if exists $telnet->{$ip};
33 my $t = $self->connect( $ip );
35 return $telnet->{$ip} = $t;
39 my ($self,$command) = @_;
41 my $t = $self->telnet;
48 my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
50 last if $match eq '#';
54 warn "## out = [$out]" if $ENV{DEBUG};
56 my $hash = $self->parse( $out );
58 warn "## ", $self->ip, " $command ",dump $hash;
64 my ($self,$port) = @_;
67 $self->{port} = $port;
69 warn "# hash $ip $port";
75 @what = keys %$hash unless @what;
76 foreach my $name (@what) {
77 $row->{$name} = $hash->{$name};
81 my $commands = $self->commands;
82 foreach my $command ( keys %$commands ) {
83 $hash = $self->command( sprintf($command, $port) );
84 copy ref $commands->{$command} eq 'ARRAY' ? @{$commands->{$command}} : undef;
87 warn "# row = ",dump $row if $ENV{DEBUG};
89 $row = $self->fixup_row( $row ) if $self->can('fixup_row');
99 my $t = delete $telnet->{$ip};
101 # die "no $ip telnet in ",dump($telnet) unless $t;
105 # FIXME removed but needed?
114 # warn "# DESTROY telnet = ",dump( keys %$telnet );
115 $self->logout($_) foreach keys %$telnet;