diff Lib/IMPL/DOM/Node.pm @ 194:4d0e1962161c

Replaced tabs with spaces IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author cin
date Tue, 10 Apr 2012 20:08:29 +0400
parents 029c9610528c
children a8db61d0ed33
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Tue Apr 10 08:13:22 2012 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Tue Apr 10 20:08:29 2012 +0400
@@ -26,12 +26,12 @@
 }
 
 our %Axes = (
-	parent => \&selectParent,
-	siblings => \&selectSiblings,
-	child => \&childNodes,
-	document => \&selectDocument,
-	ancestor => \&selectAncestors,
-	descendant => \&selectDescendant
+    parent => \&selectParent,
+    siblings => \&selectSiblings,
+    child => \&childNodes,
+    document => \&selectDocument,
+    ancestor => \&selectAncestors,
+    descendant => \&selectDescendant
 );
 
 sub CTOR {
@@ -45,7 +45,7 @@
     }
     
     while ( my ($key,$value) = each %args ) {
-    	$this->nodeProperty($key,$value);
+        $this->nodeProperty($key,$value);
     }
 }
 
@@ -105,8 +105,8 @@
 }
 
 sub childNodesRef {
-	my ($this) = @_;
-	return scalar $this->_getChildNodes;
+    my ($this) = @_;
+    return scalar $this->_getChildNodes;
 }
 
 sub removeNode {
@@ -191,52 +191,52 @@
 }
 
 sub resolveAxis {
-	my ($this,$axis) = @_;
-	return $Axes{$axis}->($this)
+    my ($this,$axis) = @_;
+    return $Axes{$axis}->($this)
 }
 
 sub selectNodes {
-	my $this = shift;
-	my $path;
-	
-	if (@_ == 1) {
-		$path = $this->translatePath($_[0]);
-	} else {
-		$path = [@_];
-	}
-	
-	my @set = ($this);
-	
-	while (@$path) {
-		my $query = shift @$path;
-		@set = map $_->selectNodesAxis($query), @set;
-	}
-	
-	return wantarray ? @set : \@set;   
+    my $this = shift;
+    my $path;
+    
+    if (@_ == 1) {
+        $path = $this->translatePath($_[0]);
+    } else {
+        $path = [@_];
+    }
+    
+    my @set = ($this);
+    
+    while (@$path) {
+        my $query = shift @$path;
+        @set = map $_->selectNodesAxis($query), @set;
+    }
+    
+    return wantarray ? @set : \@set;   
 }
 
 sub selectSingleNode {
-	my $this = shift;
-	my @result = $this->selectNodes(@_);
-	return $result[0];
+    my $this = shift;
+    my @result = $this->selectNodes(@_);
+    return $result[0];
 }
 
 sub selectNodesRef {
-	my $this = shift;
-	
-	my @result = $this->selectNodes(@_);
-	return \@result;
+    my $this = shift;
+    
+    my @result = $this->selectNodes(@_);
+    return \@result;
 }
 
 sub translatePath {
-	my ($this,$path) = @_;
-	
-	# TODO: Move path compilation here from IMPL::DOM::Schema::Validator::Compare
-	return [$path];
+    my ($this,$path) = @_;
+    
+    # TODO: Move path compilation here from IMPL::DOM::Schema::Validator::Compare
+    return [$path];
 }
 
 sub selectNodesAxis {
-	 my ($this,$query,$axis) = @_;
+     my ($this,$query,$axis) = @_;
     
     $axis ||= 'child';
     
@@ -252,9 +252,9 @@
         my %keys = map (($_,1),@$query);
         @result = grep $keys{$_->nodeName}, @{$nodes};
     } elsif (ref $query eq 'HASH') {
-    	while( my ($axis,$filter) = each %$query ) {
-    		push @result, $this->selectNodesAxis($filter,$axis);
-    	}
+        while( my ($axis,$filter) = each %$query ) {
+            push @result, $this->selectNodesAxis($filter,$axis);
+        }
     } elsif (defined $query) {
         @result = grep $_->nodeName eq $query, @{$nodes};
     } else {
@@ -265,39 +265,39 @@
 }
 
 sub selectParent {
-	my ($this) = @_;
-	
-	if ($this->parentNode) {
-		return wantarray ? $this->parentNode : [$this->parentNode];
-	} else {
-		return wantarray ? () : [];
-	}
+    my ($this) = @_;
+    
+    if ($this->parentNode) {
+        return wantarray ? $this->parentNode : [$this->parentNode];
+    } else {
+        return wantarray ? () : [];
+    }
 }
 
 sub selectSiblings {
-	my ($this) = @_;
-	
-	if ($this->parentNode) {
-		return $this->parentNode->selectNodes( sub { $_ != $this } );
-	} else {
-		return wantarray ? () : [];
-	}
+    my ($this) = @_;
+    
+    if ($this->parentNode) {
+        return $this->parentNode->selectNodes( sub { $_ != $this } );
+    } else {
+        return wantarray ? () : [];
+    }
 }
 
 sub selectDocument {
-	my ($this) = @_;
-	
-	if ($this->document) {
-		return wantarray ? $this->document : [$this->document];
-	} else {
-		return wantarray ? () : [];
-	}
+    my ($this) = @_;
+    
+    if ($this->document) {
+        return wantarray ? $this->document : [$this->document];
+    } else {
+        return wantarray ? () : [];
+    }
 }
 
 sub selectDescendant {
-	wantarray ?
-		map $_->selectAll(), $_[0]->childNodes :
-		[map $_->selectAll(), $_[0]->childNodes]
+    wantarray ?
+        map $_->selectAll(), $_[0]->childNodes :
+        [map $_->selectAll(), $_[0]->childNodes]
 }
 
 sub selectAll {
@@ -305,11 +305,11 @@
 }
 
 sub selectAncestors {
-	my $parent = $_[0]->parentNode;
-	
-	wantarray ?
-		($parent ? ($parent->selectAncestors,$parent) : ()) :
-		[$parent ? ($parent->selectAncestors,$parent) : ()]
+    my $parent = $_[0]->parentNode;
+    
+    wantarray ?
+        ($parent ? ($parent->selectAncestors,$parent) : ()) :
+        [$parent ? ($parent->selectAncestors,$parent) : ()]
 }
 
 sub firstChild {
@@ -373,52 +373,52 @@
     return unless defined $name;
     
     if (my $method = $this->can($name)) {
-    	unshift @_,$this;
-    	# use goto to preserve calling context
-    	goto &$method;
+        unshift @_,$this;
+        # use goto to preserve calling context
+        goto &$method;
     }
     # dynamic property
     if (@_) {
-		# set
-	    return $this->{$_propertyMap}{$name} = shift;
-	} else {
-	    return $this->{$_propertyMap}{$name};
+        # set
+        return $this->{$_propertyMap}{$name} = shift;
+    } else {
+        return $this->{$_propertyMap}{$name};
     }
 }
 
 sub listProperties {
-	my ($this) = @_;
-	
-	my %props = map {$_->Name, 1} $this->get_meta(typeof IMPL::Class::PropertyInfo, sub { $_->Attributes->{domProperty}},1);
-	
-	return (keys %props,keys %{$this->{$_propertyMap}});
+    my ($this) = @_;
+    
+    my %props = map {$_->Name, 1} $this->get_meta(typeof IMPL::Class::PropertyInfo, sub { $_->Attributes->{domProperty}},1);
+    
+    return (keys %props,keys %{$this->{$_propertyMap}});
 }
 
 sub save {
-	my ($this,$writer) = @_;
-	
-	if ( not ( $this->isComplex or defined $this->{$nodeValue} ) ) {
-		$writer->emptyTag(
-			$this->{$nodeName},
-			map {
-				$_,
-				$this->nodeProperty($_)
-			} grep defined $this->nodeProperty($_), $this->listProperties
-		);
-	} else {
-		$writer->startTag(
-			$this->{$nodeName},
-			map {
-				$_,
-				$this->nodeProperty($_)
-			} grep defined $this->nodeProperty($_), $this->listProperties
-		);
-		$writer->characters($this->{$nodeValue}) if $this->{$nodeValue};
-		
-		$_->save($writer) foreach $this->childNodes;
-		
-		$writer->endTag($this->{$nodeName});
-	}
+    my ($this,$writer) = @_;
+    
+    if ( not ( $this->isComplex or defined $this->{$nodeValue} ) ) {
+        $writer->emptyTag(
+            $this->{$nodeName},
+            map {
+                $_,
+                $this->nodeProperty($_)
+            } grep defined $this->nodeProperty($_), $this->listProperties
+        );
+    } else {
+        $writer->startTag(
+            $this->{$nodeName},
+            map {
+                $_,
+                $this->nodeProperty($_)
+            } grep defined $this->nodeProperty($_), $this->listProperties
+        );
+        $writer->characters($this->{$nodeValue}) if $this->{$nodeValue};
+        
+        $_->save($writer) foreach $this->childNodes;
+        
+        $writer->endTag($this->{$nodeName});
+    }
 }
 
 sub qname {