I have some modules that use each other and am getting subroutine redefined warnings when compilation is done (using perl -c) on one of the modules.

Some sample code that does what I mean is:

Foo.pm:
#!/usr/bin/perl use warnings; use strict; use lib '/tmp/'; package Foo; use Bar; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {}; return $self; } sub get_bar { return Bar->new(); } 1;
Bar.pm
#!/usr/bin/perl use warnings; use strict; use lib '/tmp/'; package Bar; use Foo; sub new { my $invocant = shift; my $class = ref($invocant) || $invocant; my $self = {}; return $self; } sub get_foo { return Foo->new(); } 1;
Running perl -c Foo.pm gives
Subroutine new redefined at Foo.pm line 13. Subroutine get_bar redefined at Foo.pm line 22. Foo.pm syntax OK

This is mainly irritating as it adds to the list of errors and warnings that appear in the Problems tab of Eclipse when editing.

I know that I can disable warning check for those problems (which I don't want to do as it may hide a real problem), or I can remove each module's use of the other and just ensure that the scripts that call these modules use both of them, but it seems to me that this sort of design should be valid.

Does anyone have any ideas of how to cross use modules without having subroutine redefinition issues?

Thanks,

Prowler
 - Spelling is a demanding task that requies you full attention.


In reply to Recursive use causes subroutine redefinition by prowler

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.