=================================================================== RCS file: /cvs/trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm,v retrieving revision 1.37 retrieving revision 1.38 diff -u -r1.37 -r1.38 --- trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/02/05 23:09:59 1.37 +++ trango/Net-Telnet-Trango/lib/Net/Telnet/Trango.pm 2007/02/06 16:22:46 1.38 @@ -1,6 +1,6 @@ package Net::Telnet::Trango; -# $RedRiver: Trango.pm,v 1.36 2007/02/05 21:09:26 andrew Exp $ +# $RedRiver: Trango.pm,v 1.37 2007/02/05 23:09:59 andrew Exp $ use strict; use warnings; use base 'Net::Telnet'; @@ -45,6 +45,9 @@ our $VERSION = '0.01'; +my $EMPTY = q{}; +my $SPACE = q{ }; + my %PRIVATE = ( is_connected => 0, logged_in => 0, @@ -217,6 +220,10 @@ Does the same as reboot() +=head2 B - alias of save_ss() + +Does the same as save_ss() + =head1 COMMANDS Most of these are just shortcuts to C METHOD)>, @@ -339,6 +346,7 @@ bye => 'exit', restart => 'reboot', Host => 'host', + save_systemseting => 'save_ss', ); my %ACCESS = map { $_ => 1 } qw( @@ -371,7 +379,7 @@ $cmd{$k} = $COMMANDS{$method}{$k}; } $cmd{'String'} ||= $method; - $cmd{'args'} .= ' ' . shift if ( @_ == 1 ); + $cmd{'args'} .= $SPACE . shift if ( @_ == 1 ); return $self->cmd( %cmd, @_ ); } @@ -505,7 +513,7 @@ sub su_password { my $self = shift; - my $new_pass = shift || ''; + my $new_pass = shift || $EMPTY; my $su = shift || 'all'; unless ( defined $new_pass ) { @@ -515,7 +523,7 @@ } return $self->cmd( - String => 'su password ' . $su . ' ' . $new_pass . ' ' . $new_pass, + String => 'su password ' . $su . $SPACE . $new_pass . $SPACE . $new_pass, expect => $success, ); } @@ -557,8 +565,8 @@ # su ipconfig return $self->cmd( - String => 'su ipconfig ' . $suid . ' ' . $new_ip . ' ' - . $new_subnet . ' ' + String => 'su ipconfig ' . $suid . $SPACE . $new_ip . $SPACE + . $new_subnet . $SPACE . $new_gateway, expect => $success, ); @@ -661,10 +669,10 @@ $self->last_error("Invalid MAC '$mac'"); return; } - $new_mac = join ' ', $new_mac =~ /../g; + $new_mac = join $SPACE, $new_mac =~ /../g; my $string = - 'sudb add ' . $suid . ' ' . $type . ' ' . $cir . ' ' . $mir . ' ' + 'sudb add ' . $suid . $SPACE . $type . $SPACE . $cir . $SPACE . $mir . $SPACE . $new_mac; return $self->cmd( String => $string, expect => $success ); @@ -744,7 +752,7 @@ return; } - my $string = 'sudb modify ' . $suid . ' ' . $opt . ' ' . $value; + my $string = 'sudb modify ' . $suid . $SPACE . $opt . $SPACE . $value; return $self->cmd( String => $string, expect => $success ); } @@ -879,7 +887,7 @@ } } if ( $cfg{'args'} ) { - $cmd{'String'} .= ' ' . $cfg{'args'}; + $cmd{'String'} .= $SPACE . $cfg{'args'}; } my @lines; @@ -928,7 +936,16 @@ } } else { - $self->last_error("Error with command ($cfg{'String'}): $last"); + my $err; + if (grep { /\[ERR\]/ } @lines) { + $err = _decode_lines(@lines); + } + + if (ref $err eq 'HASH' && $err ->{ERR}) { + $self->last_error($err->{ERR} ); + } else { + $self->last_error("Error with command ($cfg{'String'}): $last"); + } return; } } @@ -940,7 +957,7 @@ my %conf; - my $key = ''; + my $key = $EMPTY; my $val = undef; my @vals; my $in_key = 0; @@ -951,7 +968,7 @@ my @chars = split //, $line; - my $last_key = ''; + my $last_key = $EMPTY; foreach my $c (@chars) { if ( $c eq '[' || $c eq "\r" || $c eq "\n" ) { @@ -978,17 +995,17 @@ # Special case for these bastids. my $new = $last_key; $new =~ s/\s+\S+$//; - $key = $new . " " . $key; + $key = $new . $SPACE . $key; } $conf{$key} = $val; $last_key = $key; - $key = ''; + $key = $EMPTY; } elsif ($val) { push @vals, $val; } - $val = ''; + $val = $EMPTY; } elsif ( $c eq ']' ) {