Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / attributes.3
CommitLineData
920dae64
AT
1.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
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 "2001-09-21" "perl v5.8.8" "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"
212\&\fB5.005 threads only! The use of the \*(L"locked\*(R" attribute currently
213only makes sense if you are using the deprecated \*(L"Perl 5.005 threads\*(R"
214implementation of threads.\fR
215.Sp
216Setting this attribute is only meaningful when the subroutine or
217method is to be called by multiple threads. When set on a method
218subroutine (i.e., one marked with the \fBmethod\fR attribute below),
219Perl ensures that any invocation of it implicitly locks its first
220argument before execution. When set on a non-method subroutine,
221Perl ensures that a lock is taken on the subroutine itself before
222execution. The semantics of the lock are exactly those of one
223explicitly taken with the \f(CW\*(C`lock\*(C'\fR operator immediately after the
224subroutine is entered.
225.IP "method" 4
226.IX Item "method"
227Indicates that the referenced subroutine is a method.
228This has a meaning when taken together with the \fBlocked\fR attribute,
229as described there. It also means that a subroutine so marked
230will not trigger the \*(L"Ambiguous call resolved as CORE::%s\*(R" warning.
231.IP "lvalue" 4
232.IX Item "lvalue"
233Indicates that the referenced subroutine is a valid lvalue and can
234be assigned to. The subroutine must return a modifiable value such
235as a scalar variable, as described in perlsub.
236.PP
237For global variables there is \f(CW\*(C`unique\*(C'\fR attribute: see \*(L"our\*(R" in perlfunc.
238.Sh "Available Subroutines"
239.IX Subsection "Available Subroutines"
240The following subroutines are available for general use once this module
241has been loaded:
242.IP "get" 4
243.IX Item "get"
244This routine expects a single parameter\*(--a reference to a
245subroutine or variable. It returns a list of attributes, which may be
246empty. If passed invalid arguments, it uses \fIdie()\fR (via Carp::croak)
247to raise a fatal exception. If it can find an appropriate package name
248for a class method lookup, it will include the results from a
249\&\f(CW\*(C`FETCH_\f(CItype\f(CW_ATTRIBUTES\*(C'\fR call in its return list, as described in
250\&\*(L"Package\-specific Attribute Handling\*(R" below.
251Otherwise, only built-in attributes will be returned.
252.IP "reftype" 4
253.IX Item "reftype"
254This routine expects a single parameter\*(--a reference to a subroutine or
255variable. It returns the built-in type of the referenced variable,
256ignoring any package into which it might have been blessed.
257This can be useful for determining the \fItype\fR value which forms part of
258the method names described in \*(L"Package\-specific Attribute Handling\*(R" below.
259.PP
260Note that these routines are \fInot\fR exported by default.
261.Sh "Package-specific Attribute Handling"
262.IX Subsection "Package-specific Attribute Handling"
263\&\fB\s-1WARNING\s0\fR: the mechanisms described here are still experimental. Do not
264rely on the current implementation. In particular, there is no provision
265for applying package attributes to 'cloned' copies of subroutines used as
266closures. (See \*(L"Making References\*(R" in perlref for information on closures.)
267Package-specific attribute handling may change incompatibly in a future
268release.
269.PP
270When an attribute list is present in a declaration, a check is made to see
271whether an attribute 'modify' handler is present in the appropriate package
272(or its \f(CW@ISA\fR inheritance tree). Similarly, when \f(CW\*(C`attributes::get\*(C'\fR is
273called on a valid reference, a check is made for an appropriate attribute
274\&'fetch' handler. See \*(L"\s-1EXAMPLES\s0\*(R" to see how the \*(L"appropriate package\*(R"
275determination works.
276.PP
277The handler names are based on the underlying type of the variable being
278declared or of the reference passed. Because these attributes are
279associated with subroutine or variable declarations, this deliberately
280ignores any possibility of being blessed into some package. Thus, a
281subroutine declaration uses \*(L"\s-1CODE\s0\*(R" as its \fItype\fR, and even a blessed
282hash reference uses \*(L"\s-1HASH\s0\*(R" as its \fItype\fR.
283.PP
284The class methods invoked for modifying and fetching are these:
285.IP "\s-1FETCH_\s0\fItype\fR_ATTRIBUTES" 4
286.IX Item "FETCH_type_ATTRIBUTES"
287This method receives a single argument, which is a reference to the
288variable or subroutine for which package-defined attributes are desired.
289The expected return value is a list of associated attributes.
290This list may be empty.
291.IP "\s-1MODIFY_\s0\fItype\fR_ATTRIBUTES" 4
292.IX Item "MODIFY_type_ATTRIBUTES"
293This method is called with two fixed arguments, followed by the list of
294attributes from the relevant declaration. The two fixed arguments are
295the relevant package name and a reference to the declared subroutine or
296variable. The expected return value is a list of attributes which were
297not recognized by this handler. Note that this allows for a derived class
298to delegate a call to its base class, and then only examine the attributes
299which the base class didn't already handle for it.
300.Sp
301The call to this method is currently made \fIduring\fR the processing of the
302declaration. In particular, this means that a subroutine reference will
303probably be for an undefined subroutine, even if this declaration is
304actually part of the definition.
305.PP
306Calling \f(CW\*(C`attributes::get()\*(C'\fR from within the scope of a null package
307declaration \f(CW\*(C`package ;\*(C'\fR for an unblessed variable reference will
308not provide any starting package name for the 'fetch' method lookup.
309Thus, this circumstance will not result in a method call for package-defined
310attributes. A named subroutine knows to which symbol table entry it belongs
311(or originally belonged), and it will use the corresponding package.
312An anonymous subroutine knows the package name into which it was compiled
313(unless it was also compiled with a null package declaration), and so it
314will use that package name.
315.Sh "Syntax of Attribute Lists"
316.IX Subsection "Syntax of Attribute Lists"
317An attribute list is a sequence of attribute specifications, separated by
318whitespace or a colon (with optional whitespace).
319Each attribute specification is a simple
320name, optionally followed by a parenthesised parameter list.
321If such a parameter list is present, it is scanned past as for the rules
322for the \f(CW\*(C`q()\*(C'\fR operator. (See \*(L"Quote and Quote-like Operators\*(R" in perlop.)
323The parameter list is passed as it was found, however, and not as per \f(CW\*(C`q()\*(C'\fR.
324.PP
325Some examples of syntactically valid attribute lists:
326.PP
327.Vb 4
328\& switch(10,foo(7,3)) : expensive
329\& Ugly('\e(") :Bad
330\& _5x5
331\& locked method
332.Ve
333.PP
334Some examples of syntactically invalid attribute lists (with annotation):
335.PP
336.Vb 5
337\& switch(10,foo() # ()-string not balanced
338\& Ugly('(') # ()-string not balanced
339\& 5x5 # "5x5" not a valid identifier
340\& Y2::north # "Y2::north" not a simple identifier
341\& foo + bar # "+" neither a colon nor whitespace
342.Ve
343.SH "EXPORTS"
344.IX Header "EXPORTS"
345.Sh "Default exports"
346.IX Subsection "Default exports"
347None.
348.Sh "Available exports"
349.IX Subsection "Available exports"
350The routines \f(CW\*(C`get\*(C'\fR and \f(CW\*(C`reftype\*(C'\fR are exportable.
351.Sh "Export tags defined"
352.IX Subsection "Export tags defined"
353The \f(CW\*(C`:ALL\*(C'\fR tag will get all of the above exports.
354.SH "EXAMPLES"
355.IX Header "EXAMPLES"
356Here are some samples of syntactically valid declarations, with annotation
357as to how they resolve internally into \f(CW\*(C`use attributes\*(C'\fR invocations by
358perl. These examples are primarily useful to see how the \*(L"appropriate
359package\*(R" is found for the possible method lookups for package-defined
360attributes.
361.IP "1." 4
362Code:
363.Sp
364.Vb 3
365\& package Canine;
366\& package Dog;
367\& my Canine $spot : Watchful ;
368.Ve
369.Sp
370Effect:
371.Sp
372.Vb 2
373\& use attributes ();
374\& attributes::->import(Canine => \e$spot, "Watchful");
375.Ve
376.IP "2." 4
377Code:
378.Sp
379.Vb 2
380\& package Felis;
381\& my $cat : Nervous;
382.Ve
383.Sp
384Effect:
385.Sp
386.Vb 2
387\& use attributes ();
388\& attributes::->import(Felis => \e$cat, "Nervous");
389.Ve
390.IP "3." 4
391Code:
392.Sp
393.Vb 2
394\& package X;
395\& sub foo : locked ;
396.Ve
397.Sp
398Effect:
399.Sp
400.Vb 1
401\& use attributes X => \e&foo, "locked";
402.Ve
403.IP "4." 4
404Code:
405.Sp
406.Vb 2
407\& package X;
408\& sub Y::x : locked { 1 }
409.Ve
410.Sp
411Effect:
412.Sp
413.Vb 1
414\& use attributes Y => \e&Y::x, "locked";
415.Ve
416.IP "5." 4
417Code:
418.Sp
419.Vb 2
420\& package X;
421\& sub foo { 1 }
422.Ve
423.Sp
424.Vb 2
425\& package Y;
426\& BEGIN { *bar = \e&X::foo; }
427.Ve
428.Sp
429.Vb 2
430\& package Z;
431\& sub Y::bar : locked ;
432.Ve
433.Sp
434Effect:
435.Sp
436.Vb 1
437\& use attributes X => \e&X::foo, "locked";
438.Ve
439.PP
440This last example is purely for purposes of completeness. You should not
441be trying to mess with the attributes of something in a package that's
442not your own.
443.SH "SEE ALSO"
444.IX Header "SEE ALSO"
445\&\*(L"Private Variables via \fImy()\fR\*(R" in perlsub and
446\&\*(L"Subroutine Attributes\*(R" in perlsub for details on the basic declarations;
447attrs for the obsolescent form of subroutine attribute specification
448which this module replaces;
449\&\*(L"use\*(R" in perlfunc for details on the normal invocation mechanism.