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 com‐
35 patibility 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 qual‐
42 ified 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
53 Returns an arrayref which is the linearized "ISA" of the given class.
54 Uses whichever MRO is currently in effect for that class by default, or
55 the given MRO (either "c3" or "dfs" if specified as $type).
56
57 The linearized ISA of a class is a single ordered list of all of the
58 classes that would be visited in the process of resolving a method on
59 the given class, starting with itself. It does not include any dupli‐
60 cate entries.
61
62 Note that "UNIVERSAL" (and any members of "UNIVERSAL"'s MRO) are not
63 part of the MRO of a class, even though all classes implicitly inherit
64 methods from "UNIVERSAL" and its parents.
65
66 mro::import
67
68 This allows the "use mro 'dfs'" and "use mro 'c3'" syntaxes, providing
69 you "use MRO::Compat" first. Please see the "USING C3" section for
70 additional details.
71
72 mro::set_mro($classname, $type)
73
74 Sets the mro of $classname to one of the types "dfs" or "c3". Please
75 see the "USING C3" section for additional details.
76
77 mro::get_mro($classname)
78
79 Returns the MRO of the given class (either "c3" or "dfs").
80
81 It considers any Class::C3-using class to have C3 MRO even before
82 Class::C3::initialize() is called.
83
84 mro::get_isarev($classname)
85
86 Returns an arrayref of classes who are subclasses of the given class‐
87 name. In other words, classes who we exist, however indirectly, in the
88 @ISA inheritancy hierarchy of.
89
90 This is much slower on pre-5.9.5 Perls with MRO::Compat than it is on
91 5.9.5+, as it has to search the entire package namespace.
92
93 mro::is_universal($classname)
94
95 Returns a boolean status indicating whether or not the given classname
96 is either "UNIVERSAL" itself, or one of "UNIVERSAL"'s parents by @ISA
97 inheritance.
98
99 Any class for which this function returns true is "universal" in the
100 sense that all classes potentially inherit methods from it.
101
102 mro::invalidate_all_method_caches
103
104 Increments "PL_sub_generation", which invalidates method caching in all
105 packages.
106
107 Please note that this is rarely necessary, unless you are dealing with
108 a situation which is known to confuse Perl's method caching.
109
110 mro::method_changed_in($classname)
111
112 Invalidates the method cache of any classes dependent on the given
113 class. In MRO::Compat on pre-5.9.5 Perls, this is an alias for
114 "mro::invalidate_all_method_caches" above, as pre-5.9.5 Perls have no
115 other way to do this. It will still enforce the requirement that you
116 pass it a classname, for compatibility.
117
118 Please note that this is rarely necessary, unless you are dealing with
119 a situation which is known to confuse Perl's method caching.
120
121 mro::get_pkg_gen($classname)
122
123 Returns an integer which is incremented every time a local method of or
124 the @ISA of the given package changes on Perl 5.9.5+. On earlier Perls
125 with this MRO::Compat module, it will probably increment a lot more
126 often than necessary.
127
129 While this module makes the 5.9.5+ syntaxes "use mro 'c3'" and
130 "mro::set_mro("Foo", 'c3')" available on older Perls, it does so merely
131 by passing off the work to Class::C3.
132
133 It does not remove the need for you to call "Class::C3::initialize()",
134 "Class::C3::reinitialize()", and/or "Class::C3::uninitialize()" at the
135 appropriate times as documented in the Class::C3 docs. These three
136 functions are always provided by MRO::Compat, either via Class::C3
137 itself on older Perls, or directly as no-ops on 5.9.5+.
138
140 Class::C3
141
142 mro
143
145 Brandon L. Black, <blblack@gmail.com>
146
148 Copyright 2007-2008 Brandon L. Black <blblack@gmail.com>
149
150 This library is free software; you can redistribute it and/or modify it
151 under the same terms as Perl itself.
152
153
154
155perl v5.8.8 2008-05-20 MRO::Compat(3)