Moose::Role fixed for new moose
[catagits/Reaction.git] / lib / Reaction / Role.pm
CommitLineData
7adfd53f 1package Reaction::Role;
2
3use Moose::Role ();
4use Reaction::ClassExporter;
5use Reaction::Class;
6use Moose::Meta::Class;
32afff5d 7
8use Sub::Name 'subname';
9use Scalar::Util qw/blessed reftype/;
10
7adfd53f 11#TODO: review for Reaction::Object switch / Reaction::Meta::Class
32afff5d 12#lifted from class MOP as a temp fix (groditi)
13*Moose::Meta::Role::add_method
14 = subname 'Moose::Meta::Role::add_method' => sub {
15 my ($self, $method_name, $code) = @_;
16 (defined $method_name && $method_name)
17 || confess "You must define a method name";
18
19 confess "Your code block must be a CODE reference"
20 unless 'CODE' eq reftype($code);
21
22 my $method = $self->method_metaclass->wrap($code);
23 $self->get_method_map->{$method_name} = $method;
24
25 my $full_name = ($self->name . '::' . $method_name);
26 $self->add_package_symbol("&${method_name}" => subname $full_name => $code);
27 };
28
7adfd53f 29
30class Role which {
31
32 override exports_for_package => sub {
33 my ($self, $package) = @_;
34 my %exports = $self->SUPER::exports_for_package($package);
35 delete $exports{class};
36 $exports{role} = sub { $self->do_role_sub($package, @_); };
37 return %exports;
38 };
32afff5d 39
7adfd53f 40 override next_import_package => sub { 'Moose::Role' };
32afff5d 41
7adfd53f 42 override default_base => sub { () };
43
44 implements do_role_sub => as {
45 my ($self, $package, $role, $which, $setup) = @_;
46 confess "Invalid role declaration, should be: role Role which { ... }"
47 unless ($which eq 'which' && ref($setup) eq 'CODE');
48 $self->setup_and_cleanup($role, $setup);
49 };
50
51};
32afff5d 52
7adfd53f 531;
54
55=head1 NAME
56
57Reaction::Role
58
59=head1 DESCRIPTION
60
61=head1 SEE ALSO
62
63L<Moose::Role>
64
65=head1 AUTHORS
66
67See L<Reaction::Class> for authors.
68
69=head1 LICENSE
70
71See L<Reaction::Class> for the license.
72
73=cut