in reply to Abstract class methods
in thread Interfaces in Perl?
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Abstract class methods
by gregorovius (Friar) on Dec 01, 2000 at 06:15 UTC | |
by merlyn (Sage) on Dec 01, 2000 at 10:35 UTC | |
by tilly (Archbishop) on Dec 01, 2000 at 06:32 UTC | |
Re (tilly) 2 (try it): Abstract class methods
by tilly (Archbishop) on Dec 01, 2000 at 05:48 UTC | |
by Dominus (Parson) on Dec 01, 2000 at 06:01 UTC |