annotate Lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 389:5aff94ba842f

DOM Schema refactoring complete
author cin
date Wed, 12 Feb 2014 13:36:24 +0400
parents 010ceafd0c5a
children
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',
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
9 ArgException => '-IMPL::InvalidArgumentException',
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
10 NotImplException => '-IMPL::NotImplementedException'
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
11 },
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
12 base => [
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
13 'IMPL::Object' => undef
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
14 ],
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
15 props => [
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
16 model => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
17 modelType => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
18 name => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
19 label => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
20 container => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
21 template => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
22
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
23 _childMap => PROP_RO,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
24 _childNames => PROP_RO
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
25 ]
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 sub CTOR {
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
29 my ($this,$model,$type,$args) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
30
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
31 $this->model($model);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
32 $this->modelType($type);
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
33 $this->_childMap({});
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
34
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
35 #mixin other args
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
36 if ($args) {
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
37 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template);
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
38 }
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
39 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
40
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
41 sub GetProperty {
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
42 my ($this,$name) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
43
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
44 $this->GetProperties()
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
45 unless $this->_childNames;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
46
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
47 return $this->_childMap->{$name};
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
48 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
49
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
50 sub GetProperties {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
51 my ($this) = @_;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
52
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
53 if ($this->_childNames) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
54 return [ map $this->_childMap->{$_}, @{$this->_childNames} ];
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
55 } else {
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
56 my @childNames;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
57 my %childMap;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
58 my @result;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
59
368
010ceafd0c5a form metadata + tests
cin
parents: 367
diff changeset
60 foreach my $child (@{$this->PopulateProperties()}) {
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
61 $childMap{$child->name} = $child;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
62 push @childNames, $child->name;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
63 push @result, $child;
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
64 }
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
65
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
66 $this->_childMap(\%childMap);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
67 $this->_childNames(\@childNames);
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
68 return \@result;
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
69 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
70 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
71
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
72 sub PopulateProperties {
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
73 my ($this) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
74
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
75 die NotImplException->new();
366
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
76 }
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
77
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
78 sub GetItems {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
79 my ($this) = @_;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
80
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
81 die NotImplException->new();
366
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 GetItem {
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
85 my ($this,$index) = @_;
935629bf80df model metadata, in progress
cin
parents: 364
diff changeset
86
367
608e74bc309f form metadata, mostly done
cin
parents: 366
diff changeset
87 die NotImplException->new();
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
88 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
89
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
90 1;
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
91
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
92 __END__
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
93
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
94 =pod
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
95
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
96 =head1 NAME
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
97
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
98 =head1 SYNOPSIS
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
99
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
100 =head1 DESCRIPTION
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
101
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
102 Метаданные описывают модель, ее свойства, используются для построения
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
103 представления.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
104
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
105 =over
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
106
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
107 =item * type
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
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
112 =item * label
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
113
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 =item * template
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
117
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
118 Шаблон, который следует использовать для отображения модели.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
119
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
120 =item * fields
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
121
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
122 Коллекция с информацией по свойствам (полям) модели. Данный хеш используется
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
123 для определения представления при использовании C<display_for('field')>.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
124
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
125 =back
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
126
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
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
130 =head1 MEMBERS
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
131
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
132 =head2 C<GetChild($name)>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
133
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
134 Возвращает метаданные для дочернего элемента, например свойства объекта
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
135
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
136 =head2 C<GetChildren()>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
137
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
138 Возвращает ссылку на массив с метаданными для дочерних элементов
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
139
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
140 =cut