I like to initialize (and create) my fields in the constructor (even if only to undef), so my subclass constructors would look like:
my new {
my ($class, ...) = @_;
my $self = $class->SUPER::new(...);
$self->{...} = ...;
$self->{...} = ...;
return $self;
}
or
use constant IDX_... => Parent::NEXT_IDX() + 0;
use constant IDX_... => Parent::NEXT_IDX() + 1;
use constant NEXT_IDX => Parent::NEXT_IDX() + 2;
my new {
my ($class, ...) = @_;
my $self = $class->SUPER::new(...);
push(@$self,
..., # IDX_...
..., # IDX_...
);
return $self;
}
depending whether it's a hash- or array-based object.
Nothing requires this, however. I could rely on the fact that non-existant hash and array fields evaluate to undef, but I prefer the self-documenting properties of my method.
|