title: Unless constructor argument passed is a hash type, croak on invalid arguments?
body: <p>I am vaguely confused a bit on different methods of passing certain arguments to the constructor type. I want to only pass a hash reference <code>\%hash</code>, or a list <code>foo =&gt; 1, bar =&gt; 1</code> but not both and <code>croak</code> if anything else is passed i.e <code>( single elements, array reference )</code>.</p>
  
  <p>For example, I pass my reference or list.. <code>(This works for the way I do this)</code> </p>
  
  <pre><code>my $obj = foo-&gt;new;
  my $data = $obj-&gt;dump( \%hash );
  my $data = $obj-&gt;dump( foo =&gt; 1, bar =&gt; 1 );
  </code></pre>
  
  <p>or</p>
  
  <pre><code>my $obj = foo-&gt;dump( \%hash );
  my $obj = foo-&gt;dump( foo =&gt; 1, bar =&gt; 1 );
  </code></pre>
  
  <p>Package module:</p>
  
  <pre><code>package foo;
  
  use strict;
  use Carp;
  
  use Scalar::Util qw/reftype/;
  
  sub new { return bless {}, shift }
  
  sub dump {
     my $class = shift;
     my $self  = shift;
     unless ( reftype( $self ) eq reftype {} ) {
           croak("Constructor method not a hash type!");
     }
  }
  
  1;
  </code></pre>
  
  <p>I've also thought about using the conditional operator <code>? :</code> here, but I can't get it to error properly.</p>
  
  <pre><code>my $self  = reftype($_[0]) eq reftype {} ? shift : {@_};
  </code></pre>
  
  <p>Is there a better preferred way to do this?</p>