RE: [code-review] Tie::Hash::Expire [OT]
"Hodges, Paul" <Paul.Hodges-ntWzkUHD06N8olp/[email protected]> Mon, 2 Feb 2004 10:44:39 -0600
| Newsgroups | gmane.comp.lang.perl.code-review-ladder |
|---|---|
| Message-ID | <2820B295B95836498EED98D7A065C4F104DBD504@bremocmg-55> |
Apologies: I forgot to remove my "request for clarification" once I = figured it out for myself. > -----Original Message----- > From: code-review-ladder-admin-wool9L35kiek0rBIEb6pKdBc4/[email protected] > [mailto:code-review-ladder-admin-wool9L35kiek0rBIEb6pKdBc4/[email protected]]On Behalf Of > Hodges, Paul > Sent: Monday, February 02, 2004 10:35 AM > To: Jeff Yoak; code-review-ladder-wool9L35kiek0rBIEb6pKdBc4/[email protected] > Subject: RE: [code-review] Tie::Hash::Expire >=20 >=20 > > Yesterday I uploaded the first version of my first CPAN module,=20 > > Tie::Hash::Expire, a package providing hash keys that expire=20 > > and cease to exist after a user-set period. I would be much > > obliged if anyone here would take a look. >=20 > A couple of comments, including a request for clarification=20 > -- and Japhy, welcome aboard. :) >=20 > 1) My first thought was "Why not use an alarm?" After I=20 > thought about it a little, I wanted to pat you on the back=20 > for not falling into that trap. :) >=20 > 2) I agree with a previous post: the default behavior should=20 > be that without an expiration period, keys should not expire. >=20 > 3) I'd tend to use a more oo-ish approach, and put the data=20 > in a normal hash. For example > $my_tied_hash{foo} =3D 1; # $internal_hash_entry{foo} =3D {=20 > _data=3D>1, _expires=3D>time() }; > or more likely > $my_tied_hash{foo} =3D 1; # $internal_hash_entry{foo} =3D [=20 > 1, time() ]; >=20 > 4) I'd also recommend a custom timing function: > $tied_hash->set(foo =3D> 17); # THIS entry expires in 17 seconds. > which might be implemented more as > $tied_hash->set(foo =3D> 17); # $internal_hash_entry{foo} =3D=20 > [ 1, time(), 17 ]; > leaving other entries as > $my_tied_hash{foo} =3D 1; # $internal_hash_entry{foo} =3D [=20 > 1, time(), $default ]; >=20 > Depending on how elaborate you wanted to get, you might even=20 > add some convenience shortcuts: >=20 > use Tie::Hash::Expire default =3D> 10, shortcuts =3D> 'all',=20 > reqs =3D> [ qw( Time::HiRes ) ]; > $h =3D tie %h, Tie::Hash::Expire; >=20 > $h{foo} =3D 1; # expires in the default 10 seconds; > $h->set(bar =3D> 17); # expires in 17 seconds > # for the precise-minded: expires in 02:13:41.11 > $h->set(baz =3D>=20 > hours(2)+minutes(13)+seconds(41)+fracsec(.11) ); # or somesuch >=20 > You might even include days, weeks, months, etc. That may=20 > work better with the Exporter, but I like the idea of being=20 > able to set the expiration default in the use() statement.=20 >=20 > Obviously, I'm just tossing out ideas. Caveat auditor. :) >=20 > Paul >=20 >=20 >=20 > ***** > "The information transmitted is intended only for the person=20 > or entity to which it is addressed and may contain=20 > confidential, proprietary, and/or privileged material. Any=20 > review, retransmission, dissemination or other use of, or=20 > taking of any action in reliance upon, this information by=20 > persons or entities other than the intended recipient is=20 > prohibited. If you received this in error, please contact=20 > the sender and delete the material from all computers." 113 >=20 >=20 > _______________________________________________ > code-review-ladder mailing list > code-review-ladder-wool9L35kiek0rBIEb6pKdBc4/[email protected] > http://lists.netthink.co.uk/listinfo/code-review-ladder >=20