Is it possible to get a subroutine reference from a Moose object in Perl? For example:
package A;
use Moose;
1;
sub mm {
print "Hello\n";
}
Then I make an A
object:
use warnings;
use strict;
use A;
my $o=A->new();
my $sub=\&{$o->mm};
$sub->();
This does not work. It gives error:
Undefined subroutine &main::1
If I know that $o
is an A
object, I can of course solve this using my $sub=\&A::mm;
instead.
But in the case, where I am only given $o
is it possible to extract the reference to a function mm
?