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.sub INIT { ... my $ref = $inheriting_class->can($method); if (! defined($ref)|| defined(&$method) && $ref == \&$method) { $bad = 1; warn ...; } }
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
in thread Interfaces in Perl?
by gregorovius
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |