in reply to Moose and caller() for current method

Why would you need that? Wouldn't you usually already know the name of the method when you define it?

Replies are listed 'Best First'.
Re^2: Moose and caller() for current method
by ait (Hermit) on Jul 13, 2010 at 17:19 UTC
    Thanks.
    The question is: I could hardcode the method name in the code below instead of using caller, or perhaps Moose offers an easier way to determine the method name being executed. The reasons are the same anyone would need caller in the first place. Maybe I'm looking at this from the caller's perpective and it is the called object's method the one who should introspect the caller's object method?
    sub hey { &waka(((caller(0))[3]=~m/::(\w+)$/)); } sub waka { my $who = shift; print "$who called waka\n"; }

      The only good reason for doing this is error reporting, in which case Carp::cluck() does the job perfectly.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.
        Not quite the only good reason. In building something like a simple FSM it is useful to know the action being executed to validate for certain parameters to execute that action. This could be set by the calling sub as a parameter or the called sub to introspect. I'm thinking it should be the called sub instead of what I'm trying to do, but want to use Moose's best practices.