perldoc > Class::MOP::Attribute

๐Ÿงพ NAME

Class::MOP::Attribute - Attribute Meta Object

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿ—๏ธ Create a new attributeClass::MOP::Attribute->new( 'name' => ( ... ) )Define an attribute with options like accessor, default, init_arg, etc.
๐Ÿ“ฆ Set default valuedefault => 'scalar' or default => sub { [] }Provide a scalar or a subroutine reference for default initialization.
๐Ÿ”ง Use builder methodbuilder => 'build_name'Call a method on the object to initialize the attribute.
๐Ÿ”„ Custom initializerinitializer => sub { ... } or initializer => 'method_name'Munge the constructor value before setting.
๐Ÿ” Check attribute setpredicate => 'has_name'Returns true if attribute has been explicitly set (even to false).
๐Ÿงน Clear attributeclearer => 'clear_name'Uninitialize the attribute, predicate returns false.
๐Ÿ”’ Read-only accessorreader => 'name'Get value without setting.
โœ๏ธ Write-only accessorwriter => 'set_name'Set value without getting.
๐Ÿ”€ Read/write accessoraccessor => 'name'Standard Perl-style get/set.
๐Ÿ“‹ Access value directly (MOP)$attr->get_value($instance) / set_value($instance, $value)Bypass accessors, even for read-only/write-only attributes.

๐Ÿ“š VERSION

version 2.2200

๐Ÿ“‹ SYNOPSIS

Class::MOP::Attribute->new(
    foo => (
        accessor  => 'foo',           # dual purpose get/set accessor
        predicate => 'has_foo',       # predicate check for defined-ness
        init_arg  => '-foo',          # class->new will look for a -foo key
        default   => 'BAR IS BAZ!'    # if no -foo key is provided, use this
    )
);

Class::MOP::Attribute->new(
    bar => (
        reader    => 'bar',           # getter
        writer    => 'set_bar',       # setter
        predicate => 'has_bar',       # predicate check for defined-ness
        init_arg  => ':bar',          # class->new will look for a :bar key
                                      # no default value means it is undef
    )
);

๐Ÿ“– DESCRIPTION

The Attribute Protocol is almost entirely an invention of "Class::MOP". Perl 5 does not have a consistent notion of attributes. There are so many ways in which this is done, and very few (if any) are easily discoverable by this module.

With that said, this module attempts to inject some order into this chaos, by introducing a consistent API which can be used to create object attributes.

๐Ÿ› ๏ธ METHODS

๐Ÿ—๏ธ Creation

Class::MOP::Attribute->new($name, ?%options)

An attribute must (at the very least), have a $name. All other %options are added as key-value pairs.

๐Ÿ” Informational predicates

These are all basic predicate methods for the values passed into "new".

๐Ÿ’ฐ Value management

These methods are basically "back doors" to the instance, and can be used to bypass the regular accessors, but still stay within the MOP. These methods are not for general use, and should only be used if you really know what you are doing.

๐Ÿ”— Class association

These methods allow you to manage the attribute's association with the class that contains it. These methods should not be used lightly, nor are they very magical, they are mostly used internally and by metaclass instances.

โš™๏ธ Attribute Accessor generation

๐Ÿ”ฌ Introspection

Class::MOP::Attribute->meta โ€” This will return a Class::MOP::Class instance for this class. It should also be noted that Class::MOP will actually bootstrap this module by installing a number of attribute meta-objects into its metaclass.

๐Ÿ‘ฅ AUTHORS

ยฉ๏ธ COPYRIGHT AND LICENSE

This software is copyright (c) 2006 by Infinity Interactive, Inc.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

Class::MOP::Attribute
๐Ÿงพ NAME ๐Ÿš€ Quick Reference ๐Ÿ“š VERSION ๐Ÿ“‹ SYNOPSIS ๐Ÿ“– DESCRIPTION ๐Ÿ› ๏ธ METHODS
๐Ÿ—๏ธ Creation ๐Ÿ” Informational predicates ๐Ÿ’ฐ Value management ๐Ÿ”— Class association โš™๏ธ Attribute Accessor generation ๐Ÿ”ฌ Introspection
๐Ÿ‘ฅ AUTHORS ยฉ๏ธ COPYRIGHT AND LICENSE

Generated by phpman v4.9.29 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-20 18:31 @2600:1f28:365:80b0:8802:8bb4:3873:328e
CrawledBy CCBot/2.0 (https://commoncrawl.org/faq/)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^