http://qs321.pair.com?node_id=465001

cybergeek has asked for the wisdom of the Perl Monks concerning the following question:

Hi guys, could you help me on that one : I'm using two classes, one derived from the other one. My code looks like this :

* Super class (called "A") contains:
sub Schedule { my ($self) = @_; $self->addTab(\&WatchLog); $self->addTab(\&SendEmail); } sub WatchLog { ... } sub SendEmail { ... } sub addTab { ... } sub go { my ($self) = @_; foreach my $code (@{$self->{CODETAB}}){ &{$code}($self)) } }
* The derived class (called "B") contains :
use base A .... sub Schedule { my ($self) = @_; $self->addTab(\&AddLocalTime); $self->addTab(\&WatchLog);#This method is defined in the paren +t class $self->addTab(\&SendEmail); #Same here } sub AddLocalTime { }

If I create an instance of B in a script and call $b->Schedule I get an "undefined subroutine" error for the two references corresponding to the parent's methods.

I don't know how to get a reference to a parent's method (A) from the derived class (B). One hinted me to use the can method.

More over, I have been told that using references to dynamically call methods was not the best approach. Do you have an idea about how I could do the same code while being more respectful of the object structure ?

My final aim being that the script having the B instance is able to modify the Schedule by removing, inserting, adding method calls into the Scheduler via various addTab,delTab .... methods.

Thanks

** UPDATED ** The solution which consist in calling the "can" method works !