8.2 attrs (Perl in a Nutshell)

Perl in a Nutshell

Perl in a NutshellSearch this book
Previous: 8.1 AnyDBM_FileChapter 8
Standard Modules
Next: 8.3 AutoLoader
 

8.2 attrs

Sets or gets the attributes of subroutines. Attributes are set for a subroutine at compile time; therefore, setting an invalid attribute results in a compile-time error. During execution, when you call attrs::get on a subroutine reference or name, it returns the list of attributes that are set. Note that attrs::get is not exported. For example:

sub test {
    use attrs qw(locked method);
    ...
}
@a = attrs::get(\foo);
The valid attributes are:

locked

Meaningful only when the subroutine or method is to be called by multiple threads. When set on a subroutine that also has the method attribute set, invoking that subroutine implicitly locks its first argument before execution. On a non-method subroutine, a lock is taken on the subroutine itself before execution. The lock semantics are identical to one taken explicitly with the lock operator immediately after entering the subroutine.

method

The invoking subroutine is a method.


Previous: 8.1 AnyDBM_FilePerl in a NutshellNext: 8.3 AutoLoader
8.1 AnyDBM_FileBook Index8.3 AutoLoader

Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.