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

NAME

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

SYNOPSIS

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

DESCRIPTION

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

ROLE COMPOSITION

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

IMPORTED SUBROUTINES

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

SUBROUTINES

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

METHODS

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

CAVEATS

170       ·   On perl 5.8.8 and earlier, applying a role to an object won't apply
171           any overloads from the role to other copies of the object.
172
173       ·   On perl 5.16 and earlier, applying a role to a class won't apply
174           any overloads from the role to any existing instances of the class.
175

SEE ALSO

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

AUTHOR

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

CONTRIBUTORS

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

LICENSE

219       This library is free software and may be distributed under the same
220       terms as perl itself.
221
222
223
224perl v5.28.0                      2017-11-08                     Role::Tiny(3)
Impressum