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.