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   2760 use strict;
  3         4  
  3         73  
5 3     3   8 use warnings;
  3         4  
  3         72  
6              
7 3     3   9 use Scalar::Util qw(blessed);
  3         2  
  3         178  
8              
9 3     3   631 use Tree::Binary::Visitor::Base;
  3         14  
  3         438  
10              
11             our $VERSION = '1.07';
12              
13             our @ISA = qw(Tree::Binary::Visitor::Base);
14              
15             # visit routine
16             sub visit {
17 86     86 1 992 my ($self, $tree) = @_;
18 86 100 100     431 (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         74 my @results;
22             my $func;
23 82 100       140 if ($self->{_filter_function}) {
24 1     7   3 $func = sub { push @results => $self->{_filter_function}->(@_) };
  7         11  
25             }
26             else {
27 81     3483   250 $func = sub { push @results => $_[0]->getNodeValue() };
  3483         4245  
28             }
29             # then recursively to all its children
30             # if the object is configured that way
31 82         169 $tree->traverse($func);
32             # now store the results we got
33 82         224 $self->setResults(@results);
34             }
35              
36              
37             1;
38              
39             __END__