On Mar 8, 2009, at 11:48 AM, Ovid wrote:


I want to write a module which allows me to quickly detect if a method is overriding a parent class method (I already know about the method cache invalidation problem).

Potential uses would be for something like this:

   use Attribute::Override;

   use parent 'Some::Class';

   sub foo :override{...} # fails if it doesn't override
   sub bar {...}             # fails if it does override

Or:

   # needs to
   use Method::Override;
Method::Override::overriden(qw/foo/); # must be done after compilation

That can solve nasty problems where the developer accidentally overrides a parent method but doesn't realize it. Still trying to figure out a "good" interface, otherwise it will never get used (unless it's built in to the language, I suspect it will never get used anyway, but what the heck :)

Suggestions?

In Java, it's

   @Override
   public void foo() { ... }

which is very close to what you've suggested with :override. It is indeed quite useful because it checks both method name and signature. But for backward compatibility, it does not fail if it doesn't override, so there are third-party static analyzers (e.g. FindBugs) which take on that chore if you mark a superclass method as @MustOverride or something like that. That's sometimes done for clone() or the like.

Chris

Reply via email to