From: Brandon L Black Date: Fri, 11 May 2007 00:06:42 +0000 (+0000) Subject: basic stuff, docs, no implementation yet X-Git-Tag: 0.02~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMRO-Compat.git;a=commitdiff_plain;h=4c4e41705f37591fd689b7126d0711198ecd71ab basic stuff, docs, no implementation yet --- diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..43633cc --- /dev/null +++ b/ChangeLog @@ -0,0 +1,4 @@ +Revision history for Perl extension mro. + +0.01 - Not Yet Released + - Initial release diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..4a31474 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,20 @@ +^_build +^Build$ +^blib +~$ +\.bak$ +^MANIFEST\.SKIP$ +CVS +\.svn +\.DS_Store +cover_db +\..*\.sw.?$ +^Makefile$ +^pm_to_blib$ +^MakeMaker-\d +^blibdirs$ +\.old$ +^#.*#$ +^\.# +\.gz$ +Build.PL diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..cf8bc11 --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,14 @@ +use inc::Module::Install; + +name ''; +all_from 'lib/mro.pm'; + +build_requires 'Test::More' => '0.47'; + +if($] > 5.009_004) { + warn "*** There is no good reason to install this module on Perl version 5.9.5 or higher ***"; + # XXX can I prevent M::I from installing mro.pm in this case? +} + +auto_install; +WriteAll; diff --git a/README b/README new file mode 100644 index 0000000..a8f6bdd --- /dev/null +++ b/README @@ -0,0 +1,29 @@ +mro version 0.01 +=========================== + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + + Requires Test::More 0.47 to test + +IMPORTANT INFORMATION + + This module is only for use on Perls earlier than 5.9.5. + Perl version 5.9.5 and higher includes its own superior + implementation, with a version number greater than 1.00. + +COPYRIGHT AND LICENCE + +Copyright (C) 2007 Brandon L Black + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + diff --git a/lib/mro.pm b/lib/mro.pm new file mode 100644 index 0000000..8e26b64 --- /dev/null +++ b/lib/mro.pm @@ -0,0 +1,133 @@ +package mro; +use strict; +use warnings; + +# mro.pm versions >= 1.00 reserved for the Perl core +our $VERSION = '0.01'; + +our $C3_INSTALLED; +BEGIN { + eval { require Class::C3 }; + if(!$@) { + $C3_INSTALLED = 1; + } +} + +sub import { + die q{The "use mro 'foo'" syntax is only supported on Perl 5.9.5+} + if $_[1]; +} + +=head1 NAME + +mro - Method Resolution Order + +=head1 SYNOPSIS + + package FooClass; use base qw/X Y Z/; + package X; use base qw/ZZZ/; + package Y; use base qw/ZZZ/; + package Z; use base qw/ZZZ/; + + package main; + use mro; + my $linear = mro::get_linear_isa('FooClass'); + print join(q{, }, @$linear) . "\n"; + + # Prints: "FooClass, X, ZZZ, Y, Z" + +=head1 DESCRIPTION + +The "mro" namespace provides several utilities for dealing +with method resolution order and method caching in general. + +It never exports any functions. All calls must be fully +qualified with the C prefix. + +=head1 IMPORTANT INFORMATION + +This module is only for use on Perls earlier than 5.9.5. +Perl version 5.9.5 and higher includes its own superior +implementation, with a version number greater than 1.00. + +This CPAN implementation supports a small subset of the +features of the 5.9.5+ version, to make it easier for +some classes of modules to depend on these features and +be compatible with older Perls. + +=head1 Functions + +=head2 mro::get_linear_isa($classname[, $type]) + +Returns an arrayref which is the linearized MRO of the given class. +Uses whichever MRO is currently in effect for that class by default, +or the given MRO (either C or C if specified as C<$type>). + +The linearized MRO of a class is a single ordered list of all of the +classes that would be visited in the process of resolving a method +on the given class, starting with itself. It does not include any +duplicate entries. + +Explicitly asking for the C MRO of a class will die if +L is not installed. If L is installed, it will +detect C3 classes and return the correct C3 MRO unless explicitly +asked to return the C MRO. + +Note that C (and any members of C's MRO) are not +part of the MRO of a class, even though all classes implicitly inherit +methods from C and its parents. + +=head2 mro::set_mro($classname, $type) + +Not supported in this version, will die if used. + +=head2 mro::get_mro($classname) + +Returns the MRO of the given class (either C or C). + +=head2 mro::get_isarev($classname) + +Not supported in this version, will die if used. + +=head2 mro::is_universal($classname) + +Returns a boolean status indicating whether or not +the given classname is either C itself, +or one of C's parents by C<@ISA> inheritance. + +Any class for which this function returns true is +"universal" in the sense that all classes potentially +inherit methods from it. + +=head2 mro::invalidate_all_method_caches() + +Increments C, which invalidates method +caching in all packages. + +=head2 mro::method_changed_in($classname) + +Invalidates the method cache of any classes dependent on the +given class. In this version, this is an alias for +C above, as 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 with 5.9.5. + +=head1 SEE ALSO + +L + +=head1 AUTHOR + +Brandon L. Black, Eblblack@gmail.comE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2007 Brandon L. Black Eblblack@gmail.comE + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + +1;