ohloh link
[gitmo/Moose.git] / lib / Moose / Meta / Method / Overriden.pm
CommitLineData
8ee73eeb 1package Moose::Meta::Method::Overriden;
2
3use strict;
4use warnings;
5
d44714be 6our $VERSION = '0.01';
7our $AUTHORITY = 'cpan:STEVAN';
8ee73eeb 8
9use base 'Moose::Meta::Method';
10
3f9e4b0a 11use Sub::Name;
12
18c2ec0e 13use Carp qw(confess);
14
15sub new {
16 my ( $class, %args ) = @_;
17
18 # the package can be overridden by roles
19 # it is really more like body's compilation stash
20 # this is where we need to override the definition of super() so that the
21 # body of the code can call the right overridden version
22 my $_super_package = $args{package} || $args{class}->name;
23
24 my $name = $args{name};
25
26 my $super = $args{class}->find_next_method_by_name($name);
27
28 (defined $super)
29 || confess "You cannot override '$name' because it has no super method";
30
31 my $super_body = $super->body;
32
3f9e4b0a 33 my $method = $args{method};
18c2ec0e 34
35 my $body = sub {
3f9e4b0a 36 local @Moose::SUPER_ARGS = @_;
37 local $Moose::SUPER_BODY = $super_body;
38 return $method->(@_);
18c2ec0e 39 };
40
3f9e4b0a 41 # FIXME do we need this make sure this works for next::method?
42 # subname "${_super_package}::${name}", $method;
43
18c2ec0e 44 # FIXME store additional attrs
45 $class->wrap($body);
46}
47
8ee73eeb 481;
49
50__END__
51
52=pod
53
39b3bc94 54=head1 NAME
55
ecb59493 56Moose::Meta::Method::Overriden - A Moose Method metaclass for overriden methods
39b3bc94 57
58=head1 DESCRIPTION
59
18c2ec0e 60This class implements method overriding logic for the L<Moose> C<override> keyword.
61
62This involves setting up C<super> for the overriding body, and dispatching to
63the correct parent method upon its invocation.
64
65=head1 METHODS
66
67=over 4
68
69=item B<new>
39b3bc94 70
18c2ec0e 71=back
39b3bc94 72
73=head1 BUGS
74
75All complex software has bugs lurking in it, and this module is no
76exception. If you find a bug please either email me, or add the bug
77to cpan-RT.
78
79=head1 AUTHOR
80
6c36eeaa 81Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
39b3bc94 82
39b3bc94 83=head1 COPYRIGHT AND LICENSE
84
778db3ac 85Copyright 2006-2008 by Infinity Interactive, Inc.
39b3bc94 86
87L<http://www.iinteractive.com>
88
89This library is free software; you can redistribute it and/or modify
90it under the same terms as Perl itself.
91
18c2ec0e 92=cut