Assume you have a module (eg Foo.pm) with package Foo. Inside it exists many subroutine definitions, including ones for foo and default.
package Foo;
sub foo { ... }
sub default { ... }
Inside your main perl program (eg test.pl) what is the proper way to assign a value to a subref and call it, or otherwise call default?
sub call_proc {
my $args = shift;
my $subref = $args->{proc_name} // 'default';
&$Foo::subref(); # <====== Wrong
}
call_proc({ proc_name => q{foo} }); # make the call
\&$nameisn’t caught by strict refs, so:If we’re talking about methods, then it would be: