Subject: | Mark methods as overridden |
I'd like to optionally be able to specify an 'override' attribute for
methods:
package Soldier;
use Method::Signatures 'override';
use parent 'Some::Class';
method new (%args) {
return bless {%args}, $self;
}
method name : override { ... } # fails if there is no parent method
method rank { ... } # fails if it overrides
I realize that probably isn't the best way to go about this, but the
background is at:
http://stackoverflow.com/questions/623680/detecting-overridden-methods-in-perl
Basically, Perl silently overrides parent methods (many OO languages
do). C++ sort of works around this by forcing someone to declare a
method as virtual if it's to be overrideable, but that means when you're
in a subclass you can't just glance at a method and know it's overriding
a parent method. I think the notation should be in the parent method.
MRO::Compat creates an mro::get_pkg_gen method to let you know if a
packages method cache has been invalidated.
Also, this is problematic if a parent class delays installing a method
in a symbol table.
It's the nature of dynamic languages that this is fraught with error,
but twice in the past week I've been bitten by code which silently
overrode a method. This can be very hard to debug (and should there be
a mechanism to allow this code to be a no-op in a production environment?)
Feel free to mark this as rejected. Just thought I would throw it out
there.
Cheers,
Ovid