line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::PathToRoot; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
59789
|
use strict; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
51
|
|
4
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
70
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
9
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
107
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
17
|
use base qw(Tree::Simple::Visitor); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
942
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
1
|
3104
|
my ($_class) = @_; |
14
|
2
|
|
33
|
|
|
13
|
my $class = ref($_class) || $_class; |
15
|
2
|
|
|
|
|
4
|
my $visitor = {}; |
16
|
2
|
|
|
|
|
4
|
bless($visitor, $class); |
17
|
2
|
|
|
|
|
14
|
$visitor->_init(); |
18
|
2
|
|
|
|
|
32
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub visit { |
22
|
8
|
|
|
8
|
1
|
4392
|
my ($self, $tree) = @_; |
23
|
8
|
100
|
100
|
|
|
69
|
(blessed($tree) && $tree->isa("Tree::Simple")) |
24
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Simple object"; |
25
|
|
|
|
|
|
|
# create an array for our path |
26
|
4
|
|
|
|
|
7
|
my @path; |
27
|
|
|
|
|
|
|
# we need to climb up the tree and |
28
|
|
|
|
|
|
|
# collect the nodes |
29
|
4
|
|
|
|
|
13
|
my $filter_function = $self->getNodeFilter(); |
30
|
4
|
|
|
|
|
18
|
my $current_tree = $tree; |
31
|
4
|
|
|
|
|
8
|
until ($current_tree->isRoot()) { |
32
|
7
|
100
|
|
|
|
56
|
unshift @path => ($filter_function ? |
33
|
|
|
|
|
|
|
$filter_function->($current_tree) |
34
|
|
|
|
|
|
|
: |
35
|
|
|
|
|
|
|
$current_tree->getNodeValue()); |
36
|
7
|
|
|
|
|
33
|
$current_tree = $current_tree->getParent(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# now grab the trunk if specified |
39
|
4
|
50
|
|
|
|
29
|
unshift @path => ($filter_function ? |
|
|
100
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$filter_function->($current_tree) |
41
|
|
|
|
|
|
|
: |
42
|
|
|
|
|
|
|
$current_tree->getNodeValue()) if $self->includeTrunk(); |
43
|
|
|
|
|
|
|
# now store our path in results |
44
|
4
|
|
|
|
|
41
|
$self->setResults(@path); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub getPath { |
48
|
4
|
|
|
4
|
1
|
1872
|
my ($self) = @_; |
49
|
4
|
|
|
|
|
9
|
return $self->getResults(); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub getPathAsString { |
53
|
4
|
|
|
4
|
1
|
35
|
my ($self, $delimiter) = @_; |
54
|
4
|
|
100
|
|
|
12
|
$delimiter ||= ", "; |
55
|
4
|
|
|
|
|
20
|
return join $delimiter => $self->getResults(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |