| 1 | package Tree::Simple::Visitor::FromNestedHash; | ||||||||||||||||||||||||||||
| 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
MC/DC0%0/2
ref $_class || $_class
ref $_class
$_class
Truth table33%1/3
A || B
A= ref $_classB= $_class
| |||||||||||||||||||||||||||||
| 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->{hash_tree} = undef; | |||||||||||||||||||||||||||
| 24 | 4 | $self->SUPER::_init(); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 8 | ▶ | sub setHashTree { | ||||||||||||||||||||||||||
|
Subroutine
setHashTree: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | 8 | my ($self, $hash_tree) = @_; | |||||||||||||||||||||||||||
| 29 | 8 | ▶ | (defined($hash_tree) && ref($hash_tree) eq 'HASH') | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $hash_tree and ref $hash_tree eq "HASH"
MC/DC100%2/2
defined $hash_tree and ref $hash_tree eq "HASH"
defined $hash_tree
ref $hash_tree eq "HASH"
Truth table100%3/3
A and B
A= defined $hash_treeB= ref $hash_tree eq "HASH"
| |||||||||||||||||||||||||||||
| 30 | || die "Insufficient Arguments : You must supply a valid HASH reference"; | ||||||||||||||||||||||||||||
| 31 | # validate the tree ... | ||||||||||||||||||||||||||||
| 32 | # it must not be empty | ||||||||||||||||||||||||||||
| 33 | 5 | ▶ | (scalar keys %{$hash_tree} == 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | || die "Insufficient Arguments : The hash tree provided must be a single rooted tree"; | ||||||||||||||||||||||||||||
| 35 | 3 | $self->{hash_tree} = $hash_tree; | |||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 7 | ▶ | sub visit { | ||||||||||||||||||||||||||
|
Subroutine
visit: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 7 | my ($self, $tree) = @_; | |||||||||||||||||||||||||||
| 40 | 7 | ▶ | (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")
| |||||||||||||||||||||||||||||
| 41 | || die "Insufficient Arguments : You must supply a valid Tree::Simple object"; | ||||||||||||||||||||||||||||
| 42 | $self->_buildTree( | ||||||||||||||||||||||||||||
| 43 | $tree, | ||||||||||||||||||||||||||||
| 44 | $self->{hash_tree}, | ||||||||||||||||||||||||||||
| 45 | 3 | $self->getNodeFilter(), | |||||||||||||||||||||||||||
| 46 | $self->includeTrunk() | ||||||||||||||||||||||||||||
| 47 | ); | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 18 | ▶ | sub _buildTree { | ||||||||||||||||||||||||||
|
Subroutine
_buildTree: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 51 | 18 | my ($self, $tree, $hash, $node_filter, $include_trunk) = @_; | |||||||||||||||||||||||||||
| 52 | 18 | foreach my $key (sort keys %{$hash}) { | |||||||||||||||||||||||||||
| 53 | 15 | my $node = $key; | |||||||||||||||||||||||||||
| 54 | 15 | ▶ | $node = $node_filter->($node) if $node_filter; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | 15 | my $new_tree; | |||||||||||||||||||||||||||
| 56 | 15 | ▶ | if ($include_trunk) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 1 | $tree->setNodeValue($node); | |||||||||||||||||||||||||||
| 58 | 1 | $new_tree = $tree; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | else { | ||||||||||||||||||||||||||||
| 61 | 14 | $new_tree = Tree::Simple->new($node); | |||||||||||||||||||||||||||
| 62 | 14 | $tree->addChild($new_tree); | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | $self->_buildTree($new_tree, $hash->{$key}, $node_filter) | ||||||||||||||||||||||||||||
| 65 | 15 | ▶ | if ref($hash->{$key}) eq 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||