| 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
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
builtin::blessed($tree) and $tree->isa("Tree::Simple")
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")
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 74 | 55 | $clone->addChild($cloned_child); | |||||||||||||||||||||||||||
| 75 | 55 | ▶ | $self->_cloneTree($child, $cloned_child, $depth - 1, $filter) unless $child->isLeaf(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||||||||||