2 # ABSTRACT: (re)name a sub
10 subname $name, $subref;
12 $subref = subname foo => sub { ... };
16 This module has only one function, which is also exported by default:
18 =for stopwords subname
20 =head2 subname NAME, CODEREF
22 Assigns a new name to referenced sub. If package specification is omitted in
23 the name, then the current package is used. The return value is the sub.
25 The name is only used for informative routines (caller, Carp, etc). You won't
26 be able to actually invoke the sub by the given name. To allow that, you need
27 to do glob-assignment yourself.
29 Note that for anonymous closures (subs that reference lexicals declared outside
30 the sub itself) you can name each instance of the closure differently, which
31 can be very useful for debugging.
36 * L<Sub::Identify> - for getting information about subs
37 * L<Sub::Util> - set_subname is another implementation of C<subname>
41 =head1 COPYRIGHT AND LICENSE
43 This software is copyright (c) 2004, 2008 by Matthijs van Duin, all rights reserved;
44 copyright (c) 2014 cPanel Inc., all rights reserved.
46 This program is free software; you can redistribute it and/or modify
47 it under the same terms as Perl itself.
56 use Exporter 5.57 'import';
58 our @EXPORT = qw(subname);
59 our @EXPORT_OK = @EXPORT;
64 exists $Sub::Name::{VERSION}
65 ? ${ $Sub::Name::{VERSION} }