line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::GetAllDescendents; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
32184
|
use strict; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
130
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
130
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.14'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
224
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
14
|
use base qw(Tree::Simple::Visitor); |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
1350
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
7
|
|
|
7
|
1
|
1400
|
my ($_class) = @_; |
14
|
7
|
|
33
|
|
|
41
|
my $class = ref($_class) || $_class; |
15
|
7
|
|
|
|
|
14
|
my $visitor = {}; |
16
|
7
|
|
|
|
|
12
|
bless($visitor, $class); |
17
|
7
|
|
|
|
|
32
|
$visitor->_init(); |
18
|
7
|
|
|
|
|
78
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
22
|
7
|
|
|
7
|
|
33
|
my ($self) = @_; |
23
|
7
|
|
|
|
|
32
|
$self->{traversal_method} = undef; |
24
|
7
|
|
|
|
|
38
|
$self->SUPER::_init(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub setTraversalMethod { |
28
|
5
|
|
|
5
|
1
|
1073
|
my ($self, $visitor) = @_; |
29
|
5
|
100
|
100
|
|
|
66
|
(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
|
6932
|
my ($self, $tree) = @_; |
36
|
13
|
100
|
100
|
|
|
139
|
(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
|
|
|
|
|
19
|
my @descendents; |
41
|
9
|
|
|
|
|
35
|
my $filter_function = $self->getNodeFilter(); |
42
|
|
|
|
|
|
|
# build a collection function |
43
|
|
|
|
|
|
|
my $collection_function = sub { |
44
|
225
|
|
|
225
|
|
2412
|
my ($t) = @_; |
45
|
225
|
100
|
|
|
|
422
|
push @descendents => ($filter_function ? |
46
|
|
|
|
|
|
|
$filter_function->($t) |
47
|
|
|
|
|
|
|
: |
48
|
|
|
|
|
|
|
$t->getNodeValue()); |
49
|
9
|
|
|
|
|
68
|
}; |
50
|
|
|
|
|
|
|
# and collect our descendents with the |
51
|
|
|
|
|
|
|
# traversal method specified |
52
|
9
|
100
|
|
|
|
26
|
unless (defined($self->{traversal_method})) { |
53
|
8
|
|
|
|
|
24
|
$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
|
|
|
|
|
118
|
$self->setResults(@descendents); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub getAllDescendents { |
64
|
6
|
|
|
6
|
1
|
44
|
my ($self) = @_; |
65
|
6
|
|
|
|
|
13
|
return $self->getResults(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |