Skip to content

[Enhancement] Allow names for anonymous subroutines. #23993

@KES777

Description

@KES777

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions