Tested/Value/Tree.pm

filter: Statementstmt 100% 60 / 60 Branchbran 100% 18 / 18 Conditioncond 100% 13 / 13 MC/DCmcdc 100% 8 / 8 Subroutinesub 100% 11 / 11 Podpod 50.0% 1 / 2 totaltotal 99.1% 111 / 112 CC 17 SCAR 12.2
CC
17
Cov
100%
_render_from_selection_tree
5.0
_build_selection_tree
5.0
value_to_string
4.0
CRAP 3.4
« Tested/Value/Radio.pm ↑ Summary Tested/List.pm »
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package HTML::Tested::Value::Tree;
5 1 ▶use base 'HTML::Tested::Value';
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 ▶sub transform_value { return $_[2]; }
Subroutine transform_value: called CC=1 SCAR=0.0
Pod undocumented
8  
9 15 ▶sub _render_from_selection_tree {
Subroutine _render_from_selection_tree: called CC=5 SCAR=16.1
10 15 my ($self, $context, $nodes, $sel_tree, $ident) = @_;
11 15 my $res = "$ident<ul>\n";
12 15 for my $n (@$nodes) {
13 27 my $sa = $context->{selection_attribute};
14 27 ▶ my $n_sel = $sa ? $sel_tree->{ $n->{ $sa } } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$sa ? : 23 4 27
15 27 my $new_ident = "$ident ";
16 27 $res .= "$new_ident<li>\n";
17 27 ▶ if ($n_sel) {
Branch: 1 branch
BranchTrueFalseTotal
if ($n_sel) { } 14 13 27
18 14 $res .= $self->_render_selected_node(
19 $context, $n, "$new_ident ");
20 $res .= $self->_render_from_selection_tree(
21 $context, $n->{children}, $n_sel,
22 14 ▶ "$ident ") if $n->{children};
Branch: 1 branch
BranchTrueFalseTotal
if $n->{"children"} 8 6 14
23 } else {
24 13 $res .= $self->_render_collapsed_node(
25 $context, $n, "$new_ident ");
26 }
27 27 $res .= "$new_ident</li>\n";
28 }
29 15 return $res . "$ident</ul>\n";
30 }
31  
32 8 ▶sub _build_selection_tree {
Subroutine _build_selection_tree: called CC=5 SCAR=16.1
33 8 my ($self, $nodes, $selections, $sel_attr) = @_;
34 8 my $tree = {};
35 8 for my $n (@$nodes) {
36 14 my $v = $n->{$sel_attr};
37 14 my $nt = {};
38 14 ▶ if (my $c = $n->{children}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $c = $n->{"children"}) 5 9 14
39 5 $nt = $self->_build_selection_tree(
40 $c, $selections, $sel_attr);
41 }
42 14 ▶ next unless (%$nt || $selections->{$v});
Branch: 1 branch
BranchTrueFalseTotal
unless %$nt or $selections->{$v} 6 8 14
Condition100%3/3
%$nt or $selections->{$v}
l!l&&r!l&&!r
446
MC/DC100%2/2
%$nt or $selections->{$v}
%$nt $selections->{$v}
Truth table100%3/3
A or B
A= %$ntB= $selections->{$v}
ABresult
1X1
011
000
43 8 $tree->{$v} = $nt;
44 }
45 8 return $tree;
46 }
47  
48 28 ▶sub _get_tree_option {
Subroutine _get_tree_option: called CC=3 SCAR=11.0
49 28 my ($self, $caller, $val, $opt) = @_;
50 28 my $res = $val->{$opt};
51 28 ▶ return $res if ($res || !$caller);
Branch: 1 branch
BranchTrueFalseTotal
if $res or not $caller 13 15 28
Condition100%3/3
$res or not $caller
l!l&&r!l&&!r
9415
MC/DC100%2/2
$res or not $caller
$res not $caller
Truth table100%3/3
A or not(B)
A= $resB= not $caller
ABresult
1X1
011
000
52  
53 15 $res = $caller->ht_get_widget_option($self->name, $opt);
54 15 $val->{$opt} = $res;
55 15 return $res;
56 }
57  
58 7 ▶sub value_to_string {
Subroutine value_to_string: called CC=4 SCAR=13.9
Pod documented
59 7 my ($self, $name, $val, $caller) = @_;
60  
61 # Copy var aside, we'll modify it in _get_tree_option
62 7 ▶ $val = $val ? { %$val } : {};
Branch: 1 branch
BranchTrueFalseTotal
$val ? : 6 1 7
63  
64 7 my $input = $self->_get_tree_option($caller, $val, 'input_tree');
65 7 my $sel_attr = $self->_get_tree_option($caller, $val
66 , 'selection_attribute');
67  
68 # Put those into context
69 7 $self->_get_tree_option($caller, $val, 'collapsed_format');
70 7 $self->_get_tree_option($caller, $val, 'selected_format');
71  
72 7 my $tree = $val->{selection_tree};
73 $tree = $self->_build_selection_tree($input
74 7 ▶ , { map { ($_, 1) } @{ $val->{selections} } }
Branch: 1 branch
BranchTrueFalseTotal
if not $tree and $sel_attr 3 4 7
Condition100%3/3
not $tree and $sel_attr
!ll&&!rl&&r
223
MC/DC100%2/2
not $tree and $sel_attr
not $tree $sel_attr
Truth table100%3/3
not(A) and B
A= not $treeB= $sel_attr
ABresult
0X0
100
111
75 , $sel_attr) if (!$tree && $sel_attr);
76 7 return $self->_render_from_selection_tree($val, $input, $tree, '');
77 }
78  
79 27 ▶sub _render_from_format {
Subroutine _render_from_format: called CC=2 SCAR=6.9
80 27 my ($self, $format, $node, $ident) = @_;
81 27 my $res = $ident . $format . "\n";
82 27 ▶ while (my ($n, $v) = each %$node) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %$node) 52 27 79
83 52 $res =~ s/\%$n\%/$v/g;
84 }
85 27 return $res;
86 }
87  
88 14 ▶sub _render_selected_node {
Subroutine _render_selected_node: called CC=2 SCAR=6.9
89 14 my ($self, $context, $node, $ident) = @_;
90 return $self->_render_from_format($context->{selected_format}
91 14 ▶ || '<span class="selected">%value%</span>'
Condition100%2/2
$context->{'selected_format'} || '<span class="selected">%value%</span>'
l!l
77
MC/DC100%1/1
$context->{'selected_format'} || '<span class="selected">%value%</span>'
$context->{'selected_format'}
Truth table100%2/2
A
A= $context->{'selected_format'}
Aresult
11
00
92 , $node, $ident);
93 }
94  
95 13 ▶sub _render_collapsed_node {
Subroutine _render_collapsed_node: called CC=2 SCAR=6.9
96 13 my ($self, $context, $node, $ident) = @_;
97 return $self->_render_from_format($context->{collapsed_format}
98 13 ▶ || '<a href="#">%value%</a>', $node, $ident);
Condition100%2/2
$context->{'collapsed_format'} || '<a href="#">%value%</a>'
l!l
103
MC/DC100%1/1
$context->{'collapsed_format'} || '<a href="#">%value%</a>'
$context->{'collapsed_format'}
Truth table100%2/2
A
A= $context->{'collapsed_format'}
Aresult
11
00
99 }
100  
101 1 1;
« Tested/Value/Radio.pm ↑ Summary Tested/List.pm »