Commit | Line | Data |
7adfd53f |
1 | package Reaction::Role; |
2 | |
3 | use Moose::Role (); |
4 | use Reaction::ClassExporter; |
5 | use Reaction::Class; |
6 | use Moose::Meta::Class; |
32afff5d |
7 | |
8 | use Sub::Name 'subname'; |
9 | use 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 | |
30 | class 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 |
53 | 1; |
54 | |
55 | =head1 NAME |
56 | |
57 | Reaction::Role |
58 | |
59 | =head1 DESCRIPTION |
60 | |
61 | =head1 SEE ALSO |
62 | |
63 | L<Moose::Role> |
64 | |
65 | =head1 AUTHORS |
66 | |
67 | See L<Reaction::Class> for authors. |
68 | |
69 | =head1 LICENSE |
70 | |
71 | See L<Reaction::Class> for the license. |
72 | |
73 | =cut |