This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Implement use attrs qw(locked package);
[perl5.git] / ext / attrs / attrs.pm
CommitLineData
77a005ab
MB
1package attrs;
2require DynaLoader;
3use vars '@ISA';
4@ISA = 'DynaLoader';
5
6use vars qw($VERSION);
7$VERSION = "1.0";
8
9=head1 NAME
10
11attrs - 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
24This module lets you set and get attributes for subroutines.
25Setting attributes takes place at compile time; trying to set
26invalid attribute names causes a compile-time error. Calling
27C<attr::get> on a subroutine reference or name returns its list
28of attribute names. Notice that C<attr::get> is not exported.
29Valid attributes are as follows.
30
31=over
32
33=item method
34
35Indicates that the invoking subroutine is a method.
36
74efa5a2
NIS
37=item package
38
39If the subroutine is locked, lock the package in which it is
40defined.
41
77a005ab
MB
42=item locked
43
44Setting this attribute is only meaningful when the subroutine or
74efa5a2
NIS
45method is to be called by multiple threads. When the B<package>
46attribute is set then before executing the subroutine or method
47perl acquires a lock on the package in which the subroutine is
48defined.
49
50Otherwise, when set on a method subroutine (i.e. one
51marked with the B<method> attribute above), perl ensures that any
52invocation of it implicitly locks its first argument before
53execution. When set on a non-method subroutine,
54(without a B<package> attribute) perl ensures that a lock is taken
55on the subroutine itself before execution. The semantics of the
56lock are exactly those of one explicitly taken with the C<lock>
57operator immediately after the subroutine is entered.
77a005ab
MB
58
59=back
60
61=cut
62
63bootstrap attrs $VERSION;
64
651;