Visitor/PathToRoot.pm

filter: Statementstmt 100% 35 / 35 Branchbran 90.0% 9 / 10 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 92.8% 65 / 70 CC 9 SCAR 13.6
CC
9
Cov
94%
visit
7.0
new
2.0
getPathAsString
2.0
CRAP 3.9
« Visitor/FromNestedArray.pm ↑ Summary Visitor/BreadthFirstTraversal.pm »
1 package Tree::Simple::Visitor::PathToRoot;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 our $VERSION = '0.16';
7  
8 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 2 my ($_class) = @_;
14 2 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
020
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 2 my $visitor = {};
16 2 bless($visitor, $class);
17 2 $visitor->_init();
18 2 return $visitor;
19 }
20  
21 8 ▶sub visit {
Subroutine visit: called CC=7 SCAR=19.5
Pod documented
22 8 my ($self, $tree) = @_;
23 8 ▶ (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" 4 4 8
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
314
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 # create an array for our path
26 4 my @path;
27 # we need to climb up the tree and
28 # collect the nodes
29 4 my $filter_function = $self->getNodeFilter();
30 4 my $current_tree = $tree;
31 4 ▶ until ($current_tree->isRoot()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($current_tree->isRoot) 7 4 11
32 7 ▶ unshift @path => ($filter_function ?
Branch: 1 branch
BranchTrueFalseTotal
$filter_function ? : 4 3 7
33 $filter_function->($current_tree)
34 :
35 $current_tree->getNodeValue());
36 7 $current_tree = $current_tree->getParent();
37 }
38 # now grab the trunk if specified
39 4 ▶ unshift @path => ($filter_function ?
Branch: 2 branches
BranchTrueFalseTotal
if $self->includeTrunk 2 2 4
$filter_function ? : 2 0 2
40 $filter_function->($current_tree)
41 :
42 $current_tree->getNodeValue()) if $self->includeTrunk();
43 # now store our path in results
44 4 $self->setResults(@path);
45 }
46  
47 4 ▶sub getPath {
Subroutine getPath: called CC=1 SCAR=0.0
Pod documented
48 4 my ($self) = @_;
49 4 return $self->getResults();
50 }
51  
52 4 ▶sub getPathAsString {
Subroutine getPathAsString: called CC=2 SCAR=6.9
Pod documented
53 4 my ($self, $delimiter) = @_;
54 4 ▶ $delimiter ||= ", ";
Condition100%2/2
$delimiter ||= ", "
l!l
22
MC/DC100%1/1
$delimiter ||= ", "
$delimiter
Truth table100%2/2
A
A= $delimiter
Aresult
11
00
55 4 return join $delimiter => $self->getResults();
56 }
57  
58 2 1;
59  
60 __END__
« Visitor/FromNestedArray.pm ↑ Summary Visitor/BreadthFirstTraversal.pm »