bump version to 0.93_03
[gitmo/Moose.git] / lib / Moose / Meta / Method / Overridden.pm
CommitLineData
74862722 1package Moose::Meta::Method::Overridden;
8ee73eeb 2
3use strict;
4use warnings;
5
7a10df4d 6our $VERSION = '0.93_03';
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
991933fb 19 my $super_package = $args{package} || $args{class}->name;
18c2ec0e 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 {
991933fb 33 local $Moose::SUPER_PACKAGE = $super_package;
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?
991933fb 40 # subname "${super_package}::${name}", $method;
3f9e4b0a 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 501;
51
52__END__
53
54=pod
55
39b3bc94 56=head1 NAME
57
74862722 58Moose::Meta::Method::Overridden - A Moose Method metaclass for overridden methods
39b3bc94 59
60=head1 DESCRIPTION
61
cad6578d 62This class implements method overriding logic for the L<Moose>
63C<override> keyword.
18c2ec0e 64
cad6578d 65The overriding subroutine's parent will be invoked explicitly using
66the C<super> keyword from the parent class's method definition.
18c2ec0e 67
68=head1 METHODS
69
70=over 4
71
cad6578d 72=item B<< Moose::Meta::Method::Overridden->new(%options) >>
73
74This constructs a new object. It accepts the following options:
75
76=over 8
77
78=item * class
79
80The metaclass object for the class in which the override is being
81declared. This option is required.
82
83=item * name
84
85The name of the method which we are overriding. This method must exist
86in one of the class's superclasses. This option is required.
87
88=item * method
89
90The subroutine reference which implements the overriding. This option
91is required.
92
93=back
39b3bc94 94
18c2ec0e 95=back
39b3bc94 96
97=head1 BUGS
98
d4048ef3 99See L<Moose/BUGS> for details on reporting bugs.
39b3bc94 100
101=head1 AUTHOR
102
6c36eeaa 103Yuval Kogman E<lt>nothingmuch@cpan.orgE<gt>
39b3bc94 104
39b3bc94 105=head1 COPYRIGHT AND LICENSE
106
7e0492d3 107Copyright 2006-2010 by Infinity Interactive, Inc.
39b3bc94 108
109L<http://www.iinteractive.com>
110
111This library is free software; you can redistribute it and/or modify
112it under the same terms as Perl itself.
113
18c2ec0e 114=cut