On 09/13/2017 05:15 PM, ToddAndMargo wrote:
On 09/13/2017 05:01 PM, Brandon Allbery wrote:
On Wed, Sep 13, 2017 at 7:56 PM, ToddAndMargo <toddandma...@zoho.com <mailto:toddandma...@zoho.com>> wrote:

    I am trying to convert this from Perl 5:

         my $WhoCalledMe = ( caller(0) )[1];

    I use it inside a sub to determine who called the sub.

    How is this done in P6?


You want the callframe method. Note that it can be a bit more complex than perl 5's caller because there are more things that act like call frames. https://docs.perl6.org/routine/callframe (but most of the actual documentation is at https://docs.perl6.org/type/CallFrame).

Hi Brandon,

Would this be what I am looking for?


for 1..* -> $level {
     given callframe($level) -> $frame {
         when $frame ~~ CallFrame {
             next unless $frame.code ~~ Routine;
             say $frame.code.package;
             last;
         }
         default {
             say "no calling routine or method found";
             last;
         }
     }
}


And I can't put it in a pm6 or I would get the next
level down.

Thank you for the help!

-T

Would there be a way of catching the next level up?
That way I could put it in a pm6

Reply via email to