MooseX::Attribute::Deflator::Meta::Role::Attribute - Attribute meta role to support deflation
version 2.1.8
package Test; use Moose; use DateTime; use MooseX::Attribute::Deflator; deflate 'DateTime', via { $_->epoch }; inflate 'DateTime', via { DateTime->from_epoch( epoch => $_ ) }; no MooseX::Attribute::Deflator; has now => ( is => 'rw', isa => 'DateTime', required => 1, default => sub { DateTime->now }, traits => ['Deflator'] ); package main; my $obj = Test->new; my $attr = $obj->meta->get_attribute('now'); my $deflated = $attr->deflate($obj); # $deflated is now a number my inflated = $attr->inflate($obj, $deflated); # $inflated is now a DateTime object
These two methods work basically the same. They look up the type constraint which is associated with the attribute and try to find an appropriate deflator/inflator. If there is no deflator/inflator for the exact type constraint, the method will bubble up the type constraint hierarchy until it finds one.
Returns the deflated value of the attribute. It does not change the value of the attribute.
Inflates a string $string. This method does not set the value of the attribute to the inflated value.
$string
Moritz Onken
This software is Copyright (c) 2011 by Moritz Onken.
This is free software, licensed under:
The (three-clause) BSD License
To install MooseX::Attribute::Deflator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MooseX::Attribute::Deflator
CPAN shell
perl -MCPAN -e shell install MooseX::Attribute::Deflator
For more information on module installation, please visit the detailed CPAN module installation guide.