1Class::ISA(3pm) Perl Programmers Reference Guide Class::ISA(3pm)
2
3
4
6 Class::ISA -- report the search path for a class's ISA tree
7
9 # Suppose you go: use Food::Fishstick, and that uses and
10 # inherits from other things, which in turn use and inherit
11 # from other things. And suppose, for sake of brevity of
12 # example, that their ISA tree is the same as:
13
14 @Food::Fishstick::ISA = qw(Food::Fish Life::Fungus Chemicals);
15 @Food::Fish::ISA = qw(Food);
16 @Food::ISA = qw(Matter);
17 @Life::Fungus::ISA = qw(Life);
18 @Chemicals::ISA = qw(Matter);
19 @Life::ISA = qw(Matter);
20 @Matter::ISA = qw();
21
22 use Class::ISA;
23 print "Food::Fishstick path is:\n ",
24 join(", ", Class::ISA::super_path('Food::Fishstick')),
25 "\n";
26
27 That prints:
28
29 Food::Fishstick path is:
30 Food::Fish, Food, Matter, Life::Fungus, Life, Chemicals
31
33 Suppose you have a class (like Food::Fish::Fishstick) that is derived,
34 via its @ISA, from one or more superclasses (as Food::Fish::Fishstick
35 is from Food::Fish, Life::Fungus, and Chemicals), and some of those
36 superclasses may themselves each be derived, via its @ISA, from one or
37 more superclasses (as above).
38
39 When, then, you call a method in that class ($fishstick->calories),
40 Perl first searches there for that method, but if it's not there, it
41 goes searching in its superclasses, and so on, in a depth-first (or
42 maybe "height-first" is the word) search. In the above example, it'd
43 first look in Food::Fish, then Food, then Matter, then Life::Fungus,
44 then Life, then Chemicals.
45
46 This library, Class::ISA, provides functions that return that list --
47 the list (in order) of names of classes Perl would search to find a
48 method, with no duplicates.
49
51 the function Class::ISA::super_path($CLASS)
52 This returns the ordered list of names of classes that Perl would
53 search thru in order to find a method, with no duplicates in the
54 list. $CLASS is not included in the list. UNIVERSAL is not
55 included -- if you need to consider it, add it to the end.
56
57 the function Class::ISA::self_and_super_path($CLASS)
58 Just like "super_path", except that $CLASS is included as the first
59 element.
60
61 the function Class::ISA::self_and_super_versions($CLASS)
62 This returns a hash whose keys are $CLASS and its (super-)super‐
63 classes, and whose values are the contents of each class's $VERSION
64 (or undef, for classes with no $VERSION).
65
66 The code for self_and_super_versions is meant to serve as an exam‐
67 ple for precisely the kind of tasks I anticipate that
68 self_and_super_path and super_path will be used for. You are
69 strongly advised to read the source for self_and_super_versions,
70 and the comments there.
71
73 * Class::ISA doesn't export anything. You have to address the func‐
74 tions with a "Class::ISA::" on the front.
75
76 * Contrary to its name, Class::ISA isn't a class; it's just a package.
77 Strange, isn't it?
78
79 * Say you have a loop in the ISA tree of the class you're calling one
80 of the Class::ISA functions on: say that Food inherits from Matter, but
81 Matter inherits from Food (for sake of argument). If Perl, while
82 searching for a method, actually discovers this cyclicity, it will
83 throw a fatal error. The functions in Class::ISA effectively ignore
84 this cyclicity; the Class::ISA algorithm is "never go down the same
85 path twice", and cyclicities are just a special case of that.
86
87 * The Class::ISA functions just look at @ISAs. But theoretically, I
88 suppose, AUTOLOADs could bypass Perl's ISA-based search mechanism and
89 do whatever they please. That would be bad behavior, tho; and I try
90 not to think about that.
91
92 * If Perl can't find a method anywhere in the ISA tree, it then looks
93 in the magical class UNIVERSAL. This is rarely relevant to the tasks
94 that I expect Class::ISA functions to be put to, but if it matters to
95 you, then instead of this:
96
97 @supers = Class::Tree::super_path($class);
98
99 do this:
100
101 @supers = (Class::Tree::super_path($class), 'UNIVERSAL');
102
103 And don't say no-one ever told ya!
104
105 * When you call them, the Class::ISA functions look at @ISAs anew --
106 that is, there is no memoization, and so if ISAs change during runtime,
107 you get the current ISA tree's path, not anything memoized. However,
108 changing ISAs at runtime is probably a sign that you're out of your
109 mind!
110
112 Copyright (c) 1999, 2000 Sean M. Burke. All rights reserved.
113
114 This library is free software; you can redistribute it and/or modify it
115 under the same terms as Perl itself.
116
118 Sean M. Burke "sburke@cpan.org"
119
120
121
122perl v5.8.8 2001-09-21 Class::ISA(3pm)