Pixie::Complicity

Pixie::Complicity is a Perl module for making things play well with pixie.
Download

Pixie::Complicity Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • James A Duncan
  • Publisher web site:
  • http://search.cpan.org/~jduncan/Pixie-2.06/lib/Pixie/Complicity.pm

Pixie::Complicity Tags


Pixie::Complicity Description

Pixie::Complicity is a Perl module for making things play well with pixie. Pixie::Complicity is a Perl module for making things play well with pixie.RationaleFor many objects, Pixie can and does store the object transparently with no assistance from the object's class. However, sometimes that's just not the case; most commonly in the case of classes that are implemented using XS, and which store their data off in some C structure that's inaccessible from Perl. Getting at such information without the complicity of the class in question would require Pixie to be, near as dammit, telepathic. And that's not going to happen any time soon.So, we provide a set of methods in UNIVERSAL, which are used by Pixie in the process of storing and fetching objects. All you have to do is override a few of them in the class in question. (Remember, even if you're using a class from CPAN, the class's symbol table is always open, so you can cheat and add the helper methods anyway, we've chosen a method namespace (all methods begin with px_) which we hope doesn't clash with any classes that are out there, in the wild.ExampleConsider the Set::Object class. It's a very lovely class, implementing a delightfully fast set, with all the set operations you'd expect. However, in order to get the speed, it's been implemented using XS, and the Data::Dumper visible part of it is simply a scalar reference. So, if we want to use Set::Object in our project (and we do), we need to make it complicit with Pixie.So, first we make sure that Pixie knows it's storable: sub Set::Object::px_is_storable { 1 }Then we think about how we're going to render the thing storable. The only important thing about a set, for our purposes, is the list of its members (and what do you know, Set::Object provides a members method to get at that). We'll press the 'memento' pattern into use. The idea is that we create a memento object which will store enough information about an object for that object to be recreated later. We set up Set::Object's px_freeze method to create that memento: sub Set::Object::px_freeze { my $self = shift; return bless , 'Memento::Set::Object'; }Easy. For our next trick, we need to provide some way for a memento to be turned back into an object. Pixie guarantees to call px_thaw on every object that it retrieves from the data store, so, all we have to do is implement an appropriate px_thaw method in the memento class. sub Memento::Set::Object::px_thaw { my $self = shift; return Set::Object->new(@$self); }And, as if by magic, Set::Objects can now be happily persisted within your Pixie. Requirements: · Perl


Pixie::Complicity Related Software