1 # $Id: Name.pm,v 1.4 2004/08/18 12:03:42 xmath Exp $
7 Sub::Name - (re)name a sub
13 subname $name, $subref;
15 $subref = subname foo => sub { ... };
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
23 =head2 subname NAME, CODEREF
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.
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.
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.
38 Matthijs van Duin <xmath@cpan.org>
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.
51 our $VERSION = '0.01';
54 use base 'DynaLoader';
56 our @EXPORT = qw(subname);
57 our @EXPORT_OK = @EXPORT;
59 bootstrap Sub::Name $VERSION;