annotate lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 407:c6e90e02dd17 ref20150831

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