package Data::MultiValued::UglySerializationHelperRole;
use Moose::Role;
use namespace::autoclean;
sub new_in_place {
my ($class,$hash) = @_;
my $self = bless $hash,$class;
for my $attr ($class->meta->get_all_attributes) {
if ($attr->does('Data::MultiValued::AttributeTrait')) {
$attr->_rebless_slot($self);
}
}
return $self;
}
sub as_hash {
my ($self) = @_;
my %ret = %$self;
for my $attr ($self->meta->get_all_attributes) {
if ($attr->does('Data::MultiValued::AttributeTrait')) {
my $st = $attr->_as_hash($self);
if ($st) {
$ret{$attr->full_storage_slot} = $st;
}
else {
delete $ret{$attr->full_storage_slot};
}
}
}
return \%ret;
}
1;