NAME
DustyDB::Serialized - translate complex data into serial form for storage
VERSION
version 0.02
SYNOPSIS
package BlogPost;
use Moose;
use DateTime;
with 'DustyDB::Record';
has slug => ( is => 'rw', isa => 'Str', traits => [ 'DustyDB::Key' ] );
has title => ( is => 'rw', isa => 'Str' );
has body => ( is => 'rw', isa => 'Str' );
has posted_on => (
is => 'rw',
isa => 'DateTime',
traits => [ 'DustyDB::Filter' ],
encode => sub { $_->iso8601 },
decode => sub { DateTime::Format::ISO8601->parse_datetime($_) },
);
DESCRIPTION
This provides your class with the ability to use a customized serialization scheme in the database. In case you have some data in your model that doesn't store well as is, you can use this to encode the data for storage and decode it later when loading.
ATTRIBUTES
encode
This is a subroutine used to transform a Perl object into a something else you want to store. Since we use DBM::Deep to store the objects, this can be much more flexible than just a scalar.
This subroutine should expect the decoded value in $_
and return whatever value should be stored.
decode
This is a subroutine used to transform the previously encoded and stored "thing" into the object that is stored in the column.
This subroutine should expect the encoded value in $_
and return whatever value should be loaded into the model attribute.
METHODS
perform_encode
This is a helper method to make sure that encoding is performed properly.
perform_decode
This is a helper method to make sure that decoding is performed properly.