I agree this is a good idea. I'll see if I can get to it in the next
week or so.
In the meantime, you may be able to accomplish what you need using
'lock_keys' and related functions in Hash::Util. The following sort
of thing should work:
use Hash::AutoHash;
use Hash::Util qw(lock_keys);
$ah=new Hash::AutoHash abc=>123, def=>456;
lock_keys(%$ah); # note the leading '%'
on '%$ah'
print $ah->ghi; # throws exception
print $ah->jkl(789); # throws exception
This works when the underlying hash is real, but not if it's tied.
So, it will not work on the various subclasses of Hash::AutoHash like
Hash::AutoHash::MultiValued.
Best,
Nat
On Nov 30, 2009, at 7:13 AM, Dmitry Bigunyak via RT wrote:
Show quoted text> Queue: Hash-AutoHash
> Ticket <URL:
https://rt.cpan.org/Ticket/Display.html?id=51437 >
>
> On Sat Nov 28 19:14:40 2009, NATG wrote:
>> ...
>>
>> It could work like this:
>>
>> $autohash=new Hash::AutoHash::Locked key1=>value1, key2=>value2, ...
>>
>> Thereafter, the only legal keys would be the ones listed above.
>> There
>> would also be an explicit way to add new keys or unlock the whole
> thing.
>>
>> Is this closer to what you have in mind?
>>
>> Best,
>> Nat
>
>
> Yes, this is exactly what I'm talking about! :)
> In addition, can be a procedure for example autohash_locked_hash to
> write
>
> use Hash::AutoHash qw(autohash_locked_hash);
>
> I don't know, maybe this feature is interesting only for me, but
> anyway
> it will be another good use case for your module :)
>