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