line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Binary::Visitor::InOrderTraversal; |
2
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
3222
|
use strict; |
|
5
|
|
|
|
|
12
|
|
|
5
|
|
|
|
|
121
|
|
4
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
125
|
|
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
31
|
use Scalar::Util qw(blessed); |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
206
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
754
|
use Tree::Binary::Visitor::Base; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
1194
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '1.09'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Tree::Binary::Visitor::Base); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# visit routine |
15
|
|
|
|
|
|
|
sub visit { |
16
|
108
|
|
|
108
|
1
|
1046
|
my ($self, $tree) = @_; |
17
|
108
|
100
|
100
|
|
|
515
|
(blessed($tree) && $tree->isa("Tree::Binary")) |
18
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Binary object"; |
19
|
|
|
|
|
|
|
# get all things set up |
20
|
104
|
|
|
|
|
200
|
my @results; |
21
|
|
|
|
|
|
|
my $func; |
22
|
104
|
100
|
|
|
|
195
|
if ($self->{_filter_function}) { |
23
|
1
|
|
|
7
|
|
4
|
$func = sub { push @results => $self->{_filter_function}->(@_) }; |
|
7
|
|
|
|
|
12
|
|
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
else { |
26
|
103
|
|
|
4178
|
|
397
|
$func = sub { push @results => $_[0]->getNodeValue() }; |
|
4178
|
|
|
|
|
6682
|
|
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
# apply the function recursively to all its children |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $_inOrderTraverse = sub { |
31
|
4185
|
|
|
4185
|
|
5854
|
my ($tree, $func, $traversal_function) = @_; |
32
|
4185
|
100
|
|
|
|
6536
|
$traversal_function->($tree->getLeft(), $func, $traversal_function) if $tree->hasLeft(); |
33
|
4185
|
|
|
|
|
8746
|
$func->($tree); |
34
|
4185
|
100
|
|
|
|
6786
|
$traversal_function->($tree->getRight(), $func, $traversal_function) if $tree->hasRight(); |
35
|
104
|
|
|
|
|
363
|
}; |
36
|
104
|
|
|
|
|
250
|
$_inOrderTraverse->($tree, $func, $_inOrderTraverse); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# now store the results we got |
39
|
104
|
|
|
|
|
336
|
$self->setResults(@results); |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
__END__ |