1Moose::Util::MetaRole(3U)ser Contributed Perl DocumentatiMoonose::Util::MetaRole(3)
2
3
4

NAME

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

VERSION

10       version 2.2201
11

SYNOPSIS

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

DESCRIPTION

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

USAGE

58       The easiest way to use this module is through Moose::Exporter, which
59       can generate the appropriate "init_meta" method for you, and make sure
60       it is called when imported.
61

FUNCTIONS

63       This module provides two functions.
64
65   apply_metaroles( ... )
66       This function will apply roles to one or more metaclasses for the
67       specified class. It will return a new metaclass object for the class or
68       role passed in the "for" parameter.
69
70       It accepts the following parameters:
71
72       •   for => $name
73
74           This specifies the class or for which to alter the meta classes.
75           This can be a package name, or an appropriate meta-object (a
76           Moose::Meta::Class or Moose::Meta::Role).
77
78       •   class_metaroles => \%roles
79
80           This is a hash reference specifying which metaroles will be applied
81           to the class metaclass and its contained metaclasses and helper
82           classes.
83
84           Each key should in turn point to an array reference of role names.
85
86           It accepts the following keys:
87
88           class
89           attribute
90           method
91           wrapped_method
92           instance
93           constructor
94           destructor
95           error
96       •   role_metaroles => \%roles
97
98           This is a hash reference specifying which metaroles will be applied
99           to the role metaclass and its contained metaclasses and helper
100           classes.
101
102           It accepts the following keys:
103
104           role
105           attribute
106           method
107           required_method
108           conflicting_method
109           application_to_class
110           application_to_role
111           application_to_instance
112           application_role_summation
113           applied_attribute
114
115   apply_base_class_roles( for => $class, roles => \@roles )
116       This function will apply the specified roles to the object's base
117       class.
118

BUGS

120       See "BUGS" in Moose for details on reporting bugs.
121

AUTHORS

123       •   Stevan Little <stevan@cpan.org>
124
125       •   Dave Rolsky <autarch@urth.org>
126
127       •   Jesse Luehrs <doy@cpan.org>
128
129       •   Shawn M Moore <sartak@cpan.org>
130
131       •   יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
132
133       •   Karen Etheridge <ether@cpan.org>
134
135       •   Florian Ragwitz <rafl@debian.org>
136
137       •   Hans Dieter Pearcey <hdp@cpan.org>
138
139       •   Chris Prather <chris@prather.org>
140
141       •   Matt S Trout <mstrout@cpan.org>
142
144       This software is copyright (c) 2006 by Infinity Interactive, Inc.
145
146       This is free software; you can redistribute it and/or modify it under
147       the same terms as the Perl 5 programming language system itself.
148
149
150
151perl v5.34.0                      2022-01-21          Moose::Util::MetaRole(3)
Impressum