From: "Michael Kraus" <[EMAIL PROTECTED]> > If a sublass has overrides a method in a superclass, and the > subclasses method calls the superclass's method, is there any > mechanism to detect that the superclass' method has been overridden? > > > I'm wanting to write a method in an abstract class that must be > overriden by it's children. If it is called directly (i.e. without > being overriden) then it registers an error, but if its called via an > overriding method then do some common functionality. > > I'm guessing there is no in-built functionality for this, and I'll > have to examine my classes to discover how to test for it myself. Is > it possible to confirm this?
if I understand you right you want to have something like this: package Base::Class; ... sub theMethod { if (called from a child's theMethod()) { do something sensible } else { die "Base::Class->theMethod() has to be overriden!\n"; } } ... package First::Child; use base 'Base::Class'; ... sub theMethod { my $self = shift; do something $self->SUPER::theMethod(); do something more } ... package Second::Child; use base 'Base::Class'; ... # no sub theMethod {} package main; my $obj1 = new First::Class; $obj1->theMethod(); # goes fine my $obj2 = new Second::Class; $obj2->theMethod(); # dies __END__ Right? I think the best you can get is to use caller(). This will tell you whether your Base::Class::theMethod() is called from a some::package::theMethod() or from something else. If you want to be more safe you may try to make sure the some::package inherits from Base::Class ( some::package->isa('Base::Class') ). Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>