The method Attribute
The method attribute
can be used by itself:
sub afunc : method { ... }Currently, this only has the effect of marking the subroutine
so as not to trigger the “Ambiguous call
resolved as CORE::%s” warning. (We may make it mean more
someday.)
The attribute system is user-extensible, letting you create
your own attribute names. These new attributes must be valid as
simple identifier names (without any punctuation other than the
“_” character). They may have a
parameter list appended, which is currently only checked for whether
its parentheses nest properly.
Here are examples of valid syntax (even though the attributes are unknown):
sub fnord (&\%) : switch(10,foo(7,3)) : expensive;
sub plugh () : Ugly('\(") :Bad;
sub xyzzy : _5x5 { ... }Here are examples of invalid syntax:
sub fnord : switch(10,foo(); # ()–string not balanced
sub snoid : Ugly("("); # ()–string not balanced
sub xyzzy : 5x5; # "5x5" not a valid identifier
sub plugh : Y2::north; # "Y2::north" not a simple identifier
sub snurt : foo + bar; # "+" not a colon or spaceThe attribute list is passed as a list of constant strings to the code that associates them with the subroutine. Exactly how this works (or doesn’t) is highly experimental. Check attributes(3) for current details on attribute lists and their manipulation.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access