diff 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
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Thu May 13 03:46:29 2010 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Fri May 14 16:06:06 2010 +0400
@@ -183,7 +183,29 @@
 }
 
 sub selectNodes {
-    my ($this,$query,$axis) = @_;
+	my $this = shift;
+	my ($path) = @_;
+	
+	$path = ref $path eq 'ARRAY' ? $path :  ( @_ == 1 ? $this->translatePath($path) : [@_]); 
+	
+	my @set = ($this);
+	
+	while (my $query = shift @$path) {
+		@set = map $_->selectNodesAxis($query), @set;
+	}
+	
+	return wantarray ? @set : \@set;   
+}
+
+sub translatePath {
+	my ($this,$path) = @_;
+	
+	# TODO: Move path compilation here from IMPL::DOM::Schema::Validator::Compare
+	return [$path];
+}
+
+sub selectNodesAxis {
+	 my ($this,$query,$axis) = @_;
     
     $axis ||= 'child';
     
@@ -200,7 +222,7 @@
         @result = grep $keys{$_->nodeName}, @{$nodes};
     } elsif (ref $query eq 'HASH') {
     	while( my ($axis,$filter) = each %$query ) {
-    		push @result, $this->selectNodes($filter,$axis);
+    		push @result, $this->selectNodesAxis($filter,$axis);
     	}
     } elsif (defined $query) {
         @result = grep $_->nodeName eq $query, @{$nodes};
@@ -211,18 +233,6 @@
     return wantarray ? @result : \@result;
 }
 
-sub selectPath {
-	my ($this,$path) = @_;
-	
-	my @set = ($this);
-	
-	while (my $query = shift @$path) {
-		@set = map $_->selectNodes($query), @set;
-	}
-	
-	return wantarray ? @set : \@set;
-}
-
 sub selectParent {
 	my ($this) = @_;