Mercurial > pub > Impl
comparison Lib/IMPL/ORM/Schema.pm @ 30:dd4d72600c69
ORM in works
author | Sergey |
---|---|
date | Tue, 03 Nov 2009 16:31:47 +0300 |
parents | 6d33f75c6e1f |
children | d59526f6310e |
comparison
equal
deleted
inserted
replaced
29:37160f7c8edb | 30:dd4d72600c69 |
---|---|
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::DOM::Document); | 5 use base qw(IMPL::DOM::Document); |
6 use IMPL::Class::Property; | 6 use IMPL::Class::Property; |
7 require IMPL::ORM::Schema::Entity; | |
8 | |
9 our %CTOR = ( | |
10 'IMPL::DOM::Document' => sub { nodeName => 'Schema' } | |
11 ); | |
7 | 12 |
8 BEGIN { | 13 BEGIN { |
9 public property mapValueTypes => prop_get | owner_set; | 14 public property mapValueTypes => prop_get | owner_set; |
10 public property mapReferenceTypes => prop_get | owner_set; | 15 public property mapReferenceTypes => prop_get | owner_set; |
16 public property mapPending => prop_get | owner_set; | |
17 public property prefix => prop_all; | |
11 } | 18 } |
12 | 19 |
13 sub CTOR { | 20 sub CTOR { |
14 my ($this ) = @_; | 21 my ($this ) = @_; |
15 $this->mapValueTypes({}); | 22 $this->mapValueTypes({}); |
16 $this->mapReferenceTypes({}); | 23 $this->mapReferenceTypes({}); |
24 $this->mapPending({}); | |
17 } | 25 } |
18 | 26 |
19 # return an entity for the specified typename | 27 # return an entity for the specified typename |
20 # makes forward declaration if nesessary | 28 # makes forward declaration if nesessary |
21 sub resolveType { | 29 sub resolveType { |
30 } else { | 38 } else { |
31 return undef; | 39 return undef; |
32 } | 40 } |
33 } | 41 } |
34 | 42 |
43 sub declareReferenceType { | |
44 my ($this,$typeName) = @_; | |
45 | |
46 my $entity = new IMPL::ORM::Schema::Entity($typeName); | |
47 | |
48 $this->mapPending->{$typeName} = $entity; | |
49 | |
50 return $this->mapReferenceTypes->{$typeName} = $entity; | |
51 } | |
52 | |
53 sub _addReferenceType { | |
54 my ($this,$className) = @_; | |
55 | |
56 $this->mapReferenceTypes->{$className} = $className->ormGetSchema($this,delete $this->mapPending->{$className}); | |
57 } | |
58 | |
35 # returns valuetype name | 59 # returns valuetype name |
36 sub isValueType { | 60 sub isValueType { |
37 my ($this,$typeName) = @_; | 61 my ($this,$typeName) = @_; |
38 | 62 |
39 $this = ref $this ? $this : $this->instance; | 63 $this = ref $this ? $this : $this->instance; |
46 my ($class) = @_; | 70 my ($class) = @_; |
47 | 71 |
48 return ($instances{$class} || ($instances{$class} = $class->new)); | 72 return ($instances{$class} || ($instances{$class} = $class->new)); |
49 } | 73 } |
50 | 74 |
75 sub ValueTypes { | |
76 my ($this,%classes) = @_; | |
77 | |
78 $this = ref $this ? $this : $this->instance; | |
79 | |
80 $this->mapValueTypes->{$_} = $classes{$_} foreach keys %classes; | |
81 } | |
82 | |
83 sub Classes { | |
84 my ($this,@classNames) = @_; | |
85 | |
86 $this = ref $this ? $this : $this->instance; | |
87 | |
88 $this->_addReferenceType($this->prefix . $_) foreach @classNames; | |
89 } | |
90 | |
91 sub usePrefix { | |
92 my ($this,$prefix) = @_; | |
93 | |
94 (ref $this ? $this : $this->instance)->prefix($prefix); | |
95 } | |
96 | |
51 1; | 97 1; |
52 | 98 |
53 __END__ | 99 __END__ |
54 | 100 |
55 =pod | 101 =pod |