title: How can I stop or allow a perl object to be used as a hashref?
body: <p>I have a Perl class which is a based on a blessed hashref ( <a href="https://github.com/kylemhall/Koha/blob/master/Koha/Object.pm" rel="nofollow">https://github.com/kylemhall/Koha/blob/master/Koha/Object.pm</a> )</p>
  
  <p>This is a community based project, with many developers of varying skill.</p>
  
  <p>What I've seen is some developers accidentally using our objects as hashrefs. The actual data is not stored in the blessed hashref, but in a dbic object that is stored in the hashref ( in $self->{_result} ). When the dev tries something like $object->{id} perl doesn't complain, it just returns undef, as would be expected.</p>
  
  <p>What I'd like to do is to either
  A) Make the script explode with an error when this happens
  B) Allow the use of the hashref syntax for setting / getting values in the dbic objects stored in $self->{_result}</p>
  
  <p>I tried using:</p>
  
  <pre><code>use overload '%{}' =&gt; \&amp;get_hashref;
  </code></pre>
  
  <p>but when I do this, get_hashref is called any time a regular method is called! This makes sense in a way, since the object itself is a hashref. I'm sure this has something to do with the Perl internals for blessed hashrefs as objects.</p>
  
  <p>Is what I'm trying to accomplish even possible?</p>