view Lib/IMPL/Object/PublicSerializable.pm @ 197:6b1dda998839

Added IMPL::declare, IMPL::require, to simplify module definitions IMPL::Transform now admires object inheritance while searching for the transformation Added HTTP some exceptions IMPL::Web::Application::RestResource almost implemented
author sergey
date Thu, 19 Apr 2012 02:10:02 +0400
parents 4d0e1962161c
children 4ddb27ff4a0b
line wrap: on
line source

package IMPL::Object::PublicSerializable;
use strict;

use IMPL::Class::Member;

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->get_meta(
            'IMPL::Class::PropertyInfo',
            sub {
                $_->Access == IMPL::Class::Member::MOD_PUBLIC and
                $_->canGet and
                not $_->ownerSet and
                not $seen{$_->Name} ++
            },
            1
        );
}

1;