In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] (Bob Showalter) writes: >Michael Kraus wrote: >> 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. > >That's not an abstract class. > >Anyway, here's how to do it: > > sub foo { > my $self = shift; > my $class = ref $self; > if ($class->can('foo') eq \&foo) { > print "$class does not override foo\n"; > } > else { > print "$class overrides foo\n"; > } > } > >See perldoc UNIVERSAL for caveats on the can() method.
TMTOWTDI: sub foo { my $self = shift; if (ref $self eq __PACKAGE__) { print "Direct call\n"; } else { print "Called from subclass\n"; } -- Peter Scott http://www.perldebugged.com/ *** NEW *** http://www.perlmedic.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>