package MyClass;
# fully functional constructor method
sub new {
# if we're trying to instantiate the abstract class, die
my $class = shift;
die "abstract class must be subclassed" if $class eq 'MyClass';
# do some processing, all with lexically scoped variables
# ...
# call (as of yet) unimplemented function to return a hashref
my $self = _underthehood();
die "_underthehood() not implemented" if ref $self ne 'HASH';
# bless hashref as instance of the current package, and return it
bless $self, $class;
return $self;
}
# unimplemented member method
sub _underthehood {
return;
}
1;
####
package MyClass::Implemented;
use base 'MyClass';
# newly implemented member method
sub _underthehood {
# do some processing on the given arguments,
#creating a populated hashref
my $hashref = { 'key' => 'value' };
return $hashref;
}
1;
####
#!/usr/bin/perl -w
use strict;
use MyClass::Implemented;
my $obj = new MyClass::Implemented();