Mercurial > pub > Impl
diff lib/IMPL/Object/PublicSerializable.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
author | cin |
---|---|
date | Fri, 04 Sep 2015 19:40:23 +0300 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/IMPL/Object/PublicSerializable.pm Fri Sep 04 19:40:23 2015 +0300 @@ -0,0 +1,38 @@ +package IMPL::Object::PublicSerializable; +use strict; + +use IMPL::Const qw(:access); + +sub restore { + my ($class,$data,$refSurrogate) = @_; + + if ($refSurrogate) { + $refSurrogate->callCTOR(@$data); + return $refSurrogate; + } else { + return $class->new(@$data); + } +} + +sub save { + my ($this,$ctx) = @_; + + my %seen; + + my $val; + + defined($val = $this->$_()) and $ctx->AddVar($_,$val) foreach + map $_->name,$this->GetMeta( + 'IMPL::Class::PropertyInfo', + sub { + $_->access == ACCESS_PUBLIC and + $_->getter and + $_->setter and + not $_->ownerSet and + not $seen{$_->name} ++ + }, + 1 + ); +} + +1;