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';
22 Moose::Util::TypeConstraints->import($pkg);
25 if ($pkg->can('meta')) {
27 (blessed($meta) && $meta->isa('Moose::Meta::Role'))
28 || confess "Whoops, not møøsey enough";
31 $meta = Moose::Meta::Role->new(role_name => $pkg);
32 $meta->_role_meta->add_method('meta' => sub { $meta })
36 # &alias_method will install the method, but it
37 # will not name it with
40 $meta->alias_method('extends' => subname 'Moose::Role::extends' => sub {
41 confess "Moose::Role does not currently support 'extends'"
45 $meta->alias_method('with' => subname 'Moose::with' => sub {
47 Moose::_load_all_classes($role);
48 $role->meta->apply($meta);
52 $meta->alias_method('requires' => subname 'Moose::requires' => sub {
53 $meta->add_required_methods(@_);
57 $meta->alias_method('has' => subname 'Moose::Role::has' => sub {
58 my ($name, %options) = @_;
59 $meta->add_attribute($name, %options)
62 # handle method modifers
63 $meta->alias_method('before' => subname 'Moose::Role::before' => sub {
65 $meta->add_before_method_modifier($_, $code) for @_;
67 $meta->alias_method('after' => subname 'Moose::Role::after' => sub {
69 $meta->add_after_method_modifier($_, $code) for @_;
71 $meta->alias_method('around' => subname 'Moose::Role::around' => sub {
73 $meta->add_around_method_modifier($_, $code) for @_;
76 $meta->alias_method('super' => subname 'Moose::Role::super' => sub {});
77 $meta->alias_method('override' => subname 'Moose::Role::override' => sub {
78 my ($name, $code) = @_;
79 $meta->add_override_method_modifier($name, $code);
82 $meta->alias_method('inner' => subname 'Moose::Role::inner' => sub {
83 confess "Moose::Role does not currently support 'inner'";
85 $meta->alias_method('augment' => subname 'Moose::Role::augment' => sub {
86 confess "Moose::Role does not currently support 'augment'";
89 # we recommend using these things
90 # so export them for them
91 $meta->alias_method('confess' => \&Carp::confess);
92 $meta->alias_method('blessed' => \&Scalar::Util::blessed);
103 Moose::Role - The Moose Role
112 sub equal { confess "equal must be implemented" }
115 my ($self, $other) = @_;
116 !$self->equal($other);
119 # ... then in your classes
129 my ($self, $other) = @_;
130 $self->as_float == $other->as_float;
135 This is currently a very early release of Perl 6 style Roles for
136 Moose, it should be considered experimental and incomplete.
138 This feature is being actively developed, but $work is currently
139 preventing me from paying as much attention to it as I would like.
140 So I am releasing it in hopes people will help me on this I<hint hint>.
142 If you are interested in helping, please come to #moose on irc.perl.org
147 Currently, the role support has a number of caveats. They are as follows:
153 There is no support for Roles consuming other Roles. The details of this
154 are not totally worked out yet, but it will mostly follow what is set out
155 in the Perl 6 Synopsis 12.
159 At this time classes I<can> consume more than one Role, but they are simply
160 applied one after another in the order you ask for them. This is incorrect
161 behavior, the roles should be merged first, and conflicts determined, etc.
162 However, if your roles do not have any conflicts, then things will work just
167 I want to have B<required> methods, which is unlike Perl 6 roles, and more
168 like the original Traits on which roles are based. This would be similar
169 in behavior to L<Class::Trait>. These are not yet implemented or course.
173 Roles cannot use the C<extends> keyword, it will throw an exception for now.
174 The same is true of the C<augment> and C<inner> keywords (not sure those
175 really make sense for roles). All other Moose keywords will be I<deferred>
176 so that they can be applied to the consuming class.
180 Basically thats all I can think of for now, I am sure there are more though.
184 All complex software has bugs lurking in it, and this module is no
185 exception. If you find a bug please either email me, or add the bug
190 Stevan Little E<lt>stevan@iinteractive.comE<gt>
192 =head1 COPYRIGHT AND LICENSE
194 Copyright 2006 by Infinity Interactive, Inc.
196 L<http://www.iinteractive.com>
198 This library is free software; you can redistribute it and/or modify
199 it under the same terms as Perl itself.