Visitor/FromNestedArray.pm

filter: Statementstmt 100% 48 / 48 Branchbran 95.0% 19 / 20 Conditioncond 76.9% 10 / 13 MC/DCmcdc 50.0% 4 / 8 Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 92.0% 93 / 101 CC 15 SCAR 15.0
CC
15
Cov
95%
setArrayTree
7.0
_buildTree
6.0
visit
3.0
CRAP 4.5
« Visitor/LoadDirectoryTree.pm ↑ Summary Visitor/PathToRoot.pm »
1 package Tree::Simple::Visitor::FromNestedArray;
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 4 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 4 my ($_class) = @_;
14 4 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
040
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 4 my $visitor = {};
16 4 bless($visitor, $class);
17 4 $visitor->_init();
18 4 return $visitor;
19 }
20  
21 4 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
22 4 my ($self) = @_;
23 4 $self->{array_tree} = undef;
24 4 $self->SUPER::_init();
25 }
26  
27 9 ▶sub setArrayTree {
Subroutine setArrayTree: called CC=7 SCAR=19.5
Pod documented
28 9 my ($self, $array_tree) = @_;
29 9 ▶ (defined($array_tree) && ref($array_tree) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
defined $array_tree and ref $array_tree eq "ARRAY" or die "Insufficient Arguments : You must supply a valid ARRAY reference" 7 2 9
Condition100%3/3
defined $array_tree and ref $array_tree eq "ARRAY"
!ll&&!rl&&r
117
MC/DC100%2/2
defined $array_tree and ref $array_tree eq "ARRAY"
defined $array_tree ref $array_tree eq "ARRAY"
Truth table100%3/3
A and B
A= defined $array_treeB= ref $array_tree eq "ARRAY"
ABresult
0X0
100
111
30 || die "Insufficient Arguments : You must supply a valid ARRAY reference";
31 # validate the tree ...
32 # it must not be empty
33 7 ▶ (scalar @{$array_tree} != 0)
Branch: 1 branch
BranchTrueFalseTotal
scalar @{$array_tree;} != 0 or die "Insufficient Arguments : The array tree provided is empty" 6 1 7
34 || die "Insufficient Arguments : The array tree provided is empty";
35 # it's first element must not be an array
36 6 ▶ (ref($array_tree->[0]) ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
ref $array_tree->[0] ne "ARRAY" or die "Incorrect Object Type : The first value in the array tree is an array reference" 5 1 6
37 || die "Incorrect Object Type : The first value in the array tree is an array reference";
38 # and it must be a single rooted tree
39 5 ▶ (ref($array_tree->[1]) eq 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
if defined $array_tree->[1] 5 0 5
Condition75%3/4
defined $array_tree->[1] && (ref $array_tree->[1] eq 'ARRAY' || die('Incorrect Object Type : The second value in the array tree must be an array reference'))
!ll
05
ref $array_tree->[1] eq "ARRAY" or die "Incorrect Object Type : The second value in the array tree must be an array reference"
l!l
41
MC/DC0%0/2
defined $array_tree->[1] && (ref $array_tree->[1] eq 'ARRAY' || die('Incorrect Object Type : The second value in the array tree must be an array reference'))
defined $array_tree->[1] ref $array_tree->[1] eq "ARRAY"
Truth table33%1/3
A && B
A= defined $array_tree->[1]B= ref $array_tree->[1] eq "ARRAY"
ABresult
0X0
100
111
40 || die "Incorrect Object Type : The second value in the array tree must be an array reference"
41 if defined($array_tree->[1]);
42 4 $self->{array_tree} = $array_tree;
43 }
44  
45 8 ▶sub visit {
Subroutine visit: called CC=3 SCAR=11.0
Pod documented
46 8 my ($self, $tree) = @_;
47 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
48 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
49 $self->_buildTree(
50 $tree,
51 # our array tree
52 $self->{array_tree},
53 # get a node filter if we have one
54 4 $self->getNodeFilter(),
55 # pass the value of includeTrunk too
56 $self->includeTrunk()
57 );
58 }
59  
60 11 ▶sub _buildTree {
Subroutine _buildTree: called CC=6 SCAR=17.9
61 11 my ($self, $tree, $array, $node_filter, $include_trunk) = @_;
62 11 my $i = 0;
63 11 ▶ while ($i < scalar @{$array}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < scalar @{$array;}) 17 9 26
64 17 my $node = $array->[$i];
65 # check to make sure we have a well formed tree
66 17 ▶ (ref($node) ne 'ARRAY')
Branch: 1 branch
BranchTrueFalseTotal
ref $node ne "ARRAY" or die "Incorrect Object Type : The node value should never be an array reference" 16 1 17
67 || die "Incorrect Object Type : The node value should never be an array reference";
68 # filter the node if necessary
69 16 ▶ $node = $node_filter->($node) if defined($node_filter);
Branch: 1 branch
BranchTrueFalseTotal
if defined $node_filter 5 11 16
70 # create the new tree
71 16 my $new_tree;
72 16 ▶ if ($include_trunk) {
Branch: 1 branch
BranchTrueFalseTotal
if ($include_trunk) { } 1 15 16
73 1 $tree->setNodeValue($node);
74 1 $new_tree = $tree;
75 }
76 else {
77 15 $new_tree = Tree::Simple->new($node);
78 15 $tree->addChild($new_tree);
79 }
80 # increment the index value
81 16 $i++;
82 # NOTE:
83 # the value of include trunk is only
84 # passed in the recursion, so that
85 # the trunk/root can be populated,
86 # we have no more need for it after
87 # that time.
88 16 ▶ $self->_buildTree($new_tree, $array->[$i++], $node_filter)
Branch: 1 branch
BranchTrueFalseTotal
if ref $array->[$i] eq "ARRAY" 7 9 16
89 if ref($array->[$i]) eq 'ARRAY';
90 }
91 }
92  
93 1 1;
94  
95 __END__
« Visitor/LoadDirectoryTree.pm ↑ Summary Visitor/PathToRoot.pm »