Class::Std::Storable

Class::Std::Storable is a Perl module to support for creating serializable "inside-out" classes.
Download

Class::Std::Storable Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Luke Meyer
  • Publisher web site:
  • http://search.cpan.org/~lmeyer/Class-Std-Storable-v0.0.1/lib/Class/Std/Storable.pm

Class::Std::Storable Tags


Class::Std::Storable Description

Class::Std::Storable is a Perl module to support for creating serializable "inside-out" classes. Class::Std::Storable is a Perl module to support for creating serializable "inside-out" classes.SYNOPSISIn general, use this class exactly as you would Class::Std. package Ice::Cream; use Class::Std::Storable; { my %name_of :ATTR( :get :set ); my %flavor_of :ATTR( :get :set ); } package main; my $object = Ice::Cream->new; $object->set_name("Vanilla Bean"); $object->set_flavor("vanilla");But now, you may also serialize the object with Storable. use Storable; my $serialized = Storable::freeze($object); #store to a file, database, or wherever, and retrieve later. my $clone = Storable::thaw($serialized);Class::Std introduced the "inside-out" model for classes (perldoc Class::Std for details). Among its salient features is complete encapsulation; that is, an object's data may only be accessed via its methods, unlike the usual hashref model that permits direct access by any code whatsoever. However, the drawback of complete encapsulation is that normal mechanisms for serialization won't work, as they rely on direct access to an object's attributes.This class provides the class-building functionality from Class::Std, and in addition provides an interface to allow Storable to freeze and thaw any declared attributes of this class and any superclasses that were built via Class::Std::Storable.However, in order to let Storable save attributes and construct the object, it is necessary to expose the attributes of the class to the world. Thus, any code could use the same interface that Storable does to get a copy of object attributes and create new objects with arbitrary attributes without going through the constructor. While the interface CAN'T be used to replace the existing attributes of an object, it COULD be used to create an arbitrarily mutated clone of an object without going through its methods. Also, if attributes are themselves references, then the objects to which they refer can be obtained and modified.As true encapsulation is one of the major features of Class::Std, this would be a good reason NOT to use this class. But this sacrifice is required to provide serialization. You must choose which is more important for your purposes, serialization or complete encapsulation. Consider also that while bypassing the class methods is possible to a limited degree with Class::Std::Storable, doing so is much more complicated than just using the methods, so use of this class still discourages casual violations of encapsulation. Requirements: · Perl


Class::Std::Storable Related Software