Visitor/VariableDepthClone.pm

filter: Statementstmt 100% 49 / 49 Branchbran 100% 14 / 14 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 10 / 10 Podpod 100% 4 / 4 totaltotal 95.4% 83 / 87 CC 11 SCAR 11.6
CC
11
Cov
97%
visit
5.0
_cloneTree
5.0
new
2.0
CRAP 3.2
« Visitor/ToNestedHash.pm ↑ Summary Visitor/FromNestedHash.pm »
1 package Tree::Simple::Visitor::VariableDepthClone;
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 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 our $VERSION = '0.16';
9  
10 1 ▶use base qw(Tree::Simple::Visitor);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
13 13 my ($_class) = @_;
14 13 ▶ my $class = ref($_class) || $_class;
Condition33%1/3
ref $_class || $_class
l!l&&r!l&&!r
0130
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 13 my $visitor = {};
16 13 bless($visitor, $class);
17 13 $visitor->_init();
18 13 return $visitor;
19 }
20  
21 13 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
22 13 my ($self) = @_;
23 13 $self->{clone_depth} = undef;
24 13 $self->SUPER::_init();
25 }
26  
27 13 ▶sub setCloneDepth {
Subroutine setCloneDepth: called CC=2 SCAR=6.9
Pod documented
28 13 my ($self, $clone_depth) = @_;
29 13 ▶ (defined($clone_depth))
Branch: 1 branch
BranchTrueFalseTotal
defined $clone_depth or die "Insufficient Arguments : you must supply a clone depth" 12 1 13
30 || die "Insufficient Arguments : you must supply a clone depth";
31 12 $self->{clone_depth} = $clone_depth;
32 }
33  
34 12 ▶sub getClone {
Subroutine getClone: called CC=1 SCAR=0.0
Pod documented
35 12 my ($self) = @_;
36 12 return $self->getResults()->[0];
37 }
38  
39 16 ▶sub visit {
Subroutine visit: called CC=5 SCAR=16.1
Pod documented
40 16 my ($self, $tree) = @_;
41 16 ▶ (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" 12 4 16
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
!ll&&!rl&&r
3112
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
42 || die "Insufficient Arguments : You must supply a valid Tree::Simple object";
43  
44 12 my $filter = $self->getNodeFilter();
45  
46 # get a new instance of the root tree type
47 12 my $new_root = blessed($tree)->new($tree->ROOT);
48 12 my $new_tree = $new_root;
49  
50 12 ▶ if ($self->includeTrunk()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->includeTrunk) 5 7 12
51 5 my $cloned_trunk = blessed($tree)->new();
52 5 $cloned_trunk->setNodeValue(
53 Tree::Simple::_cloneNode($tree->getNodeValue())
54 );
55 5 ▶ $filter->($tree, $cloned_trunk) if defined $filter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filter 1 4 5
56 5 $new_tree->addChild($cloned_trunk);
57 5 $new_tree = $cloned_trunk;
58 }
59  
60 12 $self->_cloneTree($tree, $new_tree, $self->{clone_depth}, $filter);
61  
62 12 $self->setResults($new_root);
63 }
64  
65 33 ▶sub _cloneTree {
Subroutine _cloneTree: called CC=5 SCAR=16.1
66 33 my ($self, $tree, $clone, $depth, $filter) = @_;
67 33 ▶ return if $depth <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $depth <= 0 12 21 33
68 21 foreach my $child ($tree->getAllChildren()) {
69 55 my $cloned_child = blessed($child)->new();
70 55 $cloned_child->setNodeValue(
71 Tree::Simple::_cloneNode($child->getNodeValue())
72 );
73 55 ▶ $filter->($child, $cloned_child) if defined $filter;
Branch: 1 branch
BranchTrueFalseTotal
if defined $filter 9 46 55
74 55 $clone->addChild($cloned_child);
75 55 ▶ $self->_cloneTree($child, $cloned_child, $depth - 1, $filter) unless $child->isLeaf();
Branch: 1 branch
BranchTrueFalseTotal
unless $child->isLeaf 21 34 55
76 }
77 }
78  
79 1 1;
80  
81 __END__
« Visitor/ToNestedHash.pm ↑ Summary Visitor/FromNestedHash.pm »