.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Moose::Meta::Attribute 3pm" .TH Moose::Meta::Attribute 3pm 2024-01-21 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Moose::Meta::Attribute \- The Moose attribute metaclass .SH VERSION .IX Header "VERSION" version 2.2207 .SH DESCRIPTION .IX Header "DESCRIPTION" This class is a subclass of Class::MOP::Attribute that provides additional Moose-specific functionality. .PP To really understand this class, you will need to start with the Class::MOP::Attribute documentation. This class can be understood as a set of additional features on top of the basic feature provided by that parent class. .SH INHERITANCE .IX Header "INHERITANCE" \&\f(CW\*(C`Moose::Meta::Attribute\*(C'\fR is a subclass of Class::MOP::Attribute. .SH METHODS .IX Header "METHODS" Many of the documented below override methods in Class::MOP::Attribute and add Moose specific features. .SS Creation .IX Subsection "Creation" .ie n .IP "\fBMoose::Meta::Attribute\->new($name, \fR\fB%options\fR\fB)\fR" 4 .el .IP "\fBMoose::Meta::Attribute\->new($name, \fR\f(CB%options\fR\fB)\fR" 4 .IX Item "Moose::Meta::Attribute->new($name, %options)" This method overrides the Class::MOP::Attribute constructor. .Sp Many of the options below are described in more detail in the Moose::Manual::Attributes document. .Sp It adds the following options to the constructor: .RS 4 .IP \(bu 8 is => 'ro', 'rw', 'bare' .Sp This provides a shorthand for specifying the \f(CW\*(C`reader\*(C'\fR, \f(CW\*(C`writer\*(C'\fR, or \&\f(CW\*(C`accessor\*(C'\fR names. If the attribute is read-only ('ro') then it will have a \f(CW\*(C`reader\*(C'\fR method with the same attribute as the name. .Sp If it is read-write ('rw') then it will have an \f(CW\*(C`accessor\*(C'\fR method with the same name. If you provide an explicit \f(CW\*(C`writer\*(C'\fR for a read-write attribute, then you will have a \f(CW\*(C`reader\*(C'\fR with the same name as the attribute, and a \f(CW\*(C`writer\*(C'\fR with the name you provided. .Sp Use 'bare' when you are deliberately not installing any methods (accessor, reader, etc.) associated with this attribute; otherwise, Moose will issue a warning when this attribute is added to a metaclass. .IP \(bu 8 isa => \f(CW$type\fR .Sp 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. .Sp This option can also accept a Moose::Meta::TypeConstraint object. .Sp If you \fIalso\fR provide a \f(CW\*(C`does\*(C'\fR option, then your \f(CW\*(C`isa\*(C'\fR option must be a class name, and that class must do the role specified with \&\f(CW\*(C`does\*(C'\fR. .IP \(bu 8 does => \f(CW$role\fR .Sp This is short-hand for saying that the attribute's type must be an object which does the named role. .IP \(bu 8 coerce => \f(CW$bool\fR .Sp This option is only valid for objects with a type constraint (\f(CW\*(C`isa\*(C'\fR) that defined a coercion. If this is true, then coercions will be applied whenever this attribute is set. .Sp You cannot make both this and the \f(CW\*(C`weak_ref\*(C'\fR option true. .IP \(bu 8 trigger => \f(CW$sub\fR .Sp This option accepts a subroutine reference, which will be called after the attribute is set. .IP \(bu 8 required => \f(CW$bool\fR .Sp An attribute which is required must be provided to the constructor. An attribute which is required can also have a \f(CW\*(C`default\*(C'\fR or \f(CW\*(C`builder\*(C'\fR, which will satisfy its required-ness. .Sp A required attribute must have a \f(CW\*(C`default\*(C'\fR, \f(CW\*(C`builder\*(C'\fR or a non\-\f(CW\*(C`undef\*(C'\fR \f(CW\*(C`init_arg\*(C'\fR .IP \(bu 8 lazy => \f(CW$bool\fR .Sp A lazy attribute must have a \f(CW\*(C`default\*(C'\fR or \f(CW\*(C`builder\*(C'\fR. When an attribute is lazy, the default value will not be calculated until the attribute is read. .IP \(bu 8 weak_ref => \f(CW$bool\fR .Sp If this is true, the attribute's value will be stored as a weak reference. .IP \(bu 8 documentation .Sp An arbitrary string that can be retrieved later by calling \f(CW\*(C`$attr\->documentation\*(C'\fR. .IP \(bu 8 auto_deref => \f(CW$bool\fR .Sp \&\fBNote that in cases where you want this feature you are often better served by using a Moose::Meta::Attribute::Native trait instead\fR. .Sp 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. .IP \(bu 8 lazy_build => \f(CW$bool\fR .Sp \&\fBNote that use of this feature is strongly discouraged.\fR Some documentation used to encourage use of this feature as a best practice, but we have changed our minds. .Sp Setting this to true makes the attribute lazy and provides a number of default methods. .Sp .Vb 4 \& has \*(Aqsize\*(Aq => ( \& is => \*(Aqro\*(Aq, \& lazy_build => 1, \& ); .Ve .Sp is equivalent to this: .Sp .Vb 7 \& has \*(Aqsize\*(Aq => ( \& is => \*(Aqro\*(Aq, \& lazy => 1, \& builder => \*(Aq_build_size\*(Aq, \& clearer => \*(Aqclear_size\*(Aq, \& predicate => \*(Aqhas_size\*(Aq, \& ); .Ve .Sp If your attribute name starts with an underscore (\f(CW\*(C`_\*(C'\fR), then the clearer and predicate will as well: .Sp .Vb 4 \& has \*(Aq_size\*(Aq => ( \& is => \*(Aqro\*(Aq, \& lazy_build => 1, \& ); .Ve .Sp becomes: .Sp .Vb 7 \& has \*(Aq_size\*(Aq => ( \& is => \*(Aqro\*(Aq, \& lazy => 1, \& builder => \*(Aq_build_\|_size\*(Aq, \& clearer => \*(Aq_clear_size\*(Aq, \& predicate => \*(Aq_has_size\*(Aq, \& ); .Ve .Sp Note the doubled underscore in the builder name. Internally, Moose simply prepends the attribute name with "_build_" to come up with the builder name. .IP \(bu 8 role_attribute => \f(CW$role_attribute\fR .Sp If provided, this should be a Moose::Meta::Role::Attribute object. .RE .RS 4 .RE .ie n .IP \fR\fB$attr\fR\fB\->clone(%options)\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->clone(%options)\fR 4 .IX Item "$attr->clone(%options)" This creates a new attribute based on attribute being cloned. You must supply a \f(CW\*(C`name\*(C'\fR option to provide a new name for the attribute. .Sp The \f(CW%options\fR can only specify options handled by Class::MOP::Attribute. .SS "Value management" .IX Subsection "Value management" .ie n .IP "\fR\fB$attr\fR\fB\->initialize_instance_slot($meta_instance, \fR\fB$instance\fR\fB, \fR\fB$params\fR\fB)\fR" 4 .el .IP "\fR\f(CB$attr\fR\fB\->initialize_instance_slot($meta_instance, \fR\f(CB$instance\fR\fB, \fR\f(CB$params\fR\fB)\fR" 4 .IX Item "$attr->initialize_instance_slot($meta_instance, $instance, $params)" This method is used internally to initialize the attribute's slot in the object \f(CW$instance\fR. .Sp This overrides the Class::MOP::Attribute method to handle lazy attributes, weak references, and type constraints. .IP \fBget_value\fR 4 .IX Item "get_value" .PD 0 .IP \fBset_value\fR 4 .IX Item "set_value" .PD .Vb 4 \& eval { $point\->meta\->get_attribute(\*(Aqx\*(Aq)\->set_value($point, \*(Aqforty\-two\*(Aq) }; \& if($@) { \& print "Oops: $@\en"; \& } .Ve .Sp \&\fIAttribute (x) does not pass the type constraint (Int) with 'forty\-two'\fR .Sp Before setting the value, a check is made on the type constraint of the attribute, if it has one, to see if the value passes it. If the value fails to pass, the set operation dies. .Sp Any coercion to convert values is done before checking the type constraint. .Sp To check a value against a type constraint before setting it, fetch the attribute instance using "find_attribute_by_name" in Class::MOP::Class, fetch the type_constraint from the attribute using "type_constraint" in Moose::Meta::Attribute and call "check" in Moose::Meta::TypeConstraint. See Moose::Cookbook::Basics::Company_Subtypes for an example. .SS "Attribute Accessor generation" .IX Subsection "Attribute Accessor generation" .ie n .IP \fR\fB$attr\fR\fB\->install_accessors\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->install_accessors\fR 4 .IX Item "$attr->install_accessors" This method overrides the parent to also install delegation methods. .Sp If, after installing all methods, the attribute object has no associated methods, it throws an error unless \f(CW\*(C`is => \*(Aqbare\*(Aq\*(C'\fR was passed to the attribute constructor. (Trying to add an attribute that has no associated methods is almost always an error.) .ie n .IP \fR\fB$attr\fR\fB\->remove_accessors\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->remove_accessors\fR 4 .IX Item "$attr->remove_accessors" This method overrides the parent to also remove delegation methods. .ie n .IP "\fR\fB$attr\fR\fB\->inline_set($instance_var, \fR\fB$value_var\fR\fB)\fR" 4 .el .IP "\fR\f(CB$attr\fR\fB\->inline_set($instance_var, \fR\f(CB$value_var\fR\fB)\fR" 4 .IX Item "$attr->inline_set($instance_var, $value_var)" This method return a code snippet suitable for inlining the relevant operation. It expect strings containing variable names to be used in the inlining, like \f(CW\*(Aq$self\*(Aq\fR or \f(CW\*(Aq$_[1]\*(Aq\fR. .ie n .IP \fR\fB$attr\fR\fB\->install_delegation\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->install_delegation\fR 4 .IX Item "$attr->install_delegation" This method adds its delegation methods to the attribute's associated class, if it has any to add. .ie n .IP \fR\fB$attr\fR\fB\->remove_delegation\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->remove_delegation\fR 4 .IX Item "$attr->remove_delegation" This method remove its delegation methods from the attribute's associated class. .ie n .IP \fR\fB$attr\fR\fB\->accessor_metaclass\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->accessor_metaclass\fR 4 .IX Item "$attr->accessor_metaclass" Returns the accessor metaclass name, which defaults to Moose::Meta::Method::Accessor. .ie n .IP \fR\fB$attr\fR\fB\->delegation_metaclass\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->delegation_metaclass\fR 4 .IX Item "$attr->delegation_metaclass" Returns the delegation metaclass name, which defaults to Moose::Meta::Method::Delegation. .SS "Additional Moose features" .IX Subsection "Additional Moose features" These methods are not found in the superclass. They support features provided by Moose. .ie n .IP \fR\fB$attr\fR\fB\->does($role)\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->does($role)\fR 4 .IX Item "$attr->does($role)" This indicates whether the \fIattribute itself\fR does the given role. The role can be given as a full class name, or as a resolvable trait name. .Sp Note that this checks the attribute itself, not its type constraint, so it is checking the attribute's metaclass and any traits applied to the attribute. .ie n .IP "\fBMoose::Meta::Class\->interpolate_class_and_new($name, \fR\fB%options\fR\fB)\fR" 4 .el .IP "\fBMoose::Meta::Class\->interpolate_class_and_new($name, \fR\f(CB%options\fR\fB)\fR" 4 .IX Item "Moose::Meta::Class->interpolate_class_and_new($name, %options)" This is an alternate constructor that handles the \f(CW\*(C`metaclass\*(C'\fR and \&\f(CW\*(C`traits\*(C'\fR options. .Sp Effectively, this method is a factory that finds or creates the appropriate class for the given \f(CW\*(C`metaclass\*(C'\fR and/or \f(CW\*(C`traits\*(C'\fR. .Sp Once it has the appropriate class, it will call \f(CW\*(C`$class\->new($name, %options)\*(C'\fR on that class. .ie n .IP \fR\fB$attr\fR\fB\->clone_and_inherit_options(%options)\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->clone_and_inherit_options(%options)\fR 4 .IX Item "$attr->clone_and_inherit_options(%options)" This method supports the \f(CW\*(C`has \*(Aq+foo\*(Aq\*(C'\fR feature. It does various bits of processing on the supplied \f(CW%options\fR before ultimately calling the \f(CW\*(C`clone\*(C'\fR method. .Sp One of its main tasks is to make sure that the \f(CW%options\fR provided does not include the options returned by the \&\f(CW\*(C`illegal_options_for_inheritance\*(C'\fR method. .ie n .IP \fR\fB$attr\fR\fB\->illegal_options_for_inheritance\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->illegal_options_for_inheritance\fR 4 .IX Item "$attr->illegal_options_for_inheritance" This returns a blacklist of options that can not be overridden in a subclass's attribute definition. .Sp This exists to allow a custom metaclass to change or add to the list of options which can not be changed. .ie n .IP \fR\fB$attr\fR\fB\->type_constraint\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->type_constraint\fR 4 .IX Item "$attr->type_constraint" Returns the Moose::Meta::TypeConstraint object for this attribute, if it has one. .ie n .IP \fR\fB$attr\fR\fB\->has_type_constraint\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_type_constraint\fR 4 .IX Item "$attr->has_type_constraint" Returns true if this attribute has a type constraint. .ie n .IP \fR\fB$attr\fR\fB\->verify_against_type_constraint($value)\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->verify_against_type_constraint($value)\fR 4 .IX Item "$attr->verify_against_type_constraint($value)" Given a value, this method returns true if the value is valid for the attribute's type constraint. If the value is not valid, it throws an error. .ie n .IP \fR\fB$attr\fR\fB\->handles\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->handles\fR 4 .IX Item "$attr->handles" This returns the value of the \f(CW\*(C`handles\*(C'\fR option passed to the constructor. .ie n .IP \fR\fB$attr\fR\fB\->has_handles\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_handles\fR 4 .IX Item "$attr->has_handles" Returns true if this attribute performs delegation. .ie n .IP \fR\fB$attr\fR\fB\->is_weak_ref\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->is_weak_ref\fR 4 .IX Item "$attr->is_weak_ref" Returns true if this attribute stores its value as a weak reference. .ie n .IP \fR\fB$attr\fR\fB\->is_required\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->is_required\fR 4 .IX Item "$attr->is_required" Returns true if this attribute is required to have a value. .ie n .IP \fR\fB$attr\fR\fB\->is_lazy\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->is_lazy\fR 4 .IX Item "$attr->is_lazy" Returns true if this attribute is lazy. .ie n .IP \fR\fB$attr\fR\fB\->is_lazy_build\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->is_lazy_build\fR 4 .IX Item "$attr->is_lazy_build" Returns true if the \f(CW\*(C`lazy_build\*(C'\fR option was true when passed to the constructor. .ie n .IP \fR\fB$attr\fR\fB\->should_coerce\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->should_coerce\fR 4 .IX Item "$attr->should_coerce" Returns true if the \f(CW\*(C`coerce\*(C'\fR option passed to the constructor was true. .ie n .IP \fR\fB$attr\fR\fB\->should_auto_deref\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->should_auto_deref\fR 4 .IX Item "$attr->should_auto_deref" Returns true if the \f(CW\*(C`auto_deref\*(C'\fR option passed to the constructor was true. .ie n .IP \fR\fB$attr\fR\fB\->trigger\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->trigger\fR 4 .IX Item "$attr->trigger" This is the subroutine reference that was in the \f(CW\*(C`trigger\*(C'\fR option passed to the constructor, if any. .ie n .IP \fR\fB$attr\fR\fB\->has_trigger\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_trigger\fR 4 .IX Item "$attr->has_trigger" Returns true if this attribute has a trigger set. .ie n .IP \fR\fB$attr\fR\fB\->documentation\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->documentation\fR 4 .IX Item "$attr->documentation" Returns the value that was in the \f(CW\*(C`documentation\*(C'\fR option passed to the constructor, if any. .ie n .IP \fR\fB$attr\fR\fB\->has_documentation\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_documentation\fR 4 .IX Item "$attr->has_documentation" Returns true if this attribute has any documentation. .ie n .IP \fR\fB$attr\fR\fB\->role_attribute\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->role_attribute\fR 4 .IX Item "$attr->role_attribute" Returns the Moose::Meta::Role::Attribute object from which this attribute was created, if any. This may return \f(CW\*(C`undef\*(C'\fR. .ie n .IP \fR\fB$attr\fR\fB\->has_role_attribute\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_role_attribute\fR 4 .IX Item "$attr->has_role_attribute" Returns true if this attribute has an associated role attribute. .ie n .IP \fR\fB$attr\fR\fB\->applied_traits\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->applied_traits\fR 4 .IX Item "$attr->applied_traits" This returns an array reference of all the traits which were applied to this attribute. If none were applied, this returns \f(CW\*(C`undef\*(C'\fR. .ie n .IP \fR\fB$attr\fR\fB\->has_applied_traits\fR 4 .el .IP \fR\f(CB$attr\fR\fB\->has_applied_traits\fR 4 .IX Item "$attr->has_applied_traits" Returns true if this attribute has any traits applied. .SH BUGS .IX Header "BUGS" See "BUGS" in Moose for details on reporting bugs. .SH AUTHORS .IX Header "AUTHORS" .IP \(bu 4 Stevan Little .IP \(bu 4 Dave Rolsky .IP \(bu 4 Jesse Luehrs .IP \(bu 4 Shawn M Moore .IP \(bu 4 יובל קוג'מן (Yuval Kogman) .IP \(bu 4 Karen Etheridge .IP \(bu 4 Florian Ragwitz .IP \(bu 4 Hans Dieter Pearcey .IP \(bu 4 Chris Prather .IP \(bu 4 Matt S Trout .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2006 by Infinity Interactive, Inc. .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.