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::Role

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


NAME

Moose::Meta::Role - The Moose Role metaclass


VERSION

version 2.2201


DESCRIPTION

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

Its API looks a lot like the Moose::Meta::Class manpage, but internally it implements many things differently. This may change in the future.


INHERITANCE

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


METHODS

Construction

Moose::Meta::Role->initialize($role_name)

This method creates a new role object with the provided name.

Moose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... )

This method accepts a list of array references. Each array reference should contain a role name or the Moose::Meta::Role manpage object as its first element. The second element is an optional hash reference. The hash reference can contain -excludes and -alias keys to control how methods are composed from the role.

The return value is a new the Moose::Meta::Role::Composite manpage that represents the combined roles.

$metarole->composition_class_roles

When combining multiple roles using combine, this method is used to obtain a list of role names to be applied to the the Moose::Meta::Role::Composite manpage instance returned by combine. The default implementation returns an empty list. Extensions that need to hook into role combination may wrap this method to return additional role names.

Moose::Meta::Role->create($name, %options)

This method is identical to the the Moose::Meta::Class manpage create method.

Moose::Meta::Role->create_anon_role

This method is identical to the the Moose::Meta::Class manpage create_anon_class method.

$metarole->is_anon_role

Returns true if the role is an anonymous role.

$metarole->consumers

Returns a list of names of classes and roles which consume this role.

Role application

$metarole->apply( $thing, @options )

This method applies a role to the given $thing. That can be another the Moose::Meta::Role manpage, object, a the Moose::Meta::Class manpage object, or a (non-meta) object instance.

The options are passed directly to the constructor for the appropriate the Moose::Meta::Role::Application manpage subclass.

Note that this will apply the role even if the $thing in question already does this role. does_role in the Moose::Util manpage is a convenient wrapper for finding out if role application is necessary.

Roles and other roles

$metarole->get_roles

This returns an array reference of roles which this role does. This list may include duplicates.

$metarole->calculate_all_roles

This returns a unique list of all roles that this role does, and all the roles that its roles do.

$metarole->does_role($role)

Given a role name or the Moose::Meta::Role manpage object, returns true if this role does the given role.

$metarole->add_role($role)

Given a the Moose::Meta::Role manpage object, this adds the role to the list of roles that the role does.

$metarole->get_excluded_roles_list

Returns a list of role names which this role excludes.

$metarole->excludes_role($role_name)

Given a role name, returns true if this role excludes the named role.

$metarole->add_excluded_roles(@role_names)

Given one or more role names, adds those roles to the list of excluded roles.

Methods

The methods for dealing with a role's methods are all identical in API and behavior to the same methods in the Class::MOP::Class manpage.

$metarole->method_metaclass

Returns the method metaclass name for the role. This defaults to the Moose::Meta::Role::Method manpage.

$metarole->get_method($name)

$metarole->has_method($name)

$metarole->add_method( $name, $body )

$metarole->get_method_list

$metarole->find_method_by_name($name)

These methods are all identical to the methods of the same name in the Class::MOP::Package manpage

Attributes

As with methods, the methods for dealing with a role's attribute are all identical in API and behavior to the same methods in the Class::MOP::Class manpage.

However, attributes stored in this class are not stored as objects. Rather, the attribute definition is stored as a hash reference. When a role is composed into a class, this hash reference is passed directly to the metaclass's add_attribute method.

This is quite likely to change in the future.

$metarole->get_attribute($attribute_name)

$metarole->has_attribute($attribute_name)

$metarole->get_attribute_list

$metarole->add_attribute($name, %options)

$metarole->remove_attribute($attribute_name)

Overload introspection and creation

The methods for dealing with a role's overloads are all identical in API and behavior to the same methods in the Class::MOP::Class manpage.

$metarole->is_overloaded

$metarole->get_overloaded_operator($op)

$metarole->has_overloaded_operator($op)

$metarole->get_overload_list

$metarole->get_all_overloaded_operators

$metarole->add_overloaded_operator($op, $impl)

$metarole->remove_overloaded_operator($op)

Required methods

$metarole->get_required_method_list

Returns the list of methods required by the role.

$metarole->requires_method($name)

Returns true if the role requires the named method.

$metarole->add_required_methods(@names)

Adds the named methods to the role's list of required methods.

$metarole->remove_required_methods(@names)

Removes the named methods from the role's list of required methods.

$metarole->add_conflicting_method(%params)

Instantiate the parameters as a the Moose::Meta::Role::Method::Conflicting manpage object, then add it to the required method list.

Method modifiers

These methods act like their counterparts in the Class::MOP::Class manpage and the Moose::Meta::Class manpage.

However, method modifiers are simply stored internally, and are not applied until the role itself is applied to a class or object.

$metarole->add_after_method_modifier($method_name, $method)

$metarole->add_around_method_modifier($method_name, $method)

$metarole->add_before_method_modifier($method_name, $method)

$metarole->add_override_method_modifier($method_name, $method)

These methods all add an appropriate modifier to the internal list of modifiers.

$metarole->has_after_method_modifiers

$metarole->has_around_method_modifiers

$metarole->has_before_method_modifiers

$metarole->has_override_method_modifier

Return true if the role has any modifiers of the given type.

$metarole->get_after_method_modifiers($method_name)

$metarole->get_around_method_modifiers($method_name)

$metarole->get_before_method_modifiers($method_name)

Given a method name, returns a list of the appropriate modifiers for that method.

$metarole->get_override_method_modifier($method_name)

Given a method name, returns the override method modifier for that method, if it has one.

Introspection

Moose::Meta::Role->meta

This will return a the Class::MOP::Class manpage instance for this class.


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