Mercurial > pub > Impl
annotate Lib/IMPL/DOM/Schema/Node.pm @ 381:ced5937ff21a
Custom getters/setters support method names in theirs definitions
Initial support for localizable labels in DOM schemas
author | cin |
---|---|
date | Wed, 22 Jan 2014 16:56:10 +0400 |
parents | 4ddb27ff4a0b |
children | 2f16f13b000c |
rev | line source |
---|---|
49 | 1 package IMPL::DOM::Schema::Node; |
2 use strict; | |
3 use warnings; | |
4 | |
165 | 5 use parent qw(IMPL::DOM::Node); |
49 | 6 use IMPL::Class::Property; |
7 use IMPL::DOM::Property qw(_dom); | |
8 | |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
9 use IMPL::Const qw(:prop); |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
10 use IMPL::declare { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
11 base => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
12 'IMPL::DOM::Node' => sub { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
13 my %args = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
14 delete @args{qw( |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
15 minOccur |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
16 maxOccur |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
17 type |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
18 name |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
19 )} ; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
20 $args{nodeName} ||= 'Node'; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
21 %args |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
22 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
23 ], |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
24 props => [ |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
25 minOccur => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
26 maxOccur => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
27 type => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
28 name => { get => 1, set => 1, direct => 1, dom => 1}, |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
29 label => { get => '_getLabel', direct => 1 } |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
30 ] |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
31 }; |
49 | 32 |
381
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
33 sub _getLabel { |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
34 my ($this) = @_; |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
35 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
36 |
ced5937ff21a
Custom getters/setters support method names in theirs definitions
cin
parents:
278
diff
changeset
|
37 } |
49 | 38 |
39 sub CTOR { | |
40 my ($this,%args) = @_; | |
41 | |
42 $this->{$minOccur} = defined $args{minOccur} ? $args{minOccur} : 1; | |
43 $this->{$maxOccur} = defined $args{maxOccur} ? $args{maxOccur} : 1; | |
44 $this->{$type} = $args{type}; | |
45 $this->{$name} = $args{name} or die new IMPL::InvalidArgumentException('Argument is required','name'); | |
46 } | |
47 | |
48 sub Validate { | |
49 my ($this,$node) = @_; | |
50 | |
51 if (my $schemaType = $this->{$type} ? $this->document->resolveType($this->{$type}) : undef ) { | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
52 my @errors = $schemaType->Validate($node,{Source => $this}); |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
53 return @errors; |
49 | 54 } else { |
55 return (); | |
56 } | |
57 } | |
58 | |
241
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
59 sub isOptional { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
60 my ($this) = @_; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
61 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
62 return $this->{$minOccur} ? 0 : 1; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
63 } |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
64 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
65 sub isMultiple { |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
66 my ($this) = @_; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
67 |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
68 return ($this->{$maxOccur} eq 'unbounded' || $this->{$maxOccur} > 1 ) ? 1 : 0; |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
69 } |
f48a1a9f4fa2
+Added ViewResult to allow implementation of the view environment.
sergey
parents:
194
diff
changeset
|
70 |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
71 sub inflateValue { |
194 | 72 $_[1]; |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
73 } |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
74 |
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
75 sub inflator { undef } |
103 | 76 |
49 | 77 sub qname { |
78 $_[0]->nodeName.'[name='.$_[0]->{$name}.']'; | |
79 } | |
80 | |
81 1; | |
82 | |
83 __END__ | |
84 =pod | |
85 | |
86 =head1 SYNOPSIS | |
87 | |
104
196bf443b5e1
DOM::Schema RC0 inflators support, validation and some other things,
wizard
parents:
103
diff
changeset
|
88 package SchemaEntity; |
165 | 89 use parent qw(IMPL::DOM::Schema::Node); |
49 | 90 |
91 sub Validate { | |
92 my ($this,$node) = @_; | |
93 } | |
94 | |
95 =head1 DESCRIPTION | |
96 | |
180 | 97 Базовый класс для элементов схемы. Также позволяет объявлять узлы определенного типа. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
98 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
99 =head1 MEMBERS |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
100 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
101 =head2 PROPERTIES |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
102 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
103 =over |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
104 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
105 =item C<[get,set] minOccur> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
106 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
107 C<default: 1>. |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
108 |
180 | 109 Минимальное количество повторений узла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
110 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
111 =item C<[get,set] maxOccur> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
112 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
113 C<default: 1>. |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
114 |
180 | 115 Максимальное количество повторений узла |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
116 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
117 =item C<[get,set] type> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
118 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
119 C<default: undef> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
120 |
180 | 121 Имя типа из схемы. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
122 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
123 =item C<[get,set] name> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
124 |
180 | 125 Имя узла. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
126 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
127 =item C<[get,set] display> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
128 |
180 | 129 Имя узла для отображения. |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
130 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
131 =item C<[get,set] display_no> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
132 |
180 | 133 Имя узла для отображения (родительный падеж). |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
134 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
135 =item C<[get,set] display_blame> |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
136 |
180 | 137 Имя узла для отображения (винительный падеж). |
148
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
138 |
e6447ad85cb4
DOM objects now have a schema and schemaSource properties
wizard
parents:
104
diff
changeset
|
139 =back |
49 | 140 |
141 =cut |