README
1NAME
2 Object::Role - base class for non-Moose roles
3
4SYNOPSIS
5 {
6 package Object::Dumpable;
7 use base qw/Object::Role/;
8 use Data::Dumper;
9 sub import
10 {
11 my ($class, @args) = @_;
12 my ($caller, %args) = __PACKAGE__->parse_arguments(undef, @args);
13 my $coderef = sub
14 {
15 my ($self) = @_;
16 return Dumper($self);
17 };
18 __PACKAGE__->install_method(dump => $coderef, $caller);
19 }
20 }
21
22 {
23 package Foo;
24 use Object::Dumpable;
25 sub new { ... }
26 }
27
28 {
29 package main;
30 my $foo = Foo->new;
31 warn $foo->dump;
32 }
33
34DESCRIPTION
35 This will be better documented once I fully understand it myself!
36
37 The idea of this is to be a base class for roles like Object::DOES,
38 Object::Stash and Object::ID. It handles parsing of import arguments,
39 installing methods into the caller's namespace (like Exporter, but using
40 a technique that is immune to namespace::autoclean) and tracking which
41 packages have consumed your role.
42
43 While "Object::Role" is a base class for roles, it is not itself a role,
44 so does not export anything. Instead, your role must inherit from it.
45
46 Methods
47 "parse_arguments($default_arg_name, @arguments)"
48 Will parse:
49
50 package My::Class;
51 use My::Role -foo => 1, -bar => [2,3], 4, 5;
52
53 as:
54
55 (
56 'My::Class', # caller,
57 (
58 '-foo' => [1],
59 '-bar' => [2, 3],
60 $default_arg_name => [4, 5],
61 )
62 )
63
64 "install_method($subname => $coderef, $package)"
65 Installs $coderef as "$package\::$subname".
66
67 Automatically calls register_consumer($package).
68
69 "register_consumer($package)"
70 Records that $package has consumed (used) your role.
71
72 "has_consumer($package)"
73 Check if $package has consumed (used) your role.
74
75BUGS
76 Please report any bugs to
77 <http://rt.cpan.org/Dist/Display.html?Queue=Object-Role>.
78
79SEE ALSO
80 Object::DOES, Object::AUTHORITY.
81
82AUTHOR
83 Toby Inkster <tobyink@cpan.org>.
84
85COPYRIGHT AND LICENCE
86 This software is copyright (c) 2011 by Toby Inkster.
87
88 This is free software; you can redistribute it and/or modify it under
89 the same terms as the Perl 5 programming language system itself.
90
91DISCLAIMER OF WARRANTIES
92 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
93 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
94 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
95
96