sub gen_sub { my $self = shift; my $type = shift; my $sub_ref = sub { if (defined $self{$type}) { $value = $self{$type}; return $value; } else { return undef; } } *{"get_$type"} = $sub_ref; } #### sub AUTOLOAD { no strict "refs"; my ($self, $value) = @_; # alias these to make it easier later if ($AUTOLOAD =~ /::get_(\w+)/) { *{$AUTOLOAD} = sub { return $_[0]->{$1} }; return $self->{$1}; } elsif ($AUTOLOAD =~ /::set_(\w+)/){ *{$AUTOLOAD} = sub { $_[0]->{$1} = $_[1] }; $self->[$1] = $value; return; } # handle other methods here or throw a warning }