Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by LanX (Saint)
on Apr 15, 2019 at 11:07 UTC ( [id://1232572]=note: print w/replies, xml ) Need Help??


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

> No, you shouldn't. can performs a method lookup, not a sub lookup.

->can does a sub lookup if @ISA is empty, and the content of @ISA is introspectable too.

And using a package for a module and a class is a pretty dubious concept.

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

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

Replies are listed 'Best First'.
Re^4: Function name in a variable, can't recall the concept (introspection with ->can )
by ikegami (Patriarch) on Apr 16, 2019 at 19:21 UTC

    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?

      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:  <%-{-{-{-<

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1232572]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-18 04:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found