blib/lib/Math/RPN.pm

filter: Statementstmt 70.2% 170 / 242 Branchbran 78.0% 142 / 182 Conditioncond 75.8% 44 / 58 MC/DCmcdc 64.8% 24 / 37 Subroutinesub 100% 7 / 7 Podpod 0.0% 0 / 3 totaltotal 73.1% 387 / 529 CC 111 SCAR 58.2
CC
111
Cov
74%
rpn
360.9
logmsg
2.0
stackcheck
2.0
CRAP 336.4
↑ Summary
1 package Math::RPN;
2  
3 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use vars qw($VERSION @ISA @EXPORT);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 require Exporter;
9  
10 2 @ISA = qw(Exporter);
11 2 @EXPORT = qw( rpn );
12 2 $VERSION = '1.11';
13  
14 144 ▶sub rpn {
Subroutine rpn: called CC=109 SCAR=58.9
Pod undocumented
15 144 my $convr = join( ",", @_ ); # Get all the expressions
16 144 $convr =~ s/,,//g; # In case someone gave us extra ,'s
17 144 my @stack = ();
18 144 my @ops = split( /,/, $convr );
19 144 my $inbrace = 0;
20 144 my $bracexp = "";
21 144 my @completed = ();
22 144 ▶ while (@ops) {
Branch: 1 branch
BranchTrueFalseTotal
if (@ops) 796 140 936
23 796 $_ = uc( shift(@ops) );
24 796 s/\s+//g; # Eliminate unneeded spaces
25 796 ▶ if ( $_ eq "{" ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($_ eq '{') { } 20 776 796
elsif ($_ eq '}') { } 19 757 776
26 20 ▶ if ($inbrace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inbrace) 1 19 20
27 1 logmsg(
28 'err',
29 "Cannot nest braces expr ",
30 join( ",", @completed ),
31 ",<<<$_>>>,", join( ",", @ops )
32 );
33 1 last;
34 }
35 19 $inbrace++;
36 19 $bracexp = "";
37 19 next;
38 }
39 elsif ( $_ eq "}" ) {
40 19 ▶ unless ($inbrace) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($inbrace) 1 18 19
41 1 logmsg(
42 'err',
43 "Unexpected Right Brace ",
44 join( ",", @completed ),
45 ",<<<$_>>>,", join( ",", @ops )
46 );
47 1 last;
48 }
49 18 $inbrace--;
50 18 $bracexp =~ s/,$//; # Strip trailing comma if any
51 18 push( @stack, $bracexp );
52 18 next;
53 }
54 757 ▶ if ($inbrace) {
Branch: 1 branch
BranchTrueFalseTotal
if ($inbrace) 90 667 757
55 90 $bracexp .= $_ . ",";
56 90 next;
57 }
58  
59 667 ▶ if ( $_ eq "+" || $_ eq "ADD" ) {
Branch: 36 branches
BranchTrueFalseTotal
if ($_ eq '+' or $_ eq 'ADD') { } 13 654 667
elsif ($_ eq '++' or $_ eq 'INCR') { } 15 639 654
elsif ($_ eq '-' or $_ eq 'SUB') { } 3 636 639
elsif ($_ eq '--' or $_ eq 'DECR') { } 15 621 636
elsif ($_ eq '*' or $_ eq 'MUL') { } 42 579 621
elsif ($_ eq '/' or $_ eq 'DIV') { } 15 564 579
elsif ($_ eq '%' or $_ eq 'MOD') { } 3 561 564
elsif ($_ eq 'POW') { } 3 558 561
elsif ($_ eq 'SQRT') { } 3 555 558
elsif ($_ eq 'ABS') { } 3 552 555
elsif ($_ eq '&' or $_ eq 'AND') { } 6 546 552
elsif ($_ eq '|' or $_ eq 'OR') { } 6 540 546
elsif ($_ eq 'XOR') { } 24 516 540
elsif ($_ eq '!' or $_ eq 'NOT') { } 6 510 516
elsif ($_ eq '~') { } 9 501 510
elsif ($_ eq 'SIN') { } 3 498 501
elsif ($_ eq 'COS') { } 3 495 498
elsif ($_ eq 'TAN') { } 3 492 495
elsif ($_ eq 'LOG') { } 3 489 492
elsif ($_ eq 'EXP') { } 3 486 489
elsif ($_ eq 'INT') { } 3 483 486
elsif ($_ eq '<' or $_ eq 'LT') { } 6 477 483
elsif ($_ eq '<=' or $_ eq 'LE') { } 9 468 477
elsif ($_ eq '=' or $_ eq '==' or $_ eq 'EQ') { } 0 468 468
elsif ($_ eq '>=' or $_ eq 'GT') { } 9 459 468
elsif ($_ eq '>' or $_ eq 'GE') { } 3 456 459
elsif ($_ eq '!=' or $_ eq 'NE') { } 6 450 456
elsif ($_ eq 'IF') { } 36 414 450
elsif ($_ eq 'DUP') { } 9 405 414
elsif ($_ eq 'EXCH') { } 6 399 405
elsif ($_ eq 'POP') { } 6 393 399
elsif ($_ eq 'MIN') { } 9 384 393
elsif ($_ eq 'MAX') { } 15 369 384
elsif ($_ eq 'TIME') { } 1 368 369
elsif ($_ eq 'RAND') { } 1 367 368
elsif ($_ eq 'LRAND') { } 1 366 367
Condition66%2/3
$_ eq "+" or $_ eq "ADD"
l!l&&r!l&&!r
130654
MC/DC50%1/2
$_ eq "+" or $_ eq "ADD"
$_ eq "+" $_ eq "ADD"
Truth table66%2/3
A or B
A= $_ eq "+"B= $_ eq "ADD"
ABresult
1X1
011
000
60 13 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 1 12 13
61 1 @stack = (undef);
62 1 last;
63 }
64 12 push( @stack, pop(@stack) + pop(@stack) );
65 }
66 ▶ elsif ( $_ eq "++" || $_ eq "INCR" ) {
Condition66%2/3
$_ eq "++" or $_ eq "INCR"
l!l&&r!l&&!r
150639
MC/DC50%1/2
$_ eq "++" or $_ eq "INCR"
$_ eq "++" $_ eq "INCR"
Truth table66%2/3
A or B
A= $_ eq "++"B= $_ eq "INCR"
ABresult
1X1
011
000
67 15 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 15 15
68 0 @stack = (undef);
69 0 last;
70 }
71 15 push( @stack, pop(@stack) + 1 );
72 }
73 ▶ elsif ( $_ eq "-" || $_ eq "SUB" ) {
Condition66%2/3
$_ eq "-" or $_ eq "SUB"
l!l&&r!l&&!r
30636
MC/DC50%1/2
$_ eq "-" or $_ eq "SUB"
$_ eq "-" $_ eq "SUB"
Truth table66%2/3
A or B
A= $_ eq "-"B= $_ eq "SUB"
ABresult
1X1
011
000
74 3 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 3 3
75 0 @stack = (undef);
76 0 last;
77 }
78 3 my $v1 = pop(@stack);
79 3 my $v2 = pop(@stack);
80 3 push( @stack, $v2 - $v1 );
81 }
82 ▶ elsif ( $_ eq "--" || $_ eq "DECR" ) {
Condition66%2/3
$_ eq "--" or $_ eq "DECR"
l!l&&r!l&&!r
150621
MC/DC50%1/2
$_ eq "--" or $_ eq "DECR"
$_ eq "--" $_ eq "DECR"
Truth table66%2/3
A or B
A= $_ eq "--"B= $_ eq "DECR"
ABresult
1X1
011
000
83 15 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 15 15
84 0 @stack = (undef);
85 0 last;
86 }
87 15 push( @stack, pop(@stack) - 1 );
88 }
89 ▶ elsif ( $_ eq "\*" || $_ eq "MUL" ) {
Condition100%3/3
$_ eq "*" or $_ eq "MUL"
l!l&&r!l&&!r
366579
MC/DC100%2/2
$_ eq "*" or $_ eq "MUL"
$_ eq "*" $_ eq "MUL"
Truth table100%3/3
A or B
A= $_ eq "*"B= $_ eq "MUL"
ABresult
1X1
011
000
90 42 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 42 42
91 0 @stack = (undef);
92 0 last;
93 }
94 42 push( @stack, pop(@stack) * pop(@stack) );
95 }
96 ▶ elsif ( $_ eq "\/" || $_ eq "DIV" ) {
Condition100%3/3
$_ eq "/" or $_ eq "DIV"
l!l&&r!l&&!r
96564
MC/DC100%2/2
$_ eq "/" or $_ eq "DIV"
$_ eq "/" $_ eq "DIV"
Truth table100%3/3
A or B
A= $_ eq "/"B= $_ eq "DIV"
ABresult
1X1
011
000
97 15 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 15 15
98 0 @stack = (undef);
99 0 last;
100 }
101 15 my $v1 = pop(@stack);
102 15 my $v2 = pop(@stack);
103 15 push( @stack, $v2 / $v1 );
104 }
105 ▶ elsif ( $_ eq "%" || $_ eq "MOD" ) {
Condition66%2/3
$_ eq "%" or $_ eq "MOD"
l!l&&r!l&&!r
30561
MC/DC50%1/2
$_ eq "%" or $_ eq "MOD"
$_ eq "%" $_ eq "MOD"
Truth table66%2/3
A or B
A= $_ eq "%"B= $_ eq "MOD"
ABresult
1X1
011
000
106 3 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 3 3
107 0 @stack = (undef);
108 0 last;
109 }
110 3 my $v1 = pop(@stack);
111 3 my $v2 = pop(@stack);
112 3 push( @stack, $v2 % $v1 );
113 }
114 elsif ( $_ eq "POW" ) {
115 3 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 3 3
116 0 @stack = (undef);
117 0 last;
118 }
119 3 my $v1 = pop(@stack);
120 3 my $v2 = pop(@stack);
121 3 push( @stack, $v2**$v1 );
122 }
123 elsif ( $_ eq "SQRT" ) {
124 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
125 0 @stack = (undef);
126 0 last;
127 }
128 3 push( @stack, sqrt( pop(@stack) ) );
129 }
130 elsif ( $_ eq "ABS" ) {
131 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
132 0 @stack = (undef);
133 0 last;
134 }
135 3 push( @stack, abs( pop(@stack) ) );
136 }
137 ▶ elsif ( $_ eq "&" || $_ eq "AND" ) {
Condition100%3/3
$_ eq "&" or $_ eq "AND"
l!l&&r!l&&!r
33546
MC/DC100%2/2
$_ eq "&" or $_ eq "AND"
$_ eq "&" $_ eq "AND"
Truth table100%3/3
A or B
A= $_ eq "&"B= $_ eq "AND"
ABresult
1X1
011
000
138 6 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 6 6
139 0 @stack = (undef);
140 0 last;
141 }
142 6 my $v1 = int( pop(@stack) );
143 6 my $v2 = int( pop(@stack) );
144 6 push( @stack, ( $v1 & $v2 ) );
145 }
146 ▶ elsif ( $_ eq "|" || $_ eq "OR" ) {
Condition100%3/3
$_ eq "|" or $_ eq "OR"
l!l&&r!l&&!r
33540
MC/DC100%2/2
$_ eq "|" or $_ eq "OR"
$_ eq "|" $_ eq "OR"
Truth table100%3/3
A or B
A= $_ eq "|"B= $_ eq "OR"
ABresult
1X1
011
000
147 6 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 6 6
148 0 @stack = (undef);
149 0 last;
150 }
151 6 push( @stack, ( int( pop(@stack) ) | int( pop(@stack) ) ) );
152 }
153 elsif ( $_ eq "XOR" ) {
154 24 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 24 24
155 0 @stack = (undef);
156 0 last;
157 }
158 24 ▶ push( @stack, ( int( pop(@stack) ) xor int( pop(@stack) ) ) );
Condition100%4/4
int pop @stack ^^ int pop @stack
l&&rl&&!r!l&&r!l&&!r
9663
MC/DC100%2/2
int pop @stack ^^ int pop @stack
int pop @stack int pop @stack
Truth table100%4/4
A ^^ B
A= int pop @stackB= int pop @stack
ABresult
110
101
011
000
159 }
160 ▶ elsif ( $_ eq "!" || $_ eq "NOT" ) {
Condition100%3/3
$_ eq "!" or $_ eq "NOT"
l!l&&r!l&&!r
33510
MC/DC100%2/2
$_ eq "!" or $_ eq "NOT"
$_ eq "!" $_ eq "NOT"
Truth table100%3/3
A or B
A= $_ eq "!"B= $_ eq "NOT"
ABresult
1X1
011
000
161 6 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 6 6
162 0 @stack = (undef);
163 0 last;
164 }
165 6 push( @stack, !( int( pop(@stack) ) ) );
166 }
167 elsif ( $_ eq "~" ) {
168 9 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 9 9
169 0 @stack = (undef);
170 0 last;
171 }
172 9 push( @stack, ~( int( pop(@stack) ) ) );
173 }
174 elsif ( $_ eq "SIN" ) {
175 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
176 0 @stack = (undef);
177 0 last;
178 }
179 3 push( @stack, sin( pop(@stack) ) );
180 }
181 elsif ( $_ eq "COS" ) {
182 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
183 0 @stack = (undef);
184 0 last;
185 }
186 3 push( @stack, cos( pop(@stack) ) );
187 }
188 elsif ( $_ eq "TAN" ) {
189 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
190 0 @stack = (undef);
191 0 last;
192 }
193 3 my $v1 = pop(@stack);
194 3 push( @stack, ( sin($v1) / cos($v1) ) );
195 }
196 elsif ( $_ eq "LOG" ) {
197 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
198 0 @stack = (undef);
199 0 last;
200 }
201 3 push( @stack, log( pop(@stack) ) );
202 }
203 elsif ( $_ eq "EXP" ) {
204 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
205 0 @stack = (undef);
206 0 last;
207 }
208 3 push( @stack, exp( pop(@stack) ) );
209 }
210 elsif ( $_ eq "INT" ) {
211 3 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 3 3
212 0 @stack = (undef);
213 0 last;
214 }
215 3 push( @stack, int( pop(@stack) ) );
216 }
217 ▶ elsif ( $_ eq "<" || $_ eq "LT" ) {
Condition66%2/3
$_ eq "<" or $_ eq "LT"
l!l&&r!l&&!r
06477
MC/DC50%1/2
$_ eq "<" or $_ eq "LT"
$_ eq "<" $_ eq "LT"
Truth table66%2/3
A or B
A= $_ eq "<"B= $_ eq "LT"
ABresult
1X1
011
000
218 6 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 6 6
219 0 @stack = (undef);
220 0 last;
221 }
222 6 my $v1 = pop(@stack);
223 6 my $v2 = pop(@stack);
224 6 ▶ push( @stack, ( $v2 < $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 < $v1 ? : 3 3 6
225 }
226 ▶ elsif ( $_ eq "<=" || $_ eq "LE" ) {
Condition66%2/3
$_ eq "<=" or $_ eq "LE"
l!l&&r!l&&!r
09468
MC/DC50%1/2
$_ eq "<=" or $_ eq "LE"
$_ eq "<=" $_ eq "LE"
Truth table66%2/3
A or B
A= $_ eq "<="B= $_ eq "LE"
ABresult
1X1
011
000
227 9 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 9 9
228 0 @stack = (undef);
229 0 last;
230 }
231 9 my $v1 = pop(@stack);
232 9 my $v2 = pop(@stack);
233 9 ▶ push( @stack, ( $v2 <= $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 <= $v1 ? : 6 3 9
234 }
235 ▶ elsif ( $_ eq "=" || $_ eq "==" || $_ eq "EQ" ) {
Condition33%2/6
$_ eq "=" or $_ eq "==" or $_ eq "EQ"
l!l&&r!l&&!r
00468
$_ eq "=" or $_ eq "=="
l!l&&r!l&&!r
00468
MC/DC0%0/3
$_ eq "=" or $_ eq "==" or $_ eq "EQ"
$_ eq "=" $_ eq "==" $_ eq "EQ"
Truth table25%1/4
A or B or C
A= $_ eq "="B= $_ eq "=="C= $_ eq "EQ"
ABCresult
1XX1
01X1
0011
0000
236 0 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 0 0
237 0 @stack = (undef);
238 0 last;
239 }
240 0 my $v1 = pop(@stack);
241 0 my $v2 = pop(@stack);
242 0 ▶ push( @stack, ( $v2 == $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 == $v1 ? : 0 0 0
243 }
244 ▶ elsif ( $_ eq ">=" || $_ eq "GT" ) {
Condition66%2/3
$_ eq ">=" or $_ eq "GT"
l!l&&r!l&&!r
09459
MC/DC50%1/2
$_ eq ">=" or $_ eq "GT"
$_ eq ">=" $_ eq "GT"
Truth table66%2/3
A or B
A= $_ eq ">="B= $_ eq "GT"
ABresult
1X1
011
000
245 9 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 9 9
246 0 @stack = (undef);
247 0 last;
248 }
249 9 my $v1 = pop(@stack);
250 9 my $v2 = pop(@stack);
251 9 ▶ push( @stack, ( $v2 > $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 > $v1 ? : 6 3 9
252 }
253 ▶ elsif ( $_ eq ">" || $_ eq "GE" ) {
Condition66%2/3
$_ eq ">" or $_ eq "GE"
l!l&&r!l&&!r
03456
MC/DC50%1/2
$_ eq ">" or $_ eq "GE"
$_ eq ">" $_ eq "GE"
Truth table66%2/3
A or B
A= $_ eq ">"B= $_ eq "GE"
ABresult
1X1
011
000
254 3 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 3 3
255 0 @stack = (undef);
256 0 last;
257 }
258 3 my $v1 = pop(@stack);
259 3 my $v2 = pop(@stack);
260 3 ▶ push( @stack, ( $v2 >= $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 >= $v1 ? : 3 0 3
261 }
262 ▶ elsif ( $_ eq "!=" || $_ eq "NE" ) {
Condition66%2/3
$_ eq "!=" or $_ eq "NE"
l!l&&r!l&&!r
06450
MC/DC50%1/2
$_ eq "!=" or $_ eq "NE"
$_ eq "!=" $_ eq "NE"
Truth table66%2/3
A or B
A= $_ eq "!="B= $_ eq "NE"
ABresult
1X1
011
000
263 6 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 6 6
264 0 @stack = (undef);
265 0 last;
266 }
267 6 my $v1 = pop(@stack);
268 6 my $v2 = pop(@stack);
269 6 ▶ push( @stack, ( $v2 != $v1 ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v2 != $v1 ? : 3 3 6
270 }
271 elsif ( $_ eq "IF" ) {
272 36 ▶ unless ( stackcheck( 3, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(3, \@stack, \@completed, $_, \@ops)) 0 36 36
273 0 @stack = (undef);
274 0 last;
275 }
276 36 my $el = pop(@stack);
277 36 my $th = pop(@stack);
278 36 my $co = pop(@stack);
279 36 ▶ my $ve = ( $co ? $th : $el );
Branch: 1 branch
BranchTrueFalseTotal
$co ? : 24 12 36
280 36 ▶ if ( $ve =~ /,/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ve =~ /,/) { } 9 27 36
281  
282 # Execute brace-enclosed expression
283 9 @stack = rpn( join( ",", @stack, $ve ) );
284 }
285 else {
286 27 push( @stack, $ve );
287 }
288 }
289 elsif ( $_ eq "DUP" ) {
290 9 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 9 9
291 0 @stack = (undef);
292 0 last;
293 }
294 9 my $v1 = pop(@stack);
295 9 push( @stack, $v1, $v1 );
296 }
297 elsif ( $_ eq "EXCH" ) {
298 6 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 6 6
299 0 @stack = (undef);
300 0 last;
301 }
302 6 my $v1 = pop(@stack);
303 6 my $v2 = pop(@stack);
304 6 push( @stack, $v1, $v2 );
305 }
306 elsif ( $_ eq "POP" ) {
307 6 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 1 5 6
308 1 @stack = (undef);
309 1 last;
310 }
311 5 pop(@stack);
312 }
313 elsif ( $_ eq "MIN" ) {
314 9 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 9 9
315 0 @stack = (undef);
316 0 last;
317 }
318 9 my $v1 = pop(@stack);
319 9 my $v2 = pop(@stack);
320 9 ▶ push( @stack, ( $v1 < $v2 ? $v1 : $v2 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v1 < $v2 ? : 9 0 9
321 }
322 elsif ( $_ eq "MAX" ) {
323 15 ▶ unless ( stackcheck( 2, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(2, \@stack, \@completed, $_, \@ops)) 0 15 15
324 0 @stack = (undef);
325 0 last;
326 }
327 15 my $v1 = pop(@stack);
328 15 my $v2 = pop(@stack);
329 15 ▶ push( @stack, ( $v1 > $v2 ? $v1 : $v2 ) );
Branch: 1 branch
BranchTrueFalseTotal
$v1 > $v2 ? : 6 9 15
330 }
331 elsif ( $_ eq "TIME" ) {
332 1 push( @stack, time() );
333 }
334 elsif ( $_ eq "RAND" ) {
335 1 push( @stack, rand() );
336 }
337 elsif ( $_ eq "LRAND" ) {
338 1 ▶ unless ( stackcheck( 1, \@stack, \@completed, $_, \@ops ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (stackcheck(1, \@stack, \@completed, $_, \@ops)) 0 1 1
339 0 @stack = (undef);
340 0 last;
341 }
342 1 push( @stack, rand( pop(@stack) ) );
343 }
344 else {
345 366 push( @stack, $_ );
346 }
347  
348 # Record that we've completed the operation (for diagnostics).
349 665 push( @completed, $_ );
350 }
351  
352 # OK... Expression executed, let's return the results.
353  
354 144 ▶ unless (@stack) {
Branch: 2 branches
BranchTrueFalseTotal
if (@stack) { } 144 0 144
if (do { $#stack > 0 and wantarray == 0 }) 1 283 284
355 0 @stack = (undef);
356 0 logmsg( 'err',
357 "Stack underflow for expr " . "$convr, no value at end." );
358 }
359 0 ▶ elsif ( $#stack > 0 && wantarray == 0 ) {
Condition100%3/3
$#stack > 0 && wantarray == 0
!ll&&!rl&&r
14031
MC/DC100%2/2
$#stack > 0 && wantarray == 0
$#stack > 0 wantarray == 0
Truth table100%3/3
A && B
A= $#stack > 0B= wantarray == 0
ABresult
0X0
100
111
360 1 logmsg( 'warning',
361 "Extra values left on stack for "
362 . "expr $convr left "
363 . join( ",", @stack )
364 . " (right one used)." );
365 }
366 144 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 54 90 144
367 54 return (@stack);
368 }
369 else {
370 90 return ( pop(@stack) );
371 }
372 }
373  
374 5 ▶sub logmsg {
Subroutine logmsg: called CC=2 SCAR=7.1
Pod undocumented
375 5 my $severity;
376 my $message;
377  
378 5 ▶ if ( scalar(@_) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ > 1) { } 5 0 5
379 5 $severity = shift;
380 }
381 else {
382 0 $severity = "err"; # Default to LOG_ERR severity
383 }
384  
385 5 $message = join( "", @_ );
386 5 $message =~ s/\r/\\r/g;
387 5 $message =~ s/\n/\\n/g;
388 5 warn "$0 pid[$$]: $severity: $message at " . localtime() . "\n";
389 }
390  
391 299 ▶sub stackcheck {
Subroutine stackcheck: called CC=2 SCAR=6.9
Pod undocumented
392 299 my ( $required, $sp, $completed, $current, $todo ) = @_;
393  
394 299 my @stack = @$sp;
395  
396 299 ▶ if ( @stack < $required ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@stack < $required) 2 297 299
397 2 logmsg(
398 'err',
399 "Stack Underflow in ",
400 join( ",", (@$completed) ),
401 ",<<<$current>>>,", join( ",", (@$todo) )
402 );
403 2 return;
404 }
405 297 return scalar @stack;
406 }
407  
408 2 1;
409 __END__
↑ Summary