line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Tree::Simple::Visitor::BreadthFirstTraversal; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
63573
|
use strict; |
|
4
|
|
|
|
|
20
|
|
|
4
|
|
|
|
|
110
|
|
4
|
4
|
|
|
4
|
|
18
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
141
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.16'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
20
|
use Scalar::Util qw(blessed); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
190
|
|
9
|
|
|
|
|
|
|
|
10
|
4
|
|
|
4
|
|
23
|
use base qw(Tree::Simple::Visitor); |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
1379
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
6
|
|
|
6
|
1
|
5267
|
my ($_class) = @_; |
14
|
6
|
|
33
|
|
|
33
|
my $class = ref($_class) || $_class; |
15
|
6
|
|
|
|
|
10
|
my $visitor = {}; |
16
|
6
|
|
|
|
|
14
|
bless($visitor, $class); |
17
|
6
|
|
|
|
|
20
|
$visitor->_init(); |
18
|
6
|
|
|
|
|
65
|
return $visitor; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
22
|
6
|
|
|
6
|
|
11
|
my ($self) = @_; |
23
|
6
|
|
|
|
|
28
|
$self->SUPER::_init(); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub visit { |
27
|
11
|
|
|
11
|
1
|
3759
|
my ($self, $tree) = @_; |
28
|
11
|
100
|
100
|
|
|
92
|
(blessed($tree) && $tree->isa("Tree::Simple")) |
29
|
|
|
|
|
|
|
|| die "Insufficient Arguments : You must supply a valid Tree::Simple object"; |
30
|
|
|
|
|
|
|
# create a holder for our results |
31
|
7
|
|
|
|
|
13
|
my @results; |
32
|
|
|
|
|
|
|
# get our filter function |
33
|
7
|
|
|
|
|
27
|
my $filter_function = $self->getNodeFilter(); |
34
|
|
|
|
|
|
|
# now create a queue for |
35
|
|
|
|
|
|
|
# processing depth first |
36
|
7
|
|
|
|
|
33
|
my @queue; |
37
|
|
|
|
|
|
|
# if we are to include the trunk |
38
|
7
|
100
|
|
|
|
21
|
if ($self->includeTrunk()) { |
39
|
|
|
|
|
|
|
# then enqueue that |
40
|
3
|
|
|
|
|
20
|
@queue = ($tree); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
# if we are not including the trunk |
43
|
|
|
|
|
|
|
else { |
44
|
|
|
|
|
|
|
# then we enqueue all the |
45
|
|
|
|
|
|
|
# trunks children instead |
46
|
4
|
|
|
|
|
46
|
@queue = ($tree->getAllChildren()); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
# until our queue is empty |
49
|
7
|
|
|
|
|
41
|
while (scalar(@queue) != 0){ |
50
|
|
|
|
|
|
|
# get the first item off the queue |
51
|
78
|
|
|
|
|
350
|
my $current_tree = shift @queue; |
52
|
|
|
|
|
|
|
# enqueue all the current tree's children |
53
|
78
|
|
|
|
|
135
|
push @queue => $current_tree->getAllChildren(); |
54
|
|
|
|
|
|
|
# now collect the results |
55
|
78
|
100
|
|
|
|
461
|
push @results => (($filter_function) ? |
56
|
|
|
|
|
|
|
$filter_function->($current_tree) |
57
|
|
|
|
|
|
|
: |
58
|
|
|
|
|
|
|
$current_tree->getNodeValue()); |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
# store our results |
61
|
3
|
|
|
|
|
34
|
$self->setResults(@results); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
1; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
__END__ |