| 1 | package Excel::Template::Container::Conditional; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | #GGG Convert <conditional> to be a special case of <switch>? | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | BEGIN { | ||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use vars qw(@ISA); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | @ISA = qw(Excel::Template::Container); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Excel::Template::Container; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | my %isOp = ( | ||||||||||||||||||||||||||||
| 15 | '=' => '==', | ||||||||||||||||||||||||||||
| 16 | 6 | (map { $_ => $_ } ( '>', '<', '==', '!=', '>=', '<=' )), | |||||||||||||||||||||||||||
| 17 | 1 | (map { $_ => $_ } ( 'gt', 'lt', 'eq', 'ne', 'ge', 'le' )), | |||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | sub _conditional_passes | ||||||||||||||||||||||||||||
| 21 | { | ||||||||||||||||||||||||||||
| 22 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_conditional_passes: not called CC=28 SCAR=67.0
| |||||||||||||||||||||||||||||
| 23 | 0 | my ($context) = @_; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 0 | my $name = $context->get($self, 'NAME'); | |||||||||||||||||||||||||||
| 26 | 0 | ▶ | return 0 unless $name =~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | my $val = $context->param($name); | |||||||||||||||||||||||||||
| 29 | 0 | ▶ | $val = @{$val} while ref $val eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $val = ${$val} while ref $val eq 'SCALAR'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $value = $context->get($self, 'VALUE'); | |||||||||||||||||||||||||||
| 33 | 0 | ▶ | if (defined $value) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||
| 35 | 0 | my $op = $context->get($self, 'OP'); | |||||||||||||||||||||||||||
| 36 | $op = defined $op && exists $isOp{$op} | ||||||||||||||||||||||||||||
| 37 | 0 | ▶ | ? $isOp{$op} | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $op and exists $isOp{$op}
MC/DC0%0/2
defined $op and exists $isOp{$op}
defined $op
exists $isOp{$op}
Truth table0%0/3
A and B
A= defined $opB= exists $isOp{$op}
| |||||||||||||||||||||||||||||
| 38 | : '=='; | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | my $res; | |||||||||||||||||||||||||||
| 41 | 0 | for ($op) | |||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | /^>$/ && do { $res = ($val > $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | /^<$/ && do { $res = ($val < $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | /^==$/ && do { $res = ($val == $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | /^!=$/ && do { $res = ($val != $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | /^>=$/ && do { $res = ($val >= $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | /^<=$/ && do { $res = ($val <= $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | /^gt$/ && do { $res = ($val gt $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | /^lt$/ && do { $res = ($val lt $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | /^eq$/ && do { $res = ($val eq $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | /^ne$/ && do { $res = ($val ne $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | /^ge$/ && do { $res = ($val ge $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | /^le$/ && do { $res = ($val le $value); last }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | die "Unknown operator '$op' in conditional resolve", $/; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return $res && 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$res && 1
MC/DC0%0/1
$res && 1
$res
Truth table0%0/2
A
A= $res
| |||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my $istrue = $val && 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$val && 1
MC/DC0%0/1
$val && 1
$val
Truth table0%0/2
A
A= $val
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $is = uc($context->get($self, 'IS') || 'TRUE'); | ||||||||||||||||||||||||||
|
Condition0%0/2
$context->get($self, 'IS') || 'TRUE'
MC/DC0%0/1
$context->get($self, 'IS') || 'TRUE'
$context->get($self, 'IS')
Truth table0%0/2
A
A= $context->get($self, 'IS')
| |||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if ($is eq 'TRUE') | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | { | ||||||||||||||||||||||||||||
| 67 | 0 | ▶ | return 0 unless $istrue; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | else | ||||||||||||||||||||||||||||
| 70 | { | ||||||||||||||||||||||||||||
| 71 | 0 | ▶ | warn "Conditional 'is' value was [$is], defaulting to 'FALSE'" . $/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is ne "FALSE" and $^W
MC/DC0%0/2
$is ne "FALSE" and $^W
$is ne "FALSE"
$^W
Truth table0%0/3
A and B
A= $is ne "FALSE"B= $^W
| |||||||||||||||||||||||||||||
| 72 | if $is ne 'FALSE' && $^W; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | return 0 if $istrue; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | return 1; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | sub render | ||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
render: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | 0 | my ($context) = @_; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return 1 unless $self->_conditional_passes($context); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | return $self->iterate_over_children($context); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | #sub max_of | ||||||||||||||||||||||||||||
| 91 | #{ | ||||||||||||||||||||||||||||
| 92 | # my $self = shift; | ||||||||||||||||||||||||||||
| 93 | # my ($context, $attr) = @_; | ||||||||||||||||||||||||||||
| 94 | # | ||||||||||||||||||||||||||||
| 95 | # return 0 unless $self->_conditional_passes($context); | ||||||||||||||||||||||||||||
| 96 | # | ||||||||||||||||||||||||||||
| 97 | # return $self->SUPER::max_of($context, $attr); | ||||||||||||||||||||||||||||
| 98 | #} | ||||||||||||||||||||||||||||
| 99 | # | ||||||||||||||||||||||||||||
| 100 | #sub total_of | ||||||||||||||||||||||||||||
| 101 | #{ | ||||||||||||||||||||||||||||
| 102 | # my $self = shift; | ||||||||||||||||||||||||||||
| 103 | # my ($context, $attr) = @_; | ||||||||||||||||||||||||||||
| 104 | # | ||||||||||||||||||||||||||||
| 105 | # return 0 unless $self->_conditional_passes($context); | ||||||||||||||||||||||||||||
| 106 | # | ||||||||||||||||||||||||||||
| 107 | # return $self->SUPER::total_of($context, $attr); | ||||||||||||||||||||||||||||
| 108 | #} | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 1 | 1; | |||||||||||||||||||||||||||
| 111 | __END__ | ||||||||||||||||||||||||||||