modify_attrs#
Apply a list of attributes to a referent and return the ones Perl didn’t recognise, so the caller can hand them to a user-defined MODIFY_${type}_ATTRIBUTES handler.
Synopsis#
my @unknown = attributes::_modify_attrs(\&foo, 'lvalue', 'Bent');
## 'lvalue' consumed internally; 'Bent' returned for package dispatch.
What you get back#
The list of attribute names that weren’t built-in. Built-in attributes
(lvalue, method, const, prototype(...) for subs; shared for
variables) are applied to the referent directly and do not appear in
the returned list.
Examples#
## Mark a sub as lvalue, no leftovers:
sub s :lvalue { $x }
my @left = attributes::_modify_attrs(\&s, 'lvalue'); # ()
## Install a prototype via attribute:
sub p { }
attributes::_modify_attrs(\&p, 'prototype($$)'); # ()
## Custom attribute flows through:
my @left = attributes::_modify_attrs(\&s, 'MyTag'); # ('MyTag')
Edge cases#
Called with zero args or a non-reference first arg: croaks with
Usage: attributes::_modify_attrs(@attributes).A
prototype(attribute without a closing)croaks withUnterminated attribute parameter in attribute list.-sharedon a non-sub referent croaks withA variable may not be unshared.
Differences from upstream#
lvalueis always consumed as a built-in onCODEreferents; the “already-defined subroutine” warning dispatch lives inattributes.pmand is not mirrored inside this XS entry.
See also#
_fetch_attrs— read-side counterpart, returns built-in attrs only.get— public API:_fetch_attrsplusFETCH_${type}_ATTRIBUTES._guess_stash— used bygetto locate the owning package.