The stupid question is the question not asked | |
PerlMonks |
Faking new() method in high-level packageby belden (Friar) |
on May 08, 2002 at 21:26 UTC ( [id://165191]=perlquestion: print w/replies, xml ) | Need Help?? |
belden has asked for the wisdom of the Perl Monks concerning the following question:
I've finally wrapped my mind around objects. Sort of. My first real OO project is to develop a set of utilities for working on some of my company's proprietary tables. One of the things that my nascent module has is two packages - one is a bunch of low-level methods for interacting directly with the table data, and the other is a higher-level set of methods for doing more interesting things using (you guessed it) the low-level methods; sorting, deduping, that kind of stuff. One of the things that I've been bitten by in my test programs is that my low-level package has the object constructor, not the high-level package. The 'bite' is that sometimes I forget, and instead of typing my $tool = LowUtils->new ( file => 'foo' ) I type my $tool = Utils->new ( file => 'foo' ) Today I realized that in the high-level package I can just add a new method which calls the low-level package's new method. Here's some sample code to show what I ended up doing: Output: Utils: lines = 72 this is the LowUtils destructor LowUtils: lines = 72 this is the LowUtils destructor I arrived at this solution after deciding that it probably wouldn't be smart to set @Utils::ISA to refer back to LowUtils. My questions:
blyman
Back to
Seekers of Perl Wisdom
|
|