Visitor/ToNestedHash.pm

filter: Statementstmt 100% 34 / 34 Branchbran 100% 10 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 93.6% 59 / 63 CC 9 SCAR 11.9
CC
9
Cov
96%
visit
5.0
_buildHash
4.0
new
2.0
CRAP 3.3
« Visitor/ToNestedArray.pm ↑ Summary Visitor/VariableDepthClone.pm »
1 package Tree::Simple::Visitor::ToNestedHash;
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 5 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 5 my ($_class) = @_;
14 5 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
050
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 5 my $visitor = {};
16 5 bless($visitor, $class);
17 5 $visitor->_init();
18 5 return $visitor;
19 }
20  
21 8 ▶sub visit {
Subroutine visit: called CC=5 SCAR=16.1
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 # grab our filter (if we have one)
26 4 my $filter = $self->getNodeFilter();
27 4 my %results;
28 # get the array
29 4 $self->_buildHash($tree, \%results, $filter);
30 # add the trunk if we need to
31 4 ▶ %results = (
Branch: 2 branches
BranchTrueFalseTotal
if $self->includeTrunk 2 2 4
defined $filter ? : 1 1 2
32 ((defined($filter)) ?
33 $filter->($tree)
34 :
35 $tree->getNodeValue()) => { %results }
36 ) if $self->includeTrunk();
37 # set results
38 4 $self->setResults(\%results);
39 }
40  
41 8 ▶sub _buildHash {
Subroutine _buildHash: called CC=4 SCAR=13.9
42 8 my ($self, $tree, $accumulator, $filter) = @_;
43 8 foreach my $child ($tree->getAllChildren()) {
44 16 my $node_value = {};
45 16 ▶ my $node_key = (defined($filter) ? $filter->($child) : $child->getNodeValue());
Branch: 1 branch
BranchTrueFalseTotal
defined $filter ? : 8 8 16
46 16 ▶ $self->_buildHash($child, $node_value, $filter) unless $child->isLeaf();
Branch: 1 branch
BranchTrueFalseTotal
unless $child->isLeaf 4 12 16
47 16 $accumulator->{$node_key} = $node_value;
48 }
49 8 return $accumulator;
50 }
51  
52  
53 1 1;
54  
55 __END__
« Visitor/ToNestedArray.pm ↑ Summary Visitor/VariableDepthClone.pm »