|
|
| Keep It Simple, Stupid | |
| PerlMonks |
Re: Abstract class methodsby Dominus (Parson) |
| on Nov 30, 2000 at 23:40 UTC ( [id://44274]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
As Randal pointed out, this won't work if the abstract class itself
implements stub routines. But it also fails
for a bigger
reason: At the time you do the can test,
the
subroutine whose existence you are trying to check
has not yet been compiled! The solution I suggested in the other thread fixes this problem by deferring the check until after compilation is complete. My sample code doesn't deal properly with inherited methods, however. I think a hybrid approach might be effective. You would use the INIT block approach that I showed, and then in the INIT block, use ->can, and check to see if the returns subroutine was equal to the stub:
What is this doing? It tries to resolve the method with $can, the way Ben shows. If there is no such method, that's bad. If there is a method, it then checks to see if there's a stub routine in the abstract class itself, and, if so, if the subclass's method is actually this stub; if so, that's bad too. You still have the problem with abstract classes that inherit from other abstract classes, of course, but I think solving these problems should be just a SMOP.
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||||||