package EvilHash; use overload '%{}' => \&conditional_reference; sub conditional_reference { my @call = caller(1); if ( @call && $call[3] eq '(eval)' ) { die 'no testing'; } return { a => 1 }; } sub new { bless [], shift } package main; my $evil_hash = EvilHash->new(); ok( ref $evil_hash, '$evil_hash is a reference' ); is( reftype $evil_hash, reftype [], '$evil_hash is an array reference' ); # Useless use of a variable in void context ok( ! eval { %{$evil_hash}; 1 }, '$evil_hash will not be dereferenced inside eval' ); ok( scalar %{$evil_hash}, '$evil_hash allows dereference ouside eval' );