Moose::Meta::Role(3)
๐ Moose::Meta::Role ๐
okay bestie, welcome to Moose::Meta::Role โ yes that's the manual page name too, we're keeping it cute and consistent ๐. It's the Moose Role metaclass, and it's literally the brain behind how roles do their thing.
โจ VERSION โจ
version 2.4000 โ fresh, iconic, no notes. ๐
๐ธ DESCRIPTION ๐ธ
So. This class is a subclass of Class::MOP::Module that piles a whole extra layer of Moose-specific functionality on top. It's giving "module but make it Moose."
Its API looks a lot like Moose::Meta::Class, bestie โ like, same energy, same vibes โ but internally it implements many things differently. And heads up: this may change in the future. So don't get too attached to the internals, okay? ๐
๐ฆ INHERITANCE ๐ฆ
Moose::Meta::Role is a subclass of Class::MOP::Module. Family tree confirmed, no cap. ๐ณ
๐ METHODS ๐
๐ง Construction ๐ง
Moose::Meta::Role->initialize($role_name)โ makes a brand new role object with the name you hand it. Baby role, born. ๐ผMoose::Meta::Role->combine( [ $role => { ... } ], [ $role ], ... )โ takes a list of array references. Each array ref should have a role name or a Moose::Meta::Role object as its first element. Second element is an optional hash reference, and that hash can carry-excludesand-aliaskeys to control how methods get composed out of the role. The return value is a shiny newMoose::Meta::Role::Compositerepresenting the combined roles. Slay. ๐ฅ$metarole->composition_class_rolesโ when you're combining multiple roles withcombine, this method grabs a list of role names to apply to theMoose::Meta::Role::Compositeinstance thatcombinereturns. The default implementation returns an empty list. Extensions that need to hook into role combination can wrap this method to return extra role names. Very "let me add to that" of them. ๐Moose::Meta::Role->create($name, %options)โ identical to theMoose::Meta::Classcreatemethod. Twin behaviour, no divergence. ๐ฏMoose::Meta::Role->create_anon_roleโ identical to theMoose::Meta::Classcreate_anon_classmethod. Anonymous, mysterious, main character. ๐ถ๏ธ$metarole->is_anon_roleโ returns true if the role is an anonymous role. Secret identity check. ๐ฅธ$metarole->consumersโ returns a list of names of classes and roles which consume this role. All the people who love this role back. ๐ซถ
๐ Role application ๐
$metarole->apply( $thing, @options )โ applies a role to the given$thing. That$thingcan be anotherMoose::Meta::Role, an object, aMoose::Meta::Classobject, or a (non-meta) object instance. The options get passed directly to the constructor for the appropriateMoose::Meta::Role::Applicationsubclass.
โ ๏ธ Heads up bestie: this will apply the role even if the$thingin question alreadydoesthis role.does_rolein Moose::Util is the convenient wrapper for finding out if role application is actually necessary. Use it, don't be messy. ๐
๐ Roles and other roles ๐
$metarole->get_rolesโ returns an array reference of roles which this role does. And yes, this list may include duplicates. It's not a set, it's a vibe.$metarole->calculate_all_rolesโ returns a unique list of all the roles this role does, plus all the roles those roles do. Recursive bestie energy. ๐$metarole->does_role($role)โ give it a role name or aMoose::Meta::Roleobject and it returns true if this role does the given role. โจ$metarole->add_role($role)โ given aMoose::Meta::Roleobject, adds it to the list of roles that this role does. New friend added to the group chat. ๐$metarole->get_excluded_roles_listโ returns a list of role names which this role excludes. The blocked list, basically. ๐ซ$metarole->excludes_role($role_name)โ given a role name, returns true if this role excludes it. Are they blocked? Find out. ๐$metarole->add_excluded_roles(@role_names)โ given one or more role names, adds them to the list of excluded roles. Blocked, collectively. ๐
๐ Methods ๐
The methods for dealing with a role's methods are all identical in API and behavior to the same methods in Class::MOP::Class. Like, every single one. Copy-paste behaviour, zero drama. ๐
$metarole->method_metaclassโ returns the method metaclass name for the role. Defaults toMoose::Meta::Role::Method. That's the one. โญ$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 Class::MOP::Class. Periodt. ๐
๐ Attributes ๐
Same as methods, bestie: the methods for dealing with a role's attributes are all identical in API and behavior to the same methods in Class::MOP::Class.
BUT. Huge but. ๐จ Attributes stored in this class are not stored as objects. Instead, the attribute definition is stored as a hash reference. When a role gets composed into a class, that hash reference is passed directly to the metaclass's add_attribute method.
This is quite likely to change in the future. So like, don't build your whole personality around it, okay? ๐ญ
$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 Class::MOP::Class. Consistent queen. ๐
$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. The non-negotiables. ๐$metarole->requires_method($name)โ returns true if the role requires the named method. Is it mandatory? Yes bestie, it is. โ$metarole->add_required_methods(@names)โ adds the named methods to the role's list of required methods. Requirements loadingโฆ โณ$metarole->remove_required_methods(@names)โ removes the named methods from the role's list of required methods. Requirement revoked. โ๏ธ$metarole->add_conflicting_method(%params)โ instantiates the parameters as aMoose::Meta::Role::Method::Conflictingobject, then adds it to the required method list. Conflict, but make it a method. ๐ฅ
๐ Method modifiers ๐
These methods act like their counterparts in Class::MOP::Class and Moose::Meta::Class. Same energy, same behaviour. ๐
HOWEVER โ and this is the tea โ โ method modifiers are simply stored internally, and they are not applied until the role itself is applied to a class or object. They just sit there. Waiting. Patiently. ๐
$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. Internal list stays winning. ๐
$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. Vibe check on the modifiers. ๐
$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. Modifiers, delivered. ๐ฆ
$metarole->get_override_method_modifier($method_name)โ given a method name, returns the override method modifier for that method, if it has one. If not, wellโฆ it doesn't. ๐คท
๐ฎ Introspection ๐ฎ
Moose::Meta::Role->metaโ this will return aClass::MOP::Classinstance for this class. Meta on meta on meta. ๐ชโจ
๐ BUGS ๐
See "BUGS" in Moose for details on reporting bugs. Go tell the Moose people, they want to know. ๐โก๏ธ๐ฎ
๐ซถ AUTHORS ๐ซถ
- Stevan Little
<stevan@cpan.org> - Dave Rolsky
<autarch@urth.org> - Jesse Luehrs
<doy@cpan.org> - Shawn M Moore
<sartak@cpan.org> - ืืืื ืงืื'ืื (Yuval Kogman)
<nothingmuch@woobling.org> - Karen Etheridge
<ether@cpan.org> - Florian Ragwitz
<rafl@debian.org> - Hans Dieter Pearcey
<hdp@cpan.org> - Chris Prather
<chris@prather.org> - Matt S Trout
<mstrout@cpan.org>
The whole squad. Legends only. ๐๐
๐ธ 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. Free as in freedom, bestie. ๐๏ธ
okay that's the whole page!! ๐ this was Moose::Meta::Role(3) from the User Contributed Perl Documentation, version 2.4000, and it was generated by perl v5.42.0 on 2025-07-25. ty for reading, mwah ๐ ๐โจ๐ฆ
๐ฆ where this page comes from
- fedora 43: perl-Moose 2.4000-4.fc43 ยท GPL-1.0-or-later OR Artistic-1.0-Perl
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms