[tpm] Understanding 'use base ...'
uri at stemsystems.com
Tue Jul 15 15:28:45 PDT 2008
>>>>> "RD" == Rick Delaney <rick at bort.ca> writes:
RD> On Jul 15 2008, Uri Guttman wrote:
>> but my point about use base vs. explicit assigning of @ISA stands. there
>> is no difference between them. use base is cleaner as it loads the
>> module and sets @ISA for you in one line.
RD> That would be nice, if true. But base.pm does things to try to prevent
RD> ever-growing @ISA for loads of the same module. So for (not-real-world)
RD> package R;
RD> use base qw(Q);
RD> package S;
RD> use base qw(Q R);
RD> @S::ISA is ["Q"] instead of ["Q", "R"]. Which in this example would
RD> mean that no methods from R would be found for an object of type S.
RD> This is not what most people would expect, I think.
RD> Your point about multiple inheritance is well taken but some people do
RD> try to use it and using it along with base.pm can lead to these kinds of
RD> problems. There is a much simpler module on CPAN, parent.pm, that acts
RD> in the way one would expect base.pm to behave.
i generally avoid inheritance anyhow as i think it is not a great
concept. very few things are groupable with inheritance without some
form of compromise or square peg in round hole. but i have done wierder
things such as a module which is loaded and there are both ISA and HASA
relationships with the parent. i can't explain it quickly but it makes
for an unusually elegant solution to an odd problem.
Uri Guttman ------ uri at stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
More information about the toronto-pm