fix space before semicolumn
[APKPM.git] / lib / H1 / ZTEDSLAM.pm
old mode 100755 (executable)
new mode 100644 (file)
index 11d4fb5..8f9e856
@@ -1,93 +1,62 @@
 package H1::ZTEDSLAM;
-use warnings;
-use strict;
+use Moose;
 
-use Net::Telnet;
-use Data::Dump qw(dump);
+with 'H1::ZTE';
 
-sub hash {
-       my ($self,$ip,$port) = @_;
+sub connect {
+       my ( $self, $ip ) = @_;
 
-       warn "# hash $ip $port";
+       my $t = Net::Telnet->new( Timeout => 10, Prompt => '/#/' );
 
-my $t = Net::Telnet->new( Timeout => 10, Prompt => '/#/' );
+       $t->dump_log('/tmp/log') if $ENV{DEBUG};
 
-$t->dump_log('/tmp/log') if $ENV{DEBUG};
+       $t->open( $ip );
 
-warn "open";
-$t->open( $ip );
+       $t->print("");
+       $t->waitfor('/Login:/');
+       $t->print('admin');
+       $t->waitfor('/Password:/');
+       $t->print('admin');
+       $t->waitfor('/>/');
+       $t->print('en');
+       $t->waitfor('/Please input password:/');
+       $t->print('admin');
+       $t->waitfor('/#/');
 
-$t->print("");
-$t->waitfor('/Login:/');
-$t->print('admin');
-$t->waitfor('/Password:/');
-$t->print('admin');
-$t->waitfor('/>/');
-$t->print('en');
-$t->waitfor('/Please input password:/');
-$t->print('admin');
-$t->waitfor('/#/');
+       warn "login OK";
 
-warn "login OK";
-
-sub command {
-       my $command = shift;
-
-       $command .= ' ' . $port;
-
-       warn "# $command\n";
-       $t->print($command);
+       return $t;
+}
 
-       my $out;
-       while (1) {
-               my($prematch, $match) = $t->waitfor('/(Press any key to continue \(Q to quit\)|#)/');
-               $out .= $prematch;
-               last if $match eq '#';
-               $t->print('');
-       }
 
-       warn "## out = [$out]";
+sub parse {
+       my ( $self, $out ) = @_;
 
        my $hash;
        foreach my $line ( split(/[\n\r]+/, $out) ) {
-               warn "# $line\n";
-               if ( $line =~ m/^(\S+.*?)\s+:\s+(\S+.*)$/ ) {
+               warn "# $line\n" if $ENV{DEBUG};
+               if ( $line =~ m/^(\S+.*?)\s*:\s+(\S+.*)$/ ) {
                        my ($n,$v) = ($1,$2);
                        $n =~ s/\(.+\)//;
                        $hash->{$n} = $v;
-                       warn "## $n = $v\n";
+                       warn "## $n = $v\n" if $ENV{DEBUG};
                }
 
        }
 
-       warn dump $hash;
-
        return $hash;
 }
 
-our ( $row, $hash );
-
-sub copy {
-       foreach my $name (@_) {
-               warn "# copy $name ", dump( $row ),$/;
-               $row->{$name} = $hash->{$name};
-       }
-}
-
-$hash = command 'show interface';
-copy qw(
+sub commands {{
+       'show interface %s' => [ qw(
 AdminStatus
 LinkStatus
 LastLinkUpTime
-);
-
-$hash = command 'show adsl status';
-copy qw(
+       )],
+       'show adsl status %s' => [ qw(
 LineConfProfile
-);
-
-$hash = command 'show adsl physical';
-copy qw(
+       )],
+       'show adsl physical %s' => [ qw(
 AtucCurrSnrMgn
 AtucCurrAtn
 AtucCurrStatus
@@ -100,17 +69,8 @@ AturCurrStatus
 AturCurrOutputPwr
 AturAttainableRate
 AturDMTState
-);
-
-warn "# row = ",dump $row;
-
-warn "logout";
-$t->print('logout');
-$t->waitfor('/:/');
-$t->print('y');
-
-return $row;
+       )],
+}}
 
-} # sub
 1;