Visitor/PostOrderTraversal.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 6 / 6 Conditioncond 77.7% 7 / 9 MC/DCmcdc 66.6% 4 / 6 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 93.5% 58 / 62 CC 8 SCAR 11.0
CC
8
Cov
96%
__ANON__
5.0
visit
3.0
new
2.0
CRAP 3.0
« Visitor/FromNestedHash.pm ↑ Summary Visitor/CreateDirectoryTree.pm »
1 package Tree::Simple::Visitor::PostOrderTraversal;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '0.16';
7  
8 1 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 1 my ($_class) = @_;
14 1 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $_class || $_class
ref $_class $_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
ABresult
1X1
011
000
15 1 my $visitor = {};
16 1 bless($visitor, $class);
17 1 $visitor->_init();
18 1 return $visitor;
19 }
20  
21 6 ▶sub visit {
Subroutine visit: called CC=3 SCAR=11.0
Pod documented
22 6 my ($self, $tree) = @_;
23 6 ▶ (blessed($tree) && $tree->isa("Tree::Simple"))
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($tree) and $tree->isa("Tree::Simple") or die "Insufficient Arguments : You must supply a valid Tree::Simple object" 2 4 6
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
312
MC/DC100%2/2
builtin::blessed($tree) and $tree->isa("Tree::Simple")
builtin::blessed($tree) $tree->isa("Tree::Simple")
Truth table100%3/3
A and B
A= builtin::blessed($tree)B= $tree->isa("Tree::Simple")
ABresult
0X0
100
111
24 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
25 # get our filter function
26 2 my $filter_function = $self->getNodeFilter();
27 # use an inner subroutine to accomplish
28 # this traversal using recursion
29 32 ▶ my $_postOrderTraversal = sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
30 32 my ($current_tree, $traversal_function) = @_;
31 # get a temporary results container
32 32 my @results;
33 # process each child
34 32 foreach my $child ($current_tree->getAllChildren()) {
35 # recurse our inner subroutine by passing itself
36 # to itself, and then collect the results of this
37 # recursion
38 30 push @results => $traversal_function->($child, $traversal_function);
39 }
40 # if we are root and we are not including the trunk then
41 # we can return our results now
42 32 ▶ return @results if $current_tree->isRoot() && !$self->includeTrunk();
Branch: 1 branch
BranchTrueFalseTotal
if $current_tree->isRoot and not $self->includeTrunk 1 31 32
Condition100%3/3
$current_tree->isRoot and not $self->includeTrunk
!ll&&!rl&&r
3011
MC/DC100%2/2
$current_tree->isRoot and not $self->includeTrunk
$current_tree->isRoot not $self->includeTrunk
Truth table100%3/3
A and not(B)
A= $current_tree->isRootB= not $self->includeTrunk
ABresult
0X0
100
111
43 # however, if we don't meet those conditions, then we
44 # need to process the current tree and add it to our
45 # results
46 31 ▶ push @results => (($filter_function) ?
Branch: 1 branch
BranchTrueFalseTotal
$filter_function ? : 16 15 31
47 $filter_function->($current_tree)
48 :
49 $current_tree->getNodeValue());
50 # and then return the results
51 31 return @results;
52 2 };
53 # now store the results in our object
54 2 $self->setResults($_postOrderTraversal->($tree, $_postOrderTraversal));
55 }
56  
57 1 1;
58  
59 __END__
« Visitor/FromNestedHash.pm ↑ Summary Visitor/CreateDirectoryTree.pm »