1Role::Tiny(3)         User Contributed Perl Documentation        Role::Tiny(3)
2
3
4

NAME

6       Role::Tiny - Roles: a nouvelle cuisine portion size slice of Moose
7

SYNOPSIS

9        package Some::Role;
10
11        use Role::Tiny;
12
13        sub foo { ... }
14
15        sub bar { ... }
16
17        around baz => sub { ... };
18
19        1;
20
21       elsewhere
22
23        package Some::Class;
24
25        use Role::Tiny::With;
26
27        # bar gets imported, but not foo
28        with 'Some::Role';
29
30        sub foo { ... }
31
32        # baz is wrapped in the around modifier by Class::Method::Modifiers
33        sub baz { ... }
34
35        1;
36
37       If you wanted attributes as well, look at Moo::Role.
38

DESCRIPTION

40       "Role::Tiny" is a minimalist role composition tool.
41

ROLE COMPOSITION

43       Role composition can be thought of as much more clever and meaningful
44       multiple inheritance.  The basics of this implementation of roles is:
45
46       · If a method is already defined on a class, that method will not be
47         composed in from the role. A method inherited by a class gets
48         overridden by the role's method of the same name, though.
49
50       · If a method that the role "requires" to be implemented is not
51         implemented, role application will fail loudly.
52
53       Unlike Class::C3, where the last class inherited from "wins," role
54       composition is the other way around, where the class wins. If multiple
55       roles are applied in a single call (single with statement), then if any
56       of their provided methods clash, an exception is raised unless the
57       class provides a method since this conflict indicates a potential
58       problem.
59

IMPORTED SUBROUTINES

61   requires
62        requires qw(foo bar);
63
64       Declares a list of methods that must be defined to compose role.
65
66   with
67        with 'Some::Role1';
68
69        with 'Some::Role1', 'Some::Role2';
70
71       Composes another role into the current role (or class via
72       Role::Tiny::With).
73
74       If you have conflicts and want to resolve them in favour of Some::Role1
75       you can instead write:
76
77        with 'Some::Role1';
78        with 'Some::Role2';
79
80       If you have conflicts and want to resolve different conflicts in favour
81       of different roles, please refactor your codebase.
82
83   before
84        before foo => sub { ... };
85
86       See "before method(s) => sub { ... }" in Class::Method::Modifiers for
87       full documentation.
88
89       Note that since you are not required to use method modifiers,
90       Class::Method::Modifiers is lazily loaded and we do not declare it as a
91       dependency. If your Role::Tiny role uses modifiers you must depend on
92       both Class::Method::Modifiers and Role::Tiny.
93
94   around
95        around foo => sub { ... };
96
97       See "around method(s) => sub { ... }" in Class::Method::Modifiers for
98       full documentation.
99
100       Note that since you are not required to use method modifiers,
101       Class::Method::Modifiers is lazily loaded and we do not declare it as a
102       dependency. If your Role::Tiny role uses modifiers you must depend on
103       both Class::Method::Modifiers and Role::Tiny.
104
105   after
106        after foo => sub { ... };
107
108       See "after method(s) => sub { ... }" in Class::Method::Modifiers for
109       full documentation.
110
111       Note that since you are not required to use method modifiers,
112       Class::Method::Modifiers is lazily loaded and we do not declare it as a
113       dependency. If your Role::Tiny role uses modifiers you must depend on
114       both Class::Method::Modifiers and Role::Tiny.
115
116   Strict and Warnings
117       In addition to importing subroutines, using "Role::Tiny" applies strict
118       and warnings to the caller.
119

SUBROUTINES

121   does_role
122        if (Role::Tiny::does_role($foo, 'Some::Role')) {
123          ...
124        }
125
126       Returns true if class has been composed with role.
127
128       This subroutine is also installed as ->does on any class a Role::Tiny
129       is composed into unless that class already has an ->does method, so
130
131         if ($foo->does('Some::Role')) {
132           ...
133         }
134
135       will work for classes but to test a role, one must use ::does_role
136       directly.
137
138       Additionally, Role::Tiny will override the standard Perl "DOES" method
139       for your class. However, if "any" class in your class' inheritance
140       hierarchy provides "DOES", then Role::Tiny will not override it.
141

METHODS

143   make_role
144        Role::Tiny->make_role('Some::Role');
145
146       Makes a package into a role, but does not export any subs into it.
147
148   apply_roles_to_package
149        Role::Tiny->apply_roles_to_package(
150          'Some::Package', 'Some::Role', 'Some::Other::Role'
151        );
152
153       Composes role with package.  See also Role::Tiny::With.
154
155   apply_roles_to_object
156        Role::Tiny->apply_roles_to_object($foo, qw(Some::Role1 Some::Role2));
157
158       Composes roles in order into object directly. Object is reblessed into
159       the resulting class. Note that the object's methods get overridden by
160       the role's ones with the same names.
161
162   create_class_with_roles
163        Role::Tiny->create_class_with_roles('Some::Base', qw(Some::Role1 Some::Role2));
164
165       Creates a new class based on base, with the roles composed into it in
166       order.  New class is returned.
167
168   is_role
169        Role::Tiny->is_role('Some::Role1')
170
171       Returns true if the given package is a role.
172

CAVEATS

174       ·   On perl 5.8.8 and earlier, applying a role to an object won't apply
175           any overloads from the role to other copies of the object.
176
177       ·   On perl 5.16 and earlier, applying a role to a class won't apply
178           any overloads from the role to any existing instances of the class.
179

SEE ALSO

181       Role::Tiny is the attribute-less subset of Moo::Role; Moo::Role is a
182       meta-protocol-less subset of the king of role systems, Moose::Role.
183
184       Ovid's Role::Basic provides roles with a similar scope, but without
185       method modifiers, and having some extra usage restrictions.
186

AUTHOR

188       mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
189

CONTRIBUTORS

191       dg - David Leadbeater (cpan:DGL) <dgl@dgl.cx>
192
193       frew - Arthur Axel "fREW" Schmidt (cpan:FREW) <frioux@gmail.com>
194
195       hobbs - Andrew Rodland (cpan:ARODLAND) <arodland@cpan.org>
196
197       jnap - John Napiorkowski (cpan:JJNAPIORK) <jjn1056@yahoo.com>
198
199       ribasushi - Peter Rabbitson (cpan:RIBASUSHI) <ribasushi@cpan.org>
200
201       chip - Chip Salzenberg (cpan:CHIPS) <chip@pobox.com>
202
203       ajgb - Alex J. G. Burzyński (cpan:AJGB) <ajgb@cpan.org>
204
205       doy - Jesse Luehrs (cpan:DOY) <doy at tozt dot net>
206
207       perigrin - Chris Prather (cpan:PERIGRIN) <chris@prather.org>
208
209       Mithaldu - Christian Walde (cpan:MITHALDU)
210       <walde.christian@googlemail.com>
211
212       ilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) <ilmari@ilmari.org>
213
214       tobyink - Toby Inkster (cpan:TOBYINK) <tobyink@cpan.org>
215
216       haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>
217
219       Copyright (c) 2010-2012 the Role::Tiny "AUTHOR" and "CONTRIBUTORS" as
220       listed above.
221

LICENSE

223       This library is free software and may be distributed under the same
224       terms as perl itself.
225
226
227
228perl v5.32.0                      2020-07-28                     Role::Tiny(3)
Impressum