I'm working on yet another object persistence tool, called Pixie (blame Leon Brocard for the name, not me). One of the goals of the pixie project is to make things as simple as possible for the user (but, of course, no simpler). Amongst other things this means we want to supply simple locking.
The idea is that, if you're using a locking pixie, then fetching an object from the store will automatically grab a lock on it. That lock needs to be released at DESTROY time. This level of locking is, of course, simplistic, but it ensures that there should never be two 'active' copies of an object in play, which is generally a good thing.
So, how to handle releasing stuff at DESTROY time?
With a hash based object, things are relatively simple:
So, when the fetched object goes out of scope, so does the Pixie::ObjectInfo it contains, which handles unlocking the object in the database (along with any other cleanup that pixie needs to do). Which is rather cute, though I do say so myself. Note that the above code is rather simplified compared to what's actually in Pixie.package Pixie::ObjectInfo; ... sub DESTROY { ... $self->store->unlock($self); } package Pixie; sub get { my $self = shift; my $object_id = shift; my $obj = $self->really_get($object_id); $obj->{__Pixie} = Pixie::ObjectInfo->new(oid => $object_id); }
So, what happens when the class is a blessed arrayref? If we could rely on all pixie client classes to use fixed length arrays then it'd be a doddle, we could just do
But that means we have to assume that the array length is fixed and that the class's implementation will never use negative indices into the array.$obj->[@$obj] = Pixie::Object::Info->new
This seems to be a little to sweeping as assumptions go... There's always the trick of blessing the thing into a new 'pseudo anonymous' class and hanging the behaviour on there, but it's not exactly pretty.
So, what do you think? I'm especially interested in hearing from people who've actually used array based classes in anger. Do you use fixed length arrays? negative indices? Is there a major CPAN class that breaks either of these assumptions?
In reply to Are array based objects fixed length? by pdcawley
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |