I have a Perl class which is a based on a blessed hashref ( https://github.com/kylemhall/Koha/blob/master/Koha/Object.pm )
This is a community based project, with many developers of varying skill.
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.
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}
I tried using:
use overload '%{}' => \&get_hashref;
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.
Is what I'm trying to accomplish even possible?