Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Node.pm @ 14:65a7bb156fb7
Дом модель и схема
| author | Sergey |
|---|---|
| date | Fri, 04 Sep 2009 16:38:15 +0400 |
| parents | 75980091813b |
| children | 75d55f4ee263 |
comparison
equal
deleted
inserted
replaced
| 13:bb8d67f811ea | 14:65a7bb156fb7 |
|---|---|
| 32 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node; | 32 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node; |
| 33 | 33 |
| 34 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode}); | 34 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode}); |
| 35 | 35 |
| 36 $this->childNodes->InsertAt($pos,$node); | 36 $this->childNodes->InsertAt($pos,$node); |
| 37 | |
| 38 $node->_setParent( $this ); | |
| 39 | |
| 40 return $node; | |
| 41 } | |
| 42 | |
| 43 sub appendNode { | |
| 44 my ($this,$node,$pos) = @_; | |
| 45 | |
| 46 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node; | |
| 47 | |
| 48 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode}); | |
| 49 | |
| 50 $this->childNodes->Append($node); | |
| 37 | 51 |
| 38 $node->_setParent( $this ); | 52 $node->_setParent( $this ); |
| 39 | 53 |
| 40 return $node; | 54 return $node; |
| 41 } | 55 } |
| 92 return undef; | 106 return undef; |
| 93 } | 107 } |
| 94 } | 108 } |
| 95 | 109 |
| 96 sub selectNodes { | 110 sub selectNodes { |
| 97 my ($this,$name) = @_; | 111 my ($this,$query) = @_; |
| 112 my @result; | |
| 98 | 113 |
| 99 my @result = grep $_->nodeName eq $name, @{$this->childNodes}; | 114 if (ref $query eq 'CODE') { |
| 115 @result = grep &$query($_), @{$this->childNodes}; | |
| 116 } else { | |
| 117 @result = grep $_->nodeName eq $query, @{$this->childNodes}; | |
| 118 } | |
| 100 | 119 |
| 101 return wantarray ? @result : \@result; | 120 return wantarray ? @result : \@result; |
| 102 } | 121 } |
| 103 | 122 |
| 104 sub firstChild { | 123 sub firstChild { |
| 111 | 130 |
| 112 sub _setParent { | 131 sub _setParent { |
| 113 my ($this,$node) = @_; | 132 my ($this,$node) = @_; |
| 114 | 133 |
| 115 $this->{$parentNode} = $node; | 134 $this->{$parentNode} = $node; |
| 135 # prevent from creating cyclicreferences | |
| 116 weaken($this->{$parentNode}); | 136 weaken($this->{$parentNode}); |
| 117 } | 137 } |
| 118 | 138 |
| 119 sub text { | 139 sub text { |
| 120 my ($this) = @_; | 140 my ($this) = @_; |
