```{index} single: attributes; Perl module ``` # attributes ```{pperl-module-badges} attributes ``` The machinery behind `sub foo : lvalue method { ... }` and `my $x : Shared`. Perl attaches attributes to subs and variables in three ways, and this module is the meeting point for all of them: - **Built-in attributes** that Perl itself consumes — `lvalue`, `method`, `const`, `prototype(...)` on subs, `shared` on variables. These flip flags on the `CV` (or set a prototype string) and never leave the core. - **User-defined attributes** — any name Perl doesn't recognise is handed off to `MODIFY_${type}_ATTRIBUTES` in the caller's package. If that handler rejects an attribute (or is absent), the declaration is a fatal error. `FETCH_${type}_ATTRIBUTES` is the read-side counterpart. - **A query API** — `attributes::get($ref)` returns the combined built-in + user-defined attribute list for a referent; `reftype` is kept here as a backward-compatible alias for `builtin::reftype`. Attribute syntax is parsed by perl and the resulting list arrives here via `use attributes PACKAGE, \&sub, @attrs` — see the upstream `attributes` POD for the full compile-time expansion. ## Functions ### Query #### [`get`](attributes/get) List every attribute set on a referent — both the built-ins Perl recognises and any package-defined ones returned by a `FETCH_${type}_ATTRIBUTES` handler. #### [`reftype`](attributes/reftype) Return the underlying storage type of a reference, ignoring any class it's been blessed into. ### Low-level #### [`modify_attrs`](attributes/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. #### [`fetch_attrs`](attributes/fetch_attrs) Return the built-in attributes currently set on a referent. #### [`guess_stash`](attributes/guess_stash) Work out which package a reference "belongs to", for the purpose of looking up `FETCH_${type}_ATTRIBUTES` / `MODIFY_${type}_ATTRIBUTES`. ```{toctree} :hidden: :maxdepth: 1 attributes/modify_attrs attributes/fetch_attrs attributes/get attributes/guess_stash attributes/reftype ```