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
    > Am I missing something?

    A dollar sign?

    $connectObj->eof(); # ^ # | # Here

    "doesn't seem to work" is a vague description. Pasting the actual error messages would help us help you better.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,