NERDVANA has asked for the wisdom of the Perl Monks concerning the following question:

Hi, in one of my XS modules I want to do the equivalent of PKG->can($method). It feels like this would be in the perl api, but keyword searching for 'can' is somewhat futile. Is there any way to run this operation more efficiently than literally building a call to method 'can'?

Replies are listed 'Best First'.
Re: Is there a Perl API (XS) for ->can ?
by Anonymous Monk on Oct 08, 2021 at 09:06 UTC
      Thanks! gv_fetchmeth was what I was looking for.
Re: Is there a Perl API (XS) for ->can ?
by LanX (Saint) on Oct 08, 2021 at 08:39 UTC
    FWIW: My idea was that a direct call is more efficient.

    Hence the XS equivalent to

    $sub = UNIVERSAL::can($obj, "print");

    But UNIVERSAL says

    > # but never do this!

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

    A reply falls below the community's threshold of quality. You may see it by logging in.