in reply to RFC: Time Lock Module Idea?

Hi pileofrogs,

I like the idea, definitely. I get swamped with pages/error emails/you name it on occasion, and would love a good solution to that problem. I was actually a bit surprised I couldn't find anything on CPAN that already does this, so yes, please, build this *now* :)

As for the name, TimeLock doesn't really explain what it does. I'm not really good with names, but maybe something like "Sub::Deferred" would be clearer.

I feel your interface is too verbose, and interferes with the flow of the code. I would recommend an interface like Memoize, in that you "defer" a function or method somewhere at the top of your script, while the rest of your code stays as is:

use Sub::Deferred store => '/tmp/foo_timelock'; defer( 'page_me', 600 ); # ... if( something_really_bad() ) { my $message = "Something Really Bad just happened..."; page_me( $message ); # run only once every 600 seconds }

This way you could add it to existing scripts without having to go through a lot of code. And it's very easy to disable too.

It would probably be quite easy to decide to defer a subroutine based on its input parameters. Strategies and settings could be specified in the call to defer().

Replies are listed 'Best First'.
Re^2: RFC: Time Lock Module Idea?
by pileofrogs (Priest) on Mar 24, 2006 at 21:21 UTC

    I like the name idea, but I'm skeptical of the interface suggestions. The code would lose readability and my module would be a lot more complex. In Memoize, you don't lose readability because a memoize'd sub still does the same stuff regardless of weather it's cached or not. In this application the behavior is different. I can see a code maintainer going nuts because this thing only sends an email every 5 minutes, no matter what he does and he doesn't know why until he sees that defer() call at the top.

    If there's demand for it, though, I'd be happy to write it with both interfaces.

    Can you think of a way to make it more compact without losing readability?

    Anyone else have thoughts on that?

      So memoize your function next to its definition. It's generally the proper tool, just use it a sane way.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊