Forest/Tree/Constructor.pm

filter: Statementstmt 92.0% 23 / 25 Branchbran 70.0% 7 / 10 Conditioncond 66.6% 4 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 3 / 3 Podpod 0.0% 0 / 1 totaltotal 77.5% 38 / 49 CC 9 SCAR 21.2
CC
9
Cov
83%
create_new_subtree
9.9
BEGIN
1.0
BEGIN
1.0
CRAP 8.3
↑ Summary Forest/Tree/Builder/SimpleTextFile.pm »
1 package Forest::Tree::Constructor;
2 12 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 12 our $VERSION = '0.10';
5 12 our $AUTHORITY = 'cpan:STEVAN';
6  
7 12 requires "tree_class";
8  
9 86 ▶sub create_new_subtree {
Subroutine create_new_subtree: called CC=9 SCAR=23.0
Pod undocumented
10 86 my ($self, %options) = @_;
11 86 my $node = $options{node};
12  
13 86 ▶ if (blessed($node) && $node->isa('Forest::Tree::Pure')) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($node) and $node->isa('Forest::Tree::Pure')) { } 5 81 86
Condition66%2/3
builtin::blessed($node) and $node->isa("Forest::Tree::Pure")
!ll&&!rl&&r
8105
MC/DC50%1/2
builtin::blessed($node) and $node->isa("Forest::Tree::Pure")
builtin::blessed($node) $node->isa("Forest::Tree::Pure")
Truth table66%2/3
A and B
A= builtin::blessed($node)B= $node->isa("Forest::Tree::Pure")
ABresult
0X0
100
111
14 # when node is an tree object we assume that it's a prototype of a tree
15 # node to be filled in
16  
17 # remove meaningless keys
18 5 delete $options{node};
19 5 ▶ delete $options{children} if exists $options{children} and not @{ $options{children} };
Branch: 1 branch
BranchTrueFalseTotal
if exists $options{"children"} and not @{$options{"children"};} 0 5 5
Condition66%2/3
exists $options{"children"} and not @{$options{"children"};}
!ll&&!rl&&r
320
MC/DC0%0/2
exists $options{"children"} and not @{$options{"children"};}
exists $options{"children"} not @{$options{"children"};}
Truth table66%2/3
A and not(B)
A= exists $options{"children"}B= not @{$options{"children"};}
ABresult
0X0
100
111
20  
21 # nothing left to be done if the option cleanup deleted all keys
22 5 ▶ return $node unless keys %options;
Branch: 1 branch
BranchTrueFalseTotal
unless keys %options 3 2 5
23  
24 2 ▶ if ( $node->child_count == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->child_count == 0) { } 2 0 2
25 2 ▶ if ( $node->isa("Forest::Tree") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node->isa('Forest::Tree')) { } 2 0 2
26 # mutable trees get modified
27  
28 2 foreach my $key ( keys %options ) {
29 2 $node->$key( $options{$key} );
30 }
31  
32 2 return $node;
33 }
34 else {
35 # pure trees get cloned
36 0 return $node->clone(%options);
37 }
38 }
39 else {
40 # i suppose $options{children} could be appended to $node->children
41 # if there are any, but that doesn't really make sense IMHO, might
42 # as well write your own builder at that point instead of kludging
43 # it with the parser callback for the simple text loader or something
44 0 confess("Can't override children from proto node");
45 }
46 }
47 else {
48 81 return $self->tree_class->new(%options);
49 }
50 }
51  
52  
53 # ex: set sw=4 et
54  
55 12 ▶no Moose::Role; 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
56  
57 __END__
↑ Summary Forest/Tree/Builder/SimpleTextFile.pm »