Mercurial > pub > Impl
comparison Lib/IMPL/DOM/Node.pm @ 4:e59f44f75f20
DOM - в разработке
Testing - по мелочи
Property - изменен механизм выбора имплементора
author | Sergey |
---|---|
date | Wed, 12 Aug 2009 17:36:07 +0400 |
parents | 3b418b134d8c |
children | e2cd73ccc5bd |
comparison
equal
deleted
inserted
replaced
3:2e546a5175dd | 4:e59f44f75f20 |
---|---|
2 use strict; | 2 use strict; |
3 use warnings; | 3 use warnings; |
4 | 4 |
5 use base qw(IMPL::Object IMPL::Object::Serializable IMPL::Object::Autofill); | 5 use base qw(IMPL::Object IMPL::Object::Serializable IMPL::Object::Autofill); |
6 | 6 |
7 use IMPL::Object::List; | |
7 use IMPL::Class::Property; | 8 use IMPL::Class::Property; |
8 use IMPL::Class::Property::Direct; | 9 use IMPL::Class::Property::Direct; |
9 use Scalar::Util qw(weaken); | 10 use Scalar::Util qw(weaken); |
10 | 11 |
11 use IMPL::Exception; | 12 use IMPL::Exception; |
12 | 13 |
13 __PACKAGE__->PassThroughArgs; | 14 __PACKAGE__->PassThroughArgs; |
14 | 15 |
15 BEGIN { | 16 BEGIN { |
16 public property nodeName => prop_get | owner_set; | 17 public _direct property nodeName => prop_get | owner_set; |
17 public property isComplex => prop_get | owner_set; | 18 public _direct property isComplex => { get => \&_getIsComplex } ; |
18 public property nodeValue => prop_get | owner_set; | 19 public _direct property nodeValue => prop_all; |
19 public property childNodes => prop_get | owner_set| prop_list; | 20 public _direct property childNodes => { get => \&_getChildNodes }; |
20 public property parentNode => prop_get | owner_set; | 21 public _direct property parentNode => prop_get ; |
21 private property _propertyMap => prop_all; | 22 private _direct property _propertyMap => prop_all; |
22 } | 23 } |
23 | 24 |
24 sub CTOR { | 25 sub CTOR { |
25 my ($this,$name) = @_; | 26 my ($this,$name) = @_; |
26 | 27 |
28 $this->_propertyMap({}); | 29 $this->_propertyMap({}); |
29 } | 30 } |
30 | 31 |
31 sub insertNode { | 32 sub insertNode { |
32 my ($this,$node,$pos) = @_; | 33 my ($this,$node,$pos) = @_; |
34 | |
35 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node; | |
36 | |
37 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode}); | |
38 | |
39 $this->childNodes->InsertAt($pos,$node); | |
40 | |
41 $node->_setParent( $this ); | |
42 | |
43 return $node; | |
44 } | |
45 | |
46 sub _getChildNodes { | |
47 my ($this) = @_; | |
48 | |
49 $this->{$childNodes} = new IMPL::Object::List() unless $this->{$childNodes}; | |
50 $this->{$childNodes}; | |
33 } | 51 } |
34 | 52 |
35 sub removeNode { | 53 sub removeNode { |
36 my ($this,$node) = @_; | 54 my ($this,$node) = @_; |
55 | |
56 if ($this == $node->{$parentNode}) { | |
57 $this->childNodes->RemoveItem($node); | |
58 $node->{$parentNode} = undef; | |
59 return $this; | |
60 } else { | |
61 die new IMPL::InvalidOperationException("The specified node isn't belong to this node"); | |
62 } | |
37 } | 63 } |
38 | 64 |
39 sub removeAt { | 65 sub removeAt { |
40 my ($this,$pos) = @_; | 66 my ($this,$pos) = @_; |
67 | |
68 if ( my $node = $this->childNodes->RemoveAt($pos) ) { | |
69 $node->{$parentNode} = undef; | |
70 return $node; | |
71 } else { | |
72 return undef; | |
73 } | |
41 } | 74 } |
42 | 75 |
43 sub selectNodes { | 76 sub selectNodes { |
44 my ($this,$name) = @_; | 77 my ($this,$name) = @_; |
78 | |
79 my @result = grep $_->nodeName eq $name, @{$this->childNodes}; | |
80 | |
81 return wantarray ? @result : \@result; | |
45 } | 82 } |
46 | 83 |
47 sub setParent { | 84 sub _getIsComplex { |
85 $_[0]->childNodes->Count ? 1 : 0; | |
86 } | |
87 | |
88 sub _setParent { | |
48 my ($this,$parentNode) = @_; | 89 my ($this,$parentNode) = @_; |
90 | |
91 $this->{$parentNode} = $parentNode; | |
92 weaken($this->{$parentNode}); | |
49 } | 93 } |
50 | 94 |
51 sub text { | 95 sub text { |
52 my ($this) = @_; | 96 my ($this) = @_; |
97 | |
98 join '', $this->nodeValue, map $_->nodeValue, @{$this->childNodes}; | |
53 } | 99 } |
54 | 100 |
55 sub Property { | 101 sub Property { |
56 my $this = shift; | 102 my $this = shift; |
57 my $name = shift; | 103 my $name = shift; |