Mercurial > pub > Impl
comparison Lib/IMPL/Web/View/Metadata/BaseMeta.pm @ 367:608e74bc309f
form metadata, mostly done
author | cin |
---|---|
date | Tue, 03 Dec 2013 17:55:36 +0400 |
parents | 935629bf80df |
children | 010ceafd0c5a |
comparison
equal
deleted
inserted
replaced
366:935629bf80df | 367:608e74bc309f |
---|---|
4 use IMPL::lang; | 4 use IMPL::lang; |
5 use IMPL::Const qw(:prop); | 5 use IMPL::Const qw(:prop); |
6 use IMPL::declare { | 6 use IMPL::declare { |
7 require => { | 7 require => { |
8 Exception => 'IMPL::Exception', | 8 Exception => 'IMPL::Exception', |
9 ArgException => '-IMPL::InvalidArgumentException' | 9 ArgException => '-IMPL::InvalidArgumentException', |
10 NotImplException => '-IMPL::NotImplementedException' | |
10 }, | 11 }, |
11 base => [ | 12 base => [ |
12 'IMPL::Object' => undef | 13 'IMPL::Object' => undef |
13 ], | 14 ], |
14 props => [ | 15 props => [ |
15 model => PROP_RO, | 16 model => PROP_RO, |
16 modelType => PROP_RO, | 17 modelType => PROP_RO, |
17 holdingType => PROP_RO, | |
18 provider => PROP_RO, | |
19 name => PROP_RO, | 18 name => PROP_RO, |
20 label => PROP_RO, | 19 label => PROP_RO, |
21 container => PROP_RO, | 20 container => PROP_RO, |
22 template => PROP_RO, | 21 template => PROP_RO, |
23 | 22 |
25 _childNames => PROP_RO | 24 _childNames => PROP_RO |
26 ] | 25 ] |
27 }; | 26 }; |
28 | 27 |
29 sub CTOR { | 28 sub CTOR { |
30 my ($this,$provider,$model,$type,$args) = @_; | 29 my ($this,$model,$type,$args) = @_; |
31 | 30 |
32 $type ||= typeof($model); | |
33 | |
34 die ArgException->new(provider => 'A provider must be specified'); | |
35 | |
36 $this->provider($provider); | |
37 $this->model($model); | 31 $this->model($model); |
38 $this->modelType($type); | 32 $this->modelType($type); |
39 $this->childMap({}); | 33 $this->_childMap({}); |
40 | 34 |
41 #mixin other args | 35 #mixin other args |
42 if ($args) { | 36 if ($args) { |
43 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template holdingType); | 37 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template); |
44 } | 38 } |
45 } | 39 } |
46 | 40 |
47 sub GetProperty { | 41 sub GetProperty { |
48 my ($this,$name) = @_; | 42 my ($this,$name) = @_; |
49 | 43 |
50 $this->_PopulateProperties() | 44 $this->GetProperties() |
51 unless $this->_childNames; | 45 unless $this->_childNames; |
52 | 46 |
53 return $this->_childMap->{$name}; | 47 return $this->_childMap->{$name}; |
54 } | 48 } |
55 | 49 |
57 my ($this) = @_; | 51 my ($this) = @_; |
58 | 52 |
59 if ($this->_childNames) { | 53 if ($this->_childNames) { |
60 return [ map $this->_childMap->{$_}, @{$this->_childNames} ]; | 54 return [ map $this->_childMap->{$_}, @{$this->_childNames} ]; |
61 } else { | 55 } else { |
62 return $this->_PopulateProperties; | 56 my @childNames; |
57 my %childMap; | |
58 my @result; | |
59 | |
60 foreach my $child (@{$this->PopulateProperties($this)}) { | |
61 $childMap{$child->name} = $child; | |
62 push @childNames, $child->name; | |
63 push @result, $child; | |
64 } | |
65 | |
66 $this->_childMap(\%childMap); | |
67 $this->_childNames(\@childNames); | |
68 return \@result; | |
63 } | 69 } |
64 } | 70 } |
65 | 71 |
66 sub _PopulateProperties { | 72 sub PopulateProperties { |
67 my ($this) = @_; | 73 my ($this) = @_; |
68 | 74 |
69 my @childNames; | 75 die NotImplException->new(); |
70 my %childMap; | |
71 my @result; | |
72 | |
73 foreach my $child (@{$this->provider->PopulateProperties($this)}) { | |
74 $childMap{$child->name} = $child; | |
75 push @childNames, $child->name; | |
76 push @result, $child; | |
77 } | |
78 | |
79 $this->_childMap(\%childMap); | |
80 $this->_childNames(\@childNames); | |
81 return \@result; | |
82 } | 76 } |
83 | 77 |
84 sub GetItems { | 78 sub GetItems { |
85 my ($this) = @_; | 79 my ($this) = @_; |
86 | 80 |
87 return $this->provider->GetItems($this); | 81 die NotImplException->new(); |
88 } | 82 } |
89 | 83 |
90 sub GetItem { | 84 sub GetItem { |
91 my ($this,$index) = @_; | 85 my ($this,$index) = @_; |
92 | 86 |
93 return $this->provider->GetItem($this,$index); | 87 die NotImplException->new(); |
94 } | 88 } |
95 | 89 |
96 1; | 90 1; |
97 | 91 |
98 __END__ | 92 __END__ |