Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to modify the behaviour of common modules like Net::Telnet (slightly).
I want to re-define one or two Net::Telnet functions, while inheriting the rest. But it doesn't seem to work for no obvious reason. For example, in this script I can call the inherited ->new() and ->open() functions, but not the inherited ->eof() function.
Am I missing something?
#!/usr/bin/perl -- use strict; use diagnostics; use warnings; # No error produced: # my $connectObj = Net::Telnet->new(); # $connectObj->open( # Host => 'localhost', # Port => 5555, # ); # # connectObj->eof(); # Produces an error: my $connectObj = MyTelnet->new(); $connectObj->open( Host => 'localhost', Port => 5555, ); connectObj->eof(); ### Inherited Net::Telnet package ################################### { package MyTelnet; use base ("Net::Telnet"); # (This is what Net::Telnet->eof actually looks like) # sub eof { # my ($self) = @_; # # *$self->{net_telnet}{eofile}; # } # end sub eof }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Can't get Perl inheritance working
by choroba (Cardinal) on Oct 04, 2016 at 09:00 UTC |