X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FOverriden.pm;h=2dcda183a79e4f62e71922d0fe67188199cf58d5;hb=aa7bbf26111ba4ed260458857f0a9cf007511bd4;hp=b99660e06622a0d5b09796bcfa96c8cd54bfe4b4;hpb=778db3ac5dc266115efefdeb6dcbcf9b2444d9c9;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Overriden.pm b/lib/Moose/Meta/Method/Overriden.pm index b99660e..2dcda18 100644 --- a/lib/Moose/Meta/Method/Overriden.pm +++ b/lib/Moose/Meta/Method/Overriden.pm @@ -3,11 +3,50 @@ package Moose::Meta::Method::Overriden; use strict; use warnings; -our $VERSION = '0.01'; +our $VERSION = '0.66'; +$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_PACKAGE = $super_package; + 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__ @@ -20,12 +59,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 + +=over 4 + +=item B -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. +=back =head1 BUGS @@ -35,15 +80,15 @@ to cpan-RT. =head1 AUTHOR -Stevan Little Estevan@iinteractive.comE +Yuval Kogman Enothingmuch@cpan.orgE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2008 by Infinity Interactive, Inc. +Copyright 2006-2009 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