&?routine &?ROUTINE

Documentation for &?routine &?ROUTINE assembled from the following types:

language documentation Variables

From Variables

(Variables) &?routine &?ROUTINE

The compile time variable &?ROUTINE provides introspection about which routine the program is actually within. It returns an instance of Sub attached to the current routine. It does support the method .name to obtain the name of the called routine, as well as .signature and others method related to Sub:

sub awesome-sub { say &?ROUTINE.name }
awesome-sub # OUTPUT: awesome-sub 

The special variable &?ROUTINE allows also for recursion:

my $counter = 10;
sub do-work {
    say 'Calling myself other ' ~ $counter-- ~ ' times';
    &?ROUTINE() if ( $counter > 0 );