in reply to Re^2: error for undefined function that's been imported
in thread error for undefined function that's been imported
my first reaction is "don't do that", and my next reaction is "this is crying out desparately for refactoring".## file: SomeModule.pm ## package SomeModule; #... use OtherModule; #... __END__ ## file: OtherModule.pm ## package OtherModule; #... use SomeModule; #...
Cross-references like that turn your code into a sort of "chicken-and-egg" problem -- if not in terms of actual compilation troubles, then at least in terms of ongoing maintenance. When someone else comes along to fix or add something, they have to go around in circles to track what the code is doing (and that "someone else" could very well be you, six months from now).
The main point of creating modules is to encapsulate things that are logically independent of other things. Having mutual dependencies among modules just defeats their purpose.
Look at the functions defined in "MyUserProfile.pm" that are called from "Register.pm", and likewise at those defined in the latter that are called from the former. If you can put these functions into one or more distinct modules, and have the two original modules use the new ones instead of using each other, things will be easier all around.
Ideally, this should lead you in the same direction that rincewind suggested: an OO design. If a current module is based on certain data being shared by its various subs, you have an obvious basis for making that into an object; if not, then just dividing up the subs a bit differently to eliminate module cross-dependencies should be fairly easy and sufficient, and will reduce incoherence in your code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: error for undefined function that's been imported
by argv (Pilgrim) on Aug 18, 2005 at 17:06 UTC |