You can easilly get by strict if you use this:
eval('&' . $action . '()');
if( $@ ) {
die "Usage\n";
}
It might be good to check the text of the exception here to make sure it's from a missing sub. You might even be able to do this:
my $subref = \&{$action};
die "Usage" unless defined &$subref();
I haven't tried that last though.
There's just no good reason to use OO here, and it makes the code more confusing and JAPH-ish. Maybe there's something else in your program that justifies OO, but this problem doesn't.
Incidentally, a nicer way to write that dispatch table from your above comment would be something like this (untested): my %dispatch = (
'this' => \&do_this,
'that' => \&do_that,
);
if (defined $dispatch{$action}) {
&$dispatch{$action};
} else { die "Usage\n"; }
|