Originally posted by Karthik Guru:
Last time i read about OOP, i remember reading that Perl does support inheritance - are'nt the super/base classes specified in an array in a perl module..i dont remeber the name of the array though..had some wierd name ?
Also remember the book mentioning that OOP in perl is more of an after thought rather than 'by design'?...probably thats why the moderator did'nt choose to add perl in the list
Mmmmmm.... Obj Ori Perl.
Perl Support for Inheritance:
If you define the @ISA list for a package (class), any sub (method) calls that aren't handled explicitly by the current package, are searched for in the packages listed in the package's @ISA list.
Ok, that was fairly straightforward. But why is @ISA a list instead of a scalar? To support multiple inheritance.
One last "feature" is the AUTOLOAD sub. If you try to call a sub that isn't defined in a package or any of its @ISA packages, the AUTOLOAD sub is tried in each of those.
Frinstance,
Let's say...
- There's "base" packages A and B
- package C has @ISA=("B");
- package D has @ISA=("C", "A");
You try calling foo() on a D. Perl will look for the following subs:
- D::foo
- C::foo
- B::foo (depth first up the inheritance tree)
- A::foo
- UNIVERSAL::foo
- D::AUTOLOAD
- C::AUTOLOAD
- B::AUTOLOAD
- A::AUTOLOAD
- UNIVERSAL::AUTOLOAD
This setup allows any number of labor saving conventions.
[ December 07, 2005: Message edited by: Ryan McGuire ]