Mercurial > pub > Impl
comparison lib/IMPL/ORM/Entity.pm @ 407:c6e90e02dd17 ref20150831
renamed Lib->lib
| author | cin |
|---|---|
| date | Fri, 04 Sep 2015 19:40:23 +0300 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 406:f23fcb19d3c1 | 407:c6e90e02dd17 |
|---|---|
| 1 package IMPL::ORM::Entity; | |
| 2 use strict; | |
| 3 use warnings; | |
| 4 | |
| 5 use parent qw(IMPL::Object); | |
| 6 use IMPL::Class::Property; | |
| 7 | |
| 8 BEGIN { | |
| 9 public _direct property Name => prop_get; | |
| 10 public _direct property Class => prop_get; | |
| 11 public _direct property Values => prop_get; | |
| 12 public _direct property Schema => prop_get; | |
| 13 } | |
| 14 | |
| 15 sub CTOR { | |
| 16 my ($this,$class,$schema) = @_; | |
| 17 | |
| 18 $this->{$Class} = $class; | |
| 19 (my $name = $class) =~ s/::/_/g; | |
| 20 $this->{$Name} = $name; | |
| 21 $this->Schema = $schema; | |
| 22 $this->{$Values} = { | |
| 23 map {$_->{name},{type => $_->{type}, virtual => $_->{virtual}}} @$schema | |
| 24 }; | |
| 25 } | |
| 26 | |
| 27 sub Store; | |
| 28 *Store = \&dbgStore; | |
| 29 | |
| 30 sub dbgStore { | |
| 31 my ($this,$prop,$value) = @_; | |
| 32 | |
| 33 if ( my $container = $this->{$Values}{$prop} ) { | |
| 34 $container->{oldValue} = $container->{value}; | |
| 35 $container->{value} = $value; | |
| 36 } else { | |
| 37 die new IMPL::InvalidOperationException("Property not found",$this->Name,$prop); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 sub Get { | |
| 42 my ($this,$prop) = @_; | |
| 43 | |
| 44 return $this->{$Values}{$prop}{value}; | |
| 45 } | |
| 46 | |
| 47 1; |
