Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

I have written a perl module (package XYZ) that contains a function named test that does some testing of its internals. The module tests fine on its own. The module is used as part of a larger framework. But when I require the module from the larger framework, I get "Subroutine test redefined at XYZ.pm line 123...". I presume this is because the parent included a module that exported a function called test which is then running into my function. I am confused by perl's namespace handling, but my experience is with use, not require, so maybe that's the issue.

My module's 'test' function is not exported; but clearly a conflict is occurring when I interface with the larger structure.

Is there a way to find where the conflict is coming from? Where is 'test' originally defined? Aside from renaming my package's method, is there a way to avert the namespace conflict wiht require?

Any help is greatly appreciated!

Humbly yours,

A

  • Comment on how to find the original sub definition

Replies are listed 'Best First'.
Re: how to find the original sub definition
by Anonymous Monk on Dec 22, 2010 at 19:39 UTC
    Are you sure the subroutine is actually inside that package? Either it's not, or you're using do instead of require.
      I am pretty sure. The XYZ module is structured as follows:
      #!/usr/bin/perl package XYZ; use warnings; use strict; use Pod::Usage; { my $PrivateLexicalData; sub do_something_useful { ... } } # End of private lexial scope sub test { do_something_useful(3) == 2 or die; print "Tests complete\n." exit(0); } if (not defined caller()) { scalar @ARGV == 0 and pod2usage(); grep { m/-test/i } @ARGV and test(); } 1; =head1 NAME ...
        Found it! There was another 'XYZ' package with a test sub.