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};
60 my ($self,$command) = @_;
61 my $out = $self->command_out( $command );
62 my $hash = $self->parse( $out );
64 warn "## ", $self->ip, " $command ",dump $hash;
70 my ($self,$port) = @_;
73 $self->{port} = $port;
75 warn "# hash $ip $port";
81 @what = keys %$hash unless @what;
82 foreach my $name (@what) {
83 $row->{$name} = $hash->{$name};
87 my $commands = $self->commands;
88 foreach my $command ( keys %$commands ) {
89 $hash = $self->command( sprintf($command, $port) );
90 copy ref $commands->{$command} eq 'ARRAY' ? @{$commands->{$command}} : undef;
93 if ( $self->can('custom') ) {
94 $hash = $self->custom( $port );
98 warn "# row = ",dump $row if $ENV{DEBUG};
100 $row = $self->fixup_row( $row ) if $self->can('fixup_row');
110 my $t = delete $telnet->{$ip};
112 # die "no $ip telnet in ",dump($telnet) unless $t;
116 # FIXME removed but needed?
125 # warn "# DESTROY telnet = ",dump( keys %$telnet );
126 $self->logout($_) foreach keys %$telnet;