annotate Lib/IMPL/Web/View/Metadata/ObjectMeta.pm @ 383:2f16f13b000c

DOM localization
author cin
date Thu, 23 Jan 2014 17:26:34 +0400
parents d5c8b955bf8d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
1 package IMPL::Web::View::Metadata::ObjectMeta;
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
2 use strict;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
3
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
4 use IMPL::lang;
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
5 use IMPL::Const qw(:prop :access);
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
6 use IMPL::declare {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
7 require => {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
8 Exception => 'IMPL::Exception',
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
9 ArgException => '-IMPL::InvalidArgumentException',
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
10 OpException => '-IMPL::InvalidOperationException',
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
11 PropertyInfo => 'IMPL::Class::PropertyInfo',
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
12 AbstractObject => '-IMPL::Object::Abstract'
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
13 },
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
14 base => [
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
15 'IMPL::Web::View::Metadata::BaseMeta' => sub {
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
16 my ($model,$type,$args) = @_;
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
17 $type ||= typeof($model);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
18 return ($model,$type,$args);
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
19 }
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
20 ],
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
21 props => [
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
22 isMultiple => PROP_RO,
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
23 holdingType => PROP_RO
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
24 ]
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
25 };
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
26
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
27 use constant {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
28 Meta => __PACKAGE__
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
29 };
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
30
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
31 sub CTOR {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
32 my ($this,$model,$type,$args) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
33
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
34 $type = $this->modelType;
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
35
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
36 $args->{isMultiple} ||= $type && $type eq 'ARRAY';
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
37
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
38 if ($args) {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
39 $this->$_($args->{$_}) foreach grep $args->{$_}, qw(isMultiple holdingType);
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
40 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
41 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
42
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
43 sub PopulateProperties {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
44 my ($this) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
45
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
46 my %seen;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
47 my @props;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
48
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
49 my $modelType = $this->modelType;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
50
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
51 if ( isclass($modelType,AbstractObject) ) {
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
52 foreach my $pi (
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
53 $this->modelType->GetMeta(
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
54 PropertyInfo,
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
55 sub { not($seen{$_}++) and $_->access == ACCESS_PUBLIC },
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
56 1
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
57 )
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
58 ) {
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
59 my $pv = $this->model && $pi->getter->($this->model);
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
60 my $pt;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
61
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
62 my %args = (name => $pi->name);
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
63 if ($pi->isList) {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
64 $pt = 'ARRAY';
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
65 $args{isMultiple} = 1;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
66 $args{holdingType} = $pi->type;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
67 } else {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
68 $pt = $pi->type;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
69 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
70
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
71 push @props, Meta->new($pv, $pt, \%args);
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
72 }
370
cbf4febf0930 ObjectMeta, Tests, migrating to the new metadata model.
sergey
parents: 369
diff changeset
73 } elsif ( $modelType && $modelType eq 'HASH' ) {
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
74 while ( my ($k,$v) = each %{$this->model || {}} ) {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
75 push @props, Meta->new($v,undef,{name => $k});
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
76 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
77 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
78
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
79 return \@props;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
80 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
81
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
82 sub GetItems {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
83 my ($this) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
84
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
85 die OpException->new("The operation must be performed on the container")
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
86 unless $this->isMultiple;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
87
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
88 my $i = 0;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
89
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
90 return [
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
91 map $this->_GetItemMeta($_,$i++), @{$this->model || []}
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
92 ];
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
93 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
94
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
95 sub GetItem {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
96 my ($this,$index) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
97
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
98 die OpException->new("The operation must be performed on the container")
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
99 unless $this->isMultiple;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
100
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
101 my $item = @{$this->model || []}[$index];
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
102
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
103 return $this->_GetItemMeta($item,$index);
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
104 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
105
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
106 sub _GetItemMeta {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
107 my ($this,$item,$index) = @_;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
108
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
109 return Meta->new(
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
110 $item,
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
111 $this->holdingType,
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
112 {
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
113 name => $index,
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
114 container => $this
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
115 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
116 );
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
117 }
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
118
371
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
119 sub GetMetadataForModel {
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
120 my ($self,$model,$args) = @_;
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
121
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
122 $args ||= {};
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
123
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
124 return $self->new(
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
125 $model,
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
126 delete $args->{modelType},
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
127 $args
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
128 )
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
129 }
d5c8b955bf8d refactoring
cin
parents: 370
diff changeset
130
369
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
131 1;
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
132
7c784144d2f1 Implemented object metadata class, cleanup
cin
parents:
diff changeset
133 __END__