Object...eldAttr(3pm)

πŸ’– NAME πŸ’–

Object::Pad::MOP::FieldAttr β€” meta-object representation of a field attribute for Object::Pad. This is the Object...eldAttr(3pm) manual, bestie, and we’re doing the meta-object thing today ✨


🌸 DESCRIPTION 🌸

Okay so this API is literally how pure-perl implementations of field attributes get provided 🫢. Pure-perl attributes cannot currently add new behaviour to the way that fields work, but they do provide a means for class authors to annotate extra metadata onto fields, that can be queried by other code.

The main way this happens is via the get_attribute_value in Object::Pad::MOP::Field accessor method, on a field metadata instance.

⚠️ This API should be considered experimental, and will emit warnings to that effect. They can be silenced with:
use Object::Pad qw( :experimental(custom_field_attr) );

✨ METHODS ✨

πŸͺ„ register πŸͺ„

Object::Pad::MOP::FieldAttr->register( $name, %args );

Since version 0.60.

Creates a new field attribute of the given name. The name must begin with a capital letter, in order to distinguish this from any of the built-in core attributes, whose names are lowercase. Slay, capitalization matters πŸ’…

The attribute is only available if the hints hash contains a key of the name given by the attribute's permit_hintkey argument. This would typically be set in the hints hash by the import method of the module implementing it, and would be named based on the name of the module providing the attribute:

sub import { $^H{"Some::Package::Name/Attrname"} }

Takes the following additional named arguments:

  • permit_hintkey => STRING β€” Required. A string giving a key that must be found in the hints hash (%^H) for this attribute name to be visible.
  • no_value => BOOL β€” An optional flag; if set to true then no value is permitted on the attribute's declaration. A compiletime error will be generated if a value is provided.
  • must_value => BOOL β€” An optional flag; if set to true then a value is required on the attribute's declaration. A compiletime error will be generated if a value is not provided.

If neither of these flags are provided, then a value is optional. It is not permitted to set both flags at once. 🚨

  • apply => CODE β€” An optional code reference for a callback function to invoke when the attribute is applied to a field. If present, it is passed the field metadata instance as a Object::Pad::MOP::Field reference, and a string containing the contents of the attribute's parenthesized value. The return value of the callback will be stored as the attribute's value and can be accessed by the get_attribute_value method on the field metadata.
$result = $apply->( $fieldmeta, $value )

If the apply callback is absent then the string value itself is stored.


πŸ‘‘ AUTHOR πŸ‘‘

Paul Evans <leonerd@leonerd.org.uk> πŸ’œ


That’s the whole page, bestie 🫢. This is the Object...eldAttr(3pm) manual from the User Contributed Perl Documentation, perl v5.42.3, dated 2026-08-22 β€” go annotate some fields and stay iconic πŸŒˆπŸ’…

πŸ“¦ where this page comes from