Initial commit of OpenSPARC T2 design and verification files.
[OpenSPARC-T2-DV] / tools / perl-5.8.0 / man / man3 / attributes.3
CommitLineData
86530b38
AT
1.\" Automatically generated by Pod::Man v1.34, Pod::Parser v1.13
2.\"
3.\" Standard preamble:
4.\" ========================================================================
5.de Sh \" Subsection heading
6.br
7.if t .Sp
8.ne 5
9.PP
10\fB\\$1\fR
11.PP
12..
13.de Sp \" Vertical space (when we can't use .PP)
14.if t .sp .5v
15.if n .sp
16..
17.de Vb \" Begin verbatim text
18.ft CW
19.nf
20.ne \\$1
21..
22.de Ve \" End verbatim text
23.ft R
24.fi
25..
26.\" Set up some character translations and predefined strings. \*(-- will
27.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
28.\" double quote, and \*(R" will give a right double quote. | will give a
29.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
30.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
31.\" expand to `' in nroff, nothing in troff, for use with C<>.
32.tr \(*W-|\(bv\*(Tr
33.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
34.ie n \{\
35. ds -- \(*W-
36. ds PI pi
37. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
38. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
39. ds L" ""
40. ds R" ""
41. ds C` ""
42. ds C' ""
43'br\}
44.el\{\
45. ds -- \|\(em\|
46. ds PI \(*p
47. ds L" ``
48. ds R" ''
49'br\}
50.\"
51.\" If the F register is turned on, we'll generate index entries on stderr for
52.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
53.\" entries marked with X<> in POD. Of course, you'll have to process the
54.\" output yourself in some meaningful fashion.
55.if \nF \{\
56. de IX
57. tm Index:\\$1\t\\n%\t"\\$2"
58..
59. nr % 0
60. rr F
61.\}
62.\"
63.\" For nroff, turn off justification. Always turn off hyphenation; it makes
64.\" way too many mistakes in technical documents.
65.hy 0
66.if n .na
67.\"
68.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
69.\" Fear. Run. Save yourself. No user-serviceable parts.
70. \" fudge factors for nroff and troff
71.if n \{\
72. ds #H 0
73. ds #V .8m
74. ds #F .3m
75. ds #[ \f1
76. ds #] \fP
77.\}
78.if t \{\
79. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
80. ds #V .6m
81. ds #F 0
82. ds #[ \&
83. ds #] \&
84.\}
85. \" simple accents for nroff and troff
86.if n \{\
87. ds ' \&
88. ds ` \&
89. ds ^ \&
90. ds , \&
91. ds ~ ~
92. ds /
93.\}
94.if t \{\
95. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
96. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
97. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
98. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
99. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
100. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
101.\}
102. \" troff and (daisy-wheel) nroff accents
103.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
104.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
105.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
106.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
107.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
108.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
109.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
110.ds ae a\h'-(\w'a'u*4/10)'e
111.ds Ae A\h'-(\w'A'u*4/10)'E
112. \" corrections for vroff
113.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
114.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
115. \" for low resolution devices (crt and lpr)
116.if \n(.H>23 .if \n(.V>19 \
117\{\
118. ds : e
119. ds 8 ss
120. ds o a
121. ds d- d\h'-1'\(ga
122. ds D- D\h'-1'\(hy
123. ds th \o'bp'
124. ds Th \o'LP'
125. ds ae ae
126. ds Ae AE
127.\}
128.rm #[ #] #H #V #F C
129.\" ========================================================================
130.\"
131.IX Title "attributes 3"
132.TH attributes 3 "2002-06-01" "perl v5.8.0" "Perl Programmers Reference Guide"
133.SH "NAME"
134attributes \- get/set subroutine or variable attributes
135.SH "SYNOPSIS"
136.IX Header "SYNOPSIS"
137.Vb 3
138\& sub foo : method ;
139\& my ($x,@y,%z) : Bent = 1;
140\& my $s = sub : method { ... };
141.Ve
142.PP
143.Vb 2
144\& use attributes (); # optional, to get subroutine declarations
145\& my @attrlist = attributes::get(\e&foo);
146.Ve
147.PP
148.Vb 2
149\& use attributes 'get'; # import the attributes::get subroutine
150\& my @attrlist = get \e&foo;
151.Ve
152.SH "DESCRIPTION"
153.IX Header "DESCRIPTION"
154Subroutine declarations and definitions may optionally have attribute lists
155associated with them. (Variable \f(CW\*(C`my\*(C'\fR declarations also may, but see the
156warning below.) Perl handles these declarations by passing some information
157about the call site and the thing being declared along with the attribute
158list to this module. In particular, the first example above is equivalent to
159the following:
160.PP
161.Vb 1
162\& use attributes __PACKAGE__, \e&foo, 'method';
163.Ve
164.PP
165The second example in the synopsis does something equivalent to this:
166.PP
167.Vb 6
168\& use attributes ();
169\& my ($x,@y,%z);
170\& attributes::->import(__PACKAGE__, \e$x, 'Bent');
171\& attributes::->import(__PACKAGE__, \e@y, 'Bent');
172\& attributes::->import(__PACKAGE__, \e%z, 'Bent');
173\& ($x,@y,%z) = 1;
174.Ve
175.PP
176Yes, that's a lot of expansion.
177.PP
178\&\fB\s-1WARNING\s0\fR: attribute declarations for variables are still evolving.
179The semantics and interfaces of such declarations could change in
180future versions. They are present for purposes of experimentation
181with what the semantics ought to be. Do not rely on the current
182implementation of this feature.
183.PP
184There are only a few attributes currently handled by Perl itself (or
185directly by this module, depending on how you look at it.) However,
186package-specific attributes are allowed by an extension mechanism.
187(See \*(L"Package\-specific Attribute Handling\*(R" below.)
188.PP
189The setting of subroutine attributes happens at compile time.
190Variable attributes in \f(CW\*(C`our\*(C'\fR declarations are also applied at compile time.
191However, \f(CW\*(C`my\*(C'\fR variables get their attributes applied at run\-time.
192This means that you have to \fIreach\fR the run-time component of the \f(CW\*(C`my\*(C'\fR
193before those attributes will get applied. For example:
194.PP
195.Vb 1
196\& my $x : Bent = 42 if 0;
197.Ve
198.PP
199will neither assign 42 to \f(CW$x\fR \fInor\fR will it apply the \f(CW\*(C`Bent\*(C'\fR attribute
200to the variable.
201.PP
202An attempt to set an unrecognized attribute is a fatal error. (The
203error is trappable, but it still stops the compilation within that
204\&\f(CW\*(C`eval\*(C'\fR.) Setting an attribute with a name that's all lowercase
205letters that's not a built-in attribute (such as \*(L"foo\*(R") will result in
206a warning with \fB\-w\fR or \f(CW\*(C`use warnings 'reserved'\*(C'\fR.
207.Sh "Built-in Attributes"
208.IX Subsection "Built-in Attributes"
209The following are the built-in attributes for subroutines:
210.IP "locked" 4
211.IX Item "locked"
212Setting this attribute is only meaningful when the subroutine or
213method is to be called by multiple threads. When set on a method
214subroutine (i.e., one marked with the \fBmethod\fR attribute below),
215Perl ensures that any invocation of it implicitly locks its first
216argument before execution. When set on a non-method subroutine,
217Perl ensures that a lock is taken on the subroutine itself before
218execution. The semantics of the lock are exactly those of one
219explicitly taken with the \f(CW\*(C`lock\*(C'\fR operator immediately after the
220subroutine is entered.
221.IP "method" 4
222.IX Item "method"
223Indicates that the referenced subroutine is a method.
224This has a meaning when taken together with the \fBlocked\fR attribute,
225as described there. It also means that a subroutine so marked
226will not trigger the \*(L"Ambiguous call resolved as CORE::%s\*(R" warning.
227.IP "lvalue" 4
228.IX Item "lvalue"
229Indicates that the referenced subroutine is a valid lvalue and can
230be assigned to. The subroutine must return a modifiable value such
231as a scalar variable, as described in perlsub.
232.PP
233For global variables there is \f(CW\*(C`unique\*(C'\fR attribute: see \*(L"our\*(R" in perlfunc.
234.Sh "Available Subroutines"
235.IX Subsection "Available Subroutines"
236The following subroutines are available for general use once this module
237has been loaded:
238.IP "get" 4
239.IX Item "get"
240This routine expects a single parameter\*(--a reference to a
241subroutine or variable. It returns a list of attributes, which may be
242empty. If passed invalid arguments, it uses \fIdie()\fR (via Carp::croak)
243to raise a fatal exception. If it can find an appropriate package name
244for a class method lookup, it will include the results from a
245\&\f(CW\*(C`FETCH_\f(CItype\f(CW_ATTRIBUTES\*(C'\fR call in its return list, as described in
246\&\*(L"Package\-specific Attribute Handling\*(R" below.
247Otherwise, only built-in attributes will be returned.
248.IP "reftype" 4
249.IX Item "reftype"
250This routine expects a single parameter\*(--a reference to a subroutine or
251variable. It returns the built-in type of the referenced variable,
252ignoring any package into which it might have been blessed.
253This can be useful for determining the \fItype\fR value which forms part of
254the method names described in \*(L"Package\-specific Attribute Handling\*(R" below.
255.PP
256Note that these routines are \fInot\fR exported by default.
257.Sh "Package-specific Attribute Handling"
258.IX Subsection "Package-specific Attribute Handling"
259\&\fB\s-1WARNING\s0\fR: the mechanisms described here are still experimental. Do not
260rely on the current implementation. In particular, there is no provision
261for applying package attributes to 'cloned' copies of subroutines used as
262closures. (See \*(L"Making References\*(R" in perlref for information on closures.)
263Package-specific attribute handling may change incompatibly in a future
264release.
265.PP
266When an attribute list is present in a declaration, a check is made to see
267whether an attribute 'modify' handler is present in the appropriate package
268(or its \f(CW@ISA\fR inheritance tree). Similarly, when \f(CW\*(C`attributes::get\*(C'\fR is
269called on a valid reference, a check is made for an appropriate attribute
270\&'fetch' handler. See \*(L"\s-1EXAMPLES\s0\*(R" to see how the \*(L"appropriate package\*(R"
271determination works.
272.PP
273The handler names are based on the underlying type of the variable being
274declared or of the reference passed. Because these attributes are
275associated with subroutine or variable declarations, this deliberately
276ignores any possibility of being blessed into some package. Thus, a
277subroutine declaration uses \*(L"\s-1CODE\s0\*(R" as its \fItype\fR, and even a blessed
278hash reference uses \*(L"\s-1HASH\s0\*(R" as its \fItype\fR.
279.PP
280The class methods invoked for modifying and fetching are these:
281.IP "\s-1FETCH_\s0\fItype\fR_ATTRIBUTES" 4
282.IX Item "FETCH_type_ATTRIBUTES"
283This method receives a single argument, which is a reference to the
284variable or subroutine for which package-defined attributes are desired.
285The expected return value is a list of associated attributes.
286This list may be empty.
287.IP "\s-1MODIFY_\s0\fItype\fR_ATTRIBUTES" 4
288.IX Item "MODIFY_type_ATTRIBUTES"
289This method is called with two fixed arguments, followed by the list of
290attributes from the relevant declaration. The two fixed arguments are
291the relevant package name and a reference to the declared subroutine or
292variable. The expected return value as a list of attributes which were
293not recognized by this handler. Note that this allows for a derived class
294to delegate a call to its base class, and then only examine the attributes
295which the base class didn't already handle for it.
296.Sp
297The call to this method is currently made \fIduring\fR the processing of the
298declaration. In particular, this means that a subroutine reference will
299probably be for an undefined subroutine, even if this declaration is
300actually part of the definition.
301.PP
302Calling \f(CW\*(C`attributes::get()\*(C'\fR from within the scope of a null package
303declaration \f(CW\*(C`package ;\*(C'\fR for an unblessed variable reference will
304not provide any starting package name for the 'fetch' method lookup.
305Thus, this circumstance will not result in a method call for package-defined
306attributes. A named subroutine knows to which symbol table entry it belongs
307(or originally belonged), and it will use the corresponding package.
308An anonymous subroutine knows the package name into which it was compiled
309(unless it was also compiled with a null package declaration), and so it
310will use that package name.
311.Sh "Syntax of Attribute Lists"
312.IX Subsection "Syntax of Attribute Lists"
313An attribute list is a sequence of attribute specifications, separated by
314whitespace or a colon (with optional whitespace).
315Each attribute specification is a simple
316name, optionally followed by a parenthesised parameter list.
317If such a parameter list is present, it is scanned past as for the rules
318for the \f(CW\*(C`q()\*(C'\fR operator. (See \*(L"Quote and Quote-like Operators\*(R" in perlop.)
319The parameter list is passed as it was found, however, and not as per \f(CW\*(C`q()\*(C'\fR.
320.PP
321Some examples of syntactically valid attribute lists:
322.PP
323.Vb 4
324\& switch(10,foo(7,3)) : expensive
325\& Ugly('\e(") :Bad
326\& _5x5
327\& locked method
328.Ve
329.PP
330Some examples of syntactically invalid attribute lists (with annotation):
331.PP
332.Vb 5
333\& switch(10,foo() # ()-string not balanced
334\& Ugly('(') # ()-string not balanced
335\& 5x5 # "5x5" not a valid identifier
336\& Y2::north # "Y2::north" not a simple identifier
337\& foo + bar # "+" neither a colon nor whitespace
338.Ve
339.SH "EXPORTS"
340.IX Header "EXPORTS"
341.Sh "Default exports"
342.IX Subsection "Default exports"
343None.
344.Sh "Available exports"
345.IX Subsection "Available exports"
346The routines \f(CW\*(C`get\*(C'\fR and \f(CW\*(C`reftype\*(C'\fR are exportable.
347.Sh "Export tags defined"
348.IX Subsection "Export tags defined"
349The \f(CW\*(C`:ALL\*(C'\fR tag will get all of the above exports.
350.SH "EXAMPLES"
351.IX Header "EXAMPLES"
352Here are some samples of syntactically valid declarations, with annotation
353as to how they resolve internally into \f(CW\*(C`use attributes\*(C'\fR invocations by
354perl. These examples are primarily useful to see how the \*(L"appropriate
355package\*(R" is found for the possible method lookups for package-defined
356attributes.
357.IP "1." 4
358Code:
359.Sp
360.Vb 3
361\& package Canine;
362\& package Dog;
363\& my Canine $spot : Watchful ;
364.Ve
365.Sp
366Effect:
367.Sp
368.Vb 2
369\& use attributes ();
370\& attributes::->import(Canine => \e$spot, "Watchful");
371.Ve
372.IP "2." 4
373Code:
374.Sp
375.Vb 2
376\& package Felis;
377\& my $cat : Nervous;
378.Ve
379.Sp
380Effect:
381.Sp
382.Vb 2
383\& use attributes ();
384\& attributes::->import(Felis => \e$cat, "Nervous");
385.Ve
386.IP "3." 4
387Code:
388.Sp
389.Vb 2
390\& package X;
391\& sub foo : locked ;
392.Ve
393.Sp
394Effect:
395.Sp
396.Vb 1
397\& use attributes X => \e&foo, "locked";
398.Ve
399.IP "4." 4
400Code:
401.Sp
402.Vb 2
403\& package X;
404\& sub Y::x : locked { 1 }
405.Ve
406.Sp
407Effect:
408.Sp
409.Vb 1
410\& use attributes Y => \e&Y::x, "locked";
411.Ve
412.IP "5." 4
413Code:
414.Sp
415.Vb 2
416\& package X;
417\& sub foo { 1 }
418.Ve
419.Sp
420.Vb 2
421\& package Y;
422\& BEGIN { *bar = \e&X::foo; }
423.Ve
424.Sp
425.Vb 2
426\& package Z;
427\& sub Y::bar : locked ;
428.Ve
429.Sp
430Effect:
431.Sp
432.Vb 1
433\& use attributes X => \e&X::foo, "locked";
434.Ve
435.PP
436This last example is purely for purposes of completeness. You should not
437be trying to mess with the attributes of something in a package that's
438not your own.
439.SH "SEE ALSO"
440.IX Header "SEE ALSO"
441\&\*(L"Private Variables via \fImy()\fR\*(R" in perlsub and
442\&\*(L"Subroutine Attributes\*(R" in perlsub for details on the basic declarations;
443attrs for the obsolescent form of subroutine attribute specification
444which this module replaces;
445\&\*(L"use\*(R" in perlfunc for details on the normal invocation mechanism.