package Abstract;
use Carp;
my @inheritors;
sub import {
my $caller = caller;
push @inheritors, $caller;
}
my @abstract_methods = qw(swim fly);
sub INIT {
my $bad = 0;
for my $class (@inheritors) {
for my $meth (@abstract_methods) {
no strict 'refs';
unless (defined &{"${class}::$meth"}) {
$bad=1;
warn "Class $class inherits from Abstract, but does not define $meth.\n";
}
}
}
croak "Compilation aborted" if $bad;
}
1;
####
Class Fish inherits from Abstract, but does not define fly.
Compilation aborted at fish.pl line 0
####
package Fish;
use Abstract;
sub swim {
"bloop bloop bloop";
}
1;