7.3 UNIVERSALAll modules implicitly inherit from a built-in module called UNIVERSAL and inherit the following three methods:
Because Perl allows a package to shamelessly trample on other namespaces, some packages use the UNIVERSAL module as a holding area for some global subroutines that they wish to export to everyone. I recommend that you do not use this "feature" yourself (or at least not in those that you contribute to CPAN!). 7.3.1 Searching for MethodsWe have mentioned two places that Perl searches when it cannot find a method in the target module: the inheritance hierarchy ( @ISA ) and AUTOLOAD . While checking the inheritance hierarchy, Perl checks the base classes' @ISA arrays too: a depth-first search is conducted, and the first available one is used. Let us examine the precise order in which all these subroutines are searched. Given: package Man; @ISA = qw(Mammal Social_Animal); a call to Man->schmooze results in the following search sequence. First the normal inheritance hierarchy is checked: Then AUTOLOAD is looked up in the same order: The first available subroutine is given the control and the search is stopped. If all fails, Perl throws a run-time exception. Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|