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