File: README

package info (click to toggle)
librole-tiny-perl 1.003004-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 236 kB
  • ctags: 43
  • sloc: perl: 400; makefile: 2
file content (214 lines) | stat: -rw-r--r-- 6,383 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
NAME
    Role::Tiny - Roles. Like a nouvelle cuisine portion size slice of Moose.

SYNOPSIS
     package Some::Role;

     use Role::Tiny;

     sub foo { ... }

     sub bar { ... }

     around baz => sub { ... }

     1;

    else where

     package Some::Class;

     use Role::Tiny::With;

     # bar gets imported, but not foo
     with 'Some::Role';

     sub foo { ... }

     # baz is wrapped in the around modifier by Class::Method::Modifiers
     sub baz { ... }

     1;

    If you wanted attributes as well, look at Moo::Role.

DESCRIPTION
    "Role::Tiny" is a minimalist role composition tool.

ROLE COMPOSITION
    Role composition can be thought of as much more clever and meaningful
    multiple inheritance. The basics of this implementation of roles is:

    * If a method is already defined on a class, that method will not be
      composed in from the role.

    * If a method that the role "requires" to be implemented is not
      implemented, role application will fail loudly.

    Unlike Class::C3, where the last class inherited from "wins," role
    composition is the other way around, where the class wins. If multiple
    roles are applied in a single call (single with statement), then if any
    of their provided methods clash, an exception is raised unless the class
    provides a method since this conflict indicates a potential problem.

IMPORTED SUBROUTINES
  requires
     requires qw(foo bar);

    Declares a list of methods that must be defined to compose role.

  with
     with 'Some::Role1';

     with 'Some::Role1', 'Some::Role2';

    Composes another role into the current role (or class via
    Role::Tiny::With).

    If you have conflicts and want to resolve them in favour of Some::Role1
    you can instead write:

     with 'Some::Role1';
     with 'Some::Role2';

    If you have conflicts and want to resolve different conflicts in favour
    of different roles, please refactor your codebase.

  before
     before foo => sub { ... };

    See "before method(s) => sub { ... }" in Class::Method::Modifiers for
    full documentation.

    Note that since you are not required to use method modifiers,
    Class::Method::Modifiers is lazily loaded and we do not declare it as a
    dependency. If your Role::Tiny role uses modifiers you must depend on
    both Class::Method::Modifiers and Role::Tiny.

  around
     around foo => sub { ... };

    See "around method(s) => sub { ... }" in Class::Method::Modifiers for
    full documentation.

    Note that since you are not required to use method modifiers,
    Class::Method::Modifiers is lazily loaded and we do not declare it as a
    dependency. If your Role::Tiny role uses modifiers you must depend on
    both Class::Method::Modifiers and Role::Tiny.

  after
     after foo => sub { ... };

    See "after method(s) => sub { ... }" in Class::Method::Modifiers for
    full documentation.

    Note that since you are not required to use method modifiers,
    Class::Method::Modifiers is lazily loaded and we do not declare it as a
    dependency. If your Role::Tiny role uses modifiers you must depend on
    both Class::Method::Modifiers and Role::Tiny.

  Strict and Warnings
    In addition to importing subroutines, using "Role::Tiny" applies strict
    and fatal warnings to the caller. It's possible to disable these if
    desired:

     use Role::Tiny;
     use warnings NONFATAL => 'all';

SUBROUTINES
  does_role
     if (Role::Tiny::does_role($foo, 'Some::Role')) {
       ...
     }

    Returns true if class has been composed with role.

    This subroutine is also installed as ->does on any class a Role::Tiny is
    composed into unless that class already has an ->does method, so

      if ($foo->does('Some::Role')) {
        ...
      }

    will work for classes but to test a role, one must use ::does_role
    directly.

    Additionally, Role::Tiny will override the standard Perl "DOES" method
    for your class. However, if "any" class in your class' inheritance
    hierarchy provides "DOES", then Role::Tiny will not override it.

METHODS
  apply_roles_to_package
     Role::Tiny->apply_roles_to_package(
       'Some::Package', 'Some::Role', 'Some::Other::Role'
     );

    Composes role with package. See also Role::Tiny::With.

  apply_roles_to_object
     Role::Tiny->apply_roles_to_object($foo, qw(Some::Role1 Some::Role2));

    Composes roles in order into object directly. Object is reblessed into
    the resulting class.

  create_class_with_roles
     Role::Tiny->create_class_with_roles('Some::Base', qw(Some::Role1 Some::Role2));

    Creates a new class based on base, with the roles composed into it in
    order. New class is returned.

  is_role
     Role::Tiny->is_role('Some::Role1')

    Returns true if the given package is a role.

CAVEATS
    *   On perl 5.8.8 and earlier, applying a role to an object won't apply
        any overloads from the role to all copies of the object.

SEE ALSO
    Role::Tiny is the attribute-less subset of Moo::Role; Moo::Role is a
    meta-protocol-less subset of the king of role systems, Moose::Role.

    Ovid's Role::Basic provides roles with a similar scope, but without
    method modifiers, and having some extra usage restrictions.

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

CONTRIBUTORS
    dg - David Leadbeater (cpan:DGL) <dgl@dgl.cx>

    frew - Arthur Axel "fREW" Schmidt (cpan:FREW) <frioux@gmail.com>

    hobbs - Andrew Rodland (cpan:ARODLAND) <arodland@cpan.org>

    jnap - John Napiorkowski (cpan:JJNAPIORK) <jjn1056@yahoo.com>

    ribasushi - Peter Rabbitson (cpan:RIBASUSHI) <ribasushi@cpan.org>

    chip - Chip Salzenberg (cpan:CHIPS) <chip@pobox.com>

    ajgb - Alex J. G. Burzyński (cpan:AJGB) <ajgb@cpan.org>

    doy - Jesse Luehrs (cpan:DOY) <doy at tozt dot net>

    perigrin - Chris Prather (cpan:PERIGRIN) <chris@prather.org>

    Mithaldu - Christian Walde (cpan:MITHALDU)
    <walde.christian@googlemail.com>

    ilmari - Dagfinn Ilmari Mannsåker (cpan:ILMARI) <ilmari@ilmari.org>

    tobyink - Toby Inkster (cpan:TOBYINK) <tobyink@cpan.org>

    haarg - Graham Knop (cpan:HAARG) <haarg@haarg.org>

COPYRIGHT
    Copyright (c) 2010-2012 the Role::Tiny "AUTHOR" and "CONTRIBUTORS" as
    listed above.

LICENSE
    This library is free software and may be distributed under the same
    terms as perl itself.