53f1859809585b7f01b1a1ec6886909245fbf62a
[p5sagit/Sub-Name.git] / lib / Sub / Name.pm
1 package Sub::Name;
2 # ABSTRACT: (re)name a sub
3
4 =pod
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
16 This module has only one function, which is also exported by default:
17
18 =for stopwords subname
19
20 =head2 subname NAME, CODEREF
21
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.
24
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.
28
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.
32
33 =head1 SEE ALSO
34
35 =for :list
36 * L<Sub::Identify> - for getting information about subs
37 * L<Sub::Util> - set_subname is another implementation of C<subname>
38
39 =for stopwords cPanel
40
41 =head1 COPYRIGHT AND LICENSE
42
43 This software is copyright (c) 2004, 2008 by Matthijs van Duin, all rights reserved;
44 copyright (c) 2014 cPanel Inc., all rights reserved.
45
46 This program is free software; you can redistribute it and/or modify
47 it under the same terms as Perl itself.
48
49 =cut
50
51 use 5.006;
52
53 use strict;
54 use warnings;
55
56 our $VERSION = '0.13';
57
58 use Exporter 5.57 'import';
59
60 our @EXPORT = qw(subname);
61 our @EXPORT_OK = @EXPORT;
62
63 use XSLoader;
64 XSLoader::load(
65     __PACKAGE__,
66     $VERSION,
67 );
68
69 1;