Commit | Line | Data |
16c23894 |
1 | package Sub::Name; |
54595ea8 |
2 | # ABSTRACT: (re)name a sub |
16c23894 |
3 | |
54595ea8 |
4 | =pod |
16c23894 |
5 | |
6 | =head1 SYNOPSIS |
7 | |
8 | use Sub::Name; |
9 | |
10 | subname $name, $subref; |
11 | |
12 | $subref = subname foo => sub { ... }; |
13 | |
14 | =head1 DESCRIPTION |
15 | |
d73d8321 |
16 | This module has only one function, which is also exported by default: |
16c23894 |
17 | |
18 | =head2 subname NAME, CODEREF |
19 | |
a0f015f5 |
20 | Assigns a new name to referenced sub. If package specification is omitted in |
16c23894 |
21 | the name, then the current package is used. The return value is the sub. |
22 | |
a0f015f5 |
23 | The name is only used for informative routines (caller, Carp, etc). You won't |
24 | be able to actually invoke the sub by the given name. To allow that, you need |
16c23894 |
25 | to do glob-assignment yourself. |
26 | |
a0f015f5 |
27 | Note that for anonymous closures (subs that reference lexicals declared outside |
28 | the sub itself) you can name each instance of the closure differently, which |
d73d8321 |
29 | can be very useful for debugging. |
16c23894 |
30 | |
fa1e9525 |
31 | =head1 SEE ALSO |
32 | |
33 | =over 4 |
34 | |
35 | =item * |
36 | L<Sub::Identify> - for getting information about subs |
37 | |
38 | =back |
39 | |
54595ea8 |
40 | =head1 COPYRIGHT AND LICENSE |
16c23894 |
41 | |
54595ea8 |
42 | This software is copyright (c) 2004, 2008 by Matthijs van Duin, all rights reserved; |
43 | copyright (c) 2014 cPanel Inc., all rights reserved. |
16c23894 |
44 | |
a0f015f5 |
45 | This program is free software; you can redistribute it and/or modify |
16c23894 |
46 | it under the same terms as Perl itself. |
47 | |
48 | =cut |
49 | |
50 | use 5.006; |
51 | |
52 | use strict; |
53 | use warnings; |
54 | |
16c23894 |
55 | use base 'Exporter'; |
16c23894 |
56 | |
57 | our @EXPORT = qw(subname); |
58 | our @EXPORT_OK = @EXPORT; |
59 | |
54595ea8 |
60 | use XSLoader; |
61 | XSLoader::load( |
62 | __PACKAGE__, |
63 | exists $Sub::Name::{VERSION} |
64 | ? ${ $Sub::Name::{VERSION} } |
65 | : (), |
66 | ); |
16c23894 |
67 | |
68 | 1; |