Here's a little something I toss into packages that should be subclassed. I do something similar for "virtual" functions, too.
-v
sub new {
my $this = shift;
my $class = ref($this) || $this;
# This part prevents a user from creating an
# instance of the package, but still permits
# subclasses to call the parent's new().
my (undef, $filename, $line) = caller;
$filename =~ s/^.*\///;
die "Abstract class $class must " .
"be subclassed at $filename " .
"line $line.\n"
if $class =~ /^Processor$/;
bless $self, $class;
return $self;
The subclassed code's new looks like this:
sub new {
my $this = shift;
my $class = ref($this) || $this;
my $self = $this->SUPER::new(@_);
bless $self, $class;
return $self;
}