Re: [code-review] Hello!

Torsten Hofmann <Torsten.Hofmann-3fy81iOio07EklRYOP+eR4QuADTiUCJX@public.gmane.org> Mon, 02 Feb 2004 11:42:38 +0100
Newsgroups gmane.comp.lang.perl.code-review-ladder
Organization Friedrich-Alexander-Universitaet Erlangen/Nuernberg
Message-ID <[email protected]>
Jean-Michel Hiver wrote:
> Jeff Yoak wrote:
> 
>> At 03:50 AM 1/31/2004, Jean-Michel Hiver wrote:
>>> That's quite an fun / interesting module. It would be nice to allow 
>>> expiration times under one second when Time::HiRes is installed.
>>
>> Yes, I thought about that.  What is your suggestion about the best way 
>> to go about it?  I don't like requiring Time::HiRes.  It's not in the 
> 
> Something like this in your module would do:
> 
>    package Tie::Hash::Expire;
>    use strict;
>    use warnings;
>    use POSIX qw/ceil/;
>    use Carp;
> 
>    our $TIME_HIRES_INSTALLED = 0;
>    eval { "use Time::HiRes qw()" };
>    $TIME_HIRES_INSTALLED = 1 unless ($@);
> 
> Then if $TIME_HIRES_INSTALLED is equals to 1 you can use the functions 
> of Time::HiRes:: rather than the perl core functions.
> 
>    Time::HiRes::time()
>    Time::HiRes::sleep()
>    Time::HiRes::alarm()
>    etc. See perldoc Time::HiRes.
> 
> Well, that's how I'd do it anyway. I'm sure others on the list will 
> correct me if it's not optimal :)

Well, it's not optimal as it doesn't work ;-)

This should be

   our $TIME_HIRES_INSTALLED = 0;
   eval "use Time::HiRes qw()"; # string eval!!
   $TIME_HIRES_INSTALLED = 1 unless ($@);

Cheers,
Torsten