I'm a fan of Hash::Util when working with hash-based objects, myself. I tend to use init routines that look
like this (to make it impossible to accidentally create a hashkey that's not supposed to be there):
use Hash::Util qw( lock_keys unlock_keys );
sub init {
my $self = shift;
my $args = shift;
unlock_keys( %{ $self } );
my @attributes = qw(
something_or_other
another_something
);
foreach my $field (@attributes) {
$ATTRIBUTES{ $field } = 1;
$self->{ $field } = $args->{ $field };
}
lock_keys( %{ $self } );
return $self;
}
|