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              
2             package Tree::Binary::Visitor::PostOrderTraversal;
3              
4 3     3   1305 use strict;
  3         4  
  3         67  
5 3     3   7 use warnings;
  3         3  
  3         66  
6              
7 3     3   7 use Scalar::Util qw(blessed);
  3         3  
  3         119  
8              
9 3     3   10 use Tree::Binary::Visitor::Base;
  3         2  
  3         606  
10              
11             our $VERSION = '1.08';
12              
13             our @ISA = qw(Tree::Binary::Visitor::Base);
14              
15             # visit routine
16             sub visit {
17 26     26 1 1038 my ($self, $tree) = @_;
18 26 100 100     185 (blessed($tree) && $tree->isa("Tree::Binary"))
19             || die "Insufficient Arguments : You must supply a valid Tree::Binary object";
20             # get all things set up
21 22         33 my @results;
22             my $func;
23 22 100       47 if ($self->{_filter_function}) {
24 1     7   3 $func = sub { push @results => $self->{_filter_function}->(@_) };
  7         10  
25             }
26             else {
27 21     1205   73 $func = sub { push @results => $_[0]->getNodeValue() };
  1205         1395  
28             }
29             # apply the function recursively to all its children
30              
31             my $_postOrderTraverse = sub {
32 1212     1212   807 my ($tree, $func, $traversal_function) = @_;
33 1212 100       1427 $traversal_function->($tree->getLeft(), $func, $traversal_function) if $tree->hasLeft();
34 1212 100       1556 $traversal_function->($tree->getRight(), $func, $traversal_function) if $tree->hasRight();
35 1212         1111 $func->($tree);
36 22         77 };
37 22         41 $_postOrderTraverse->($tree, $func, $_postOrderTraverse);
38              
39             # now store the results we got
40 22         68 $self->setResults(@results);
41             }
42              
43             1;
44              
45             __END__