9 use Sub::Name 'subname';
11 our $VERSION = '0.01';
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->role_meta->alias_method('extends' => subname 'Moose::Role::extends' => sub {
41 confess "Moose::Role does not currently support 'extends'"
45 $meta->role_meta->alias_method('has' => subname 'Moose::Role::has' => sub {
46 my ($name, %options) = @_;
47 $meta->add_attribute($name, %options)
50 # handle method modifers
51 $meta->role_meta->alias_method('before' => subname 'Moose::Role::before' => sub {
53 $meta->add_method_modifier('before' => $_, $code) for @_;
55 $meta->role_meta->alias_method('after' => subname 'Moose::Role::after' => sub {
57 $meta->add_method_modifier('after' => $_, $code) for @_;
59 $meta->role_meta->alias_method('around' => subname 'Moose::Role::around' => sub {
61 $meta->add_method_modifier('around' => $_, $code) for @_;
64 $meta->role_meta->alias_method('super' => subname 'Moose::Role::super' => sub {});
65 $meta->role_meta->alias_method('override' => subname 'Moose::Role::override' => sub {
66 my ($name, $code) = @_;
67 $meta->add_method_modifier('override' => $name, $code);
70 $meta->role_meta->alias_method('inner' => subname 'Moose::Role::inner' => sub {
71 confess "Moose::Role does not currently support 'inner'";
73 $meta->role_meta->alias_method('augment' => subname 'Moose::Role::augment' => sub {
74 confess "Moose::Role does not currently support 'augment'";
77 # we recommend using these things
78 # so export them for them
79 $meta->role_meta->alias_method('confess' => \&Carp::confess);
80 $meta->role_meta->alias_method('blessed' => \&Scalar::Util::blessed);
91 Moose::Role - The Moose Role
103 All complex software has bugs lurking in it, and this module is no
104 exception. If you find a bug please either email me, or add the bug
109 Stevan Little E<lt>stevan@iinteractive.comE<gt>
111 =head1 COPYRIGHT AND LICENSE
113 Copyright 2006 by Infinity Interactive, Inc.
115 L<http://www.iinteractive.com>
117 This library is free software; you can redistribute it and/or modify
118 it under the same terms as Perl itself.