annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package IMPL::DOM::Node;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use warnings;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
5 use base qw(IMPL::Object IMPL::Object::Serializable IMPL::Object::Autofill);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
6
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
7 use IMPL::Object::List;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
8 use IMPL::Class::Property;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
9 use IMPL::Class::Property::Direct;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
10 use Scalar::Util qw(weaken);
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
11
1
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
12 use IMPL::Exception;
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
13
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
14 __PACKAGE__->PassThroughArgs;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
15
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
16 BEGIN {
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
17 public _direct property nodeName => prop_get | owner_set;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
18 public _direct property isComplex => { get => \&_getIsComplex } ;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
19 public _direct property nodeValue => prop_all;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
20 public _direct property childNodes => { get => \&_getChildNodes };
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
21 public _direct property parentNode => prop_get ;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
22 private _direct property _propertyMap => prop_all;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
23 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
24
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
25 sub CTOR {
1
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
26 my ($this,$name) = @_;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
27
1
3b418b134d8c ORM in progress
Sergey
parents: 0
diff changeset
28 $this->nodeName($name) or die new IMPL::InvalidArgumentException("A name is required");
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29 $this->_propertyMap({});
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
30 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
31
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
32 sub insertNode {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
33 my ($this,$node,$pos) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
34
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
35 die new IMPL::InvalidOperationException("You can't insert the node to itselft") if $this == $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
36
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
37 $node->{$parentNode}->removeNode($node) if ($node->{$parentNode});
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
38
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
39 $this->childNodes->InsertAt($pos,$node);
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
40
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
41 $node->_setParent( $this );
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
42
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
43 return $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
44 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
45
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
46 sub _getChildNodes {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
47 my ($this) = @_;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
48
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
49 $this->{$childNodes} = new IMPL::Object::List() unless $this->{$childNodes};
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
50 $this->{$childNodes};
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
51 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
52
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
53 sub removeNode {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
54 my ($this,$node) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
55
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
56 if ($this == $node->{$parentNode}) {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
57 $this->childNodes->RemoveItem($node);
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
58 $node->{$parentNode} = undef;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
59 return $this;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
60 } else {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
61 die new IMPL::InvalidOperationException("The specified node isn't belong to this node");
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
62 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
63 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
64
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
65 sub removeAt {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
66 my ($this,$pos) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
67
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
68 if ( my $node = $this->childNodes->RemoveAt($pos) ) {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
69 $node->{$parentNode} = undef;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
70 return $node;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
71 } else {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
72 return undef;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
73 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
74 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
75
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
76 sub selectNodes {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
77 my ($this,$name) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
78
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
79 my @result = grep $_->nodeName eq $name, @{$this->childNodes};
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
80
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
81 return wantarray ? @result : \@result;
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
82 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
83
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
84 sub _getIsComplex {
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
85 $_[0]->childNodes->Count ? 1 : 0;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
86 }
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
87
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
88 sub _setParent {
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
89 my ($this,$parentNode) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
90
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
91 $this->{$parentNode} = $parentNode;
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
92 weaken($this->{$parentNode});
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
93 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
94
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
95 sub text {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
96 my ($this) = @_;
4
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
97
e59f44f75f20 DOM - в разработке
Sergey
parents: 1
diff changeset
98 join '', $this->nodeValue, map $_->nodeValue, @{$this->childNodes};
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
99 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
100
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
101 sub Property {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
102 my $this = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
103 my $name = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
104
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
105 if (@_) {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
106 # set
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
107 return $this->_propertyMap->{$name} = shift;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
108 } else {
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
109 return $this->_propertyMap->{$name};
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
110 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
111 }
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
112
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
113 1;