I've run into some odd Exporter errors. Exported functions are working fine in some modules, but not in others. Possibly a load order dependency?

An example exporting module:

package MyNameSpace::Faction; ... BEGIN { #use Exporter 'import'; use Exporter qw (import); #@MyNameSpace::Faction::ISA = qw(MyNameSpace::Player Exporter); #@MyNameSpace::Faction::ISA = qw(Exporter MyNameSpace::Player); @MyNameSpace::Faction::ISA = qw(MyNameSpace::Player); @MyNameSpace::Faction::EXPORT_OK = qw( &get_faction &max_faction ); }

(As you can see from the commented-out lines, I've tried several syntactic variations for calling Exporter, but they haven't made any difference.)

Calling module 1:

package MyNameSpace::Player; ... use MyNameSpace::Faction qw (get_faction); ... $self->{faction} = get_faction($faction);

This produces Undefined subroutine &MyNameSpace::Player::get_faction called at [the last line included above] when I try to use the module.

Calling module 2:

package MyNameSpace::Territory; ... use MyNameSpace::Faction qw (get_faction); ... $self->{faction} = get_faction($faction);

This works perfectly fine.

Both reference the same package and import it with identical use statements, yet one successfully imports get_faction and the other doesn't. How do I track this down and resolve it? I know I can work around it by changing the failing line to $self->{faction} = MyNameSpace::Faction::get_faction($faction);, but that neither explains nor resolves the inconsistency of why Territory imports get_faction and Player doesn't.

(This may not be the best example, as it looks a little circular (Faction isa Player and exports the function that Player fails to import), but I've run into similar issues between otherwise unrelated modules, so I'm fairly sure that circularity isn't the cause. This example is just the one I recently encountered and finally drove me to ask about it.)


In reply to EXPORT_OKed function refusing to import by dsheroh

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.