comparison 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
comparison
equal deleted inserted replaced
365:7c621bb95e53 366:935629bf80df
12 'IMPL::Object' => undef 12 'IMPL::Object' => undef
13 ], 13 ],
14 props => [ 14 props => [
15 model => PROP_RO, 15 model => PROP_RO,
16 modelType => PROP_RO, 16 modelType => PROP_RO,
17 holdingType => PROP_RO,
17 provider => PROP_RO, 18 provider => PROP_RO,
18 name => PROP_RO, 19 name => PROP_RO,
19 label => PROP_RO, 20 label => PROP_RO,
20 container => PROP_RO, 21 container => PROP_RO,
21 template => PROP_RO, 22 template => PROP_RO,
37 $this->modelType($type); 38 $this->modelType($type);
38 $this->childMap({}); 39 $this->childMap({});
39 40
40 #mixin other args 41 #mixin other args
41 if ($args) { 42 if ($args) {
42 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template); 43 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(name label container template holdingType);
43 } 44 }
44 } 45 }
45 46
46 sub GetChild { 47 sub GetProperty {
47 my ($this,$name) = @_; 48 my ($this,$name) = @_;
48 49
49 if(my $child = $this->_childMap->{$name}) { 50 $this->_PopulateProperties()
50 return $child; 51 unless $this->_childNames;
51 } else { 52
52 return $this->_childMap->{$name} = $this->provider->GetChild($this,$name); 53 return $this->_childMap->{$name};
53 }
54 } 54 }
55 55
56 sub GetChildren { 56 sub GetProperties {
57 my ($this) = @_; 57 my ($this) = @_;
58 58
59 if ($this->_childNames) { 59 if ($this->_childNames) {
60 return [ map $this->_childMap->{$_}, @{$this->_childNames} ]; 60 return [ map $this->_childMap->{$_}, @{$this->_childNames} ];
61 } else { 61 } else {
62 my @childNames; 62 return $this->_PopulateProperties;
63 my %childMap; 63 }
64 my @result; 64 }
65
66 sub _PopulateProperties {
67 my ($this) = @_;
65 68
66 foreach my $child (@{$this->provider->PopulateChildren($this)}) { 69 my @childNames;
67 $childMap{$child->name} = $child; 70 my %childMap;
68 push @childNames, $child->name; 71 my @result;
69 push @result, $child; 72
70 } 73 foreach my $child (@{$this->provider->PopulateProperties($this)}) {
71 74 $childMap{$child->name} = $child;
72 $this->_childMap(\%childMap); 75 push @childNames, $child->name;
73 $this->_childNames(\@childNames); 76 push @result, $child;
74 return \@result; 77 }
75 } 78
79 $this->_childMap(\%childMap);
80 $this->_childNames(\@childNames);
81 return \@result;
82 }
83
84 sub GetItems {
85 my ($this) = @_;
86
87 return $this->provider->GetItems($this);
88 }
89
90 sub GetItem {
91 my ($this,$index) = @_;
92
93 return $this->provider->GetItem($this,$index);
76 } 94 }
77 95
78 1; 96 1;
79 97
80 __END__ 98 __END__