annotate Lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 364:82b6c967bcf1

sync, working on metadata
author cin
date Fri, 29 Nov 2013 16:33:07 +0400
parents Lib/IMPL/Web/View/Metadata/Meta.pm@d67e45705be5
children 935629bf80df
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,
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
17 provider => 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 {
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
29 my ($this,$provider,$model,$type,$args) = @_;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
30
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
31 $type ||= typeof($model);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
32
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
33 die ArgException->new(provider => 'A provider must be specified');
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
34
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
35 $this->provider($provider);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
36 $this->model($model);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
37 $this->modelType($type);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
38 $this->childMap({});
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
39
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
40 #mixin other args
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
41 if ($args) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
42 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
43 }
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
44 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
45
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
46 sub GetChild {
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
47 my ($this,$name) = @_;
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
48
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
49 if(my $child = $this->_childMap->{$name}) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
50 return $child;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
51 } else {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
52 return $this->_childMap->{$name} = $this->provider->GetChild($this,$name);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
53 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
54 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
55
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
56 sub GetChildren {
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 {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
62 my @childNames;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
63 my %childMap;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
64 my @result;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
65
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
66 foreach my $child (@{$this->provider->PopulateChildren($this)}) {
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
67 $childMap{$child->name} = $child;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
68 push @childNames, $child->name;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
69 push @result, $child;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
70 }
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
71
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
72 $this->_childMap(\%childMap);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
73 $this->_childNames(\@childNames);
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
74 return \@result;
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
75 }
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
76 }
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
77
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
78 1;
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
79
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
80 __END__
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
81
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
82 =pod
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
83
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
84 =head1 NAME
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
85
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
86 =head1 SYNOPSIS
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
87
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
88 =head1 DESCRIPTION
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
89
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
90 Метаданные описывают модель, ее свойства, используются для построения
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
91 представления.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
92
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
93 =over
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
94
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
95 =item * type
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
96
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
97 Опционально. Тип модели. В случаях, когда модель не определена, данное свойство
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
98 позволяет определить ее тип.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
99
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
100 =item * label
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 =item * template
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
105
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
106 Шаблон, который следует использовать для отображения модели.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
107
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
108 =item * fields
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 для определения представления при использовании C<display_for('field')>.
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
112
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
113 =back
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
364
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
118 =head1 MEMBERS
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
119
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
120 =head2 C<GetChild($name)>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
121
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
122 Возвращает метаданные для дочернего элемента, например свойства объекта
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
123
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
124 =head2 C<GetChildren()>
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
125
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
126 Возвращает ссылку на массив с метаданными для дочерних элементов
82b6c967bcf1 sync, working on metadata
cin
parents: 363
diff changeset
127
363
d67e45705be5 sync, model metadata
cin
parents:
diff changeset
128 =cut