X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2Fmro.pm;h=858b8e545128e5617ec06b344b6ecd40e7ca911b;hb=4c38808d92b95edd5d3bf512019007a1e4a385d9;hp=31da81bcb27b974f1dae814d639c1a9590a76f7c;hpb=70cd14a10b623c21342f84d4826106411378add8;p=p5sagit%2Fp5-mst-13.2.git diff --git a/lib/mro.pm b/lib/mro.pm index 31da81b..858b8e5 100644 --- a/lib/mro.pm +++ b/lib/mro.pm @@ -9,14 +9,33 @@ package mro; use strict; use warnings; -# mro.pm versions < 1.00 reserved for possible CPAN mro dist -# (for partial back-compat to 5.[68].x) +# mro.pm versions < 1.00 reserved for MRO::Compat +# for partial back-compat to 5.[68].x our $VERSION = '1.00'; sub import { mro::set_mro(scalar(caller), $_[1]) if $_[1]; } +package # hide me from PAUSE + next; + +sub can { mro::_nextcan($_[0], 0) } + +sub method { + my $method = mro::_nextcan($_[0], 1); + goto &$method; +} + +package # hide me from PAUSE + maybe::next; + +sub method { + my $method = mro::_nextcan($_[0], 0); + goto &$method if defined $method; + return; +} + 1; __END__ @@ -27,6 +46,8 @@ mro - Method Resolution Order =head1 SYNOPSIS + use mro; # enables next::method and friends globally + use mro 'dfs'; # enable DFS MRO for this class (Perl default) use mro 'c3'; # enable C3 MRO for this class @@ -43,9 +64,12 @@ implementation for older Perls. It's possible to change the MRO of a given class either by using C as shown in the synopsis, or by using the L function -below. The functions do not require loading the C module, as they -are actually provided by the core perl interpreter. The C syntax -is just syntactic sugar for setting the current package's MRO. +below. The functions in the mro namespace do not require loading the +C module, as they are actually provided by the core perl interpreter. + +The special methods C, C, and +C are not available until this C module +has been loaded via C or C. =head1 The C3 MRO @@ -291,39 +315,6 @@ In simple cases, it is equivalent to: But there are some cases where only this solution works (like C); -=head1 PERFORMANCE CONSIDERATIONS - -Specifying the mro type of a class before setting C<@ISA> will -be faster than the other way around. Also, making all of your -C<@ISA> manipulations in a single assignment statement will be -faster that doing them one by one via C (which is what -C does currently). - -Examples: - - # The slowest way - package Foo; - use base qw/A B C/; - use mro 'c3'; - - # The fastest way - # (not exactly equivalent to above, - # as base.pm can do other magic) - use mro 'c3'; - use A (); - use B (); - use C (); - our @ISA = qw/A B C/; - -Generally speaking, every time C<@ISA> is modified, the MRO -of that class will be recalculated, because of the way array -magic works. Pushing multiple items onto C<@ISA> in one push -statement still counts as multiple modifications. However, -assigning a list to C<@ISA> only counts as a single -modification. Thus if you really need to do C as -opposed to assignment, C<@ISA = (@ISA, qw/A B C/);> -will still be faster than C - =head1 SEE ALSO =head2 The original Dylan paper