in reply to Module Undefined Subroutines, works one way - not another
You have a case where ModA uses ModB (indirectly) and ModB uses ModA.
If ModA uses ModB, ModB uses ModA, and both ModA and ModB export symbols, you have a bad design.
If ModA uses ModB, ModB uses ModA, and both ModA and ModB export symbols, one needs to pay attention to code execution order. The best way I've found to avoid problems is to do:
# ModA.pm use strict; use warnings; package ModA; BEGIN { our @ISA = qw( Exporter ); our @EXPORT_OK = qw( ... ); require Exporter; } use This; use ModB; use That; ... 1;
# ModB.pm use strict; use warnings; package ModB; BEGIN { our @ISA = qw( Exporter ); our @EXPORT_OK = qw( ... ); require Exporter; } use This; use ModA; use That; ... 1;
Basically, move your use statments from where they to after your BEGIN.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Module Undefined Subroutines, works one way - not another
by duane_ellis (Initiate) on Jan 11, 2007 at 22:24 UTC | |
by ikegami (Patriarch) on Jan 11, 2007 at 22:52 UTC |