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