From: Brandon L Black Date: Sat, 12 May 2007 21:22:54 +0000 (+0000) Subject: 0.02, isarev arrayref, pkg_gen, ... X-Git-Tag: 0.02~1 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a9edfcb9874ce24af3262da4a4e35e4cce633d11;p=gitmo%2FMRO-Compat.git 0.02, isarev arrayref, pkg_gen, ... --- diff --git a/ChangeLog b/ChangeLog index ad2ca12..efad0a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,12 @@ Revision history for Perl extension MRO::Compat. +0.02 - Sat May 12, 2007 + - Added mro::get_pkg_gen (which optionally works + even faster with Class::C3::XS 0.04) in + anticipation of it being added to 5.9.5 + - Changed mro::get_isarev to return arrayref in + anticipation of that change in 5.9.5 + - Bumped requirements, added more docs + 0.01_01 - Fri May 11, 2007 - Initial dev release diff --git a/Makefile.PL b/Makefile.PL index f82bf35..5878ada 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -6,7 +6,8 @@ all_from 'lib/MRO/Compat.pm'; build_requires 'Test::More' => '0.47'; if($] < 5.009_005) { - requires 'Class::C3' => '0.17'; + feature 'XS Speedups', 'Class::C3::XS' => '0.04'; + requires 'Class::C3' => '0.18'; } auto_install; diff --git a/README b/README index b82080a..9e257d7 100644 --- a/README +++ b/README @@ -1,4 +1,4 @@ -MRO::Compat version 0.01 +MRO::Compat version 0.02 =========================== INSTALLATION @@ -13,6 +13,8 @@ To install this module type the following: DEPENDENCIES Requires Test::More 0.47 to test + Requires Class::C3 0.18 for runtime + Recommends Class::C3::XS 0.04 for runtime COPYRIGHT AND LICENCE diff --git a/lib/MRO/Compat.pm b/lib/MRO/Compat.pm index ea0df45..fc2d58c 100644 --- a/lib/MRO/Compat.pm +++ b/lib/MRO/Compat.pm @@ -5,14 +5,15 @@ require 5.006_000; # Keep this < 1.00, so people can tell the fake # mro.pm from the real one -our $VERSION = '0.01_01'; +our $VERSION = '0.02'; BEGIN { # Alias our private functions over to # the mro:: namespace and load # Class::C3 if Perl < 5.9.5 if($] < 5.009_005) { - require Class::C3; + $mro::VERSION = $VERSION; + $INC{'mro.pm'} = 'Faked by MRO::Compat'; *mro::import = \&__import; *mro::get_linear_isa = \&__get_linear_isa; *mro::set_mro = \&__set_mro; @@ -22,8 +23,13 @@ BEGIN { *mro::method_changed_in = \&__method_changed_in; *mro::invalidate_all_method_caches = \&__invalidate_all_method_caches; - $mro::VERSION = $VERSION; - $INC{'mro.pm'} = 'Faked by MRO::Compat'; + require Class::C3; + if($Class::C3::XS::VERSION && $Class::C3::XS::VERSION > 0.03) { + *mro::get_pkg_gen = \&__get_pkg_gen_c3xs; + } + else { + *mro::get_pkg_gen = \&__get_pkg_gen_pp; + } } # Provide no-op Class::C3::.*initialize() funcs for 5.9.5+ @@ -68,15 +74,30 @@ the parts of 5.9.5+'s mro:: interfaces that are supported here, and you want compatibility with older Perls, this is the module for you. +Some parts of this interface will work better with +L installed, but it's not a requirement. + This module never exports any functions. All calls must be fully qualified with the C prefix. -=head1 VERSION 0.01_01 +The interface documentation here serves only as a quick +reference of what the function basically does, and what +differences between L and 5.9.5+ one should +look out for. The main docs in 5.9.5's L are the real +interface docs, and contain a lot of other useful information. -This is the first dev release of this new module, and on top of that, +=head1 VERSION 0.02 + +This is the first release of this new module, and on top of that, the Perl 5.9.5 it seeks to provide compatibility with isn't even -out yet. Consider it not fully stabilized for the time being. -These interfaces are not necessarily nailed down yet. +out yet. + +If you're going to use/depend on this, please keep abreast of +possible interface changes in the next few versions. Once Perl +5.9.5 is out the door the interfaces should stabilize on whatever +5.9.5 has to offer. In the meantime, don't be surprised if +L and 5.9.5's interfaces aren't perfectly in sync +at all times. =head1 Functions @@ -193,8 +214,8 @@ sub __get_mro { =head2 mro::get_isarev($classname) -Returns an array of classes who are subclasses of the -given classname. In other words, classes who we exists, +Returns an arrayref of classes who are subclasses of the +given classname. In other words, classes who we exist, however indirectly, in the @ISA inheritancy hierarchy of. This is much slower on pre-5.9.5 Perls with MRO::Compat @@ -265,7 +286,7 @@ sub __get_isarev { my $classname = shift; die "mro::get_isarev requires a classname" if !$classname; - @{__get_isarev_recurse($classname, __get_all_pkgs_with_isas(), 0)}; + __get_isarev_recurse($classname, __get_all_pkgs_with_isas(), 0); } =head2 mro::is_universal($classname) @@ -297,6 +318,10 @@ sub __is_universal { Increments C, which invalidates method caching in all packages. +Please note that this is rarely necessary, unless you are +dealing with a situation which is known to confuse Perl's +method caching. + =cut sub __invalidate_all_method_caches { @@ -314,6 +339,10 @@ pre-5.9.5 Perls have no other way to do this. It will still enforce the requirement that you pass it a classname, for compatibility. +Please note that this is rarely necessary, unless you are +dealing with a situation which is known to confuse Perl's +method caching. + =cut sub __method_changed_in { @@ -323,6 +352,29 @@ sub __method_changed_in { __invalidate_all_method_caches(); } +=head2 mro::get_pkg_gen($classname) + +Returns an integer which is incremented every time a local +method of or the C<@ISA> of the given package changes on +Perl 5.9.5+. On earlier Perls with this L module, +it will probably increment a lot more often than necessary. + +=cut + +my $__pkg_gen = 2; +sub __get_pkg_gen_pp { + my $classname = shift; + die "mro::get_pkg_gen requires a classname" if !$classname; + return $__pkg_gen++; +} + +sub __get_pkg_gen_c3xs { + my $classname = shift; + die "mro::get_pkg_gen requires a classname" if !$classname; + + return Class::C3::XS::_plsubgen(); +} + =head1 USING C3 While this module makes the 5.9.5+ syntaxes diff --git a/t/10basic.t b/t/10basic.t index 999fd5b..2dde8a9 100644 --- a/t/10basic.t +++ b/t/10basic.t @@ -26,20 +26,20 @@ is_deeply( ); is_deeply( - [sort (mro::get_isarev('GGG'))], + [sort @{mro::get_isarev('GGG')}], [], "get_isarev for GGG", ); is_deeply( - [sort (mro::get_isarev('DDD'))], + [sort @{mro::get_isarev('DDD')}], [ 'EEE', 'FFF', 'GGG', 'UNIVERSAL' ], "get_isarev for DDD", ); is_deeply( - [sort (mro::get_isarev('AAA'))], + [sort @{mro::get_isarev('AAA')}], [ 'BBB', 'CCC', 'DDD', 'EEE', 'FFF', 'GGG', 'UNIVERSAL' ], "get_isarev for AAA", );