| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::GetAllDescendents; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
21625
|
use strict; |
|
|
3
|
|
|
|
|
5
|
|
|
|
3
|
|
|
|
|
67
|
|
|
4
|
3
|
|
|
3
|
|
8
|
use warnings; |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
93
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
10
|
use Scalar::Util qw(blessed); |
|
|
3
|
|
|
|
|
4
|
|
|
|
3
|
|
|
|
|
184
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
10
|
use base qw(Tree::Simple::Visitor); |
|
|
3
|
|
|
|
|
12
|
|
|
|
3
|
|
|
|
|
1033
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
|
13
|
7
|
|
|
7
|
1
|
1889
|
my ($_class) = @_; |
|
14
|
7
|
|
33
|
|
|
30
|
my $class = ref($_class) || $_class; |
|
15
|
7
|
|
|
|
|
9
|
my $visitor = {}; |
|
16
|
7
|
|
|
|
|
10
|
bless($visitor, $class); |
|
17
|
7
|
|
|
|
|
26
|
$visitor->_init(); |
|
18
|
7
|
|
|
|
|
45
|
return $visitor; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
|
22
|
7
|
|
|
7
|
|
7
|
my ($self) = @_; |
|
23
|
7
|
|
|
|
|
23
|
$self->{traversal_method} = undef; |
|
24
|
7
|
|
|
|
|
27
|
$self->SUPER::_init(); |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub setTraversalMethod { |
|
28
|
5
|
|
|
5
|
1
|
910
|
my ($self, $visitor) = @_; |
|
29
|
5
|
100
|
100
|
|
|
64
|
(blessed($visitor) && $visitor->isa("Tree::Simple::Visitor")) |
|
30
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Simple::Visitor object"; |
|
31
|
1
|
|
|
|
|
3
|
$self->{traversal_method} = $visitor; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub visit { |
|
35
|
13
|
|
|
13
|
1
|
6462
|
my ($self, $tree) = @_; |
|
36
|
13
|
100
|
100
|
|
|
124
|
(blessed($tree) && $tree->isa("Tree::Simple")) |
|
37
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Simple object"; |
|
38
|
|
|
|
|
|
|
# create an closure for the |
|
39
|
|
|
|
|
|
|
# collection function |
|
40
|
9
|
|
|
|
|
14
|
my @descendents; |
|
41
|
9
|
|
|
|
|
33
|
my $filter_function = $self->getNodeFilter(); |
|
42
|
|
|
|
|
|
|
# build a collection function |
|
43
|
|
|
|
|
|
|
my $collection_function = sub { |
|
44
|
225
|
|
|
225
|
|
1661
|
my ($t) = @_; |
|
45
|
225
|
100
|
|
|
|
316
|
push @descendents => ($filter_function ? |
|
46
|
|
|
|
|
|
|
$filter_function->($t) |
|
47
|
|
|
|
|
|
|
: |
|
48
|
|
|
|
|
|
|
$t->getNodeValue()); |
|
49
|
9
|
|
|
|
|
53
|
}; |
|
50
|
|
|
|
|
|
|
# and collect our descendents with the |
|
51
|
|
|
|
|
|
|
# traversal method specified |
|
52
|
9
|
100
|
|
|
|
19
|
unless (defined($self->{traversal_method})) { |
|
53
|
8
|
|
|
|
|
18
|
$tree->traverse($collection_function); |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
else { |
|
56
|
1
|
|
|
|
|
5
|
$self->{traversal_method}->setNodeFilter($collection_function); |
|
57
|
1
|
|
|
|
|
5
|
$self->{traversal_method}->visit($tree); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
# now store our collected descendents |
|
60
|
9
|
|
|
|
|
96
|
$self->setResults(@descendents); |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub getAllDescendents { |
|
64
|
6
|
|
|
6
|
1
|
48
|
my ($self) = @_; |
|
65
|
6
|
|
|
|
|
13
|
return $self->getResults(); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |