title: Dealing with multiple-inherited constructors in Moose
body: <p>Greetings,</p>
  
  <p>I'm learning <a href="http://search.cpan.org/~drolsky/Moose/" rel="noreferrer">Moose</a> and I'm trying to write a <a href="http://search.cpan.org/~markstos/CGI-Application/" rel="noreferrer">CGI::Application</a> subclass with Moose, which is made difficult by the fact that CGI-App is not based on Moose. </p>
  
  <p>In my other CGI-App subclasses, I like to have a parent class with a <code>setup</code> method that looks at the child class's symbol table and automatically sets up the runmodes. I figure I can use Moose's metaclass facilities to achieve the same thing in a cleaner way. So here is what I have in my parent class:</p>
  
  <pre><code>use MooseX::Declare;
  
  class MyApp::CGI 
  extends Moose::Object
  extends CGI::Application { 
  
      method setup { 
          $self-&gt;start_mode( 'main' );
  
          my @methods = map { $_-&gt;name } $self-&gt;meta-&gt;get_all_methods;
  
          $self-&gt;run_modes( map  { /^rm_(.+)$/  =&gt; $_ }
                            grep { /^rm_/ }
                            @methods
                          );
      }
  
  }
  </code></pre>
  
  <p>...and in my child class:</p>
  
  <pre><code>use MooseX::Declare;
  
  class MyApp::CGI::Login 
  extends MyApp::CGI { 
      method rm_main { 
          return "it works";
      }
  }
  </code></pre>
  
  <p>I realized that the reason my runmodes were not getting setup properly is because <code>setup</code> is called by the CGI-App constructor, and <code>Moose::Object</code> is sticking its own constructor in my class. I tried to solve this with a method modifier:</p>
  
  <pre><code>around new { 
      $self = $orig-&gt;( @_ );
      $self-&gt;CGI::Application::new( @_ );
  }
  </code></pre>
  
  <p>This gives me </p>
  
  <pre><code>Can't call method "BUILDARGS" on unblessed reference at ...Moose/Object.pm line 21.
  </code></pre>
  
  <p>I have a feeling, however, that I'm going about this in completely the wrong way, and Moose has a much better facility for achieving what I want, which I have not as yet discovered.</p>