title: How can I detect recursing package calls in Perl?
body: <p>I have a Perl project were I just had a problem by making a circular package call.  The code below demonstrates the problem.  </p>
  
  <p>When this is executed, each package will call the other until all of the memory of the computer is consumed and it locks up.  I agree that this is a bad design and that circular calls like this should not be made in the design, but my project is sufficiently big that I would like to detect this at run time.  </p>
  
  <p>I have read about the weaken function and Data::Structure::Util, but I have not figured out a way to detect if there is a circular package load (I am assume, because a new copy is being made at each iteration and stored in each copy of the $this hash).  Any ideas?</p>
  
  <pre><code>use system::one;
  
  my $one = new system::one(); 
  
  package system::one;
  
  use strict;
  
  use system::two;
  
  sub new {
    my ($class) = @_; 
    my $this = {};  
    bless($this,$class); 
    # attributes
    $this-&gt;{two} = new system::two();
    return $this; 
  } 
  
  package system::two;
  
  use strict;
  
  use system::one;
  
  sub new {
    my ($class) = @_; 
    my $this = {};  
    bless($this,$class); 
    # attributes
    $this-&gt;{one} = new system::one();
    return $this; 
  } 
  </code></pre>