Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Node.pm @ 7:94d47b388442
Улучшены тесты
Исправлены ошибки
Улучшена документация
Работа над схемой DOM
author | Sergey |
---|---|
date | Mon, 24 Aug 2009 01:05:34 +0400 |
parents | e2cd73ccc5bd |
children | 75980091813b |
comparison
equal
deleted
inserted
replaced
6:e2cd73ccc5bd | 7:94d47b388442 |
---|---|
59 } else { | 59 } else { |
60 die new IMPL::InvalidOperationException("The specified node isn't belong to this node"); | 60 die new IMPL::InvalidOperationException("The specified node isn't belong to this node"); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 sub replaceNodeAt { | |
65 my ($this,$index,$node) = @_; | |
66 | |
67 my $nodeOld = $this->childNodes->[$index]; | |
68 | |
69 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node; | |
70 | |
71 # unlink node from previous parent | |
72 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode}); | |
73 | |
74 # replace (or set) old node | |
75 $this->childNodes->[$index] = $node; | |
76 | |
77 # save new parent | |
78 $node->_setParent( $this ); | |
79 | |
80 # unlink old node if we have one | |
81 $nodeOld->{$parentNode} = undef if $nodeOld; | |
82 | |
83 # return old node | |
84 return $nodeOld; | |
85 } | |
86 | |
64 sub removeAt { | 87 sub removeAt { |
65 my ($this,$pos) = @_; | 88 my ($this,$pos) = @_; |
66 | 89 |
67 if ( my $node = $this->childNodes->RemoveAt($pos) ) { | 90 if ( my $node = $this->childNodes->RemoveAt($pos) ) { |
68 $node->{$parentNode} = undef; | 91 $node->{$parentNode} = undef; |
76 my ($this,$name) = @_; | 99 my ($this,$name) = @_; |
77 | 100 |
78 my @result = grep $_->nodeName eq $name, @{$this->childNodes}; | 101 my @result = grep $_->nodeName eq $name, @{$this->childNodes}; |
79 | 102 |
80 return wantarray ? @result : \@result; | 103 return wantarray ? @result : \@result; |
104 } | |
105 | |
106 sub firstChild { | |
107 @_ >=2 ? $_[0]->replaceNodeAt(0,$_[1]) : $_[0]->childNodes->[0]; | |
81 } | 108 } |
82 | 109 |
83 sub _getIsComplex { | 110 sub _getIsComplex { |
84 $_[0]->childNodes->Count ? 1 : 0; | 111 $_[0]->childNodes->Count ? 1 : 0; |
85 } | 112 } |