# from Ovid
# on Sunday 08 March 2009 09:48:
>I want to write a module which allows me to quickly detect if a method
> is overriding a parent class method
>...
> sub foo :override{...} # fails if it doesn't override
> sub bar {...} # fails if it does override
>...
> use Method::Override;
> Method::Override::overriden(qw/foo/);
>
>That can solve nasty problems where the developer accidentally
> overrides a parent method but doesn't realize it.
For clarity and not having to type a method name twice, I think the
attribute implementation would be the way to go. Alternatively, you
might go with something like:
override(foo => sub {...});
Where you then install the sub foo into caller. The advantage would be
that you have the ability to e.g. wrap it with a sub to enforce the
constraint at runtime (iff you're willing to pay that cost) and
possibly some options. You've probably noticed the drawback where you
need to run INIT{} or something to perform the not-overridden check.
Or:
define(bar => sub {...});
Yeah, that forces syntax to be rather widespread.
I always seem to want to be able to install something like a UNITCHECK
block into caller from import(). Alas.
And anyway, the attributes implementation can probably be made to do
wrapping for run-time checking and various other features.
How does Perl 6 (or some other language) do (or allow for) this?
--Eric
--
software: a hypothetical exercise which happens to compile.
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------