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