Syntactic Confectionery Delight | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
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 reply to Re: Abstract class methods
by Dominus
|
|