comparison Lib/IMPL/ORM/Schema.pm @ 28:6d33f75c6e1f

ORM in works
author Sergey
date Mon, 19 Oct 2009 04:13:54 +0400
parents
children dd4d72600c69
comparison
equal deleted inserted replaced
27:b544a772b654 28:6d33f75c6e1f
1 package IMPL::ORM::Schema;
2 use strict;
3 use warnings;
4
5 use base qw(IMPL::DOM::Document);
6 use IMPL::Class::Property;
7
8 BEGIN {
9 public property mapValueTypes => prop_get | owner_set;
10 public property mapReferenceTypes => prop_get | owner_set;
11 }
12
13 sub CTOR {
14 my ($this ) = @_;
15 $this->mapValueTypes({});
16 $this->mapReferenceTypes({});
17 }
18
19 # return an entity for the specified typename
20 # makes forward declaration if nesessary
21 sub resolveType {
22 my ($this,$typeName) = @_;
23
24 $this = ref $this ? $this : $this->instance;
25
26 if (my $entity = $this->mapReferenceTypes->{$typeName}) {
27 return $entity;
28 } elsif (UNIVERSAL::isa($typeName,'IMPL::ORM::Object')) {
29 return $this->declareReferenceType($typeName);
30 } else {
31 return undef;
32 }
33 }
34
35 # returns valuetype name
36 sub isValueType {
37 my ($this,$typeName) = @_;
38
39 $this = ref $this ? $this : $this->instance;
40
41 return $this->mapValueTypes->{$typeName};
42 }
43
44 my %instances;
45 sub instance {
46 my ($class) = @_;
47
48 return ($instances{$class} || ($instances{$class} = $class->new));
49 }
50
51 1;
52
53 __END__
54
55 =pod
56
57 =head1 DESCRIPTION
58
59 Схема данных, представляет собой DOM документ, элементами которой
60 являются сущности.
61
62 Каждый узел - это описание сущности.
63
64 =cut