View/ASCII.pm

filter: Statementstmt 89.0% 57 / 64 Branchbran 75.0% 27 / 36 Conditioncond 60.0% 9 / 15 MC/DCmcdc 33.3% 3 / 9 Subroutinesub 100% 12 / 12 Podpod 100% 3 / 3 totaltotal 79.8% 111 / 139 CC 25 SCAR 23.4
CC
25
Cov
81%
_merge_characters
33.8
_processNode
9.0
expandPathSimple
5.0
CRAP 10.4
↑ Summary View/HTML.pm »
1 package Tree::Simple::View::ASCII;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Tree::Simple::View::Exceptions;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use parent 'Tree::Simple::View';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.20';
10  
11 4 ▶sub expandPathSimple {
Subroutine expandPathSimple: called CC=5 SCAR=16.1
Pod documented
12 4 my ( $self, $tree, @full_path ) = @_;
13  
14 4 my $output = '';
15 4 my @vert_dashes;
16  
17 12 ▶ my $traversal = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
18 12 my ( $t, $redo, $current_path, @path ) = @_;
19 12 ▶ $output .= $self->_processNode( $t, \@vert_dashes ) unless $t->isRoot;
Branch: 1 branch
BranchTrueFalseTotal
unless $t->isRoot 8 4 12
20 12 my @children = $t->getAllChildren;
21 12 for my $i ( 0 .. $#children ) {
22 36 my $subcat = $children[$i];
23 36 my $is_last = $i == $#children;
24 36 $output .=
25 $self->_handle_child( $subcat, $redo, \@path, $current_path,
26 \@vert_dashes, $is_last );
27 }
28 4 };
29  
30 $output .= $self->_processNode( $tree, \@vert_dashes )
31 4 ▶ if $self->{include_trunk};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_trunk"} 2 2 4
32  
33 shift @full_path
34 if ( $self->{include_trunk}
35 4 ▶ && defined $full_path[0]
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_trunk"} and defined $full_path[0] and $self->_compareNodeToPath($full_path[0], $tree) 2 2 4
Condition66%4/6
$self->{"include_trunk"} and defined $full_path[0] and $self->_compareNodeToPath($full_path[0], $tree)
!ll&&!rl&&r
202
$self->{"include_trunk"} and defined $full_path[0]
!ll&&!rl&&r
202
MC/DC33%1/3
$self->{"include_trunk"} and defined $full_path[0] and $self->_compareNodeToPath($full_path[0], $tree)
$self->{"include_trunk"} defined $full_path[0] $self->_compareNodeToPath($full_path[0], $tree)
Truth table50%2/4
A and B and C
A= $self->{"include_trunk"}B= defined $full_path[0]C= $self->_compareNodeToPath($full_path[0], $tree)
ABCresult
0XX0
10X0
1100
1111
36 && $self->_compareNodeToPath( $full_path[0], $tree ) );
37  
38 # Its the U combinator baby!
39 4 $traversal->( $tree, $traversal, @full_path );
40  
41 4 return $output;
42 }
43  
44 4 ▶sub expandAllSimple {
Subroutine expandAllSimple: called CC=2 SCAR=6.9
Pod documented
45 4 my ($self) = @_;
46  
47 4 my $output = '';
48 4 my @vert_dashes;
49  
50 $output .= $self->_processNode( $self->{tree}, \@vert_dashes )
51 4 ▶ if $self->{include_trunk};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_trunk"} 2 2 4
52 $self->{tree}->traverse(
53 60 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
54 60 my $t = shift;
55 60 my @siblings = $t->getParent->getAllChildren;
56 60 ▶ $output .=
Branch: 1 branch
BranchTrueFalseTotal
$t == $siblings[-1] ? : 28 32 60
57 $self->_processNode( $t, \@vert_dashes,
58 $t == $siblings[-1] ? 1 : 0 );
59 }
60 4 );
61  
62 4 return $output;
63 }
64  
65 2 ▶sub expandPathComplex {
Subroutine expandPathComplex: called CC=1 SCAR=0.0
Pod documented
66 2 my ( $self, $tree, undef, @full_path ) = @_;
67  
68 # complex stuff is not supported here ...
69 2 $self->expandPathSimple( $tree, @full_path );
70 }
71  
72 2 *expandAllComplex = \&expandAllSimple;
73  
74 100 ▶sub _processNode {
Subroutine _processNode: called CC=9 SCAR=22.0
75 100 my ( $self, $t, $vert_dashes, $is_last ) = @_;
76 100 my $depth = $t->getDepth;
77 100 ▶ my $sibling_count = $t->isRoot ? 1 : $t->getParent->getChildCount;
Branch: 1 branch
BranchTrueFalseTotal
$t->isRoot ? : 4 96 100
78  
79 100 ▶ $depth++ if $self->{include_trunk};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"include_trunk"} 52 48 100
80  
81 100 my $chars = $self->_merge_characters;
82 my @indents =
83 100 ▶ map { $vert_dashes->[$_] || $chars->{indent} } 0 .. $depth - 1;
Condition33%1/3
$vert_dashes->[$_] || $chars->{'indent'}
l!l&&r!l&&!r
13600
MC/DC0%0/2
$vert_dashes->[$_] || $chars->{'indent'}
$vert_dashes->[$_] $chars->{'indent'}
Truth table33%1/3
A || B
A= $vert_dashes->[$_]B= $chars->{'indent'}
ABresult
1X1
011
000
84  
85 @$vert_dashes =
86 100 ▶ ( @indents, ( $sibling_count == 1 ? $chars->{indent} : $chars->{pipe} ) );
Branch: 1 branch
BranchTrueFalseTotal
$sibling_count == 1 ? : 12 88 100
87 $vert_dashes->[$depth] = $chars->{indent}
88 100 ▶ if ( $sibling_count == ( $t->getIndex + 1 ) );
Branch: 1 branch
BranchTrueFalseTotal
if $sibling_count == $t->getIndex + 1 40 60 100
89  
90 my $node =
91 exists $self->{config}->{node_formatter}
92 100 ▶ ? $self->{config}->{node_formatter}->($t)
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'config'}{'node_formatter'} ? : 50 50 100
93 : $t->getNodeValue;
94  
95 return (
96 ( join "" => @indents[ 1 .. $#indents ] )
97 . (
98 $depth
99 ? ( $is_last ? $chars->{last_branch} : $chars->{branch} )
100 100 ▶ : ""
Branch: 2 branches
BranchTrueFalseTotal
$depth ? : 80 20 100
$is_last ? : 36 44 80
101 )
102 . $node . "\n"
103 );
104 }
105  
106 36 ▶sub _handle_child {
Subroutine _handle_child: called CC=3 SCAR=11.0
107 36 my ( $self, $child, $redo, $path, $current_path, $vert_dashes, $is_last ) =
108 @_;
109 36 ▶ return $redo->( $child, $redo, @$path )
Branch: 1 branch
BranchTrueFalseTotal
if defined $current_path and $self->_compareNodeToPath($current_path, $child) 8 28 36
Condition100%3/3
defined $current_path and $self->_compareNodeToPath($current_path, $child)
!ll&&!rl&&r
8208
MC/DC100%2/2
defined $current_path and $self->_compareNodeToPath($current_path, $child)
defined $current_path $self->_compareNodeToPath($current_path, $child)
Truth table100%3/3
A and B
A= defined $current_pathB= $self->_compareNodeToPath($current_path, $child)
ABresult
0X0
100
111
110 if ( defined $current_path
111 && $self->_compareNodeToPath( $current_path, $child ) );
112 28 return $self->_processNode( $child, $vert_dashes, $is_last );
113 }
114  
115 100 ▶sub _merge_characters {
Subroutine _merge_characters: called CC=7 SCAR=35.2
116 100 my ($self) = shift;
117  
118 return {
119 pipe => ' | ',
120 indent => ' ',
121 last_branch => ' \---',
122 branch => ' |---',
123 }
124 100 ▶ if ( !defined $self->{config} || !defined $self->{config}->{characters} );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"config"} and defined $self->{"config"}{"characters"} 100 0 100
Condition33%1/3
defined $self->{"config"} and defined $self->{"config"}{"characters"}
!ll&&!rl&&r
01000
MC/DC0%0/2
defined $self->{"config"} and defined $self->{"config"}{"characters"}
defined $self->{"config"} defined $self->{"config"}{"characters"}
Truth table33%1/3
A and B
A= defined $self->{"config"}B= defined $self->{"config"}{"characters"}
ABresult
0X0
100
111
125  
126 0 my $chars = { @{ $self->{config}->{characters} } };
127 0 ▶ $chars->{pipe} = ' | ' unless $chars->{pipe};
Branch: 1 branch
BranchTrueFalseTotal
unless $chars->{"pipe"} 0 0 0
128 0 ▶ $chars->{indent} = ' ' unless $chars->{indent};
Branch: 1 branch
BranchTrueFalseTotal
unless $chars->{"indent"} 0 0 0
129 0 ▶ $chars->{last_branch} = ' \---' unless $chars->{last_branch};
Branch: 1 branch
BranchTrueFalseTotal
unless $chars->{"last_branch"} 0 0 0
130 0 ▶ $chars->{branch} = ' |---' unless $chars->{branch};
Branch: 1 branch
BranchTrueFalseTotal
unless $chars->{"branch"} 0 0 0
131 0 return $chars;
132 }
133  
134 2 1;
135  
136 __END__
↑ Summary View/HTML.pm »