| 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
| |||||||||||||||||||||||||||||
| 15 | 27 | my $new_ident = "$ident "; | |||||||||||||||||||||||||||
| 16 | 27 | $res .= "$new_ident<li>\n"; | |||||||||||||||||||||||||||
| 17 | 27 | ▶ | if ($n_sel) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 39 | 5 | $nt = $self->_build_selection_tree( | |||||||||||||||||||||||||||
| 40 | $c, $selections, $sel_attr); | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 14 | ▶ | next unless (%$nt || $selections->{$v}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
%$nt or $selections->{$v}
MC/DC100%2/2
%$nt or $selections->{$v}
%$nt
$selections->{$v}
Truth table100%3/3
A or B
A= %$ntB= $selections->{$v}
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$res or not $caller
MC/DC100%2/2
$res or not $caller
$res
not $caller
Truth table100%3/3
A or not(B)
A= $resB= not $caller
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
not $tree and $sel_attr
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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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>'
MC/DC100%1/1
$context->{'selected_format'} || '<span class="selected">%value%</span>'
$context->{'selected_format'}
Truth table100%2/2
A
A= $context->{'selected_format'}
| |||||||||||||||||||||||||||||
| 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>'
MC/DC100%1/1
$context->{'collapsed_format'} || '<a href="#">%value%</a>'
$context->{'collapsed_format'}
Truth table100%2/2
A
A= $context->{'collapsed_format'}
| |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 1 | 1; | |||||||||||||||||||||||||||