0
|
1 package IMPL::DOM::Navigator;
|
|
2 use strict;
|
|
3 use warnings;
|
|
4
|
11
|
5 use base qw(IMPL::Object);
|
|
6 use IMPL::Class::Property;
|
|
7 use IMPL::Class::Property::Direct;
|
|
8 BEGIN {
|
|
9 public _direct property Path => prop_get | owner_set;
|
|
10 public _direct property Current => prop_get | owner_set;
|
|
11 }
|
|
12
|
|
13 sub CTOR {
|
|
14 my ($this,$CurrentNode) = @_;
|
|
15
|
|
16 $this->{$Current} = $CurrentNode or die IMPL::InvalidArgumentException("A starting node is a required paramater");
|
|
17 }
|
0
|
18
|
11
|
19 sub Navigate {
|
|
20 my ($this,$query) = @_;
|
|
21
|
|
22 if ( my ($newNode) = $this->{$Current}->selectNodes($query) ) {
|
|
23 push @{$this->{$Path}}, $this->{$Current};
|
|
24 return $this->{$Current} = $newNode;
|
|
25 } else {
|
|
26 return undef;
|
|
27 }
|
|
28 }
|
0
|
29
|
11
|
30 sub Back {
|
|
31 my ($this) = @_;
|
|
32
|
|
33 if ( my $newNode = $this->{$Path} ? pop @{$this->{$Path}} : undef ) {
|
|
34 return $this->{$Current} = $newNode;
|
|
35 } else {
|
|
36 return undef;
|
|
37 }
|
|
38 }
|
|
39
|
|
40 sub PathToString {
|
|
41 my $this = shift;
|
|
42
|
|
43 join('/',map $_->nodeName, $this->{$Path} ? (@{$this->{$Path}}, $this->{$Current}) : $this->{$Current});
|
|
44 }
|
0
|
45
|
|
46 1;
|
11
|
47
|
|
48 __END__
|
|
49 =pod
|
|
50
|
|
51 =head1 DESCRIPTION
|
|
52
|
|
53 DOM .
|
|
54
|
|
55 =head1 METHODS
|
|
56
|
|
57 =over
|
|
58
|
|
59 =item C<$obj->new($nodeStart)>
|
|
60
|
|
61 .
|
|
62
|
|
63 =item C<$obj->Navigate($query)>
|
|
64
|
|
65 C<$query>.
|
|
66 .
|
|
67 , .
|
|
68
|
|
69 , C<undef>.
|
|
70
|
|
71 =item C<$obj->Back()>
|
|
72
|
|
73 , .
|
|
74
|
|
75 , C<undef>.
|
|
76
|
|
77 =back
|
|
78
|
|
79 =cut |