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