in reply to Re^3: Help migrating script from TELNET to SSH
in thread Help migrating script from TELNET to SSH

Subclassing external modules that are not designed for doing so is not a good idea. You could unintentionally give to some of your methods names already used on the base class (now, or in a future release) and break it.

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

    For a module that has only 4 versions on CPAN going back 9 years (and those only bug fixes) that is meant to mimic the interface of an even older Tcl library, whose purpose boils down to matching and sending strings through a pty...

    I'm not going to lose any sleep over the possibility of Expect conflicts.