Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

mouse::util::metarole(3pm) [debian man page]

Mouse::Util::MetaRole(3pm)				User Contributed Perl Documentation				Mouse::Util::MetaRole(3pm)

Mouse::Util::MetaRole - Apply roles to any metaclass, as well as the object base class SYNOPSIS
package MyApp::Mouse; use Mouse (); use Mouse::Exporter; use Mouse::Util::MetaRole; use MyApp::Role::Meta::Class; use MyApp::Role::Meta::Method::Constructor; use MyApp::Role::Object; Mouse::Exporter->setup_import_methods( also => 'Mouse' ); sub init_meta { shift; my %args = @_; Mouse->init_meta(%args); Mouse::Util::MetaRole::apply_metaroles( for => $args{for_class}, class_metaroles => { class => ['MyApp::Role::Meta::Class'], constructor => ['MyApp::Role::Meta::Method::Constructor'], }, ); Mouse::Util::MetaRole::apply_base_class_roles( for => $args{for_class}, roles => ['MyApp::Role::Object'], ); return $args{for_class}->meta(); } DESCRIPTION
This utility module is designed to help authors of Mouse extensions write extensions that are able to cooperate with other Mouse extensions. To do this, you must write your extensions as roles, which can then be dynamically applied to the caller's metaclasses. This module makes sure to preserve any existing superclasses and roles already set for the meta objects, which means that any number of extensions can apply roles in any order. USAGE
It is very important that you only call this module's functions when your module is imported by the caller. The process of applying roles to the metaclass reinitializes the metaclass object, which wipes out any existing attributes already defined. However, as long as you do this when your module is imported, the caller should not have any attributes defined yet. The easiest way to ensure that this happens is to use Mouse::Exporter, which can generate the appropriate "init_meta" method for you, and make sure it is called when imported. FUNCTIONS
This module provides two functions. apply_metaroles( ... ) This function will apply roles to one or more metaclasses for the specified class. It accepts the following parameters: o for => $name This specifies the class or for which to alter the meta classes. This can be a package name, or an appropriate meta-object (a Mouse::Meta::Class or Mouse::Meta::Role). o class_metaroles => \%roles This is a hash reference specifying which metaroles will be applied to the class metaclass and its contained metaclasses and helper classes. Each key should in turn point to an array reference of role names. It accepts the following keys: class attribute method constructor destructor o role_metaroles => \%roles This is a hash reference specifying which metaroles will be applied to the role metaclass and its contained metaclasses and helper classes. It accepts the following keys: role method apply_base_class_roles( for => $class, roles => @roles ) This function will apply the specified roles to the object's base class. SEE ALSO
Moose::Util::MetaRole perl v5.14.2 2012-06-30 Mouse::Util::MetaRole(3pm)

Check Out this Related Man Page

Mouse::Role(3pm)					User Contributed Perl Documentation					  Mouse::Role(3pm)

Mouse::Role - The Mouse Role VERSION
This document describes Mouse version 0.99 SYNOPSIS
package Comparable; use Mouse::Role; # the package is now a Mouse role # Declare methods that are required by this role requires qw(compare); # Define methods this role provides sub equals { my($self, $other) = @_; return $self->compare($other) == 0; } # and later package MyObject; use Mouse; with qw(Comparable); # Now MyObject can equals() sub compare { # ... } my $foo = MyObject->new(); my $bar = MyObject->new(); $obj->equals($bar); # yes, it is comparable DESCRIPTION
This module declares the caller class to be a Mouse role. The concept of roles is documented in Moose::Manual::Roles. This document serves as API documentation. EXPORTED FUNCTIONS
Mouse::Role supports all of the functions that Mouse exports, but differs slightly in how some items are handled (see "CAVEATS" below for details). Mouse::Role also offers two role-specific keywords: "requires(@method_names)" Roles can require that certain methods are implemented by any class which "does" the role. Note that attribute accessors also count as methods for the purposes of satisfying the requirements of a role. "excludes(@role_names)" This is exported but not implemented in Mouse. IMPORT AND UNIMPORT
import Importing Mouse::Role will give you sugar. "-traits" are also supported. unimport Please unimport ("no Mouse::Role") so that if someone calls one of the keywords (such as "has") it will break loudly instead breaking subtly. CAVEATS
Role support has only a few caveats: o Roles cannot use the "extends" keyword; it will throw an exception for now. The same is true of the "augment" and "inner" keywords (not sure those really make sense for roles). All other Mouse keywords will be deferred so that they can be applied to the consuming class. o Role composition does its best to not be order-sensitive when it comes to conflict resolution and requirements detection. However, it is order-sensitive when it comes to method modifiers. All before/around/after modifiers are included whenever a role is composed into a class, and then applied in the order in which the roles are used. This also means that there is no conflict for before/around/after modifiers. In most cases, this will be a non-issue; however, it is something to keep in mind when using method modifiers in a role. You should never assume any ordering. SEE ALSO
Mouse Moose::Role Moose::Manual::Roles Moose::Spec::Role perl v5.14.2 2012-06-30 Mouse::Role(3pm)
Man Page

Featured Tech Videos