Commit | Line | Data |
77a005ab |
1 | package attrs; |
2 | require DynaLoader; |
3 | use vars '@ISA'; |
4 | @ISA = 'DynaLoader'; |
5 | |
6 | use vars qw($VERSION); |
7 | $VERSION = "1.0"; |
8 | |
9 | =head1 NAME |
10 | |
11 | attrs - set/get attributes of a subroutine |
12 | |
13 | =head1 SYNOPSIS |
14 | |
15 | sub foo { |
16 | use attrs qw(locked method); |
17 | ... |
18 | } |
19 | |
20 | @a = attrs::get(\&foo); |
21 | |
22 | =head1 DESCRIPTION |
23 | |
24 | This module lets you set and get attributes for subroutines. |
25 | Setting attributes takes place at compile time; trying to set |
26 | invalid attribute names causes a compile-time error. Calling |
27 | C<attr::get> on a subroutine reference or name returns its list |
28 | of attribute names. Notice that C<attr::get> is not exported. |
29 | Valid attributes are as follows. |
30 | |
31 | =over |
32 | |
33 | =item method |
34 | |
35 | Indicates that the invoking subroutine is a method. |
36 | |
37 | =item locked |
38 | |
39 | Setting this attribute is only meaningful when the subroutine or |
40 | method is to be called by multiple threads. When set on a method |
41 | subroutine (i.e. one marked with the B<method> attribute above), |
42 | perl ensures that any invocation of it implicitly locks its first |
43 | argument before execution. When set on a non-method subroutine, |
44 | perl ensures that a lock is taken on the subroutine itself before |
45 | execution. The semantics of the lock are exactly those of one |
46 | explicitly taken with the C<lock> operator immediately after the |
47 | subroutine is entered. |
48 | |
cd06dffe |
49 | =item lvalue |
50 | |
51 | Setting this attribute enables the subroutine to be used in |
52 | lvalue context. See L<perlsub/"Lvalue subroutines">. |
53 | |
77a005ab |
54 | =back |
55 | |
56 | =cut |
57 | |
58 | bootstrap attrs $VERSION; |
59 | |
60 | 1; |