Summary
Implement restricted hashes for Hash::Util::lock_keys (and the corresponding
query/unlock operations). PerlOnJava currently registers lock_keys but
returns without changing the hash, on both the JVM and interpreter backends.
Expected Perl behaviour
use Hash::Util qw(lock_keys);
my %hash = (foo => undef);
lock_keys(%hash);
eval { my $value = $hash{bar} };
print $@;
On standard Perl, the access dies with:
Attempt to access disallowed key 'bar' in a restricted hash
Internals::SvREADONLY(%hash) is true after lock_keys, and permitted keys
can be inspected with Hash::Util::legal_keys.
Actual PerlOnJava behaviour
The same program succeeds with no exception on both backends. The hash is not
marked readonly/restricted and its key set is not enforced.
The current Java implementation labels lock_keys and unlock_keys as
placeholder implementations. This also explains the existing feature-matrix
entry that marks restricted hashes unsupported.
CPAN evidence
Types::ReadOnly 0.003 failed in CPAN tester run 20260827-171032-2227.
Its Locked[...] constraints use Hash::Util::lock_keys plus
Internals::SvREADONLY to recognize restricted hash references. The affected
tests were t/03locked.t, t/10combinations.t, t/20moo.t, t/30moose.t,
and t/50typeparams.t: 13 of 60 subtests failed across 5 of 8 test programs.
Ecosystem impact
MetaCPAN reports 79 unique Hash::Util reverse-dependant distributions, 12
updated in the preceding 12 months. That total covers all Hash::Util APIs,
not only restricted hashes. Inspection of five representative dependants found
active lock_keys use in:
DBIx-DataModel runtime schema metadata, to prevent typo-created keys.
Net-Amazon-S3 shipped API/client parameter-validation helpers.
CPAN-Testers-ParseReport option-parsing utility.
The same sample found only non-restricted APIs in Sereal-Encoder
(num_buckets test) and Function-Parameters (fieldhash test).
Suggested acceptance coverage
- Lock an existing hash and reject reads, writes, and deletes for disallowed
keys using Perl-compatible diagnostics.
- Support explicitly declared allowed-but-absent keys.
- Make
legal_keys report the declared key set.
- Verify
unlock_keys restores ordinary hash behaviour.
- Ensure
Internals::SvREADONLY reports the restricted-hash state expected by
Type::Tiny/Types::ReadOnly.
- Exercise equivalent behavior on the JVM and interpreter backends.
Summary
Implement restricted hashes for
Hash::Util::lock_keys(and the correspondingquery/unlock operations). PerlOnJava currently registers
lock_keysbutreturns without changing the hash, on both the JVM and interpreter backends.
Expected Perl behaviour
On standard Perl, the access dies with:
Internals::SvREADONLY(%hash)is true afterlock_keys, and permitted keyscan be inspected with
Hash::Util::legal_keys.Actual PerlOnJava behaviour
The same program succeeds with no exception on both backends. The hash is not
marked readonly/restricted and its key set is not enforced.
The current Java implementation labels
lock_keysandunlock_keysasplaceholder implementations. This also explains the existing feature-matrix
entry that marks restricted hashes unsupported.
CPAN evidence
Types::ReadOnly0.003 failed in CPAN tester run20260827-171032-2227.Its
Locked[...]constraints useHash::Util::lock_keysplusInternals::SvREADONLYto recognize restricted hash references. The affectedtests were
t/03locked.t,t/10combinations.t,t/20moo.t,t/30moose.t,and
t/50typeparams.t: 13 of 60 subtests failed across 5 of 8 test programs.Ecosystem impact
MetaCPAN reports 79 unique
Hash::Utilreverse-dependant distributions, 12updated in the preceding 12 months. That total covers all
Hash::UtilAPIs,not only restricted hashes. Inspection of five representative dependants found
active
lock_keysuse in:DBIx-DataModelruntime schema metadata, to prevent typo-created keys.Net-Amazon-S3shipped API/client parameter-validation helpers.CPAN-Testers-ParseReportoption-parsing utility.The same sample found only non-restricted APIs in
Sereal-Encoder(
num_bucketstest) andFunction-Parameters(fieldhashtest).Suggested acceptance coverage
keys using Perl-compatible diagnostics.
legal_keysreport the declared key set.unlock_keysrestores ordinary hash behaviour.Internals::SvREADONLYreports the restricted-hash state expected byType::Tiny/Types::ReadOnly.