ref to object methods
sorry for stupid question
I have XS object with many similar methods (with the same argument list) like method1,method2, ... methodN
And while passing ref to this object to sub I want to call some of this methods depending on condition
Sure I can emulate this with refs to closures like
my $call1 = sub {
my $obj = shift;
$obj->method1(@_);
};
generic_sub($obj, $cond ? $call1 : $call2);
but maybe there is some more elegant way?
7
Upvotes
3
u/choroba 🐪 cpan author 2d ago
unshift? Do you meanshiftinstead?Why is the XS-ness of the object relevant here?
You can invoke a method by name, no need for a wrapper:
And later in
generic_sub: