Yes it is possible, but it is not recommended. I just ran into a problem with a module on CPAN that suffers from a circular dependency that crops up in the strangest ways. It has to do with the fact that it is importing functions in a circular dependancy, which by the way is exactly what you are suffering from. Here is an example:

#!/usr/bin/perl use Crypt::Random; use Crypt::Random::Generator; my $gen = new Crypt::Random::Generator Strength => 0; print $gen->integer(Upper => 100), $/;

The above will fail (if you are using version 1.13 of Crypt::Random) with the following error:

Undefined subroutine &Crypt::Random::Generator::makerandom_itv called at lib/Crypt/Random/Generator.pm line 82.

Which looks pretty similar to your problem!

The solution is to fully qualify your functions instead of importing them (ie use cspace::chelp in your bspace module).

What can make this really frustrating, is that the module may appear to work correctly in most instances, but if the modules get used in the wrong order, you hit a problem. Check out the following code snippet which also triggers the Crypt::Random circular reference bug.

#!/usr/bin/perl use Tk; use Net::SFTP; my $sftp = Net::SFTP->new('localhost');

Which spews out the following errors:

"makerandom" is not exported by the Crypt::Random module "makerandom_itv" is not exported by the Crypt::Random module "makerandom_octet" is not exported by the Crypt::Random module Can't continue after import errors at /usr/local/share/perl/5.8.2/Cryp +t/Random/Generator.pm line 12 BEGIN failed--compilation aborted at /usr/local/share/perl/5.8.2/Crypt +/Random/Generator.pm line 12, <GEN0> line 1. Compilation failed in require at /usr/local/share/perl/5.8.2/Crypt/Ran +dom.pm line 18, <GEN0> line 1. BEGIN failed--compilation aborted at /usr/local/share/perl/5.8.2/Crypt +/Random.pm line 18, <GEN0> line 1. Compilation failed in require at ../Crypt-DH-0.03/lib//Crypt/DH.pm lin +e 6, <GEN0> line 1. BEGIN failed--compilation aborted at ../Crypt-DH-0.03/lib//Crypt/DH.pm + line 6, <GEN0> line 1. Compilation failed in require at ../Net-SSH-Perl-1.25/lib//Net/SSH/Per +l/Kex/DH1.pm line 13, <GEN0> line 1. BEGIN failed--compilation aborted at ../Net-SSH-Perl-1.25/lib//Net/SSH +/Perl/Kex/DH1.pm line 13, <GEN0> line 1. Compilation failed in require at ../Net-SSH-Perl-1.25/lib//Net/SSH/Per +l/Kex.pm line 6, <GEN0> line 1. BEGIN failed--compilation aborted at ../Net-SSH-Perl-1.25/lib//Net/SSH +/Perl/Kex.pm line 6, <GEN0> line 1. Compilation failed in require at ../Net-SSH-Perl-1.25/lib//Net/SSH/Per +l/SSH2.pm line 6, <GEN0> line 1. BEGIN failed--compilation aborted at ../Net-SSH-Perl-1.25/lib//Net/SSH +/Perl/SSH2.pm line 6, <GEN0> line 1. Compilation failed in require at ../Net-SSH-Perl-1.25/lib//Net/SSH/Per +l.pm line 51, <GEN0> line 1.

Not very nice is it... So the moral of the story is, don't use circular references, and if you really have to, fully qualify your functions.

- Cees


In reply to Re: Circular usage by cees
in thread Circular usage by Sprad

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.