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

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