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