1MRO::Compat(3) User Contributed Perl Documentation MRO::Compat(3)
2
3
4
6 MRO::Compat - mro::* interface compatibility for Perls < 5.9.5
7
9 package FooClass; use base qw/X Y Z/;
10 package X; use base qw/ZZZ/;
11 package Y; use base qw/ZZZ/;
12 package Z; use base qw/ZZZ/;
13
14 package main;
15 use MRO::Compat;
16 my $linear = mro::get_linear_isa('FooClass');
17 print join(q{, }, @$linear);
18
19 # Prints: "FooClass, X, ZZZ, Y, Z"
20
22 The "mro" namespace provides several utilities for dealing with method
23 resolution order and method caching in general in Perl 5.9.5 and
24 higher.
25
26 This module provides those interfaces for earlier versions of Perl
27 (back to 5.6.0 anyways).
28
29 It is a harmless no-op to use this module on 5.9.5+. That is to say,
30 code which properly uses MRO::Compat will work unmodified on both older
31 Perls and 5.9.5+.
32
33 If you're writing a piece of software that would like to use the parts
34 of 5.9.5+'s mro:: interfaces that are supported here, and you want
35 compatibility with older Perls, this is the module for you.
36
37 Some parts of this code will work better and/or faster with
38 Class::C3::XS installed (which is an optional prereq of Class::C3,
39 which is in turn a prereq of this package), but it's not a requirement.
40
41 This module never exports any functions. All calls must be fully
42 qualified with the "mro::" prefix.
43
44 The interface documentation here serves only as a quick reference of
45 what the function basically does, and what differences between
46 MRO::Compat and 5.9.5+ one should look out for. The main docs in
47 5.9.5's mro are the real interface docs, and contain a lot of other
48 useful information.
49
51 mro::get_linear_isa($classname[, $type])
52 Returns an arrayref which is the linearized "ISA" of the given class.
53 Uses whichever MRO is currently in effect for that class by default, or
54 the given MRO (either "c3" or "dfs" if specified as $type).
55
56 The linearized ISA of a class is a single ordered list of all of the
57 classes that would be visited in the process of resolving a method on
58 the given class, starting with itself. It does not include any
59 duplicate entries.
60
61 Note that "UNIVERSAL" (and any members of "UNIVERSAL"'s MRO) are not
62 part of the MRO of a class, even though all classes implicitly inherit
63 methods from "UNIVERSAL" and its parents.
64
65 mro::import
66 This allows the "use mro 'dfs'" and "use mro 'c3'" syntaxes, providing
67 you "use MRO::Compat" first. Please see the "USING C3" section for
68 additional details.
69
70 mro::set_mro($classname, $type)
71 Sets the mro of $classname to one of the types "dfs" or "c3". Please
72 see the "USING C3" section for additional details.
73
74 mro::get_mro($classname)
75 Returns the MRO of the given class (either "c3" or "dfs").
76
77 It considers any Class::C3-using class to have C3 MRO even before
78 Class::C3::initialize() is called.
79
80 mro::get_isarev($classname)
81 Returns an arrayref of classes who are subclasses of the given
82 classname. In other words, classes in whose @ISA hierarchy we appear,
83 no matter how indirectly.
84
85 This is much slower on pre-5.9.5 Perls with MRO::Compat than it is on
86 5.9.5+, as it has to search the entire package namespace.
87
88 mro::is_universal($classname)
89 Returns a boolean status indicating whether or not the given classname
90 is either "UNIVERSAL" itself, or one of "UNIVERSAL"'s parents by @ISA
91 inheritance.
92
93 Any class for which this function returns true is "universal" in the
94 sense that all classes potentially inherit methods from it.
95
96 mro::invalidate_all_method_caches
97 Increments "PL_sub_generation", which invalidates method caching in all
98 packages.
99
100 Please note that this is rarely necessary, unless you are dealing with
101 a situation which is known to confuse Perl's method caching.
102
103 mro::method_changed_in($classname)
104 Invalidates the method cache of any classes dependent on the given
105 class. In MRO::Compat on pre-5.9.5 Perls, this is an alias for
106 "mro::invalidate_all_method_caches" above, as pre-5.9.5 Perls have no
107 other way to do this. It will still enforce the requirement that you
108 pass it a classname, for compatibility.
109
110 Please note that this is rarely necessary, unless you are dealing with
111 a situation which is known to confuse Perl's method caching.
112
113 mro::get_pkg_gen($classname)
114 Returns an integer which is incremented every time a local method of or
115 the @ISA of the given package changes on Perl 5.9.5+. On earlier Perls
116 with this MRO::Compat module, it will probably increment a lot more
117 often than necessary.
118
120 While this module makes the 5.9.5+ syntaxes "use mro 'c3'" and
121 "mro::set_mro("Foo", 'c3')" available on older Perls, it does so merely
122 by passing off the work to Class::C3.
123
124 It does not remove the need for you to call "Class::C3::initialize()",
125 "Class::C3::reinitialize()", and/or "Class::C3::uninitialize()" at the
126 appropriate times as documented in the Class::C3 docs. These three
127 functions are always provided by MRO::Compat, either via Class::C3
128 itself on older Perls, or directly as no-ops on 5.9.5+.
129
131 Class::C3
132
133 mro
134
136 Brandon L. Black, <blblack@gmail.com>
137
139 Copyright 2007-2008 Brandon L. Black <blblack@gmail.com>
140
141 This library is free software; you can redistribute it and/or modify it
142 under the same terms as Perl itself.
143
144
145
146perl v5.12.0 2009-05-27 MRO::Compat(3)