my %handler; for my $item (values %$spec) { my $n = $item->{name}; my $fetch; $result->{$n} = []; if (0 == $item->{arg_count}) { $fetch = sub() { push @{ $result->{$n}}, 1; }; } elsif (1 == $item->{arg_count}) { $fetch = sub($) { push @{ $result->{$n} }, @_; }; } elsif (2 == $item->{arg_count}) { $fetch = sub($$) { push @{ $result->{$n} }, [@_]; }; } else { $fetch = sub($;) { push @{ $result->{$n}}, [@_]; }; }; $handler{$n} = $fetch; }; # Install the subroutines for (keys %handler) { no strict 'refs'; *{$_} = $handler{ $_ }; }; # "execute" the config: my $cfg_str = join ";\n", "package " . __PACKAGE__, "#line $config_source#1", "$config_data", "1"; #warn $cfg_str; my $ok = eval $cfg_str; my $err = $@; if ($ok) { return $result } else { warn $err; return };