| 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
Condition66%2/3
builtin::blessed($node) and $node->isa("Forest::Tree::Pure")
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")
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
exists $options{"children"} and not @{$options{"children"};}
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"};}
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # nothing left to be done if the option cleanup deleted all keys | ||||||||||||||||||||||||||||
| 22 | 5 | ▶ | return $node unless keys %options; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | ▶ | if ( $node->child_count == 0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 2 | ▶ | if ( $node->isa("Forest::Tree") ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||