diff options
author | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 12:28:48 +0000 |
---|---|---|
committer | Gianni Ceccarelli <dakkar@thenautilus.net> | 2011-11-10 12:28:48 +0000 |
commit | 35889e01e09360ee274434d77f5f1024a537ed5d (patch) | |
tree | de99cf6fbdef2588e30c275f0d9ad1e2ff4f5d88 /Data-MultiValued/lib | |
parent | json-ify, works everywhere (diff) | |
download | data-multivalued-35889e01e09360ee274434d77f5f1024a537ed5d.tar.gz data-multivalued-35889e01e09360ee274434d77f5f1024a537ed5d.tar.bz2 data-multivalued-35889e01e09360ee274434d77f5f1024a537ed5d.zip |
ugly serialization helper role
no, I'm not changing the name, it's really an ugly thing
Diffstat (limited to 'Data-MultiValued/lib')
-rw-r--r-- | Data-MultiValued/lib/Data/MultiValued/UglySerializationHelperRole.pm | 35 |
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; |