Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Node.pm @ 108:c6fb6964de4c
Removed absolute modules
Updated DOM model, selectNodes can now select a complex path
Web DOM model release candidate
| author | wizard |
|---|---|
| date | Fri, 14 May 2010 16:06:06 +0400 |
| parents | 196bf443b5e1 |
| children | ddf0f037d460 |
comparison
equal
deleted
inserted
replaced
| 107:0e72ad99eef7 | 108:c6fb6964de4c |
|---|---|
| 181 my ($this,$axis) = @_; | 181 my ($this,$axis) = @_; |
| 182 return $Axes{$axis}->($this) | 182 return $Axes{$axis}->($this) |
| 183 } | 183 } |
| 184 | 184 |
| 185 sub selectNodes { | 185 sub selectNodes { |
| 186 my ($this,$query,$axis) = @_; | 186 my $this = shift; |
| 187 my ($path) = @_; | |
| 188 | |
| 189 $path = ref $path eq 'ARRAY' ? $path : ( @_ == 1 ? $this->translatePath($path) : [@_]); | |
| 190 | |
| 191 my @set = ($this); | |
| 192 | |
| 193 while (my $query = shift @$path) { | |
| 194 @set = map $_->selectNodesAxis($query), @set; | |
| 195 } | |
| 196 | |
| 197 return wantarray ? @set : \@set; | |
| 198 } | |
| 199 | |
| 200 sub translatePath { | |
| 201 my ($this,$path) = @_; | |
| 202 | |
| 203 # TODO: Move path compilation here from IMPL::DOM::Schema::Validator::Compare | |
| 204 return [$path]; | |
| 205 } | |
| 206 | |
| 207 sub selectNodesAxis { | |
| 208 my ($this,$query,$axis) = @_; | |
| 187 | 209 |
| 188 $axis ||= 'child'; | 210 $axis ||= 'child'; |
| 189 | 211 |
| 190 die new IMPL::InvalidOperationException('Unknown axis',$axis) unless exists $Axes{$axis}; | 212 die new IMPL::InvalidOperationException('Unknown axis',$axis) unless exists $Axes{$axis}; |
| 191 | 213 |
| 198 } elsif (ref $query eq 'ARRAY' ) { | 220 } elsif (ref $query eq 'ARRAY' ) { |
| 199 my %keys = map (($_,1),@$query); | 221 my %keys = map (($_,1),@$query); |
| 200 @result = grep $keys{$_->nodeName}, @{$nodes}; | 222 @result = grep $keys{$_->nodeName}, @{$nodes}; |
| 201 } elsif (ref $query eq 'HASH') { | 223 } elsif (ref $query eq 'HASH') { |
| 202 while( my ($axis,$filter) = each %$query ) { | 224 while( my ($axis,$filter) = each %$query ) { |
| 203 push @result, $this->selectNodes($filter,$axis); | 225 push @result, $this->selectNodesAxis($filter,$axis); |
| 204 } | 226 } |
| 205 } elsif (defined $query) { | 227 } elsif (defined $query) { |
| 206 @result = grep $_->nodeName eq $query, @{$nodes}; | 228 @result = grep $_->nodeName eq $query, @{$nodes}; |
| 207 } else { | 229 } else { |
| 208 return wantarray ? @{$nodes} : $nodes; | 230 return wantarray ? @{$nodes} : $nodes; |
| 209 } | 231 } |
| 210 | 232 |
| 211 return wantarray ? @result : \@result; | 233 return wantarray ? @result : \@result; |
| 212 } | |
| 213 | |
| 214 sub selectPath { | |
| 215 my ($this,$path) = @_; | |
| 216 | |
| 217 my @set = ($this); | |
| 218 | |
| 219 while (my $query = shift @$path) { | |
| 220 @set = map $_->selectNodes($query), @set; | |
| 221 } | |
| 222 | |
| 223 return wantarray ? @set : \@set; | |
| 224 } | 234 } |
| 225 | 235 |
| 226 sub selectParent { | 236 sub selectParent { |
| 227 my ($this) = @_; | 237 my ($this) = @_; |
| 228 | 238 |
