annotate lib/IMPL/ORM/Entity.pm @ 412:30e8c6a74937 ref20150831

working on di container (role based registrations)
author cin
date Mon, 21 Sep 2015 19:54:10 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::ORM::Entity;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use parent qw(IMPL::Object);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Class::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 BEGIN {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 public _direct property Name => prop_get;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 public _direct property Class => prop_get;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 public _direct property Values => prop_get;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 public _direct property Schema => prop_get;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 my ($this,$class,$schema) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 $this->{$Class} = $class;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 (my $name = $class) =~ s/::/_/g;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 $this->{$Name} = $name;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 $this->Schema = $schema;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 $this->{$Values} = {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 map {$_->{name},{type => $_->{type}, virtual => $_->{virtual}}} @$schema
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 sub Store;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 *Store = \&dbgStore;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 sub dbgStore {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31 my ($this,$prop,$value) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 if ( my $container = $this->{$Values}{$prop} ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 $container->{oldValue} = $container->{value};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 $container->{value} = $value;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 die new IMPL::InvalidOperationException("Property not found",$this->Name,$prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 sub Get {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 my ($this,$prop) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 return $this->{$Values}{$prop}{value};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 1;