annotate Lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 366:935629bf80df

model metadata, in progress
author cin
date Mon, 02 Dec 2013 17:44:38 +0400
parents 82b6c967bcf1
children 608e74bc309f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
1 package IMPL::Web::View::Metadata::BaseMeta;
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
2 use strict;
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
3
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
4 use IMPL::lang;
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
5 use IMPL::Const qw(:prop);
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
6 use IMPL::declare {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
7 require => {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
8 Exception => 'IMPL::Exception',
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
9 ArgException => '-IMPL::InvalidArgumentException'
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
10 },
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
11 base => [
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
12 'IMPL::Object' => undef
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
13 ],
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
14 props => [
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
15 model => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
16 modelType => PROP_RO,
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
17 holdingType => PROP_RO,
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
18 provider => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
19 name => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
20 label => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
21 container => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
22 template => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
23
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
24 _childMap => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
25 _childNames => PROP_RO
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
26 ]
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
27 };
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
28
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
29 sub CTOR {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
30 my ($this,$provider,$model,$type,$args) = @_;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
31
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
32 $type ||= typeof($model);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
33
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
34 die ArgException->new(provider => 'A provider must be specified');
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
35
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
36 $this->provider($provider);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
37 $this->model($model);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
38 $this->modelType($type);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
39 $this->childMap({});
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
40
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
41 #mixin other args
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
42 if ($args) {
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
43 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template holdingType);
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
44 }
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
45 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
46
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
47 sub GetProperty {
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
48 my ($this,$name) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
49
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
50 $this->_PopulateProperties()
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
51 unless $this->_childNames;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
52
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
53 return $this->_childMap->{$name};
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
54 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
55
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
56 sub GetProperties {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
57 my ($this) = @_;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
58
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
59 if ($this->_childNames) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
60 return [ map $this->_childMap->{$_}, @{$this->_childNames} ];
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
61 } else {
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
62 return $this->_PopulateProperties;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
63 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
64 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
65
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
66 sub _PopulateProperties {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
67 my ($this) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
68
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
69 my @childNames;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
70 my %childMap;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
71 my @result;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
72
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
73 foreach my $child (@{$this->provider->PopulateProperties($this)}) {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
74 $childMap{$child->name} = $child;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
75 push @childNames, $child->name;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
76 push @result, $child;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
77 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
78
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
79 $this->_childMap(\%childMap);
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
80 $this->_childNames(\@childNames);
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
81 return \@result;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
82 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
83
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
84 sub GetItems {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
85 my ($this) = @_;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
86
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
87 return $this->provider->GetItems($this);
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
88 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
89
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
90 sub GetItem {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
91 my ($this,$index) = @_;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
92
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
93 return $this->provider->GetItem($this,$index);
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
94 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
95
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
96 1;
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
97
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
98 __END__
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
99
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
100 =pod
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
101
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
102 =head1 NAME
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
103
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
104 =head1 SYNOPSIS
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
105
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
106 =head1 DESCRIPTION
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
107
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
108 Метаданные описывают модель, ее свойства, используются для построения
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
109 представления.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
110
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
111 =over
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
112
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
113 =item * type
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
114
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
115 Опционально. Тип модели. В случаях, когда модель не определена, данное свойство
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
116 позволяет определить ее тип.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
117
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
118 =item * label
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
119
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
120 Опционально. Имя модели для отображения.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
121
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
122 =item * template
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
123
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
124 Шаблон, который следует использовать для отображения модели.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
125
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
126 =item * fields
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
127
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
128 Коллекция с информацией по свойствам (полям) модели. Данный хеш используется
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
129 для определения представления при использовании C<display_for('field')>.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
130
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
131 =back
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
132
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
133 Метаданные публикуются провайдером, кроме того они могут быть расширены
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
134 дополнительными свойствами.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
135
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
136 =head1 MEMBERS
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
137
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
138 =head2 C<GetChild($name)>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
139
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
140 Возвращает метаданные для дочернего элемента, например свойства объекта
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
141
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
142 =head2 C<GetChildren()>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
143
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
144 Возвращает ссылку на массив с метаданными для дочерних элементов
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
145
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
146 =cut