Subject: | Hash trait: Tied hashes become "untied" when using setter |
Hello
The following example shows the problem:
package HashTest;
use Mouse;
use Tie::IxHash;
use Test::Simple tests => 2;
has values => is => 'ro',
isa => 'HashRef',
traits => ['Hash'],
default => sub { tie my %e, 'Tie::IxHash'; \%e },
handles => {
set_value => 'set',
};
my $test = __PACKAGE__->new;
$test->values->{a} = 'a';
ok tied(%{$test->values}) =~ /Tie::IxHash/, 'HashRef is still tied after set directly'; # PASSES
$test->set_value('b' => 'b');
ok tied(%{$test->values}) =~ /Tie::IxHash/, 'HashRef is still tied after set via NativeTraits'; # FAILS
__END__
The second test is failing here, so I'm guessing somewhere in the setter either the hashref is getting
untied, or a new hashref is installed (seems the more likely).
I've tried this code with Moose and both tests pass, so it appears to be a quirk on the Mouse side.
Cheers!
$ perl -v
This is perl 5, version 14, subversion 0 (v5.14.0) built for i686-linux-thread-multi
$ uname -a
Linux rich-laptop 2.6.32-31-generic #61-Ubuntu SMP Fri Apr 8 18:24:35 UTC 2011 i686
GNU/Linux