annotate Lib/IMPL/DOM/Navigator.pm @ 18:818c74b038ae

DOM Schema + tests
author Sergey
date Thu, 10 Sep 2009 17:42:47 +0400
parents bb8d67f811ea
children 7f00786f8210
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
1 package IMPL::DOM::Navigator;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
2 use strict;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
3 use warnings;
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
4
11
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
5 use base qw(IMPL::Object);
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
6 use IMPL::Class::Property;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
7 use IMPL::Class::Property::Direct;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
8 BEGIN {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
9 public _direct property Path => prop_get | owner_set;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
10 public _direct property Current => prop_get | owner_set;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
11 }
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
12
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
13 sub CTOR {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
14 my ($this,$CurrentNode) = @_;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
15
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
16 $this->{$Current} = $CurrentNode or die IMPL::InvalidArgumentException("A starting node is a required paramater");
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
17 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
18
11
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
19 sub Navigate {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
20 my ($this,$query) = @_;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
21
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
22 if ( my ($newNode) = $this->{$Current}->selectNodes($query) ) {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
23 push @{$this->{$Path}}, $this->{$Current};
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
24 return $this->{$Current} = $newNode;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
25 } else {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
26 return undef;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
27 }
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
28 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
29
18
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
30 sub _NavigateNode {
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
31 my ($this,$newNode) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
32 push @{$this->{$Path}}, $this->{$Current};
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
33 return $this->{$Current} = $newNode;
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
34 }
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
35
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
36 sub _NavigateNodeStirct {
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
37 my ($this,$newNode) = @_;
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
38
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
39 die new IMPL::InvalidOperationException("A newNode doesn't belongs to the current") unless $newNode->parentNode == $this->{$Current};
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
40 push @{$this->{$Path}}, $this->{$Current};
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
41 return $this->{$Current} = $newNode;
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
42 }
818c74b038ae DOM Schema + tests
Sergey
parents: 13
diff changeset
43
11
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
44 sub Back {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
45 my ($this) = @_;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
46
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
47 if ( my $newNode = $this->{$Path} ? pop @{$this->{$Path}} : undef ) {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
48 return $this->{$Current} = $newNode;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
49 } else {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
50 return undef;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
51 }
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
52 }
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
53
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
54 sub PathToString {
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
55 my $this = shift;
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
56
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
57 join('/',map $_->nodeName, $this->{$Path} ? (@{$this->{$Path}}, $this->{$Current}) : $this->{$Current});
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
58 }
0
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
59
03e58a454b20 Создан репозитарий
Sergey
parents:
diff changeset
60 1;
11
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
61
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
62 __END__
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
63 =pod
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
64
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
65 =head1 DESCRIPTION
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
66
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
67 DOM .
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
68
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
69 =head1 METHODS
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
70
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
71 =over
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
72
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
73 =item C<$obj->new($nodeStart)>
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
74
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
75 .
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
76
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
77 =item C<$obj->Navigate($query)>
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
78
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
79 C<$query>.
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
80 .
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
81 , .
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
82
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
83 , C<undef>.
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
84
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
85 =item C<$obj->Back()>
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
86
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
87 , .
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
88
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
89 , C<undef>.
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
90
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
91 =back
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
92
75980091813b DOM и навигация
Sergey
parents: 0
diff changeset
93 =cut