9 use Sub::Name 'subname';
13 our $VERSION = '0.03';
15 use Moose::Meta::Role;
18 my ( $CALLER, %METAS );
23 return $METAS{$class} if exists $METAS{$class};
26 if ($class->can('meta')) {
27 $meta = $class->meta();
28 (blessed($meta) && $meta->isa('Moose::Meta::Role'))
29 || confess "Whoops, not møøsey enough";
32 $meta = Moose::Meta::Role->new(role_name => $class);
33 $meta->_role_meta->add_method('meta' => sub { $meta })
36 return $METAS{$class} = $meta;
42 my $meta = _find_meta();
43 return subname 'Moose::Role::extends' => sub {
44 confess "Moose::Role does not currently support 'extends'"
48 my $meta = _find_meta();
49 return subname 'Moose::Role::with' => sub {
51 Moose::_load_all_classes($role);
52 $role->meta->apply($meta);
56 my $meta = _find_meta();
57 return subname 'Moose::Role::requires' => sub {
58 $meta->add_required_methods(@_);
62 my $meta = _find_meta();
63 return subname 'Moose::Role::has' => sub {
64 my ($name, %options) = @_;
65 $meta->add_attribute($name, %options)
69 my $meta = _find_meta();
70 return subname 'Moose::Role::before' => sub {
72 $meta->add_before_method_modifier($_, $code) for @_;
76 my $meta = _find_meta();
77 return subname 'Moose::Role::after' => sub {
79 $meta->add_after_method_modifier($_, $code) for @_;
83 my $meta = _find_meta();
84 return subname 'Moose::Role::around' => sub {
86 $meta->add_around_method_modifier($_, $code) for @_;
90 my $meta = _find_meta();
91 return subname 'Moose::Role::super' => sub {};
94 my $meta = _find_meta();
95 return subname 'Moose::Role::override' => sub {
96 my ($name, $code) = @_;
97 $meta->add_override_method_modifier($name, $code);
101 my $meta = _find_meta();
102 return subname 'Moose::Role::inner' => sub {
103 confess "Moose::Role does not currently support 'inner'";
107 my $meta = _find_meta();
108 return subname 'Moose::Role::augment' => sub {
109 confess "Moose::Role does not currently support 'augment'";
113 return \&Carp::confess;
116 return \&Scalar::Util::blessed;
120 my $exporter = Sub::Exporter::build_exporter({
121 exports => \%exports,
130 # we should never export to main
131 return if $CALLER eq 'main';
146 Moose::Role - The Moose Role
158 my ($self, $other) = @_;
159 !$self->equal($other);
162 # ... then in your classes
172 my ($self, $other) = @_;
173 $self->as_float == $other->as_float;
178 This is currently a very early release of Perl 6 style Roles for
179 Moose, it is still incomplete, but getting much closer. If you are
180 interested in helping move this feature along, please come to
181 #moose on irc.perl.org and we can talk.
185 Currently, the role support has a few of caveats. They are as follows:
191 At this time classes I<cannot> correctly consume more than one role. The
192 role composition process, and it's conflict detection has not been added
193 yet. While this should be considered a major feature, it can easily be
194 worked around, and in many cases, is not needed at all.
196 A class can actually consume multiple roles, they are just applied one
197 after another in the order you ask for them. This is incorrect behavior,
198 the roles should be merged first, and conflicts determined, etc. However,
199 if your roles do not have any conflicts, then things will work just
200 fine. This actually tends to be quite sufficient for basic roles.
204 Roles cannot use the C<extends> keyword, it will throw an exception for now.
205 The same is true of the C<augment> and C<inner> keywords (not sure those
206 really make sense for roles). All other Moose keywords will be I<deferred>
207 so that they can be applied to the consuming class.
213 All complex software has bugs lurking in it, and this module is no
214 exception. If you find a bug please either email me, or add the bug
219 Stevan Little E<lt>stevan@iinteractive.comE<gt>
221 =head1 COPYRIGHT AND LICENSE
223 Copyright 2006 by Infinity Interactive, Inc.
225 L<http://www.iinteractive.com>
227 This library is free software; you can redistribute it and/or modify
228 it under the same terms as Perl itself.