package SomePackage; use base 'Class::Base'; ## super-simple 'new' sub new { my $self = shift; bless { one => 1, two => 2 }, $self; } sub set { my $self = shift; my $attrib = shift; return $self->error("No such attribute '$attrib'") unless exists $self->{$attrib} my $value = shift; # check to make sure we're setting the same kind of reference, if it matters if (ref $self->{$attrib} && ref $value ne ref $self->{$attrib}) { return $self->error("Reference types do not match for '$attrib' set.") } $self->{$attrib} = $value; return 1; # true on success } sub get { my ($self, $attrib) = @_; return $self->error("Attribute '$attrib' doesn't exist") unless exists $self->{$attrib}; my $value = $self->{$attrib}; return $value; } 1;