Perl Diver 2.31
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Moose::Meta::Attribute

Name Moose::Meta::Attribute
Version 2.2201
Located at /usr/local/lib64/perl5
File /usr/local/lib64/perl5/Moose/Meta/Attribute.pm
Is Core No
Search CPAN for this module Moose::Meta::Attribute
Documentation Moose::Meta::Attribute
Module Details Moose::Meta::Attribute


NAME

Moose::Meta::Attribute - The Moose attribute metaclass


VERSION

version 2.2201


DESCRIPTION

This class is a subclass of the Class::MOP::Attribute manpage that provides additional Moose-specific functionality.

To really understand this class, you will need to start with the the Class::MOP::Attribute manpage documentation. This class can be understood as a set of additional features on top of the basic feature provided by that parent class.


INHERITANCE

Moose::Meta::Attribute is a subclass of the Class::MOP::Attribute manpage.


METHODS

Many of the documented below override methods in the Class::MOP::Attribute manpage and add Moose specific features.

Creation

Moose::Meta::Attribute->new($name, %options)
This method overrides the the Class::MOP::Attribute manpage constructor.

Many of the options below are described in more detail in the the Moose::Manual::Attributes manpage document.

It adds the following options to the constructor:

$attr->clone(%options)
This creates a new attribute based on attribute being cloned. You must supply a name option to provide a new name for the attribute.

The %options can only specify options handled by the Class::MOP::Attribute manpage.

Value management

$attr->initialize_instance_slot($meta_instance, $instance, $params)
This method is used internally to initialize the attribute's slot in the object $instance.

This overrides the the Class::MOP::Attribute manpage method to handle lazy attributes, weak references, and type constraints.

get_value
set_value
  eval { $point->meta->get_attribute('x')->set_value($point, 'forty-two') };
  if($@) {
    print "Oops: $@\n";
  }

Attribute (x) does not pass the type constraint (Int) with 'forty-two'

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.

Any coercion to convert values is done before checking the type constraint.

To check a value against a type constraint before setting it, fetch the attribute instance using find_attribute_by_name in the Class::MOP::Class manpage, fetch the type_constraint from the attribute using type_constraint in the Moose::Meta::Attribute manpage and call check in the Moose::Meta::TypeConstraint manpage. See the Moose::Cookbook::Basics::Company_Subtypes manpage for an example.

Attribute Accessor generation

$attr->install_accessors
This method overrides the parent to also install delegation methods.

If, after installing all methods, the attribute object has no associated methods, it throws an error unless is => 'bare' was passed to the attribute constructor. (Trying to add an attribute that has no associated methods is almost always an error.)

$attr->remove_accessors
This method overrides the parent to also remove delegation methods.

$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 '$self' or '$_[1]'.

$attr->install_delegation
This method adds its delegation methods to the attribute's associated class, if it has any to add.

$attr->remove_delegation
This method remove its delegation methods from the attribute's associated class.

$attr->accessor_metaclass
Returns the accessor metaclass name, which defaults to the Moose::Meta::Method::Accessor manpage.

$attr->delegation_metaclass
Returns the delegation metaclass name, which defaults to the Moose::Meta::Method::Delegation manpage.

Additional Moose features

These methods are not found in the superclass. They support features provided by Moose.

$attr->does($role)
This indicates whether the attribute itself does the given role. The role can be given as a full class name, or as a resolvable trait name.

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.

Moose::Meta::Class->interpolate_class_and_new($name, %options)
This is an alternate constructor that handles the metaclass and traits options.

Effectively, this method is a factory that finds or creates the appropriate class for the given metaclass and/or traits.

Once it has the appropriate class, it will call $class->new($name, %options) on that class.

$attr->clone_and_inherit_options(%options)
This method supports the has '+foo' feature. It does various bits of processing on the supplied %options before ultimately calling the clone method.

One of its main tasks is to make sure that the %options provided does not include the options returned by the illegal_options_for_inheritance method.

$attr->illegal_options_for_inheritance
This returns a blacklist of options that can not be overridden in a subclass's attribute definition.

This exists to allow a custom metaclass to change or add to the list of options which can not be changed.

$attr->type_constraint
Returns the the Moose::Meta::TypeConstraint manpage object for this attribute, if it has one.

$attr->has_type_constraint
Returns true if this attribute has a type constraint.

$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.

$attr->handles
This returns the value of the handles option passed to the constructor.

$attr->has_handles
Returns true if this attribute performs delegation.

$attr->is_weak_ref
Returns true if this attribute stores its value as a weak reference.

$attr->is_required
Returns true if this attribute is required to have a value.

$attr->is_lazy
Returns true if this attribute is lazy.

$attr->is_lazy_build
Returns true if the lazy_build option was true when passed to the constructor.

$attr->should_coerce
Returns true if the coerce option passed to the constructor was true.

$attr->should_auto_deref
Returns true if the auto_deref option passed to the constructor was true.

$attr->trigger
This is the subroutine reference that was in the trigger option passed to the constructor, if any.

$attr->has_trigger
Returns true if this attribute has a trigger set.

$attr-documentation >>$attr->documentation
Returns the value that was in the documentation option passed to the constructor, if any.

$attr->has_documentation
Returns true if this attribute has any documentation.

$attr->role_attribute
Returns the the Moose::Meta::Role::Attribute manpage object from which this attribute was created, if any. This may return undef.

$attr->has_role_attribute
Returns true if this attribute has an associated role attribute.

$attr->applied_traits
This returns an array reference of all the traits which were applied to this attribute. If none were applied, this returns undef.

$attr->has_applied_traits
Returns true if this attribute has any traits applied.


BUGS

See Moose/BUGS for details on reporting bugs.


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.

Perl Diver brought to you by ScriptSolutions.com © 1997- 2024