vandaleur has asked for the wisdom of the Perl Monks concerning the following question:

I have some code that I'm working on/improving that uses a number of packages that were designed in-house. These packages are referenced like this:

# in my main module
use ABC::HandleData;

with the HandleData.pm module referring to other members of the ABC namespace:

# in HandleData.pm
use ABC::HandleImages; use ABC::HandleOtherData;

The ABC group doesn't handle data in the way I want, so I'd like to set up an improved version of it. I thought I could just make copies of all ABC::xyz.pm file, rename them ABC2::xvz.pm, then change all references in my main module to use ABC2. (And change all references in the ABC2 modules as well.) This does not work. I'm getting an internal server error instead.

Is it even possible to do this the way I want? Do I have to set up a completely different namespace for these packages? If so, how would I do that? I'm completely new to Perl OOP, so any pointers will be greatly appreciated!

Replies are listed 'Best First'.
Re: Newbie question on packages/OOP
by dsheroh (Monsignor) on Aug 30, 2009 at 22:59 UTC
    Regarding the immediate issue, my first thought would be that you made your copies in the same directory as the originals. When perl sees use ABC::HandleData, it scans through the directories in @INC and, in each one, looks for ABC/HandleData.pm. If you want to use packages in the ABC2 namespace, they need to go into an ABC2 subdirectory, not the existing ABC subdirectory.

    And, since you phrased this as an OOP question rather than only as one about package management... Might it be more appropriate to subclass the existing ABC packages? Although there are (a very few) exceptions, "copy-paste inheritance" is generally inferior to the real thing.

Re: Newbie question on packages/OOP
by Anonymous Monk on Aug 30, 2009 at 23:22 UTC