[ The need to use this technique is a very strong indicator of a design flaw in your system, but I recognize that the resources are not always available to fix design flaws. ]
If ModA uses ModB, ModB uses ModA, and ModA or ModB imports symbols from the other, one needs to pay attention to code execution order. The best way I've found to avoid problems is to setup Exporter before loading any other module.
# ModA.pm package ModA; use strict; use warnings; use Exporter qw( import ); BEGIN { our @EXPORT = qw( ... ); } use This; use ModB; use That; ... 1;
# ModB.pm package ModB; use strict; use warnings; use Exporter qw( import ); BEGIN { our @EXPORT = qw( ... ); } use This; use ModA; use That; ... 1;
Update: Added preamble. Details can be found in Jenda's and tilly's replies.
Update: Now uses Exporter more modern interface.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Mini-Tutorial: Mutual Use of Exporting Modules
by tilly (Archbishop) on Jul 10, 2009 at 04:30 UTC | |
Re: Mini-Tutorial: Mutual Use of Exporting Modules
by Jenda (Abbot) on Jul 09, 2009 at 23:04 UTC | |
by ikegami (Patriarch) on Jul 09, 2009 at 23:13 UTC | |
by tilly (Archbishop) on Jul 10, 2009 at 04:16 UTC | |
by Jenda (Abbot) on Jul 10, 2009 at 11:09 UTC | |
Re: Mini-Tutorial: Mutual Use of Exporting Modules
by roubi (Hermit) on Jul 10, 2009 at 00:28 UTC | |
by ikegami (Patriarch) on Jul 10, 2009 at 00:55 UTC |