9 use Sub::Name 'subname';
11 our $VERSION = '0.02';
13 use Moose::Meta::Role;
19 # we should never export to main
20 return if $pkg eq 'main';
23 if ($pkg->can('meta')) {
25 (blessed($meta) && $meta->isa('Moose::Meta::Role'))
26 || confess "Whoops, not møøsey enough";
29 $meta = Moose::Meta::Role->new(role_name => $pkg);
30 $meta->_role_meta->add_method('meta' => sub { $meta })
34 # &alias_method will install the method, but it
35 # will not name it with
38 $meta->alias_method('extends' => subname 'Moose::Role::extends' => sub {
39 confess "Moose::Role does not currently support 'extends'"
43 $meta->alias_method('with' => subname 'Moose::with' => sub {
45 Moose::_load_all_classes($role);
46 $role->meta->apply($meta);
50 $meta->alias_method('requires' => subname 'Moose::requires' => sub {
51 $meta->add_required_methods(@_);
55 $meta->alias_method('has' => subname 'Moose::Role::has' => sub {
56 my ($name, %options) = @_;
57 $meta->add_attribute($name, %options)
60 # handle method modifers
61 $meta->alias_method('before' => subname 'Moose::Role::before' => sub {
63 $meta->add_before_method_modifier($_, $code) for @_;
65 $meta->alias_method('after' => subname 'Moose::Role::after' => sub {
67 $meta->add_after_method_modifier($_, $code) for @_;
69 $meta->alias_method('around' => subname 'Moose::Role::around' => sub {
71 $meta->add_around_method_modifier($_, $code) for @_;
74 $meta->alias_method('super' => subname 'Moose::Role::super' => sub {});
75 $meta->alias_method('override' => subname 'Moose::Role::override' => sub {
76 my ($name, $code) = @_;
77 $meta->add_override_method_modifier($name, $code);
80 $meta->alias_method('inner' => subname 'Moose::Role::inner' => sub {
81 confess "Moose::Role does not currently support 'inner'";
83 $meta->alias_method('augment' => subname 'Moose::Role::augment' => sub {
84 confess "Moose::Role does not currently support 'augment'";
87 # we recommend using these things
88 # so export them for them
89 $meta->alias_method('confess' => \&Carp::confess);
90 $meta->alias_method('blessed' => \&Scalar::Util::blessed);
101 Moose::Role - The Moose Role
113 my ($self, $other) = @_;
114 !$self->equal($other);
117 # ... then in your classes
127 my ($self, $other) = @_;
128 $self->as_float == $other->as_float;
133 This is currently a very early release of Perl 6 style Roles for
134 Moose, it is still incomplete, but getting much closer. If you are
135 interested in helping move this feature along, please come to
136 #moose on irc.perl.org and we can talk.
140 Currently, the role support has a few of caveats. They are as follows:
146 At this time classes I<cannot> correctly consume more than one role. The
147 role composition process, and it's conflict detection has not been added
148 yet. While this should be considered a major feature, it can easily be
149 worked around, and in many cases, is not needed at all.
151 A class can actually consume multiple roles, they are just applied one
152 after another in the order you ask for them. This is incorrect behavior,
153 the roles should be merged first, and conflicts determined, etc. However,
154 if your roles do not have any conflicts, then things will work just
155 fine. This actually tends to be quite sufficient for basic roles.
159 Roles cannot use the C<extends> keyword, it will throw an exception for now.
160 The same is true of the C<augment> and C<inner> keywords (not sure those
161 really make sense for roles). All other Moose keywords will be I<deferred>
162 so that they can be applied to the consuming class.
168 All complex software has bugs lurking in it, and this module is no
169 exception. If you find a bug please either email me, or add the bug
174 Stevan Little E<lt>stevan@iinteractive.comE<gt>
176 =head1 COPYRIGHT AND LICENSE
178 Copyright 2006 by Infinity Interactive, Inc.
180 L<http://www.iinteractive.com>
182 This library is free software; you can redistribute it and/or modify
183 it under the same terms as Perl itself.