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