I want to get a pointer to an object method, for instance for this class
class Foo {
has $thing = "baz";
method bar() { say $thing }
};
sub quux( Callable $flimflam ) {
$flimflam()
};
my $foo = Foo.new;
I want to grab of the $foo.bar
method pointer to pas it to quux. However, this
quux(&($foo.bar))
fails with Type check failed in binding to parameter '$flimflam'; expected Callable but got Bool (Bool::True) in sub quux
This does not work either
quux($foo.bar)
maybe because it takes no parameters; however, if we change the definition of bar
to:
method bar($some ) { say $some ~ $thing }
Then the error for the call above becomes Too few positionals passed; expected 2 arguments but got 1 in method bar
, the error creeps up to bar itself, which means the object itself does not get in.
I have checked out this answer, but it's for a class method (new) and it involves using the meta-object protocol. Would there be a simpler way of doing that?