title: Why same function call bring different results in object internals?
body: <p>I'm dynamically adding classes, methods and attributes using Moose::Meta::Class.</p>
  
  <p>Can someone explain why this code is working (calling <code>generate()</code> subroutine internally, inside <code>Cat</code> class):</p>
  
  <pre><code>package Cat;
  
  use Moose;
  
  sub generate {
  
      my $siberian = Moose::Meta::Class-&gt;create( 'Siberian' );
      $siberian-&gt;add_method( echo =&gt; sub { print "yeah!\n" } );
  
  
      my $tiger = Moose::Meta::Class-&gt;create( 'Tiger' );
      $tiger-&gt;add_attribute(
          Siberian =&gt; {
              is      =&gt; 'ro',
              default =&gt; sub { $siberian-&gt;new_object; }
          },
      );
  
      __PACKAGE__-&gt;meta-&gt;add_attribute(
          Tiger =&gt; {
              is      =&gt; 'ro',
              default =&gt; sub { $tiger-&gt;new_object },
          },
      );
  
      print "Generation done!\n";
  }
  
  generate();
  
  
  package main;
  
  use Data::Printer;
  
  my $a = Cat-&gt;new;
  
  # $a-&gt;generate;
  p( $a );
  $a-&gt;Tiger-&gt;Siberian-&gt;echo;    # returns 'yeah!'
  </code></pre>
  
  <p>output of <code>p($a)</code>:</p>
  
  <pre><code>Cat  {
      Parents       Moose::Object
      public methods (3) : generate, meta, Tiger
      private methods (0)
      internals: {
          Tiger   Tiger
      }
  }
  </code></pre>
  
  <p>and this one (calling <code>generate</code> sub externally, via <code>$a-&gt;generate</code>) doesn't:</p>
  
  <pre><code>package Cat;
  use Moose;
  
  sub generate {
  
      my $siberian = Moose::Meta::Class-&gt;create('Siberian');
      $siberian-&gt;add_method(
          echo =&gt; sub { print "yeah!\n" }
      );
  
      my $tiger = Moose::Meta::Class-&gt;create('Tiger');
      $tiger-&gt;add_attribute(
          Siberian =&gt; {
              is      =&gt; 'ro',
              default =&gt; sub { $siberian-&gt;new_object; }
          },
      );
  
      __PACKAGE__-&gt;meta-&gt;add_attribute(
          Tiger =&gt; {
              is      =&gt; 'ro',
              default =&gt; sub { $tiger-&gt;new_object },
          },
      );
  
      print "Generation done!\n";
  
  }
  
  # generate();
  
  
  package main;
  use Data::Printer;
  
  my $a = Cat-&gt;new;
  $a-&gt;generate;
  p($a);
  $a-&gt;Tiger-&gt;Siberian-&gt;echo; # returns 'yeah!'
  </code></pre>
  
  <p>output of <code>p($a)</code>:</p>
  
  <pre><code>Cat  {
      Parents       Moose::Object
      public methods (3) : generate, meta, Tiger
      private methods (0)
      internals: {}
  }
  </code></pre>
  
  <p>and program returns an error:</p>
  
  <blockquote>
    <p>Can't call method "Siberian" on an undefined value at base2.pl line
    39.</p>
  </blockquote>