Sub::Name β (Re)name a sub
| Use Case | Command | Description |
|---|---|---|
| Rename an existing subroutine reference | subname $name, $subref |
Assigns a new informative name to $subref for debugging and stack traces |
| Rename an anonymous subroutine | $subref = subname foo => sub { ... } |
Creates a named reference to a closure; useful for differentiating closures in traces |
version 0.26
use Sub::Name;
subname $name, $subref;
$subref = subname foo => sub { ... };
This module has only one function, which is also exported by default:
π οΈ subname NAME, CODEREF β Assigns a new name to referenced sub. If package specification is omitted in the name, then the current package is used. The return value is the sub.
The name is only used for informative routines (caller, Carp, etc). You won't be able to actually invoke the sub by the given name. To allow that, you need to do glob-assignment yourself.
Note that for anonymous closures (subs that reference lexicals declared outside the sub itself) you can name each instance of the closure differently, which can be very useful for debugging.
set_subname is another implementation of "subname"Bugs may be submitted through the RT bug tracker <https://rt.cpan.org/Public/Dist/Display.html?Name=Sub-Name> (or bug-Sub-Name AT rt.org <mailto:bug-Sub-Name AT rt.org>).
There is also an irc channel available for users of this distribution, at "#toolchain" on "irc.perl.org" <irc://irc.perl.org/#toolchain>.
Matthijs van Duin <xmath AT cpan.org>
This software is copyright (c) 2004, 2008 by Matthijs van Duin, all rights reserved; copyright (c) 2014 cPanel Inc., all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-17 06:49 @216.73.217.35
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)