X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=examples%2FC3MethodDispatchOrder.pod;h=b635f5683f6843553490825c3d513010cc6d7476;hb=87f3c1333528a6d43b8a061c12babfff778116da;hp=419bb120a3a0d0c56ff2e97042965cbe0cb34790;hpb=6d5355c3845e060d269b664be7b4284c606691b8;p=gitmo%2FClass-MOP.git diff --git a/examples/C3MethodDispatchOrder.pod b/examples/C3MethodDispatchOrder.pod index 419bb12..b635f56 100644 --- a/examples/C3MethodDispatchOrder.pod +++ b/examples/C3MethodDispatchOrder.pod @@ -23,35 +23,42 @@ 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 $method_name; - { - no strict 'refs'; - my $label = ${$meta->name . '::AUTOLOAD'}; - $method_name = (split /\:\:/ => $label)[-1]; - } - my $method = $_find_method->($meta, $method_name); + + # 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->($_[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'); + return $meta; }); sub superclasses { my $self = shift; - $self->add_package_variable('@SUPERS' => []) - unless $self->has_package_variable('@SUPERS'); + $self->add_package_symbol('@SUPERS' => []) + unless $self->has_package_symbol('@SUPERS'); if (@_) { my @supers = @_; - @{$self->get_package_variable('@SUPERS')} = @supers; + @{$self->get_package_symbol('@SUPERS')} = @supers; } - @{$self->get_package_variable('@SUPERS')}; + @{$self->get_package_symbol('@SUPERS')}; } sub class_precedence_list { @@ -121,13 +128,15 @@ This example could be used as a template for other method dispatch orders as well, all that is required is to write a the C method which will return a linearized list of classes to dispatch along. -=head1 AUTHOR +=head1 AUTHORS Stevan Little Estevan@iinteractive.comE +Yuval Kogman Enothingmuch@woobling.comE + =head1 COPYRIGHT AND LICENSE -Copyright 2006 by Infinity Interactive, Inc. +Copyright 2006-2008 by Infinity Interactive, Inc. L