X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FOverriden.pm;h=c6b1ccde9328b6d78396ba00481a70a6f9d943f8;hb=e1737edc1aeb23724d9da1fec93ed82e900d8e00;hp=a740f41ac7bd6b23e20cda1c803fcea991af545a;hpb=b77fdbed20f583feab7a3990da4ebc04898217fc;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Overriden.pm b/lib/Moose/Meta/Method/Overriden.pm index a740f41..c6b1ccd 100644 --- a/lib/Moose/Meta/Method/Overriden.pm +++ b/lib/Moose/Meta/Method/Overriden.pm @@ -3,10 +3,49 @@ package Moose::Meta::Method::Overriden; use strict; use warnings; -our $VERSION = '0.01'; +our $VERSION = '0.62_02'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method'; +sub new { + my ( $class, %args ) = @_; + + # the package can be overridden by roles + # it is really more like body's compilation stash + # this is where we need to override the definition of super() so that the + # body of the code can call the right overridden version + my $_super_package = $args{package} || $args{class}->name; + + my $name = $args{name}; + + my $super = $args{class}->find_next_method_by_name($name); + + (defined $super) + || $class->throw_error("You cannot override '$name' because it has no super method", data => $name); + + my $super_body = $super->body; + + my $method = $args{method}; + + my $body = sub { + local @Moose::SUPER_ARGS = @_; + local $Moose::SUPER_BODY = $super_body; + return $method->(@_); + }; + + # FIXME do we need this make sure this works for next::method? + # subname "${_super_package}::${name}", $method; + + # FIXME store additional attrs + $class->wrap( + $body, + package_name => $args{class}->name, + name => $name + ); +} + 1; __END__ @@ -19,12 +58,18 @@ Moose::Meta::Method::Overriden - A Moose Method metaclass for overriden methods =head1 DESCRIPTION -This is primarily used to tag methods created with the C keyword. It -is currently just a subclass of L. +This class implements method overriding logic for the L C keyword. + +This involves setting up C for the overriding body, and dispatching to +the correct parent method upon its invocation. + +=head1 METHODS -Later releases will likely encapsulate the C behavior of overriden methods, -rather than that being the responsibility of the class. But this is low priority -for now. +=over 4 + +=item B + +=back =head1 BUGS @@ -34,17 +79,15 @@ to cpan-RT. =head1 AUTHOR -Stevan Little Estevan@iinteractive.comE - -Yuval Kogman Enothingmuch@woobling.comE +Yuval Kogman Enothingmuch@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2006, 2007 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut \ No newline at end of file +=cut