diff Lib/IMPL/DOM/Node.pm @ 14:65a7bb156fb7

Дом модель и схема
author Sergey
date Fri, 04 Sep 2009 16:38:15 +0400
parents 75980091813b
children 75d55f4ee263
line wrap: on
line diff
--- a/Lib/IMPL/DOM/Node.pm	Wed Sep 02 23:11:14 2009 +0400
+++ b/Lib/IMPL/DOM/Node.pm	Fri Sep 04 16:38:15 2009 +0400
@@ -40,6 +40,20 @@
     return $node;
 }
 
+sub appendNode {
+    my ($this,$node,$pos) = @_;
+    
+    die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
+    
+    $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
+    
+    $this->childNodes->Append($node);
+    
+    $node->_setParent( $this );
+    
+    return $node;
+}
+
 sub _getChildNodes {
     my ($this) = @_;
     
@@ -94,9 +108,14 @@
 }
 
 sub selectNodes {
-    my ($this,$name) = @_;
+    my ($this,$query) = @_;
+    my @result;
     
-    my @result = grep $_->nodeName eq $name, @{$this->childNodes};
+    if (ref $query eq 'CODE') {
+        @result = grep &$query($_), @{$this->childNodes};
+    } else {
+        @result = grep $_->nodeName eq $query, @{$this->childNodes};
+    }
     
     return wantarray ? @result : \@result;
 }
@@ -113,6 +132,7 @@
     my ($this,$node) = @_;
     
     $this->{$parentNode} = $node;
+    # prevent from creating cyclicreferences
     weaken($this->{$parentNode});
 }