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