Section: User Contributed Perl Documentation (3pm)
# Suppose you go: use Food::Fishstick, and that uses and # inherits from other things, which in turn use and inherit # from other things. And suppose, for sake of brevity of # example, that their ISA tree is the same as: @Food::Fishstick::ISA = qw(Food::Fish Life::Fungus Chemicals); @Food::Fish::ISA = qw(Food); @Food::ISA = qw(Matter); @Life::Fungus::ISA = qw(Life); @Chemicals::ISA = qw(Matter); @Life::ISA = qw(Matter); @Matter::ISA = qw(); use Class::ISA; print "Food::Fishstick path is:\n ", join(", ", Class::ISA::super_path('Food::Fishstick')), "\n";
Food::Fishstick path is: Food::Fish, Food, Matter, Life::Fungus, Life, Chemicals
@ISA, from one or more superclasses (as Food::Fish::Fishstick is from Food::Fish, Life::Fungus, and Chemicals), and some of those superclasses may themselves each be derived, via its
@ISA, from one or more superclasses (as above).
When, then, you call a method in that class ($fishstick->calories), Perl first searches there for that method, but if it's not there, it goes searching in its superclasses, and so on, in a depth-first (or maybe ``height-first'' is the word) search. In the above example, it'd first look in Food::Fish, then Food, then Matter, then Life::Fungus, then Life, then Chemicals.
$CLASSis not included in the list. UNIVERSAL is not included --- if you need to consider it, add it to the end.:
"super_path", except that
$CLASSis included as the first element.:
$CLASSand its (super-)superclasses, and whose values are the contents of each class's
$VERSION(or undef, for classes with no
The code for self_and_super_versions is meant to serve as an example for precisely the kind of tasks I anticipate that self_and_super_path and super_path will be used for. You are strongly advised to read the source for self_and_super_versions, and the comments there.
@ISAs. But theoretically, I suppose, AUTOLOADs could bypass Perl's ISA-based search mechanism and do whatever they please. That would be bad behavior, tho; and I try not to think about that.
@supers = Class::Tree::super_path($class);
@supers = (Class::Tree::super_path($class), 'UNIVERSAL');
And don't say no-one ever told ya!
@ISAsanew --- that is, there is no memoization, and so if ISAs change during runtime, you get the current ISA tree's path, not anything memoized. However, changing ISAs at runtime is probably a sign that you're out of your mind!
Copyright (c) 1999-2009 Sean M. Burke. All rights reserved.
Tutoriais de Tecnologia Web