Skip Menu |

This queue is for tickets about the Hash-AutoHash CPAN distribution.

Report information
The Basics
Id: 51437
Status: open
Priority: 0/
Queue: Hash-AutoHash

People
Owner: NATG [...] cpan.org
Requestors: icestar [...] inbox.ru
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: throw exceptions when accessors for non-existent keys are called
Hello! Thank you for your excellent module, this is almost what I needed. But what do you think about creating another type of objects which will throw exceptions when accessors for non-existent keys are called?
RT-Send-CC: natg [...] shore.net
That's an interesting idea. I don't quite understand how you want it to work. I'm guessing you want keys to come into existence when they're set. So, this would work: $autohash->new_key('new_value'); print $autohash->new_key; while this would throw an exception: print $autohash->nonexistent_key; This is easy enough to do (although I would need to think about providing this feature cleanly to other subclasses in the series). Any suggestions for what the new class should be called? Thanks, Nat
Show quoted text
> I'm guessing you want keys to come into existence when they're
set. Yes, absolutely right. Maybe a new class isn't needed here, I think you should know better. This feature can be used when you want to make an unnamed object with accessors from existing hash. And in this case, if you make a simple mistake in accessor name, you will get a run time exception immediately. This helps you to find a mistake shortly in opposite using a hash.
RT-Send-CC: natg [...] shore.net
Sorry, it's taken me a while to get back to you. For some reason, I'm not receiving the emails and only see them when I log in... Okay, so it sounds like what you want is something closer to a "locked hash". You want to be able to control which keys are legal so that typing mistakes are caught quickly. 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
On Sat Nov 28 19:14:40 2009, NATG wrote: Show quoted text
> ... > > 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. Show quoted text
> > 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 :)
Subject: Re: [rt.cpan.org #51437] throw exceptions when accessors for non-existent keys are called
Date: Tue, 1 Dec 2009 04:12:37 -0800
To: bug-Hash-AutoHash [...] rt.cpan.org
From: "Nathan (Nat) Goodman" <ngoodman [...] systemsbiology.org>
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 :) >
Subject: Re: [rt.cpan.org #51437] throw exceptions when accessors for non-existent keys are called
Date: Thu, 03 Dec 2009 12:45:45 +0300
To: bug-Hash-AutoHash [...] rt.cpan.org
From: Dmitry Bigunyak <icestar [...] inbox.ru>
Thanks for your suggestion I'll consider it. Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=51437 > > > 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: > >
>> 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 :) >> >>
-- Dima: Nosce te ipsum e-mail: icestar@inbox.ru