view Lib/IMPL/ORM/Entity.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents 4267a2ac3d46
children 4ddb27ff4a0b
line wrap: on
line source

package IMPL::ORM::Entity;
use strict;
use warnings;

use parent qw(IMPL::Object);
use IMPL::Class::Property;
use IMPL::Class::Property::Direct;

BEGIN {
    public _direct property Name => prop_get;
    public _direct property Class => prop_get;
    public _direct property Values => prop_get;
    public _direct property Schema => prop_get;
}

sub CTOR {
    my ($this,$class,$schema) = @_;
    
    $this->{$Class} = $class;
    (my $name = $class) =~ s/::/_/g;
    $this->{$Name} = $name;
    $this->Schema = $schema;
    $this->{$Values} = {
        map {$_->{name},{type => $_->{type}, virtual => $_->{virtual}}} @$schema
    };
}

sub Store;
*Store = \&dbgStore;

sub dbgStore {
    my ($this,$prop,$value) = @_;
    
    if ( my $container = $this->{$Values}{$prop} ) {
        $container->{oldValue} = $container->{value};
        $container->{value} = $value;
    } else {
        die new IMPL::InvalidOperationException("Property not found",$this->Name,$prop);
    }
}

sub Get {
    my ($this,$prop) = @_;
    
    return $this->{$Values}{$prop}{value};
}

1;