You shouldn't need to solve this problem.

If you do, the best solution should be to make one module use the other, and the other one require the first inside of the function(s) that need it. This gives a predictable loading order. For an example look at the source to Carp and Exporter.

If each really does need stuff from the other, and you're unwilling to use/require, then I would still suggest the cleaner pattern:

use Exporter qw(import); BEGIN {@EXPORT_OK = qw( ... );}
That makes the magic BEGIN block much shorter. And it avoids inheriting all of Exporter.

Also you need to warn people that it is very important that neither module in its initialization can do anything that relies on the other module being fully loaded yet. Because if the other module is used first, then its compilation will be put on hold to load this one, and therefore while this module gets loaded, that one will not be loaded. I've seen people get badly bitten by this, and get in a situation where one module breaks if the other is loaded first, or worse yet where neither works if the other is loaded first. (And that is one reason that I recommend the use/require relationship instead of use/use.)

If this scares you, then I'd suggest thinking through your problem clearly enough to not need to do circular dependencies. Many other languages don't even allow them, and I don't think that is a particularly bad restriction.


In reply to Re: Mini-Tutorial: Mutual Use of Exporting Modules by tilly
in thread Mini-Tutorial: Mutual Use of Exporting Modules by ikegami

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.