line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::GetAllDescendents; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
62548
|
use strict; |
|
3
|
|
|
|
|
14
|
|
|
3
|
|
|
|
|
76
|
|
4
|
3
|
|
|
3
|
|
13
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
106
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
7
|
|
|
|
|
|
|
|
8
|
3
|
|
|
3
|
|
14
|
use Scalar::Util qw(blessed); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
160
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
16
|
use base qw(Tree::Simple::Visitor); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
1286
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
7
|
|
|
7
|
1
|
2239
|
my ($_class) = @_; |
14
|
7
|
|
33
|
|
|
36
|
my $class = ref($_class) || $_class; |
15
|
7
|
|
|
|
|
17
|
my $visitor = {}; |
16
|
7
|
|
|
|
|
17
|
bless($visitor, $class); |
17
|
7
|
|
|
|
|
26
|
$visitor->_init(); |
18
|
7
|
|
|
|
|
63
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
22
|
7
|
|
|
7
|
|
21
|
my ($self) = @_; |
23
|
7
|
|
|
|
|
31
|
$self->{traversal_method} = undef; |
24
|
7
|
|
|
|
|
34
|
$self->SUPER::_init(); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub setTraversalMethod { |
28
|
5
|
|
|
5
|
1
|
1099
|
my ($self, $visitor) = @_; |
29
|
5
|
100
|
100
|
|
|
48
|
(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
|
6721
|
my ($self, $tree) = @_; |
36
|
13
|
100
|
100
|
|
|
110
|
(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
|
|
|
|
|
16
|
my @descendents; |
41
|
9
|
|
|
|
|
46
|
my $filter_function = $self->getNodeFilter(); |
42
|
|
|
|
|
|
|
# build a collection function |
43
|
|
|
|
|
|
|
my $collection_function = sub { |
44
|
225
|
|
|
225
|
|
3508
|
my ($t) = @_; |
45
|
225
|
100
|
|
|
|
416
|
push @descendents => ($filter_function ? |
46
|
|
|
|
|
|
|
$filter_function->($t) |
47
|
|
|
|
|
|
|
: |
48
|
|
|
|
|
|
|
$t->getNodeValue()); |
49
|
9
|
|
|
|
|
81
|
}; |
50
|
|
|
|
|
|
|
# and collect our descendents with the |
51
|
|
|
|
|
|
|
# traversal method specified |
52
|
9
|
100
|
|
|
|
25
|
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
|
|
|
|
|
7
|
$self->{traversal_method}->visit($tree); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
# now store our collected descendents |
60
|
9
|
|
|
|
|
174
|
$self->setResults(@descendents); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub getAllDescendents { |
64
|
6
|
|
|
6
|
1
|
74
|
my ($self) = @_; |
65
|
6
|
|
|
|
|
21
|
return $self->getResults(); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
1; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
__END__ |