I have a test case for my issue, and a real case. In the real case I have a dbg module I use to manage my debug code. And I have a libs module that has various useful subs. The dbg module calls some of the procs in the libs, and most of the libs procs call dbg procs at some point. Kinda a loop, but it is all good, as I have code to detect looping cases and act appropriately. Anyway, to make it more interesting, several procs from dbg are exported with @EXPORT (yes not with EXPORT_OK). None of the libs stuff is exported. The issue comes when I have a script that uses the dbg but not the libs. When that happens, and the script calls a sub in dbg that calls a sub in libs that calls a different sub in dbg, then the libs sub can't find the exported dbg sub.
Now the libs module does use dbg, and the dbg does use libs. But it seems that the export doesn't happen for the libs module in this case... However if I write a script that just uses the libs module and not the dbg, then the export of dbg subs to libs does work...
so here is the test case code, module L represents libs, module Z represents the dbg module.
it.pl
use strict;
use Z;
print "hey 1\n";
zProc();
subzProc();
print "hey 2\n";
L.pm
package L;
use strict;
use Exporter;
our (@ISA) = qw(Exporter);
use Z;
sub lProc {
print "I am lProc\n";
}
sub sublProc {
print "I am sublProc\n";
zProc();
}
Z.pm
package Z;
use strict;
use Exporter;
use L;
our (@EXPORT) = qw(zProc subzProc);
our (@ISA) = qw(Exporter);
sub zProc {
print "I am zProc\n";
}
sub subzProc {
print "I am subzProc\n";
L::lProc();
L::sublProc();
}
1;
perl version is v5.8.5
The output is
hey 1
I am zProc
I am subzProc
I am lProc
I am sublProc
Undefined subroutine &L::zProc called at L.pm line 22.
So in sub sublProc, the call to zProc doesn't work, cause the import/export didn't happen.
I do know a few workarounds, none of which are what I would like to do, and I would really like to know what is happening under the hood to cause this, as well as any possible solutions...
workarounds:
in it.pl if I use L before I use Z then it works... if after, doesn't work... (this is undesirable of course since it should not be a requirement for the end script to use L just to use Z...)
in L.pm I can simply not rely on the export and simply put the module name and :: in front of all calls to Z in L. This is undesirable cause I actually intend for other people to write scripts using these modules (all people in my team) and most people do the copy other code method of programing, and would likely copy some of the L code as starters for things, and thus the end code would be a mix of using the module name and not. That said, this is my top solution at the moment for lack of a better one...
so... any wisdom from the gurus on this would be great... I have poked around the web and found some mention of funky things...
http://perldoc.perl.org/Exporter.html
under the heading Playing Safe mentions a caveat, but doesn't explain it. It also mentions a solution of using a begin block, but that failed to work.
Thanks in advance for your time and thoughts...
Randell
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.