line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::PathToRoot; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
19751
|
use strict; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
6
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.15'; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
6
|
use Scalar::Util qw(blessed); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
189
|
|
9
|
|
|
|
|
|
|
|
10
|
2
|
|
|
2
|
|
8
|
use base qw(Tree::Simple::Visitor); |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
932
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
2
|
|
|
2
|
1
|
2081
|
my ($_class) = @_; |
14
|
2
|
|
33
|
|
|
13
|
my $class = ref($_class) || $_class; |
15
|
2
|
|
|
|
|
5
|
my $visitor = {}; |
16
|
2
|
|
|
|
|
3
|
bless($visitor, $class); |
17
|
2
|
|
|
|
|
11
|
$visitor->_init(); |
18
|
2
|
|
|
|
|
18
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub visit { |
22
|
8
|
|
|
8
|
1
|
3397
|
my ($self, $tree) = @_; |
23
|
8
|
100
|
100
|
|
|
84
|
(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
|
|
|
|
|
5
|
my @path; |
27
|
|
|
|
|
|
|
# we need to climb up the tree and |
28
|
|
|
|
|
|
|
# collect the nodes |
29
|
4
|
|
|
|
|
23
|
my $filter_function = $self->getNodeFilter(); |
30
|
4
|
|
|
|
|
11
|
my $current_tree = $tree; |
31
|
4
|
|
|
|
|
8
|
until ($current_tree->isRoot()) { |
32
|
7
|
100
|
|
|
|
49
|
unshift @path => ($filter_function ? |
33
|
|
|
|
|
|
|
$filter_function->($current_tree) |
34
|
|
|
|
|
|
|
: |
35
|
|
|
|
|
|
|
$current_tree->getNodeValue()); |
36
|
7
|
|
|
|
|
29
|
$current_tree = $current_tree->getParent(); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
# now grab the trunk if specified |
39
|
4
|
50
|
|
|
|
26
|
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
|
|
|
|
|
48
|
$self->setResults(@path); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub getPath { |
48
|
4
|
|
|
4
|
1
|
1143
|
my ($self) = @_; |
49
|
4
|
|
|
|
|
10
|
return $self->getResults(); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub getPathAsString { |
53
|
4
|
|
|
4
|
1
|
29
|
my ($self, $delimiter) = @_; |
54
|
4
|
|
100
|
|
|
10
|
$delimiter ||= ", "; |
55
|
4
|
|
|
|
|
10
|
return join $delimiter => $self->getResults(); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
1; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__END__ |