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