File Coverage

blib/lib/Tree/Binary/Visitor/PreOrderTraversal.pm
Criterion Covered Total %
statement 22 22 100.0
branch 4 4 100.0
condition 3 3 100.0
subroutine 7 7 100.0
pod 1 1 100.0
total 37 37 100.0


line stmt bran cond sub pod time code
1              
2             package Tree::Binary::Visitor::PreOrderTraversal;
3              
4 3     3   3032 use strict;
  3         3  
  3         71  
5 3     3   8 use warnings;
  3         3  
  3         71  
6              
7 3     3   9 use Scalar::Util qw(blessed);
  3         3  
  3         172  
8              
9 3     3   685 use Tree::Binary::Visitor::Base;
  3         14  
  3         425  
10              
11             our $VERSION = '1.08';
12              
13             our @ISA = qw(Tree::Binary::Visitor::Base);
14              
15             # visit routine
16             sub visit {
17 86     86 1 1020 my ($self, $tree) = @_;
18 86 100 100     445 (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 82         91 my @results;
22             my $func;
23 82 100       144 if ($self->{_filter_function}) {
24 1     7   3 $func = sub { push @results => $self->{_filter_function}->(@_) };
  7         10  
25             }
26             else {
27 81     4799   226 $func = sub { push @results => $_[0]->getNodeValue() };
  4799         5374  
28             }
29             # then recursively to all its children
30             # if the object is configured that way
31 82         165 $tree->traverse($func);
32             # now store the results we got
33 82         208 $self->setResults(@results);
34             }
35              
36              
37             1;
38              
39             __END__