annotate lib/IMPL/DOM/Navigator.pm @ 411:ee36115f6a34 ref20150831

sync
author cin
date Mon, 21 Sep 2015 00:53:10 +0300
parents c6e90e02dd17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
1 package IMPL::DOM::Navigator;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
2 use strict;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
3 use warnings;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
4
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
5 use parent qw(IMPL::Object);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
6 use IMPL::Class::Property;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
7 BEGIN {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
8 private _direct property _path => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
9 private _direct property _state => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
10 private _direct property _savedstates => prop_all;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
11 public property Current => {get => \&_getCurrent};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
12 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
13
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
14 sub CTOR {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
15 my ($this,$CurrentNode) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
16
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
17 die IMPL::InvalidArgumentException->new("A starting node is a required paramater") unless $CurrentNode;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
18
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
19 $this->{$_state} = { alternatives => [ $CurrentNode ], current => 0 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
20 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
21
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
22 sub _initNavigator {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
23 my ($this,$CurrentNode) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
24
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
25 die IMPL::InvalidArgumentException->new("A starting node is a required paramater") unless $CurrentNode;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
26
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
27 $this->{$_state} = { alternatives => [ $CurrentNode ], current => 0 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
28 delete $this->{$_path};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
29 delete $this->{$_savedstates};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
30 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
31
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
32 sub _getCurrent {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
33 $_[0]->{$_state}{alternatives}[$_[0]->{$_state}{current}]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
34 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
35
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
36 sub Navigate {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
37 my ($this,@path) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
38
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
39 return unless @path;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
40
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
41 my $node;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
42
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
43 foreach my $query (@path) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
44 if (my $current = $this->Current) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
45
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
46 my @alternatives = $current->selectNodes($query);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
47
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
48 unless (@alternatives) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
49 $current = $this->advanceNavigator or return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
50 @alternatives = $current->selectNodes($query);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
51 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
52
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
53 push @{$this->{$_path}},$this->{$_state};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
54 $this->{$_state} = {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
55 alternatives => \@alternatives,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
56 current => 0,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
57 query => $query
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
58 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
59
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
60 $node = $alternatives[0];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
61 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
62 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
63 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
64 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
65
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
66 $node;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
67 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
68
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
69 sub selectNodes {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
70 my ($this,@path) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
71
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
72 return $this->Current->selectNodes(@path);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
73 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
74
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
75 sub internalNavigateNodeSet {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
76 my ($this,@nodeSet) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
77
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
78 push @{$this->{$_path}}, $this->{$_state};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
79
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
80 $this->{$_state} = {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
81 alternatives => \@nodeSet,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
82 current => 0
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
83 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
84
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
85 $nodeSet[0];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
86 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
87
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
88 sub fetch {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
89 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
90
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
91 my $result = $this->Current;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
92 $this->advanceNavigator;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
93 return $result;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
94 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
95
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
96 sub advanceNavigator {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
97 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
98
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
99 $this->{$_state}{current}++;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
100
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
101 if (@{$this->{$_state}{alternatives}} <= $this->{$_state}{current}) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
102 if ( exists $this->{$_state}{query} ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
103 my $query = $this->{$_state}{query};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
104
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
105 $this->Back or return; # that meams the end of the history
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
106
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
107 undef while ( $this->advanceNavigator and not $this->Navigate($query));
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
108
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
109 return $this->Current;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
110 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
111 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
112 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
113
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
114 return $this->Current;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
115 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
116
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
117 sub doeach {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
118 my ($this,$code) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
119 local $_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
120
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
121 do {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
122 for (my $i = $this->{$_state}{current}; $i < @{$this->{$_state}{alternatives}}; $i++) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
123 $_ = $this->{$_state}{alternatives}[$i];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
124 $code->();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
125 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
126 $this->{$_state}{current} = @{$this->{$_state}{alternatives}};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
127 } while ($this->advanceNavigator);
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
128 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
129
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
130 sub Back {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
131 my ($this,$steps) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
132
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
133 if ($this->{$_path} and @{$this->{$_path}}) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
134 if ( (not defined $steps) || $steps == 1) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
135 $this->{$_state} = pop @{$this->{$_path}};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
136 } elsif ($steps > 0) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
137 $steps = @{$this->{$_path}} - 1 if $steps >= @{$this->{$_path}};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
138
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
139 $this->{$_state} = (splice @{$this->{$_path}},-$steps)[0];
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
140 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
141 $this->Current if defined wantarray;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
142 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
143 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
144 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
145 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
146
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
147 sub PathToString {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
148 my ($this,$delim) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
149
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
150 $delim ||= '/';
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
151
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
152 join($delim,map $_->{alternatives}[$_->{current}]->nodeName, $this->{$_path} ? (@{$this->{$_path}}, $this->{$_state}) : $this->{$_state});
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
153 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
154
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
155 sub pathLength {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
156 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
157 $this->{$_path} ? scalar @{$this->{$_path}} : 0;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
158 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
159
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
160 sub GetNodeFromHistory {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
161 my ($this,$index) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
162
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
163 if (my $state = $this->{$_path} ? $this->{$_path}->[$index] : undef ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
164 return $state->{alternatives}[$state->{current}]
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
165 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
166 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
167 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
168 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
169
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
170 sub clone {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
171 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
172
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
173 my $newNavi = __PACKAGE__->surrogate;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
174
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
175 $newNavi->{$_path} = [ map { { %{ $_ } } } @{$this->{$_path}} ] if $this->{$_path};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
176 $newNavi->{$_state} = { %{$this->{$_state}} };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
177
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
178 return $newNavi;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
179
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
180 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
181
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
182 sub saveState {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
183 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
184
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
185 my %state;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
186
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
187 $state{path} = [ map { { %{ $_ } } } @{$this->{$_path}} ] if $this->{$_path};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
188 $state{state} = { %{$this->{$_state}} };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
189
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
190 push @{$this->{$_savedstates}}, \%state;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
191 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
192
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
193 sub restoreState {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
194 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
195
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
196 if ( my $state = pop @{$this->{$_savedstates}||[]} ) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
197 $this->{$_path} = $state->{path};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
198 $this->{$_state} = $state->{state};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
199 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
200 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
201
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
202 sub applyState {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
203 my ($this) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
204
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
205 pop @{$this->{$_savedstates}||[]};
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
206 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
207
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
208 sub dosafe {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
209 my ($this,$transaction) = @_;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
210
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
211 $this->saveState();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
212
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
213 my $result;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
214
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
215 eval {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
216 $result = $transaction->();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
217 };
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
218
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
219 if ($@) {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
220 $this->restoreState();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
221 return;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
222 } else {
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
223 $this->applyState();
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
224 return $result;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
225 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
226 }
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
227
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
228 1;
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
229
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
230 __END__
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
231 =pod
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
232
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
233 =head1 DESCRIPTION
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
234
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
235 Объект для хождения по дереву DOM объектов.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
236
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
237 Результатом навигации является множество узлов (альтернатив).
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
238
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
239 Состоянием навигатора является текущий набор узлов, позиция в данном наборе,
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
240 а также запрос по которому были получены данные результаты.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
241
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
242 Если при навигации указан путь сосящий из нескольких фильтров, то он разбивается
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
243 этапы простой навигации по кадой из частей пути. На каждом элементарном этапе
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
244 навигации образуется ряд альтернатив, и при каждом следующем этапе навигации
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
245 альтернативы предыдущих этапов могут перебираться, до получения положительного
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
246 результата навигации, в противном случае навигация считается невозможной.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
247
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
248 =head1 METHODS
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
249
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
250 =over
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
251
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
252 =item C<<$obj->new($nodeStart)>>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
253
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
254 Создает объект навигатора с указанной начальной позицией.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
255
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
256 =item C<<$obj->Navigate([$query,...])>>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
257
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
258 Перейти в новый узел используя запрос C<$query>. На данный момент запросом может
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
259 быть только имя узла и будет взят только первый узел. Если по запросу ничего не
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
260 найдено, переход не будет осуществлен.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
261
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
262 Возвращает либо новый узел в который перешли, либо C<undef>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
263
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
264 =item C<<$obj->Back()>>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
265
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
266 Возвращается в предыдущий узел, если таковой есть.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
267
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
268 Возвращает либо узел в который перешли, либо C<undef>.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
269
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
270 =item C<<$obj->advanceNavigator()>>
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
271
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
272 Переходит в следующую альтернативу, соответствующую текущему запросу.
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
273
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
274 =back
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
275
c6e90e02dd17 renamed Lib->lib
cin
parents:
diff changeset
276 =cut