summaryrefslogtreecommitdiff
path: root/Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm
diff options
context:
space:
mode:
Diffstat (limited to 'Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm')
-rw-r--r--Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm35
1 files changed, 35 insertions, 0 deletions
diff --git a/Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm b/Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm
new file mode 100644
index 0000000..e586dec
--- /dev/null
+++ b/Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm
@@ -0,0 +1,35 @@
+package Data::MultiValued::UglySerializationHelperRole;
+use Moose::Role;
+
+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;