Doh, yet another typo in the manual name
[gitmo/Moose.git] / lib / Moose / Meta / Method / Augmented.pm
CommitLineData
3f9e4b0a 1package Moose::Meta::Method::Augmented;
2
3use strict;
4use warnings;
5
b2ad68e3 6our $VERSION = '0.67';
e606ae5f 7$VERSION = eval $VERSION;
3f9e4b0a 8our $AUTHORITY = 'cpan:STEVAN';
9
10use base 'Moose::Meta::Method';
11
3f9e4b0a 12sub new {
13 my ( $class, %args ) = @_;
14
15 # the package can be overridden by roles
16 # it is really more like body's compilation stash
17 # this is where we need to override the definition of super() so that the
18 # body of the code can call the right overridden version
19 my $name = $args{name};
20 my $meta = $args{class};
21
22 my $super = $meta->find_next_method_by_name($name);
23
24 (defined $super)
3e504337 25 || $meta->throw_error("You cannot augment '$name' because it has no super method", data => $name);
3f9e4b0a 26
27 my $_super_package = $super->package_name;
6549b0d1 28 # BUT!,... if this is an overridden method ....
3f9e4b0a 29 if ($super->isa('Moose::Meta::Method::Overriden')) {
30 # we need to be sure that we actually
31 # find the next method, which is not
32 # an 'override' method, the reason is
33 # that an 'override' method will not
34 # be the one calling inner()
35 my $real_super = $meta->_find_next_method_by_name_which_is_not_overridden($name);
36 $_super_package = $real_super->package_name;
37 }
38
39 my $super_body = $super->body;
40
41 my $method = $args{method};
42
43 my $body = sub {
44 local $Moose::INNER_ARGS{$_super_package} = [ @_ ];
45 local $Moose::INNER_BODY{$_super_package} = $method;
46 $super_body->(@_);
47 };
48
49 # FIXME store additional attrs
1b2aea39 50 $class->wrap(
51 $body,
52 package_name => $meta->name,
53 name => $name
54 );
3f9e4b0a 55}
56
571;
58
59__END__
60
61=pod
62
63=head1 NAME
64
65Moose::Meta::Method::Augmented - A Moose Method metaclass for augmented methods
66
67=head1 DESCRIPTION
68
69This class implements method augmenting logic for the L<Moose> C<augment> keyword.
70
71This involves setting up C<inner> for the superclass body, and dispatching to
72the superclass from the normal body.
73
74The subclass definition (the augmentation itself) will be invoked explicitly
75using the C<inner> keyword from the parent class's method definition.
76
77=head1 METHODS
78
79=over 4
80
81=item B<new>
82
83=back
84
85=head1 BUGS
86
87All complex software has bugs lurking in it, and this module is no
88exception. If you find a bug please either email me, or add the bug
89to cpan-RT.
90
91=head1 AUTHOR
92
6c36eeaa 93Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
3f9e4b0a 94
95=head1 COPYRIGHT AND LICENSE
96
2840a3b2 97Copyright 2006-2009 by Infinity Interactive, Inc.
3f9e4b0a 98
99L<http://www.iinteractive.com>
100
101This library is free software; you can redistribute it and/or modify
102it under the same terms as Perl itself.
103
104=cut