line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CLI::Var; |
2
|
1
|
|
|
1
|
|
226
|
use CLI::Base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
46
|
|
3
|
|
|
|
|
|
|
@ISA = ("CLI::Base"); |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
|
|
37
|
use CLI qw(INTEGER FLOAT STRING SSTRING TIME DEGREE |
7
|
1
|
|
|
1
|
|
2
|
BOOLEAN parse_string ); |
|
1
|
|
|
|
|
1
|
|
8
|
1
|
|
|
1
|
|
4
|
use Astro::Time qw(turn2str str2turn); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
122
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
994
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
6
|
|
|
6
|
0
|
6
|
my $proto = shift; |
14
|
6
|
|
33
|
|
|
21
|
my $class = ref($proto) || $proto; |
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
|
|
6
|
my $name = shift; |
17
|
6
|
|
|
|
|
5
|
my $type = shift; |
18
|
6
|
|
|
|
|
7
|
my $value = shift; |
19
|
6
|
|
|
|
|
4
|
my $hash = shift; |
20
|
|
|
|
|
|
|
|
21
|
6
|
|
|
|
|
30
|
my $self = { |
22
|
|
|
|
|
|
|
NAME => $name, |
23
|
|
|
|
|
|
|
TYPE => $type, |
24
|
|
|
|
|
|
|
VALUE => $value, |
25
|
|
|
|
|
|
|
FUNC => undef, |
26
|
|
|
|
|
|
|
MIN => undef, |
27
|
|
|
|
|
|
|
MAX => undef, |
28
|
|
|
|
|
|
|
}; |
29
|
|
|
|
|
|
|
|
30
|
6
|
|
|
|
|
10
|
bless ($self, $class); |
31
|
|
|
|
|
|
|
|
32
|
6
|
50
|
|
|
|
15
|
$self->function($hash->{function}) if (defined $hash->{function}); |
33
|
6
|
100
|
|
|
|
30
|
$self->min($hash->{min}) if (defined $hash->{min}); |
34
|
6
|
100
|
|
|
|
20
|
$self->max($hash->{max}) if (defined $hash->{max}); |
35
|
|
|
|
|
|
|
|
36
|
6
|
|
|
|
|
20
|
return $self; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub TIESCALAR { |
40
|
6
|
|
|
6
|
|
10
|
return new(@_); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub value { |
44
|
19
|
|
|
19
|
0
|
9
|
my $self = shift; |
45
|
|
|
|
|
|
|
|
46
|
19
|
100
|
|
|
|
28
|
if (@_) { |
47
|
9
|
|
|
|
|
7
|
my $value = shift; |
48
|
9
|
|
|
|
|
17
|
my $oldvalue = $self->{VALUE}; |
49
|
9
|
|
|
|
|
15
|
my $min = $self->min(); |
50
|
9
|
|
|
|
|
15
|
my $max = $self->max(); |
51
|
9
|
|
|
|
|
5
|
my $inrange = 1; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# Is the value in range? |
54
|
9
|
100
|
|
|
|
15
|
if (defined $min) { |
55
|
3
|
50
|
|
|
|
8
|
if ($value<$min) { |
56
|
0
|
|
|
|
|
0
|
warn " $value less than minimum ($min)\n"; |
57
|
0
|
|
|
|
|
0
|
$inrange = 0; |
58
|
0
|
|
|
|
|
0
|
$max = undef; # Stop pathological case of complaining about min and max |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
9
|
100
|
|
|
|
12
|
if (defined $max) { |
62
|
1
|
50
|
|
|
|
4
|
if ($value>$max) { |
63
|
0
|
|
|
|
|
0
|
warn " $value greater than maximum ($max)\n"; |
64
|
0
|
|
|
|
|
0
|
$inrange = 0; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
} |
67
|
9
|
50
|
|
|
|
11
|
if ($inrange) { |
68
|
9
|
|
|
|
|
8
|
$self->{VALUE} = $value; |
69
|
9
|
50
|
|
|
|
17
|
if (defined $self->function()) { |
70
|
0
|
|
|
|
|
0
|
my $type = $self->type(); |
71
|
0
|
0
|
0
|
|
|
0
|
if ($type == STRING || $type == SSTRING) { |
72
|
0
|
0
|
|
|
|
0
|
if ($oldvalue ne $value) { |
73
|
0
|
|
|
|
|
0
|
&{$self->function()}($self->{VALUE}, $oldvalue, $self); |
|
0
|
|
|
|
|
0
|
|
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} else { |
77
|
0
|
0
|
|
|
|
0
|
if ($oldvalue != $value) { |
78
|
0
|
|
|
|
|
0
|
&{$self->function()}($self->{VALUE}, $oldvalue, $self); |
|
0
|
|
|
|
|
0
|
|
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
19
|
|
|
|
|
66
|
return $self->{VALUE}; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub FETCH { |
88
|
4
|
|
|
4
|
|
36
|
return shift->{VALUE}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub STORE { |
92
|
0
|
|
|
0
|
|
0
|
my $self = shift; |
93
|
0
|
|
|
|
|
0
|
$self->value(shift); |
94
|
|
|
|
|
|
|
#print "Saved $self->{NAME} as $self->{VALUE}\n"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub svalue { |
98
|
4
|
|
|
4
|
0
|
2
|
my $self = shift; |
99
|
4
|
|
|
|
|
4
|
my $type = $self->{TYPE}; |
100
|
4
|
50
|
|
|
|
7
|
if ($type == TIME) { |
|
|
50
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
return turn2str($self->value(), 'H', 2); |
102
|
|
|
|
|
|
|
} elsif ($type == DEGREE) { |
103
|
4
|
|
|
|
|
5
|
return turn2str($self->value(), 'D', 2); |
104
|
|
|
|
|
|
|
} else { |
105
|
0
|
|
|
|
|
0
|
return $self->value(); |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub parse { |
110
|
11
|
|
|
11
|
0
|
10
|
my $self = shift; |
111
|
11
|
|
|
|
|
8
|
my $string = shift; |
112
|
11
|
|
|
|
|
17
|
my $type = $self->type(); |
113
|
|
|
|
|
|
|
|
114
|
11
|
100
|
|
|
|
14
|
if (defined $string) { |
115
|
9
|
|
|
|
|
14
|
my $value = parse_string($type, $string); |
116
|
|
|
|
|
|
|
|
117
|
9
|
50
|
|
|
|
98
|
if (! defined $value) { |
118
|
0
|
|
|
|
|
0
|
carp "Bad value \"$string\" for type $type\n"; |
119
|
0
|
|
|
|
|
0
|
return; |
120
|
|
|
|
|
|
|
} |
121
|
9
|
50
|
|
|
|
11
|
if (defined $string) { # String should be undef if only one value was passed |
122
|
0
|
|
|
|
|
0
|
carp "Did not understand \"$string\n"; |
123
|
0
|
|
|
|
|
0
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
9
|
|
|
|
|
18
|
$self->value($value); |
127
|
|
|
|
|
|
|
} else { |
128
|
2
|
50
|
|
|
|
4
|
if (defined $self->svalue()) { |
129
|
2
|
|
|
|
|
64
|
print ' ',$self->svalue(),"\n"; |
130
|
|
|
|
|
|
|
} else { |
131
|
0
|
|
|
|
|
|
print " undef\n"; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
1; |
137
|
|
|
|
|
|
|
|