| DustyDB documentation | Contained in the DustyDB distribution. |
DustyDB::Meta::Attribute - Moose meta-class for DustyDB::Record attributes
version 0.06
For any model class (one that uses DustyDB::Object and does DustyDB::Record), all the attributes will be given this Moose meta-class role. These attributes are used to help with encoding and decoding types that might not be easily stored directly within DBM::Deep.
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.
Be careful, though, not to store a hash with a class_name key or very bad things might happen.
This subroutine should expect the decoded value in $_ and return whatever value should be stored.
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.
This is a helper method to make sure that encoding is performed properly.
This is a helper method to make sure that decoding is performed properly.
| DustyDB documentation | Contained in the DustyDB distribution. |
package DustyDB::Meta::Attribute; our $VERSION = '0.06'; use Moose::Role; use Scalar::Util qw( blessed );
has encode => ( is => 'rw', isa => 'CodeRef', required => 1, default => sub { sub { $_ } }, );
has decode => ( is => 'rw', isa => 'CodeRef', required => 1, default => sub { sub { $_ } }, );
sub perform_encode { my ($attr, $value) = @_; local $_ = $value; return $attr->encode->($value); }
sub perform_decode { my ($attr, $value) = @_; local $_ = $value; return $attr->decode->($value); } 1;