Well, as far as making it
impossible to subclass, no, I don't think that's doable.
However making things difficult is easy. (isn't it always?)
Suppose you have a method selfcheck, that checks the species of itself before running each other method (and at destruction):
package Foo::Bar;
my @lineage = ('Mom', 'Dad');
@ISA = (@lineage);
sub selfcheck {
die "You can\'t change who I am." unless __PACKAGE__ eq 'Foo::Bar';
map {
die "You can\'t change who my parents are." unless $lineage[$_] eq
+ $ISA[$_]
} (0..(scalar @ISA - 1));
}
sub DESTROY {
$self->Foo::Bar::selfcheck;
}
sub method_name {
my $self=shift;
$self->Foo::Bar::selfcheck;
# method stuff here
}
sub method_name2 {
$self->Foo::Bar::selfcheck;
# method stuff here
}
Now, you can overload all methods in the child class, but if you do you aren't really subclassing. You might as well subclass an anonymous hash. If you don't cover all bases, then the first time an inherited method is called, the program will die uglily and point out to the foolish programmer the error of his ways.
- d