1Role::Commons(3) User Contributed Perl Documentation Role::Commons(3)
2
3
4
6 Role::Commons - roles that can be commonly used, for the mutual benefit
7 of all
8
10 use 5.010;
11
12 {
13 package Local::Class;
14 use Moo;
15 use Role::Commons -all;
16 our $AUTHORITY = 'cpan:JOEBLOGGS';
17 our $VERSION = '1.000';
18 }
19
20 say Local::Class->AUTHORITY
21 if Local::Class->DOES('Role::Commons::Authority');
22
23 my $obj = Local::Class->new;
24 say $obj->object_id
25 if $obj->DOES('Role::Commons::ObjectID');
26
28 Role-Commons is not yet another implementation of roles. It is a
29 collection of generic, reusable roles that hopefully you will love to
30 apply to your classes. These roles are built using Moo::Role, so
31 automatically integrate into the Moose object system if you're using
32 it, but they do not require Moose.
33
34 The Role::Commons module itself provides shortcuts for applying roles
35 to your package, so that instead of doing:
36
37 {
38 package Local::Class;
39
40 use Moo; # or "use Moose"
41 with qw( Role::Commons::Authority Role::Commons::ObjectID );
42 }
43
44 You can just do this:
45
46 {
47 package Local::Class;
48
49 use Moo;
50 use Role::Commons qw( Authority ObjectID );
51 }
52
53 It also handles passing some simple parameters through to the role from
54 the consuming class. (Because Moo doesn't have anything like
55 MooseX::Role::Parameterized.)
56
57 Roles
58 Role::Commons::Authority
59 Sets up a "AUTHORITY" method for your class which is conceptually a
60 little like "VERSION".
61
62 Role::Commons::ObjectID
63 Provides an "object_id" method for your class which returns a
64 unique identifier for each object.
65
66 Role::Commons::Tap
67 Provides a "tap" method for your class, inspired by Ruby's method
68 of the same name. Helpful for writing chained method calls.
69
70 Obsolescence
71 Role-Commons is the successor for my older projects: authority-shared,
72 Object-AUTHORITY, Object-DOES, Object-Role, and Object-Tap.
73
74 Role-Commons bundles Object::AUTHORITY for the sake of backwards
75 compatibility. This is being phased out.
76
78 Please report any bugs to
79 <http://rt.cpan.org/Dist/Display.html?Queue=Role-Commons>.
80
82 Role::Commons::Authority, Role::Commons::ObjectID, Role::Commons::Tap.
83
84 Role::Tiny, Moo::Role, Moose::Role.
85
87 Toby Inkster <tobyink@cpan.org>.
88
90 This software is copyright (c) 2012, 2014 by Toby Inkster.
91
92 This is free software; you can redistribute it and/or modify it under
93 the same terms as the Perl 5 programming language system itself.
94
96 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
97 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
98 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
99
100
101
102perl v5.38.0 2023-07-21 Role::Commons(3)