annotate lib/IMPL/DOM/Schema/Node.pm @ 422:b0481c071bea ref20150831

IMPL::Config::Container tests, YAMLConfiguration now works and tested
author cin
date Sun, 20 Aug 2017 00:20:41 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Schema::Node;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use IMPL::Const qw(:prop);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::declare {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 require => {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 Label => 'IMPL::DOM::Schema::Label'
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 },
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 base => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 'IMPL::DOM::Node' => sub {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 my %args = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13 delete @args{qw(
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 minOccur
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 maxOccur
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16 type
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 name
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18 )} ;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 $args{nodeName} ||= 'Node';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 %args
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 ],
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 props => [
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24 minOccur => { get => 1, set => 1, direct => 1, dom => 1},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 maxOccur => { get => 1, set => 1, direct => 1, dom => 1},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26 type => { get => 1, set => 1, direct => 1, dom => 1},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 name => { get => 1, set => 1, direct => 1, dom => 1},
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 label => { get => '_getLabel', direct => 1 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 ]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 sub _getLabel {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35 $this->{$label} ||= Label->new($this->document->stringMap, $this->name );
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 my ($this,%args) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 $this->{$minOccur} = defined $args{minOccur} ? $args{minOccur} : 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42 $this->{$maxOccur} = defined $args{maxOccur} ? $args{maxOccur} : 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 $this->{$type} = $args{type};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 $this->{$name} = $args{name} or die new IMPL::InvalidArgumentException('Argument is required','name');
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47 sub Validate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 my ($this,$node,$ctx) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 $ctx->{schemaNode} = $this; # запоминаем источник ссылки
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52 if (my $schemaType = $this->{$type} ? $this->document->ResolveType($this->{$type}) : undef ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 my @errors = $schemaType->Validate($node,$ctx);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 return @errors;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 return ();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 sub isOptional {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 return $this->{$minOccur} ? 0 : 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 sub isMultiple {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 return ($this->{$maxOccur} eq 'unbounded' || $this->{$maxOccur} > 1 ) ? 1 : 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 sub qname {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 $_[0]->nodeName.'[name='.$_[0]->{$name}.']';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 =head1 SYNOPSIS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83 package SchemaEntity;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84 use parent qw(IMPL::DOM::Schema::Node);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 sub Validate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87 my ($this,$node) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92 Базовый класс для элементов схемы. Также позволяет объявлять узлы определенного типа.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 =head1 MEMBERS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 =head2 PROPERTIES
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100 =item C<[get,set] minOccur>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 C<default: 1>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104 Минимальное количество повторений узла.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106 =item C<[get,set] maxOccur>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108 C<default: 1>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 Максимальное количество повторений узла
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 =item C<[get,set] type>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
113
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
114 C<default: undef>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
115
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
116 Имя типа из схемы.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
117
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
118 =item C<[get,set] name>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
119
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
120 Имя узла.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
121
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
122 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
123
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
124 =cut