line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Array; |
2
|
1
|
|
|
1
|
|
4
|
use CLI::Base; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
3
|
|
|
|
|
|
|
@ISA = ("CLI::Base"); |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
90
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use CLI qw(parse_string typeStr string_value); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
56
|
|
8
|
|
|
|
|
|
|
#use CLI::Var; |
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
910
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
13
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $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
|
0
|
|
|
|
|
$self->function($hash->{function}) if (defined $hash->{function}); |
31
|
0
|
0
|
|
|
|
|
$self->min($hash->{min}) if (defined $hash->{min}); |
32
|
0
|
0
|
|
|
|
|
$self->max($hash->{max}) if (defined $hash->{max}); |
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
|
|
|
|
|
|
|
sub TIEARRAY { |
44
|
0
|
|
|
0
|
|
|
return new(@_); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub value { |
48
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
49
|
0
|
|
|
|
|
|
my $index = shift; |
50
|
0
|
|
|
|
|
|
my $value = shift; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
if (!defined $index) { # Return the whole lot as a list |
53
|
0
|
|
|
|
|
|
return @{$self->{VALUE}}; |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} else { |
55
|
|
|
|
|
|
|
# Verify the index value |
56
|
0
|
0
|
|
|
|
|
if ($index<0) { |
57
|
0
|
|
|
|
|
|
carp "Index $index out of range"; |
58
|
0
|
|
|
|
|
|
return undef; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
if (!defined $value) { # Return a value |
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
|
0
|
|
|
|
|
if (defined $min) { |
70
|
0
|
0
|
|
|
|
|
if ($value<$min) { |
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
|
0
|
|
|
|
|
if (defined $max) { |
77
|
0
|
0
|
|
|
|
|
if ($value>$max) { |
78
|
0
|
|
|
|
|
|
warn " $value greater than maximum ($max)\n"; |
79
|
0
|
|
|
|
|
|
$inrange = 0; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
|
|
|
|
if ($inrange) { |
84
|
0
|
|
|
|
|
|
$self->{VALUE}[$index] = $value; |
85
|
0
|
0
|
|
|
|
|
if (defined $self->function()) { |
86
|
0
|
|
|
|
|
|
my $type = $self->type(); |
87
|
0
|
0
|
0
|
|
|
|
if ($type eq 'STRING' || $type eq 'SSTRING') { |
88
|
0
|
0
|
|
|
|
|
if ($oldvalue ne $value) { |
89
|
0
|
|
|
|
|
|
&{$self->function()}($self->{VALUE}, $index, $oldvalue, $self); |
|
0
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
} else { |
92
|
0
|
0
|
|
|
|
|
if ($oldvalue != $value) { |
93
|
0
|
|
|
|
|
|
&{$self->function()}($self->{VALUE}, $index, $oldvalue, $self); |
|
0
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
return $self->{VALUE}[$index]; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub FETCH { |
104
|
0
|
|
|
0
|
|
|
return value(@_); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub FETCHSIZE { |
108
|
0
|
|
|
0
|
|
|
return scalar(@{shift->{VALUE}}); |
|
0
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub POP { |
112
|
0
|
|
|
0
|
|
|
return pop @{shift->{VALUE}}; |
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub SHIFT { |
116
|
0
|
|
|
0
|
|
|
return shift @{shift->{VALUE}}; |
|
0
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub STORE { |
120
|
0
|
|
|
0
|
|
|
value(@_); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub PUSH { |
124
|
0
|
|
|
0
|
|
|
my $self = shift; |
125
|
|
|
|
|
|
|
|
126
|
0
|
|
|
|
|
|
my $vals = $self->{VALUE}; |
127
|
|
|
|
|
|
|
|
128
|
0
|
|
|
|
|
|
my $index; |
129
|
0
|
|
|
|
|
|
foreach (@_) { |
130
|
0
|
|
|
|
|
|
$index = scalar(@{$vals}); |
|
0
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
$vals->[$index] = undef; |
132
|
0
|
|
|
|
|
|
$self->value($index, $_); |
133
|
0
|
0
|
|
|
|
|
if (!defined $vals->[$index]) { # The value was not accepted |
134
|
0
|
|
|
|
|
|
pop @{$vals}; # so get rid of this element |
|
0
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub UNSHIFT { |
140
|
0
|
|
|
0
|
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
my $vals = $self->{VALUE}; |
142
|
|
|
|
|
|
|
|
143
|
0
|
|
|
|
|
|
while (defined($_ = pop @_)) { |
144
|
0
|
|
|
|
|
|
unshift @{$vals}, undef; |
|
0
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
$self->value(0, $_); |
146
|
0
|
0
|
|
|
|
|
if (!defined $vals->[0]) { # The value was not accepted |
147
|
0
|
|
|
|
|
|
shift @{$vals}; # so get rid of this element |
|
0
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub parse { |
153
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
154
|
0
|
|
|
|
|
|
my $string = shift; |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
my $type = $self->type(); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
my @oldvals; |
159
|
0
|
0
|
|
|
|
|
if (defined $string) { |
160
|
0
|
0
|
|
|
|
|
if ($string =~ /^\s*unset\s*$/i) { # Magic undef command |
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
|
|
0
|
|
|
|
while (defined $string && defined($val = parse_string($type, $string))) { |
168
|
0
|
0
|
|
|
|
|
if ($first) { |
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
|
0
|
|
|
|
|
if (scalar(@$vals)!=$nval) { # Something went wrong, such as exceeding max |
177
|
0
|
|
|
|
|
|
$vals = [@oldvals]; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
0
|
0
|
|
|
|
|
if (defined $string) { |
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
|
0
|
0
|
|
|
|
if (!defined $self->{VALUE} || scalar(@{$self->{VALUE}})==0) { |
|
0
|
|
|
|
|
|
|
188
|
0
|
|
|
|
|
|
print ' unset'; |
189
|
|
|
|
|
|
|
} |
190
|
0
|
|
|
|
|
|
foreach my $val (@{$self->{VALUE}}) { |
|
0
|
|
|
|
|
|
|
191
|
0
|
|
|
|
|
|
print ' ', string_value($val, $type); |
192
|
|
|
|
|
|
|
} |
193
|
0
|
|
|
|
|
|
print "\n"; |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
|