Commit | Line | Data |
3f9e4b0a |
1 | package Moose::Meta::Method::Augmented; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
3f9e4b0a |
6 | our $AUTHORITY = 'cpan:STEVAN'; |
7 | |
8 | use base 'Moose::Meta::Method'; |
9 | |
3f9e4b0a |
10 | sub new { |
11 | my ( $class, %args ) = @_; |
12 | |
13 | # the package can be overridden by roles |
14 | # it is really more like body's compilation stash |
15 | # this is where we need to override the definition of super() so that the |
16 | # body of the code can call the right overridden version |
17 | my $name = $args{name}; |
18 | my $meta = $args{class}; |
19 | |
20 | my $super = $meta->find_next_method_by_name($name); |
21 | |
22 | (defined $super) |
3e504337 |
23 | || $meta->throw_error("You cannot augment '$name' because it has no super method", data => $name); |
3f9e4b0a |
24 | |
25 | my $_super_package = $super->package_name; |
6549b0d1 |
26 | # BUT!,... if this is an overridden method .... |
74862722 |
27 | if ($super->isa('Moose::Meta::Method::Overridden')) { |
3f9e4b0a |
28 | # we need to be sure that we actually |
29 | # find the next method, which is not |
30 | # an 'override' method, the reason is |
31 | # that an 'override' method will not |
32 | # be the one calling inner() |
33 | my $real_super = $meta->_find_next_method_by_name_which_is_not_overridden($name); |
34 | $_super_package = $real_super->package_name; |
35 | } |
36 | |
37 | my $super_body = $super->body; |
38 | |
39 | my $method = $args{method}; |
40 | |
41 | my $body = sub { |
42 | local $Moose::INNER_ARGS{$_super_package} = [ @_ ]; |
43 | local $Moose::INNER_BODY{$_super_package} = $method; |
44 | $super_body->(@_); |
45 | }; |
46 | |
47 | # FIXME store additional attrs |
1b2aea39 |
48 | $class->wrap( |
49 | $body, |
50 | package_name => $meta->name, |
51 | name => $name |
52 | ); |
3f9e4b0a |
53 | } |
54 | |
55 | 1; |
56 | |
ad46f524 |
57 | # ABSTRACT: A Moose Method metaclass for augmented methods |
58 | |
3f9e4b0a |
59 | __END__ |
60 | |
61 | =pod |
62 | |
3f9e4b0a |
63 | =head1 DESCRIPTION |
64 | |
c03bf2a6 |
65 | This class implements method augmentation logic for the L<Moose> |
66 | C<augment> keyword. |
3f9e4b0a |
67 | |
c03bf2a6 |
68 | The augmentation subroutine reference will be invoked explicitly using |
69 | the C<inner> keyword from the parent class's method definition. |
3f9e4b0a |
70 | |
c03bf2a6 |
71 | =head1 INHERITANCE |
72 | |
73 | C<Moose::Meta::Method::Augmented> is a subclass of L<Moose::Meta::Method>. |
3f9e4b0a |
74 | |
75 | =head1 METHODS |
76 | |
77 | =over 4 |
78 | |
c03bf2a6 |
79 | =item B<< Moose::Meta::Method::Augmented->new(%options) >> |
80 | |
81 | This constructs a new object. It accepts the following options: |
82 | |
83 | =over 8 |
84 | |
85 | =item * class |
86 | |
87 | The metaclass object for the class in which the augmentation is being |
88 | declared. This option is required. |
89 | |
90 | =item * name |
91 | |
92 | The name of the method which we are augmenting. This method must exist |
93 | in one of the class's superclasses. This option is required. |
94 | |
95 | =item * method |
96 | |
97 | The subroutine reference which implements the augmentation. This |
98 | option is required. |
99 | |
100 | =back |
3f9e4b0a |
101 | |
102 | =back |
103 | |
104 | =head1 BUGS |
105 | |
d4048ef3 |
106 | See L<Moose/BUGS> for details on reporting bugs. |
3f9e4b0a |
107 | |
3f9e4b0a |
108 | =cut |