annotate Lib/IMPL/DOM/Node.pm @ 57:bf59ee1cd506

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