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 -excludes and -alias keys to control how methods get composed out of the role. The return value is a shiny new Moose::Meta::Role::Composite representing the combined roles. Slay. ๐Ÿ”ฅ
  • $metarole->composition_class_roles โ€” when you're combining multiple roles with combine, this method grabs a list of role names to apply to the Moose::Meta::Role::Composite instance that combine returns. 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 the Moose::Meta::Class create method. Twin behaviour, no divergence. ๐Ÿ‘ฏ
  • Moose::Meta::Role->create_anon_role โ€” identical to the Moose::Meta::Class create_anon_class method. 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 $thing can be another Moose::Meta::Role, an object, a Moose::Meta::Class object, or a (non-meta) object instance. The options get passed directly to the constructor for the appropriate Moose::Meta::Role::Application subclass.
โš ๏ธ Heads up bestie: this will apply the role even if the $thing in question already does this role. does_role in 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 a Moose::Meta::Role object and it returns true if this role does the given role. โœจ
  • $metarole->add_role($role) โ€” given a Moose::Meta::Role object, 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 to Moose::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 a Moose::Meta::Role::Method::Conflicting object, 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 a Class::MOP::Class instance 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. ๐Ÿ‘‘๐Ÿ’–


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