comparison Lib/IMPL/DOM/Navigator.pm @ 11:75980091813b

DOM и навигация
author Sergey
date Wed, 02 Sep 2009 17:47:44 +0400
parents 03e58a454b20
children bb8d67f811ea
comparison
equal deleted inserted replaced
10:63f6653b094e 11:75980091813b
1 package IMPL::DOM::Navigator; 1 package IMPL::DOM::Navigator;
2 use strict; 2 use strict;
3 use warnings; 3 use warnings;
4 4
5 require Exporter; 5 use base qw(IMPL::Object);
6 our @ISA = qw(Exporter); 6 use IMPL::Class::Property;
7 our @EXPORT_OK = qw(); 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 }
8 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 }
9 18
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 }
29
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 }
10 45
11 1; 46 1;
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