File Coverage

blib/lib/Tree/Binary/Visitor/PostOrderTraversal.pm
Criterion Covered Total %
statement 27 27 100.0
branch 8 8 100.0
condition 3 3 100.0
subroutine 8 8 100.0
pod 1 1 100.0
total 47 47 100.0


line stmt bran cond sub pod time code
1             package Tree::Binary::Visitor::PostOrderTraversal;
2              
3 3     3   1562 use strict;
  3         6  
  3         72  
4 3     3   12 use warnings;
  3         5  
  3         74  
5              
6 3     3   40 use Scalar::Util qw(blessed);
  3         7  
  3         140  
7              
8 3     3   16 use Tree::Binary::Visitor::Base;
  3         5  
  3         752  
9              
10             our $VERSION = '1.09';
11              
12             our @ISA = qw(Tree::Binary::Visitor::Base);
13              
14             # visit routine
15             sub visit {
16 26     26 1 958 my ($self, $tree) = @_;
17 26 100 100     174 (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 22         49 my @results;
21             my $func;
22 22 100       54 if ($self->{_filter_function}) {
23 1     7   4 $func = sub { push @results => $self->{_filter_function}->(@_) };
  7         11  
24             }
25             else {
26 21     1008   97 $func = sub { push @results => $_[0]->getNodeValue() };
  1008         1708  
27             }
28             # apply the function recursively to all its children
29              
30             my $_postOrderTraverse = sub {
31 1015     1015   1732 my ($tree, $func, $traversal_function) = @_;
32 1015 100       1588 $traversal_function->($tree->getLeft(), $func, $traversal_function) if $tree->hasLeft();
33 1015 100       1775 $traversal_function->($tree->getRight(), $func, $traversal_function) if $tree->hasRight();
34 1015         1582 $func->($tree);
35 22         130 };
36 22         61 $_postOrderTraverse->($tree, $func, $_postOrderTraverse);
37              
38             # now store the results we got
39 22         85 $self->setResults(@results);
40             }
41              
42             1;
43              
44             __END__