initial import of Sub-Name 0.01 from CPAN
[p5sagit/Sub-Name.git] / lib / Sub / Name.pm
CommitLineData
16c23894 1# $Id: Name.pm,v 1.4 2004/08/18 12:03:42 xmath Exp $
2
3package Sub::Name;
4
5=head1 NAME
6
7Sub::Name - (re)name a sub
8
9=head1 SYNOPSIS
10
11 use Sub::Name;
12
13 subname $name, $subref;
14
15 $subref = subname foo => sub { ... };
16
17=head1 DESCRIPTION
18
19This module has two functions to assign a new name to a sub -- in particular an
20anonymous sub -- which is displayed in tracebacks and such. Both functions are
21exported by default.
22
23=head2 subname NAME, CODEREF
24
25Assigns a new name to referenced sub. If package specification is omitted in
26the name, then the current package is used. The return value is the sub.
27
28The name is only used for informative routines (caller, Carp, etc). You won't
29be able to actually invoke the sub by the given name. To allow that, you need
30to do glob-assignment yourself.
31
32Note that for closures (anonymous subs that reference lexicals outside the sub
33itself) you can name each instance of the closure differently, which can be
34very useful for debugging.
35
36=head1 AUTHOR
37
38Matthijs van Duin <xmath@cpan.org>
39
40Copyright (C) 2004 Matthijs van Duin. All rights reserved.
41This program is free software; you can redistribute it and/or modify
42it under the same terms as Perl itself.
43
44=cut
45
46use 5.006;
47
48use strict;
49use warnings;
50
51our $VERSION = '0.01';
52
53use base 'Exporter';
54use base 'DynaLoader';
55
56our @EXPORT = qw(subname);
57our @EXPORT_OK = @EXPORT;
58
59bootstrap Sub::Name $VERSION;
60
611;