in reply to Re: How to call sub defined in a variable?
in thread How to call sub defined in a variable?
Usually the lack of distinction between function and method is a problem in Perl, but here it means that you can use can() on a package name even if it's not a class and get back a subroutine reference even if it's not a method.
package My::Awesome::Package; use 5.010; sub foo { ... } sub bar { ... } sub baz { ... } package main; for my $func (qw( foo bar baz quux )) { next unless my $func_ref = My::Awesome::Package->can( $func ); say "Found code for '$func': ", $func->(); }
|
|---|