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