I'm finding myself repeatedly writing and rewriting the following kind of code:
my %default = (x => "a", y => "b");
sub new
{
my ($package, $config) = @_;
my $self = {%default};
for my $k (keys %default) {
$self->{$k} = $config->{$k} if defined $config->{$k};
}
for my $k (keys %$config) {
if (! exists $default{$k}) {
carp "Unknown config option $k\n";
}
}
bless $self;
# etc. etc.
}
Before I make my own module to do this, I was just wondering if there is anything already on CPAN like that? I just want this very simple above functionality, so suggesting using Moose is not a suitable answer to this question.