As others have said, a
dispatch table is almost certainly the way to go. But, of course, there's more than one way to symbolically dereference a subroutine in compliance with
strictures
use strict;
sub foo { print "this is foo(@_)\n" }
sub bar { print "this is bar(@_)\n" }
__PACKAGE__->can($_)->('invoked via can()')
for qw/ foo bar /;
( \&$_ )->('invoked without a temp var')
for qw/ foo bar /;
__output__
this is foo(invoked via can())
this is bar(invoked via can())
this is foo(invoked without a temp var)
this is bar(invoked without a temp var)
In the first instance we're executing the subroutine returned by
UNIVERSAL, and in the second instance we're creating a sub reference and then executing (the parens are necessary for syntactical disambiguation).