CLI/Var.pm

filter: Statementstmt 73.1% 60 / 82 Branchbran 57.8% 22 / 38 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 91.6% 11 / 12 Podpod 0.0% 0 / 4 totaltotal 64.3% 94 / 146 CC 22 SCAR 26.1
CC
22
Cov
66%
value
31.1
parse
6.1
new
5.1
CRAP 13.6
« CLI.pm ↑ Summary CLI/Base.pm »
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
l!l&&r!l&&!r
060
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
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
BranchTrueFalseTotal
if defined $hash->{"function"} 0 6 6
33 6 ▶ $self->min($hash->{min}) if (defined $hash->{min});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"min"} 2 4 6
34 6 ▶ $self->max($hash->{max}) if (defined $hash->{max});
Branch: 1 branch
BranchTrueFalseTotal
if defined $hash->{"max"} 1 5 6
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
BranchTrueFalseTotal
if (@_) 9 10 19
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
BranchTrueFalseTotal
if (defined $min) 3 6 9
55 3 ▶ if ($value<$min) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value < $min) 0 3 3
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
BranchTrueFalseTotal
if (defined $max) 1 8 9
62 1 ▶ if ($value>$max) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value > $max) 0 1 1
63 0 warn " $value greater than maximum ($max)\n";
64 0 $inrange = 0;
65 }
66 }
67 9 ▶ if ($inrange) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inrange) 9 0 9
68 9 $self->{VALUE} = $value;
69 9 ▶ if (defined $self->function()) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->function) 0 9 9
70 0 my $type = $self->type();
71 0 ▶ if ($type == STRING || $type == SSTRING) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type == 3 or $type == 4) { } 0 0 0
Condition0%0/3
$type == 3 or $type == 4
l!l&&r!l&&!r
000
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
ABresult
1X1
011
000
72 0 ▶ if ($oldvalue ne $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldvalue ne $value) 0 0 0
73 0 &{$self->function()}($self->{VALUE}, $oldvalue, $self);
74 }
75  
76 } else {
77 0 ▶ if ($oldvalue != $value) {
Branch: 1 branch
BranchTrueFalseTotal
if ($oldvalue != $value) 0 0 0
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
BranchTrueFalseTotal
if ($type == 5) { } 0 4 4
elsif ($type == 6) { } 4 0 4
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
BranchTrueFalseTotal
if (defined $string) { } 9 2 11
115 9 my $value = parse_string($type, $string);
116  
117 9 ▶ if (! defined $value) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $value) 0 9 9
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
BranchTrueFalseTotal
if (defined $string) 0 9 9
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
BranchTrueFalseTotal
if (defined $self->svalue) { } 2 0 2
129 2 print ' ',$self->svalue(),"\n";
130 } else {
131 0 print " undef\n";
132 }
133 }
134 }
135  
136 1 1;
137  
« CLI.pm ↑ Summary CLI/Base.pm »