perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

[Enhancement] Allow names for anonymous subroutines.

Open KES777 opened this issue 3 days ago • 4 comments

Description When code has many ANON subs it becomes nightmare to debug that code. Code traces becomes not so useful.

There are many workarounds exists for the issue: https://www.perlmonks.org/?node_id=304883 https://www.masteringperl.org/2014/02/naming-anonymous-subroutines/ https://metacpan.org/pod/Sub::Util#set_subname

Steps to Reproduce

sub{ die "Here" }->();

This will show something like "died at main::ANON line 1".

Expected behavior I am not sure what is the technical issue to not have this elegant solution:

sub name{ die "Here" }->();

OR:

my $x = sub name{ die "Here" }; $x->();

Which will show "name" instead of "__ ANON__" for dumped stack frames.

The difference with the regular subroutines will be that it will not be available through STASH and only affects names in frames returned by the call to caller.

at the moment both variants are "syntax error".

KES777 avatar Dec 09 '25 00:12 KES777