You have two aspects here that I see. First is an API. Second is an implementation. This may not sound too useful as most modules have an API, and implement that API. However, I want to seperate these out because I think that once there is a set way of doing this, I can still imagine many people wanting to do it differently under the covers.

For example, you talk about GDBM. What if I don't have GDBM capabilities? Perhaps another implementation would use a directory passed in as part of the constructor to hold lock files. Or another would use DBI to store in a RDBMS. Or another would use shared memory. Which backend to use would be part of your constructor.

As for the API, I would suggest some minor changes:

new(driver => $driver, ...)
The parameters would first be which driver to use, which could default to your filesystem-based one. Other parameters would be passed in to that. Perhaps the string would be the name of the module, and that might be all relative to "Sub::Deferred", e.g., $driver as "Filesys" would actually load "Sub::Deferred::Filesys". If the object is a reference, assume it has already been initialised, and use it.
$lock = get_lock($key)
Returns a Sub::Deferred::Lock object. Does not set, reset, or anything else, for the lock. Just retrieves a handle.
list_keys()
Some way to list what locks are in use. The precise definition of this is somewhat ambiguous, though, since once a lock expires, it may get cleaned up. I suppose the caveat here is that just because it's in the list doesn't mean it's locked, and just because it's not in the list doesn't mean it has never been used.
$lock->set($span)
What is $span? Seconds? Milliseconds? Hours? Parsed somehow? Could you accept a DateTime object or something to specify the lock-until time instead? Or some other object(s) that specify a span of time?
$lock->is_locked()
Boolean methods/functions should start with "is" or something to show it's a boolean query function.
$lock->time_left()
Some way to query when the lock will be freed is probably nice. Should return 0 if the lock isn't set.
$lock->reset()
Immediately resets the lock to "unlocked". Trust me, it'll be handy ;->
Just my two cents.


In reply to Re: RFC: Time Lock Module Idea? by Tanktalus
in thread RFC: Time Lock Module Idea? by pileofrogs

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.