in reply to Re^7: Function name in a variable, can't recall the concept (introspection with ->can )
in thread Function name in a variable, can't recall the concept

Some code that gets a reference to the sub by name. What that code is doesn't matter, though it could be as simple as \&{ $pkg . '::' . $name }.

  • Comment on Re^8: Function name in a variable, can't recall the concept (introspection with ->can )
  • Download Code

Replies are listed 'Best First'.
Re^9: Function name in a variable, can't recall the concept (introspection with ->can )
by LanX (Saint) on Apr 19, 2019 at 18:28 UTC
    > could be as simple as \&{ $pkg . :: . $name }.

    nope, this will autovivify a missing function glob $name and return a broken coderef.

    try again.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      You're missing the point. I'm not proposing a solution; I'm saying that yours is ludicrous. It makes absolutely no sense to use

      my $sub = @{ get_array_by_name($pkg, 'ISA') } ? get_sub_by_name($pkg, $name) : $pkg->can($name);

      instead of

      my $sub = get_sub_by_name($pkg, $name);

      The implementation of get_sub_by_name isn't relevant to that point.

        it's getting more and more ridiculous, I'm out.

        edit

        I replied to

        1) What's wrong with that? 2) You're missing the point. It doesn't matter what the code is, since + it's needed no matter what.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice