diff Lib/IMPL/DOM/Node.pm @ 7:94d47b388442

Улучшены тесты Исправлены ошибки Улучшена документация Работа над схемой DOM
author Sergey
date Mon, 24 Aug 2009 01:05:34 +0400
parents e2cd73ccc5bd
children 75980091813b
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Fri Aug 14 16:14:13 2009 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Mon Aug 24 01:05:34 2009 +0400
@@ -61,6 +61,29 @@
     }
 }
 
+sub replaceNodeAt {
+    my ($this,$index,$node) = @_;
+    
+    my $nodeOld = $this->childNodes->[$index];
+        
+    die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
+        
+    # unlink node from previous parent
+    $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
+        
+    # replace (or set) old node
+    $this->childNodes->[$index] = $node;
+        
+    # save new parent
+    $node->_setParent( $this );
+        
+    # unlink old node if we have one
+    $nodeOld->{$parentNode} = undef if $nodeOld;
+        
+    # return old node
+    return $nodeOld;
+}
+
 sub removeAt {
     my ($this,$pos) = @_;
     
@@ -80,6 +103,10 @@
     return wantarray ? @result : \@result;
 }
 
+sub firstChild {
+    @_ >=2 ? $_[0]->replaceNodeAt(0,$_[1]) : $_[0]->childNodes->[0];
+}
+
 sub _getIsComplex {
     $_[0]->childNodes->Count ? 1 : 0;
 }