| 1 | package CLI::Array; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use CLI::Base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | @ISA = ("CLI::Base"); | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use CLI qw(parse_string typeStr string_value); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | #use CLI::Var; | ||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | 0 | my $proto = shift; | |||||||||||||||||||||||||||
| 13 | 0 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 16 | 0 | my $type = shift; | |||||||||||||||||||||||||||
| 17 | 0 | my $vals = shift; # List reference | |||||||||||||||||||||||||||
| 18 | 0 | my $hash = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my $self = { | |||||||||||||||||||||||||||
| 21 | NAME => $name, | ||||||||||||||||||||||||||||
| 22 | TYPE => $type, | ||||||||||||||||||||||||||||
| 23 | VALUE => [], | ||||||||||||||||||||||||||||
| 24 | FUNC => undef, | ||||||||||||||||||||||||||||
| 25 | MIN => undef, | ||||||||||||||||||||||||||||
| 26 | MAX => undef | ||||||||||||||||||||||||||||
| 27 | }; | ||||||||||||||||||||||||||||
| 28 | 0 | bless ($self, $class); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | $self->function($hash->{function}) if (defined $hash->{function}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | $self->min($hash->{min}) if (defined $hash->{min}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | ▶ | $self->max($hash->{max}) if (defined $hash->{max}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $i = 0; | |||||||||||||||||||||||||||
| 35 | 0 | foreach my $val (@$vals) { | |||||||||||||||||||||||||||
| 36 | 0 | $self->value($i, $val); | |||||||||||||||||||||||||||
| 37 | 0 | $i++; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 0 | return $self; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | sub TIEARRAY { | ||||||||||||||||||||||||||
|
Subroutine
TIEARRAY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 44 | 0 | return new(@_); | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub value { | ||||||||||||||||||||||||||
|
Subroutine
value: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | 0 | my $index = shift; | |||||||||||||||||||||||||||
| 50 | 0 | my $value = shift; | |||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | if (!defined $index) { # Return the whole lot as a list | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 0 | return @{$self->{VALUE}}; | |||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||
| 55 | # Verify the index value | ||||||||||||||||||||||||||||
| 56 | 0 | ▶ | if ($index<0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 57 | 0 | carp "Index $index out of range"; | |||||||||||||||||||||||||||
| 58 | 0 | return undef; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if (!defined $value) { # Return a value | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | return $self->{VALUE}[$index]; | |||||||||||||||||||||||||||
| 62 | } else { # Save the value | ||||||||||||||||||||||||||||
| 63 | 0 | my $oldvalue = $self->{VALUE}[$index]; | |||||||||||||||||||||||||||
| 64 | 0 | my $min = $self->min(); | |||||||||||||||||||||||||||
| 65 | 0 | my $max = $self->max(); | |||||||||||||||||||||||||||
| 66 | 0 | my $inrange = 1; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # Is the value in range? | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if (defined $min) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | if ($value<$min) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | warn " $value less than minimum ($min)\n"; | |||||||||||||||||||||||||||
| 72 | 0 | $inrange = 0; | |||||||||||||||||||||||||||
| 73 | 0 | $max = undef; # Stop pathological case of complaining about min and max | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if (defined $max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ($value>$max) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | warn " $value greater than maximum ($max)\n"; | |||||||||||||||||||||||||||
| 79 | 0 | $inrange = 0; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | if ($inrange) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | $self->{VALUE}[$index] = $value; | |||||||||||||||||||||||||||
| 85 | 0 | ▶ | if (defined $self->function()) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | my $type = $self->type(); | |||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ($type eq 'STRING' || $type eq 'SSTRING') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type eq "STRING" or $type eq "SSTRING"
MC/DC0%0/2
$type eq "STRING" or $type eq "SSTRING"
$type eq "STRING"
$type eq "SSTRING"
Truth table0%0/3
A or B
A= $type eq "STRING"B= $type eq "SSTRING"
| |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($oldvalue ne $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | &{$self->function()}($self->{VALUE}, $index, $oldvalue, $self); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | } else { | ||||||||||||||||||||||||||||
| 92 | 0 | ▶ | if ($oldvalue != $value) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | 0 | &{$self->function()}($self->{VALUE}, $index, $oldvalue, $self); | |||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | return $self->{VALUE}[$index]; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub FETCH { | ||||||||||||||||||||||||||
|
Subroutine
FETCH: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 104 | 0 | return value(@_); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 0 | ▶ | sub FETCHSIZE { | ||||||||||||||||||||||||||
|
Subroutine
FETCHSIZE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 108 | 0 | return scalar(@{shift->{VALUE}}); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | sub POP { | ||||||||||||||||||||||||||
|
Subroutine
POP: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 112 | 0 | return pop @{shift->{VALUE}}; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub SHIFT { | ||||||||||||||||||||||||||
|
Subroutine
SHIFT: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 116 | 0 | return shift @{shift->{VALUE}}; | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub STORE { | ||||||||||||||||||||||||||
|
Subroutine
STORE: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | 0 | value(@_); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub PUSH { | ||||||||||||||||||||||||||
|
Subroutine
PUSH: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 124 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | 0 | my $vals = $self->{VALUE}; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | my $index; | |||||||||||||||||||||||||||
| 129 | 0 | foreach (@_) { | |||||||||||||||||||||||||||
| 130 | 0 | $index = scalar(@{$vals}); | |||||||||||||||||||||||||||
| 131 | 0 | $vals->[$index] = undef; | |||||||||||||||||||||||||||
| 132 | 0 | $self->value($index, $_); | |||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (!defined $vals->[$index]) { # The value was not accepted | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | pop @{$vals}; # so get rid of this element | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub UNSHIFT { | ||||||||||||||||||||||||||
|
Subroutine
UNSHIFT: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 140 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 141 | 0 | my $vals = $self->{VALUE}; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | while (defined($_ = pop @_)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 0 | unshift @{$vals}, undef; | |||||||||||||||||||||||||||
| 145 | 0 | $self->value(0, $_); | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if (!defined $vals->[0]) { # The value was not accepted | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | 0 | shift @{$vals}; # so get rid of this element | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub parse { | ||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=11 SCAR=48.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | my $string = shift; | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | my $type = $self->type(); | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | my @oldvals; | |||||||||||||||||||||||||||
| 159 | 0 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($string =~ /^\s*unset\s*$/i) { # Magic undef command | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | $self->{VALUE} = []; | |||||||||||||||||||||||||||
| 162 | } else { | ||||||||||||||||||||||||||||
| 163 | 0 | my $vals; | |||||||||||||||||||||||||||
| 164 | my $val; | ||||||||||||||||||||||||||||
| 165 | 0 | my $first = 1; | |||||||||||||||||||||||||||
| 166 | 0 | my $nval = 0; | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | while (defined $string && defined($val = parse_string($type, $string))) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $string and defined($val = &parse_string($type, $string))
MC/DC0%0/2
defined $string and defined($val = &parse_string($type, $string))
defined $string
defined($val = &parse_string($type, $string))
Truth table0%0/3
A and B
A= defined $stringB= defined($val = &parse_string($type, $string))
| |||||||||||||||||||||||||||||
| 168 | 0 | ▶ | if ($first) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 0 | $first = 0; | |||||||||||||||||||||||||||
| 170 | 0 | $vals = $self->{VALUE} = []; | |||||||||||||||||||||||||||
| 171 | 0 | @oldvals = @$vals; # Save in ase of error | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | 0 | $self->PUSH($val); | |||||||||||||||||||||||||||
| 174 | 0 | $nval++; | |||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | 0 | ▶ | if (scalar(@$vals)!=$nval) { # Something went wrong, such as exceeding max | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 0 | $vals = [@oldvals]; | |||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (defined $string) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | warn "Ignored \"$string\"\n"; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | } else { # Print out the values in the list | ||||||||||||||||||||||||||||
| 185 | 0 | print $self->name(), ':'; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (!defined $self->{VALUE} || scalar(@{$self->{VALUE}})==0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $self->{"VALUE"} or scalar @{$self->{"VALUE"};} == 0
MC/DC0%0/2
not defined $self->{"VALUE"} or scalar @{$self->{"VALUE"};} == 0
not defined $self->{"VALUE"}
scalar @{$self->{"VALUE"};} == 0
Truth table0%0/3
not(A) or B
A= not defined $self->{"VALUE"}B= scalar @{$self->{"VALUE"};} == 0
| |||||||||||||||||||||||||||||
| 188 | 0 | print ' unset'; | |||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||
| 190 | 0 | foreach my $val (@{$self->{VALUE}}) { | |||||||||||||||||||||||||||
| 191 | 0 | print ' ', string_value($val, $type); | |||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 1 | 1; | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||