in reply to Re^3: Help migrating script from TELNET to SSH
in thread Help migrating script from TELNET to SSH
Delegation is a better approach. You can use AUTOLOAD to proxy all the methods unknown to your class to the slave object.
package My::Expect; use Expect; sub new { my $class = shift; my $expect = Expect->new(@_); bless { expect => $expect }, $class; } sub login { ... } sub enable { ... } sub cmd { ... } sub AUTOLOAD { my $method_name = $AUTOLOAD; $method_name =~ s/.*:://; my $sub = sub { shift->{expect}->$method_name(@_) } { no strict 'refs'; *$method_name = $sub; } goto &$sub; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Help migrating script from TELNET to SSH
by zengargoyle (Deacon) on Sep 23, 2011 at 11:37 UTC |