1Mouse::Util::MetaRole(3U)ser Contributed Perl DocumentatiMoonuse::Util::MetaRole(3)
2
3
4

NAME

6       Mouse::Util::MetaRole - Apply roles to any metaclass, as well as the
7       object base class
8

SYNOPSIS

10         package MyApp::Mouse;
11
12         use Mouse ();
13         use Mouse::Exporter;
14         use Mouse::Util::MetaRole;
15
16         use MyApp::Role::Meta::Class;
17         use MyApp::Role::Meta::Method::Constructor;
18         use MyApp::Role::Object;
19
20         Mouse::Exporter->setup_import_methods( also => 'Mouse' );
21
22         sub init_meta {
23             shift;
24             my %args = @_;
25
26             Mouse->init_meta(%args);
27
28             Mouse::Util::MetaRole::apply_metaroles(
29                 for             => $args{for_class},
30                 class_metaroles => {
31                     class       => ['MyApp::Role::Meta::Class'],
32                     constructor => ['MyApp::Role::Meta::Method::Constructor'],
33                 },
34             );
35
36             Mouse::Util::MetaRole::apply_base_class_roles(
37                 for   => $args{for_class},
38                 roles => ['MyApp::Role::Object'],
39             );
40
41             return $args{for_class}->meta();
42         }
43

DESCRIPTION

45       This utility module is designed to help authors of Mouse extensions
46       write extensions that are able to cooperate with other Mouse
47       extensions. To do this, you must write your extensions as roles, which
48       can then be dynamically applied to the caller's metaclasses.
49
50       This module makes sure to preserve any existing superclasses and roles
51       already set for the meta objects, which means that any number of
52       extensions can apply roles in any order.
53

USAGE

55       It is very important that you only call this module's functions when
56       your module is imported by the caller. The process of applying roles to
57       the metaclass reinitializes the metaclass object, which wipes out any
58       existing attributes already defined. However, as long as you do this
59       when your module is imported, the caller should not have any attributes
60       defined yet.
61
62       The easiest way to ensure that this happens is to use Mouse::Exporter,
63       which can generate the appropriate "init_meta" method for you, and make
64       sure it is called when imported.
65

FUNCTIONS

67       This module provides two functions.
68
69   apply_metaroles( ... )
70       This function will apply roles to one or more metaclasses for the
71       specified class. It accepts the following parameters:
72
73       ·   for => $name
74
75           This specifies the class or for which to alter the meta classes.
76           This can be a package name, or an appropriate meta-object (a
77           Mouse::Meta::Class or Mouse::Meta::Role).
78
79       ·   class_metaroles => \%roles
80
81           This is a hash reference specifying which metaroles will be applied
82           to the class metaclass and its contained metaclasses and helper
83           classes.
84
85           Each key should in turn point to an array reference of role names.
86
87           It accepts the following keys:
88
89           class
90           attribute
91           method
92           constructor
93           destructor
94       ·   role_metaroles => \%roles
95
96           This is a hash reference specifying which metaroles will be applied
97           to the role metaclass and its contained metaclasses and helper
98           classes.
99
100           It accepts the following keys:
101
102           role
103           method
104
105   apply_base_class_roles( for => $class, roles => \@roles )
106       This function will apply the specified roles to the object's base
107       class.
108

SEE ALSO

110       Moose::Util::MetaRole
111
112
113
114perl v5.28.1                      2019-02-02          Mouse::Util::MetaRole(3)
Impressum