package Test::HashK; use Moose; use Types::Standard qw( Dict Optional Int ); use Types::ReadOnly qw( Locked ); my $colour_hash = Locked[ Dict[ red => Optional[Int], blue => Optional[Int], green => Optional[Int], ], ]; has scores => ( is => 'rw', isa => $colour_hash, default => sub{ {} }, coerce => 1, ); __PACKAGE__->meta->make_immutable; package main; my $thk = Test::HashK->new(scores => { green => 0 }); $thk->scores->{red} = 2000; $thk->scores->{bloo} = 'tobyink'; # dies