From: Shawn M Moore Date: Sun, 18 May 2008 11:31:45 +0000 (+0000) Subject: Fix C3 test with AUTOLOAD + subname wackiness by using get_code_info on \&AUTOLOAD X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2904cd3bd9fec7f9240568b0b096abab5f4c53f4;p=gitmo%2FClass-MOP.git Fix C3 test with AUTOLOAD + subname wackiness by using get_code_info on \&AUTOLOAD --- diff --git a/examples/C3MethodDispatchOrder.pod b/examples/C3MethodDispatchOrder.pod index 0ce9db2..83f3806 100644 --- a/examples/C3MethodDispatchOrder.pod +++ b/examples/C3MethodDispatchOrder.pod @@ -23,14 +23,24 @@ my $_find_method = sub { C3MethodDispatchOrder->meta->add_around_method_modifier('initialize' => sub { my $cont = shift; my $meta = $cont->(@_); - $meta->add_method('AUTOLOAD' => sub { - my $meta = $_[0]->meta; - my $label = ${ $meta->get_package_symbol('$AUTOLOAD') }; + + # we need to look at $AUTOLOAD in the package where the coderef belongs + # if subname works, then it'll be where this AUTOLOAD method was installed + # otherwise, it'll be $C3MethodDispatchOrder::AUTOLOAD. get_code_info + # tells us where AUTOLOAD will look + my $autoload; + $autoload = sub { + my ($package) = Class::MOP::get_code_info($autoload); + my $label = ${ $package->meta->get_package_symbol('$AUTOLOAD') }; my $method_name = (split /\:\:/ => $label)[-1]; - my $method = $_find_method->($meta, $method_name); + my $method = $_find_method->($_[0]->meta, $method_name); (defined $method) || confess "Method ($method_name) not found"; goto &$method; - }) unless $meta->has_method('AUTOLOAD'); + }; + + $meta->add_method('AUTOLOAD' => $autoload) + unless $meta->has_method('AUTOLOAD'); + $meta->add_method('can' => sub { $_find_method->($_[0]->meta, $_[1]); }) unless $meta->has_method('can');