Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl 6: Getting the name of function from inside it

In Perl 6, how can I get name of the function/subroutine from within its body, at runtime?

For example,

sub foo {
    say "My name is: " ~  <WHAT-API-HERE??> ;
}
...
foo();

The above code should print:

My name is: foo

I've looked in places like MOP, FAQ, and Functions.

like image 711
Harry Avatar asked Sep 18 '16 03:09

Harry


1 Answers

sub foo { say &?ROUTINE.name }
foo

displays:

foo

See the &$ROUTINE doc.

like image 79
raiph Avatar answered Oct 22 '22 08:10

raiph