sub new {
my ($class, @args) = @_;
my $this;
unless (defined @args) {
$this = $class->SUPER::new(); # call zero-arg ctor
return bless($this, $class); # rebless to our class
} else {
# do argument checking to figure out what ought to go
# to the superclass ctor and what needs to be initialized here.
$this = $class->SUPER::new(@some_args);
# then initialize the parts of the object that are unique to this class
return bless($this, $class); # rebless to our class
}
####
sub new {
my ($class, %args) = @_;
my $this = $class->SUPER::new(%args);
# Do additional processing on the args, e.g ...
$$this{foo} = $args{foo};
return bless($this, $class); # rebless to our class
}
##
##
package SomeSuperclass;
sub new {
my $class = shift();
my $this = {};
bless($this, $class);
$this->_init(@_);
return $this;
}
##
##
package SomeSubclass;
use base SomeSuperclass;
sub _init {
my ($this, $foo, $bar, $baz) = @_;
$this->SUPER::_init($bar, $baz);
$$this{foo} = $foo;
}