title: What’s the proper way to create a BUILDARGS method using MooseX::Declare?
body: <p>I'm having difficulty using MooseX::Declare properly when calling BUILDARGS.</p>
  
  <p>I'm trying to create an object as an interface for a file.  (Specifically, I want an interface to a binary file that lets me peek at the next few bytes in the file then chomp them off for further processing.)</p>
  
  <p>I want to be able to create one of these objects like this</p>
  
  <pre><code>my $f = binary_file_buffer-&gt;new( $file_name );
  </code></pre>
  
  <p>and then use it like this</p>
  
  <pre><code>while( my $block_id = $f-&gt;peek( $id_offset, $id_length ) ) {
      $block_id = unpack_block_id( $block_id );
      $munge_block{ $block_id }-&gt;(
          $f-&gt;pop( $block_size[ $block_id ] )
      );
  }
  </code></pre>
  
  <p>My of binary_file_buffer class definition/declaration looks like this</p>
  
  <pre><code>use MooseX::Declare;
  class binary_file_buffer {
      use FileHandle;
      use Carp;
  
      has _file      =&gt; ( is =&gt; 'ro', isa =&gt; 'FileHandle' );
      has _file_name =&gt; ( is =&gt; 'ro', isa =&gt; 'Str' );
      has _buff      =&gt; ( is =&gt; 'rw', isa =&gt; 'Str',  default =&gt; '' );
  
      method BUILDARGS ( Str $file_name ) {
        my $file = FileHandle-&gt;new( $file_name );
        carp "unable to open $file_name : $!" unless defined $file;
        $file-&gt;binmode;
        return (
          _file_name =&gt; $file_name,
          _file      =&gt; $file,
        );
      }
  
      # get the next n bytes from the buffer.
      method pop ( Int $len ) {
          # ... Make sure there is data in _buff
          return substr( $self-&gt;{_buff}, 0, $len, '' );
      }
  
      # Look around inside the buffer without changing the location for pop
      method peek ( Int $offset, Int $len ) {
          # ... Make sure there is data in _buff
          return substr( $self-&gt;{_buff}, $offset, $len );
      }
  }
  </code></pre>
  
  <p>(There is buffer loading and managing code that I didn't include here. It is fairly straight forward.)</p>
  
  <p>The problem is, I use the keyword <code>method</code> in the <code>BUILDARGS</code> declaration.  So, MooseX::Declare expects a <code>binary_file_buffer</code> <em>object</em> as the first argument to <code>BUILDARGS</code>.  But <code>BUILDARGS</code> gets the arguments passed to new, so the first argument is the <em>string</em> a <code>'binary_file_buffer'</code>, the name of the package. As a result it fails the type checking and dies when creating an object using new, like I did in the first code snippet.  (At least that's my understanding of what is happening.)</p>
  
  <p>The error message I get is:</p>
  
  <pre><code>Validation failed for 'MooseX::Types::Structured::Tuple[MooseX::Types::Structured::Tuple[Object,Str,Bool],MooseX::Types::Structured::Dict[]]' failed with value [ [ "binary_file_buffer", "drap_iono_t1.log", 0 ], {  } ], Internal Validation Error is: Validation failed for 'MooseX::Types::Structured::Tuple[Object,Str,Bool]' failed with value [ "binary_file_buffer", "drap_iono_t1.log", 0 ] at C:/bin/perl/site/lib/MooseX/Method/Signatures/Meta/Method.pm line 445
   MooseX::Method::Signatures::Meta::Method::validate('MooseX::Method::Signatures::Meta::Method=HASH(0x2a623b4)', 'ARRAY(0x2a62764)') called at C:/bin/perl/site/lib/MooseX/Method/Signatures/Meta/Method.pm line 145
   binary_file_buffer::BUILDARGS('binary_file_buffer', 'drap_iono_t1.log') called at generated method (unknown origin) line 5
   binary_file_buffer::new('binary_file_buffer', 'drap_iono_t1.log') called at logshred.pl line 13
  </code></pre>
  
  <p>I like the type checking sugar the <code>method</code> keyword supplies for $file_name, but I don't know how to get it since <code>BUILDARGS</code> isn't technically a method.</p>
  
  <p>Does MooseX::Declare have a way to skip the <code>$self</code> creation, or something like that?</p>
  
  <p>Am I doing this the proper MooseX::Declare way?  Or am I missing something?</p>