basic stuff, docs, no implementation yet
[gitmo/MRO-Compat.git] / lib / mro.pm
CommitLineData
4c4e4170 1package mro;
2use strict;
3use warnings;
4
5# mro.pm versions >= 1.00 reserved for the Perl core
6our $VERSION = '0.01';
7
8our $C3_INSTALLED;
9BEGIN {
10 eval { require Class::C3 };
11 if(!$@) {
12 $C3_INSTALLED = 1;
13 }
14}
15
16sub import {
17 die q{The "use mro 'foo'" syntax is only supported on Perl 5.9.5+}
18 if $_[1];
19}
20
21=head1 NAME
22
23mro - Method Resolution Order
24
25=head1 SYNOPSIS
26
27 package FooClass; use base qw/X Y Z/;
28 package X; use base qw/ZZZ/;
29 package Y; use base qw/ZZZ/;
30 package Z; use base qw/ZZZ/;
31
32 package main;
33 use mro;
34 my $linear = mro::get_linear_isa('FooClass');
35 print join(q{, }, @$linear) . "\n";
36
37 # Prints: "FooClass, X, ZZZ, Y, Z"
38
39=head1 DESCRIPTION
40
41The "mro" namespace provides several utilities for dealing
42with method resolution order and method caching in general.
43
44It never exports any functions. All calls must be fully
45qualified with the C<mro::> prefix.
46
47=head1 IMPORTANT INFORMATION
48
49This module is only for use on Perls earlier than 5.9.5.
50Perl version 5.9.5 and higher includes its own superior
51implementation, with a version number greater than 1.00.
52
53This CPAN implementation supports a small subset of the
54features of the 5.9.5+ version, to make it easier for
55some classes of modules to depend on these features and
56be compatible with older Perls.
57
58=head1 Functions
59
60=head2 mro::get_linear_isa($classname[, $type])
61
62Returns an arrayref which is the linearized MRO of the given class.
63Uses whichever MRO is currently in effect for that class by default,
64or the given MRO (either C<c3> or C<dfs> if specified as C<$type>).
65
66The linearized MRO of a class is a single ordered list of all of the
67classes that would be visited in the process of resolving a method
68on the given class, starting with itself. It does not include any
69duplicate entries.
70
71Explicitly asking for the C<c3> MRO of a class will die if
72L<Class::C3> is not installed. If L<Class::C3> is installed, it will
73detect C3 classes and return the correct C3 MRO unless explicitly
74asked to return the C<dfs> MRO.
75
76Note that C<UNIVERSAL> (and any members of C<UNIVERSAL>'s MRO) are not
77part of the MRO of a class, even though all classes implicitly inherit
78methods from C<UNIVERSAL> and its parents.
79
80=head2 mro::set_mro($classname, $type)
81
82Not supported in this version, will die if used.
83
84=head2 mro::get_mro($classname)
85
86Returns the MRO of the given class (either C<c3> or C<dfs>).
87
88=head2 mro::get_isarev($classname)
89
90Not supported in this version, will die if used.
91
92=head2 mro::is_universal($classname)
93
94Returns a boolean status indicating whether or not
95the given classname is either C<UNIVERSAL> itself,
96or one of C<UNIVERSAL>'s parents by C<@ISA> inheritance.
97
98Any class for which this function returns true is
99"universal" in the sense that all classes potentially
100inherit methods from it.
101
102=head2 mro::invalidate_all_method_caches()
103
104Increments C<PL_sub_generation>, which invalidates method
105caching in all packages.
106
107=head2 mro::method_changed_in($classname)
108
109Invalidates the method cache of any classes dependent on the
110given class. In this version, this is an alias for
111C<mro::invalidate_all_method_caches> above, as pre-5.9.5
112Perls have no other way to do this. It will still enforce
113the requirement that you pass it a classname, for
114compatibility with 5.9.5.
115
116=head1 SEE ALSO
117
118L<Class::C3>
119
120=head1 AUTHOR
121
122Brandon L. Black, E<lt>blblack@gmail.comE<gt>
123
124=head1 COPYRIGHT AND LICENSE
125
126Copyright 2007 Brandon L. Black E<lt>blblack@gmail.comE<gt>
127
128This library is free software; you can redistribute it and/or modify
129it under the same terms as Perl itself.
130
131=cut
132
1331;