Mouse:...ribute(3pm)
β¨ NAME β¨
Mouse::Meta::Attribute β The Mouse attribute metaclass. This is the manual page for it, bestie β the header calls it Mouse:...ribute(3pm), and itβs part of the User Contributed Perl Documentation. Iconic. π
π VERSION π
This document describes Mouse version v2.6.2. Slay. β¨
π¦ DESCRIPTION π¦
This is a meta object protocol for Mouse attributes, which is a subset of Moose::Meta::Attribute. Itβs giving very βmeta but make it Mouseβ energy, and weβre obsessed. π
πΈ METHODS πΈ
π new(%options) -> Mouse::Meta::Attribute
Instantiates a new Mouse::Meta::Attribute. Does nothing else. Literally just that. π«Ά
It adds the following options to the constructor:
is => 'ro', 'rw', 'bare'β this provides a shorthand for specifying thereader,writer, oraccessornames. Hereβs the tea:- If the attribute is read-only (
'ro') then it will have areadermethod with the same attribute as the name. - If it is read-write (
'rw') then it will have anaccessormethod with the same name. If you provide an explicitwriterfor a read-write attribute, then you will have areaderwith the same name as the attribute, and awriterwith the name you provided. - Use
'bare'when you are deliberately not installing any methods (accessor, reader, etc.) associated with this attribute; otherwise, Moose will issue a deprecation warning when this attribute is added to a metaclass. So likeβ¦ donβt skip the bare unless you mean it, bestie. π
- If the attribute is read-only (
isa => Typeβ this option accepts a type. The type can be a string, which should be a type name. If the type name is unknown, it is assumed to be a class name.- This option can also accept a
Moose::Meta::TypeConstraintobject. - If you also provide a
doesoption, then yourisaoption must be a class name, and that class must do the role specified withdoes. No cap.
- This option can also accept a
does => Roleβ this is short-hand for saying that the attribute's type must be an object which does the named role.- This option is not yet supported. Not me getting excited for something thatβs not here yet π
coerce => Boolβ this option is only valid for objects with a type constraint (isa). If this is true, then coercions will be applied whenever this attribute is set.- You can make both this and the
weak_refoption true. Cute combo, lowkey.
- You can make both this and the
trigger => CodeRefβ this option accepts a subroutine reference, which will be called after the attribute is set. Itβs giving βafterparty but for your attributeβ β¨required => Boolβ an attribute which is required must be provided to the constructor. An attribute which is required can also have adefaultorbuilder, which will satisfy its required-ness.- A required attribute must have a
default,builderor a non-undefinit_arg. That part is not optional, periodt.
- A required attribute must have a
lazy => Boolβ a lazy attribute must have adefaultorbuilder. When an attribute is lazy, the default value will not be calculated until the attribute is read. Main character energy: it arrives exactly when it needs to. πweak_ref => Boolβ if this is true, the attribute's value will be stored as a weak reference.auto_deref => Boolβ if this is true, then the reader will dereference the value when it is called. The attribute must have a type constraint which defines the attribute as an array or hash reference. Very specific, very valid. πlazy_build => Boolβ setting this to true makes the attribute lazy and provides a number of default methods.
So this:
has 'size' => (
is => 'ro',
lazy_build => 1,
);
is equivalent to this:
has 'size' => (
is => 'ro',
lazy => 1,
builder => '_build_size',
clearer => 'clear_size',
predicate => 'has_size',
);
The way that little glow-up works is genuinely iconic. π
π associate_method(MethodName)
Associates a method with the attribute. Typically, this is called internally when an attribute generates its accessors.
Currently the argument MethodName is ignored in Mouse. So yeahβ¦ itβs there, itβs cute, itβs lowkey just vibing. π¦
π verify_against_type_constraint(Item) -> TRUE | ERROR
Checks that the given value passes this attribute's type constraint. Returns "true" on success, otherwise "confess"es. Itβs giving vibe check with consequences, ngl. π
π clone_and_inherit_options(options) -> Mouse::Meta::Attribute
Creates a new attribute in the owner class, inheriting options from parent classes. Accessors and helper methods are installed. Some error checking is done. So itβs not just copying β itβs inheriting the whole aesthetic. π
π get_read_method_ref / get_write_method_ref
Returns the subroutine reference of a method suitable for reading or writing the attribute's value in the associated class. These methods always return a subroutine reference, regardless of whether or not the attribute is read- or write-only. Always. No cap. π₯
π SEE ALSO π
Moose::Meta::AttributeClass::MOP::Attribute
perl v5.42.2 β’ 2026-04-21 β thatβs the source/version and date for this page, bestie. Signing off with maximum sparkle. πβ¨π
π¦ where this page comes from
- alpine 3.24: perl-mouse-doc 2.6.2-r0 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms