in reply to Re^3: 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

If I understand correctly, you're saying it's ok to use can if you make sure to check that @ISA is empty first?

1) You didn't do that, so I guess you're saying your code is wrong too?

2) You'd need to use an alternative approach when @ISA isn't empty. Why not use that all the time?

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

Replies are listed 'Best First'.
Re^5: Function name in a variable, can't recall the concept (introspection with ->can )
by LanX (Saint) on Apr 16, 2019 at 21:30 UTC
    No I'm saying if one is really worried that the inspected module is a class, one can easily check @ISA.

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

      What about a base class? Do such classes always have a declared  @ISA that is empty?


      Give a man a fish:  <%-{-{-{-<

        Actually I don't understand the discussion anymore, if the OP was willing to inspect a class the natural solution would be ->can.

        If he wasn't inspecting a class ->can would do the job, too.

        Are there pathological cases where an approach might break?

        Of course, this is Perl, with high flexibility to bend internals.

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

      So it is as I said. You're suggesting that we 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);

      That's ludicrous.

        > get_sub_by_name

        which get_sub_by_name?

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

        > You're suggesting that we use

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

        No, I don't!

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