annotate Lib/IMPL/DOM/Node.pm @ 46:75148ccd732d

Upgrading resources
author Sergey
date Tue, 02 Feb 2010 17:09:49 +0300
parents d660fb38b7cc
children 16ada169ca75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package IMPL::DOM::Node;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use warnings;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
11
75980091813b DOM и навигация
Sergey
parents: 7
diff changeset
5 use base qw(IMPL::Object);
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
7 use IMPL::Object::List;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 use Scalar::Util qw(weaken);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11
1
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
12 use IMPL::Exception;
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
13
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 BEGIN {
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
15 public _direct property nodeName => prop_get;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
16 public _direct property document => prop_get;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
17 public _direct property isComplex => { get => \&_getIsComplex } ;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
18 public _direct property nodeValue => prop_all;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
19 public _direct property childNodes => { get => \&_getChildNodes };
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
20 public _direct property parentNode => prop_get ;
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
21 private _direct property _propertyMap => prop_all ;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
22 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24 sub CTOR {
11
75980091813b DOM и навигация
Sergey
parents: 7
diff changeset
25 my ($this,%args) = @_;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
26
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
27 $this->{$nodeName} = delete $args{nodeName} or die new IMPL::InvalidArgumentException("A name is required");
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
28 $this->{$nodeValue} = delete $args{nodeValue} if exists $args{nodeValue};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
29 if ( exists $args{document} ) {
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
30 $this->{$document} = delete $args{document};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
31 weaken($this->{$document});
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
32 }
34
a8086f85a571 Dom Builder
Sergey
parents: 30
diff changeset
33
a8086f85a571 Dom Builder
Sergey
parents: 30
diff changeset
34 $this->{$_propertyMap} = \%args;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
35 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
36
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
37 sub insertNode {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
38 my ($this,$node,$pos) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
39
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
40 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
41
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
42 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
43
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
44 $this->childNodes->InsertAt($pos,$node);
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
45
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
46 $node->_setParent( $this );
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
47
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
48 return $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
49 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
50
30
dd4d72600c69 ORM in works
Sergey
parents: 24
diff changeset
51 sub appendChild {
16
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
52 my ($this,$node) = @_;
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
53
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
54 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
55
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
56 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
57
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
58 my $children = $this->childNodes;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
59 $children->Append($node);
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
60
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
61 $node->_setParent( $this );
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
62
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
63 return $node;
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
64 }
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
65
30
dd4d72600c69 ORM in works
Sergey
parents: 24
diff changeset
66 sub appendNode {
dd4d72600c69 ORM in works
Sergey
parents: 24
diff changeset
67 goto &appendChild;
dd4d72600c69 ORM in works
Sergey
parents: 24
diff changeset
68 }
dd4d72600c69 ORM in works
Sergey
parents: 24
diff changeset
69
16
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
70 sub appendRange {
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
71 my ($this,@range) = @_;
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
72
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
73 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if grep $_ == $this, @range;
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
74
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
75 foreach my $node (@range) {
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
76 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
77 $node->_setParent( $this );
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
78 }
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
79
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
80 $this->childNodes->Append(@range);
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
81
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
82 return $this;
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
83 }
75d55f4ee263 Окончательная концепция описания схем и построения DOM документов
Sergey
parents: 14
diff changeset
84
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
85 sub _getChildNodes {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
86 my ($this) = @_;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
87
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
88 $this->{$childNodes} = new IMPL::Object::List() unless $this->{$childNodes};
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
89 return $this->{$childNodes};
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
90 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
91
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
92 sub removeNode {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
93 my ($this,$node) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
94
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
95 if ($this == $node->{$parentNode}) {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
96 $this->childNodes->RemoveItem($node);
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
97 $node->_setParent(undef);
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
98 return $node;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
99 } else {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
100 die new IMPL::InvalidOperationException("The specified node isn't belong to this node");
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
101 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
102 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
103
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
104 sub replaceNodeAt {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
105 my ($this,$index,$node) = @_;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
106
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
107 my $nodeOld = $this->childNodes->[$index];
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
108
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
109 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
110
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
111 # unlink node from previous parent
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
112 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
113
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
114 # replace (or set) old node
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
115 $this->childNodes->[$index] = $node;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
116
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
117 # set new parent
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
118 $node->_setParent( $this );
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
119
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
120 # unlink old node if we have one
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
121 $nodeOld->_setParent(undef) if $nodeOld;
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
122
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
123 # return old node
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
124 return $nodeOld;
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
125 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
126
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
127 sub removeAt {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
128 my ($this,$pos) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
129
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
130 if ( my $node = $this->childNodes->RemoveAt($pos) ) {
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
131 $node->_setParent(undef);
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
132 return $node;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
133 } else {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
134 return undef;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
135 }
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
136 }
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
137
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
138 sub removeLast {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
139 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
140
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
141 if ( my $node = $this->{$childNodes} ? $this->{$childNodes}->RemoveLast() : undef) {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
142 $node->_setParent(undef);
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
143 return $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
144 } else {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
145 return undef;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
146 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
147 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
148
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
149 sub removeSelected {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
150 my ($this,$query) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
151
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
152 my @newSet;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
153 my @result;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
154
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
155 if (ref $query eq 'CODE') {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
156 &$query($_) ? push @result, $_ : push @newSet, $_ foreach @{$this->childNodes};
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
157 } elsif (defined $query) {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
158 $_->nodeName eq $query ? push @result, $_ : push @newSet, $_ foreach @{$this->childNodes};
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
159 } else {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
160 my $children = $this->childNodes;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
161 $_->_setParent(undef) foreach @$children;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
162 delete $this->{$childNodes};
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
163 return wantarray ? @$children : $children;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
164 }
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
165
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
166 $_->_setParent(undef) foreach @result;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
167
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
168 $this->{$childNodes} = @newSet ? bless \@newSet ,'IMPL::Object::List' : undef;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
169
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
170 return wantarray ? @result : \@result;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
171 }
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
172
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
173 sub selectNodes {
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
174 my ($this,$query) = @_;
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
175
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
176 my @result;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
177
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
178 if (ref $query eq 'CODE') {
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
179 @result = grep &$query($_), @{$this->childNodes};
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
180 } elsif (ref $query eq 'ARRAY' ) {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
181 my %keys = map (($_,1),@$query);
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
182 @result = grep $keys{$_->nodeName}, @{$this->childNodes};
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
183 } elsif (defined $query) {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
184 @result = grep $_->nodeName eq $query, @{$this->childNodes};
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
185 } else {
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
186 if (wantarray) {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
187 return @{$this->childNodes};
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
188 } else {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
189 @result = $this->childNodes;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
190 return \@result;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
191 }
14
65a7bb156fb7 Дом модель и схема
Sergey
parents: 11
diff changeset
192 }
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
193
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
194 return wantarray ? @result : \@result;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
195 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
196
7
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
197 sub firstChild {
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
198 @_ >=2 ? $_[0]->replaceNodeAt(0,$_[1]) : $_[0]->childNodes->[0];
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
199 }
94d47b388442 Улучшены тесты
Sergey
parents: 6
diff changeset
200
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
201 sub _getIsComplex {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
202 $_[0]->childNodes->Count ? 1 : 0;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
203 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
204
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
205 sub _updateDocRefs {
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
206 my ($this) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
207
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
208 # this method is called by the parent node on his children, so we need no to check parent
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
209 $this->{$document} = $this->{$parentNode}->document;
36
1828103371d0 DOM in works
Sergey
parents: 34
diff changeset
210
38
d660fb38b7cc small fixes
Sergey
parents: 37
diff changeset
211 # prevent cyclic
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
212 weaken($this->{$document}) if $this->{$document};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
213
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
214 $_->_updateDocRefs foreach @{$this->{$childNodes}};
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
215 }
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
216
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
217 sub _setParent {
11
75980091813b DOM и навигация
Sergey
parents: 7
diff changeset
218 my ($this,$node) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
219
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
220
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
221 if (($node || 0) != ($this->{$parentNode} || 0)) {
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
222 my $newOwner;
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
223 if ($node) {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
224 $this->{$parentNode} = $node;
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
225 $newOwner = $node->document || 0;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
226
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
227 # prevent from creating cyclicreferences
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
228 weaken($this->{$parentNode});
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
229
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
230 } else {
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
231 delete $this->{$parentNode};
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
232 $newOwner = 0;
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
233 }
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
234
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
235 if (($this->{$document}||0) != $newOwner) {
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
236 $this->{$document} = $newOwner;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
237 weaken($this->{$document}) if $newOwner;
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
238 $_->_updateDocRefs foreach @{$this->childNodes};
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
239 }
18
818c74b038ae DOM Schema + tests
Sergey
parents: 16
diff changeset
240 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
241 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
242
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
243 sub text {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
244 my ($this) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
245
37
c2e7f7c96bcd performance improvements, DOM reworked (a little)
Sergey
parents: 36
diff changeset
246 join ('', $this->nodeValue || '', map ($_->text || '', @{$this->childNodes}));
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
247 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
248
21
fafe56cfcd69 temp commit
Sergey
parents: 18
diff changeset
249 sub nodeProperty {
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
250 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
251 my $name = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
252
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
253 if (@_) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
254 # set
6
e2cd73ccc5bd DOM In development
Sergey
parents: 4
diff changeset
255 return $this->{$_propertyMap}{$name} = shift;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
256 } else {
6
e2cd73ccc5bd DOM In development
Sergey
parents: 4
diff changeset
257 return $this->{$_propertyMap}{$name};
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
258 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
259 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
260
24
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
261 sub qname {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
262 $_[0]->{$nodeName};
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
263 }
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
264
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
265 sub path {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
266 my ($this) = @_;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
267
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
268 if ($this->parentNode) {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
269 return $this->parentNode->path.'.'.$this->qname;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
270 } else {
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
271 return $this->qname;
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
272 }
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
273 }
7f00786f8210 Первая рабочая реазизация схемы и навигаторов
Sergey
parents: 21
diff changeset
274
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
275 1;