Kit/Steer.pm

filter: Statementstmt 100% 72 / 72 Branchbran 98.0% 49 / 50 Conditioncond 90.7% 49 / 54 MC/DCmcdc 81.8% 27 / 33 Subroutinesub 100% 9 / 9 Podpod 100% 6 / 6 totaltotal 94.6% 212 / 224 CC 47 SCAR 23.0
CC
47
Cov
97%
nearest
15.0
axis
11.3
clamp
10.0
CRAP 9.9
« Kit/Options.pm ↑ Summary Kit/Canvas.pm »
1 package Game::Terminal::Kit::Steer;
2  
3 6 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.02';
8  
9 6 my %WAY = (
10 up => [ 0, -1 ],
11 down => [ 0, 1 ],
12 left => [ -1, 0 ],
13 right => [ 1, 0 ],
14 );
15  
16 6 ▶sub way {
Subroutine way: called CC=3 SCAR=11.0
Pod documented
17 6 my ($key) = @_;
18 6 ▶ return () unless defined $key && $WAY{$key};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key and $WAY{$key} 2 4 6
Condition100%3/3
defined $key and $WAY{$key}
!ll&&!rl&&r
114
MC/DC100%2/2
defined $key and $WAY{$key}
defined $key $WAY{$key}
Truth table100%3/3
A and B
A= defined $keyB= $WAY{$key}
ABresult
0X0
100
111
19 4 return @{ $WAY{$key} };
20 }
21  
22 113 ▶sub ring {
Subroutine ring: called CC=7 SCAR=19.5
Pod documented
23 113 my ($count, $at, $delta, $skip) = @_;
24 113 ▶ return $at unless $count && $delta;
Branch: 1 branch
BranchTrueFalseTotal
unless $count and $delta 2 111 113
Condition100%3/3
$count and $delta
!ll&&!rl&&r
11111
MC/DC100%2/2
$count and $delta
$count $delta
Truth table100%3/3
A and B
A= $countB= $delta
ABresult
0X0
100
111
25 111 ▶ my $step = $delta > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$delta > 0 ? : 58 53 111
26 111 my $next = ($at + $delta) % $count;
27 111 for (1 .. $count) {
28 130 ▶ return $next unless $skip && $skip->($next);
Branch: 1 branch
BranchTrueFalseTotal
unless $skip and &$skip($next) 109 21 130
Condition100%3/3
$skip and &$skip($next)
!ll&&!rl&&r
149521
MC/DC100%2/2
$skip and &$skip($next)
$skip &$skip($next)
Truth table100%3/3
A and B
A= $skipB= &$skip($next)
ABresult
0X0
100
111
29 21 $next = ($next + $step) % $count;
30 }
31 2 return $at;
32 }
33  
34 11 ▶sub clamp {
Subroutine clamp: called CC=10 SCAR=23.0
Pod documented
35 11 my ($count, $at, $delta, $skip) = @_;
36 11 ▶ return $at unless $count && $delta;
Branch: 1 branch
BranchTrueFalseTotal
unless $count and $delta 1 10 11
Condition66%2/3
$count and $delta
!ll&&!rl&&r
1010
MC/DC50%1/2
$count and $delta
$count $delta
Truth table66%2/3
A and B
A= $countB= $delta
ABresult
0X0
100
111
37 10 ▶ my $step = $delta > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
$delta > 0 ? : 5 5 10
38 10 my $next = $at + $delta;
39 10 ▶ $next = 0 if $next < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $next < 0 4 6 10
40 10 ▶ $next = $count - 1 if $next > $count - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $next > $count - 1 2 8 10
41 10 ▶ while ($next >= 0 && $next < $count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next >= 0 and $next < $count) 11 3 14
Condition100%3/3
$next >= 0 and $next < $count
!ll&&!rl&&r
2111
MC/DC100%2/2
$next >= 0 and $next < $count
$next >= 0 $next < $count
Truth table100%3/3
A and B
A= $next >= 0B= $next < $count
ABresult
0X0
100
111
42 11 ▶ return $next unless $skip && $skip->($next);
Branch: 1 branch
BranchTrueFalseTotal
unless $skip and &$skip($next) 7 4 11
Condition100%3/3
$skip and &$skip($next)
!ll&&!rl&&r
614
MC/DC100%2/2
$skip and &$skip($next)
$skip &$skip($next)
Truth table100%3/3
A and B
A= $skipB= &$skip($next)
ABresult
0X0
100
111
43 4 $next += $step;
44 }
45 3 return $at;
46 }
47  
48 27 ▶sub nearest {
Subroutine nearest: called CC=15 SCAR=27.1
Pod documented
49 27 my ($points, $at, $dx, $dy, %option) = @_;
50 27 ▶ return undef unless $dx || $dy;
Branch: 1 branch
BranchTrueFalseTotal
unless $dx or $dy 1 26 27
Condition100%3/3
$dx or $dy
l!l&&r!l&&!r
2151
MC/DC100%2/2
$dx or $dy
$dx $dy
Truth table100%3/3
A or B
A= $dxB= $dy
ABresult
1X1
011
000
51 26 ▶ my $from = $points->[$at] or return undef;
Branch: 1 branch
BranchTrueFalseTotal
my $from = $points->[$at] or return undef 25 1 26
52 25 my $skip = $option{skip};
53 25 my ($best, $best_cost, $best_across);
54 25 for my $index (0 .. $#{$points}) {
55 160 ▶ next if $index == $at;
Branch: 1 branch
BranchTrueFalseTotal
if $index == $at 25 135 160
56 135 ▶ next if $skip && $skip->($index);
Branch: 1 branch
BranchTrueFalseTotal
if $skip and &$skip($index) 1 134 135
Condition100%3/3
$skip and &$skip($index)
!ll&&!rl&&r
12771
MC/DC100%2/2
$skip and &$skip($index)
$skip &$skip($index)
Truth table100%3/3
A and B
A= $skipB= &$skip($index)
ABresult
0X0
100
111
57 134 my $x = $points->[$index][0] - $from->[0];
58 134 my $y = $points->[$index][1] - $from->[1];
59 134 my $along = $x * $dx + $y * $dy;
60 134 my $across = abs($x * $dy - $y * $dx);
61 134 ▶ next if $along <= 0;
Branch: 1 branch
BranchTrueFalseTotal
if $along <= 0 83 51 134
62 51 ▶ next if $option{cone} && $across > $along;
Branch: 1 branch
BranchTrueFalseTotal
if $option{"cone"} and $across > $along 1 50 51
Condition100%3/3
$option{"cone"} and $across > $along
!ll&&!rl&&r
4821
MC/DC100%2/2
$option{"cone"} and $across > $along
$option{"cone"} $across > $along
Truth table100%3/3
A and B
A= $option{"cone"}B= $across > $along
ABresult
0X0
100
111
63 50 my $cost = $along + 2 * $across;
64 50 ▶ next if defined $best
Branch: 1 branch
BranchTrueFalseTotal
if defined $best and $cost > $best_cost || $cost == $best_cost && $across >= $best_across 18 32 50
Condition100%9/9
defined $best and $cost > $best_cost || $cost == $best_cost && $across >= $best_across
!ll&&!rl&&r
191318
$cost > $best_cost or $cost == $best_cost and $across >= $best_across
l!l&&r!l&&!r
13513
$cost == $best_cost and $across >= $best_across
!ll&&!rl&&r
1215
MC/DC100%4/4
defined $best and $cost > $best_cost || $cost == $best_cost && $across >= $best_across
defined $best $cost > $best_cost $cost == $best_cost $across >= $best_across
Truth table100%5/5
A and B or C and D
A= defined $bestB= $cost > $best_costC= $cost == $best_costD= $across >= $best_across
ABCDresult
0XXX0
100X0
10100
11XX1
10111
65 && ($cost > $best_cost || ($cost == $best_cost && $across >= $best_across));
66 32 ($best, $best_cost, $best_across) = ($index, $cost, $across);
67 }
68 25 return $best;
69 }
70  
71 11 ▶sub axis {
Subroutine axis: called CC=11 SCAR=24.3
Pod documented
72 11 my ($points, $at, $dx, $dy) = @_;
73 11 ▶ return $at unless $dx || $dy;
Branch: 1 branch
BranchTrueFalseTotal
unless $dx or $dy 1 10 11
Condition100%3/3
$dx or $dy
l!l&&r!l&&!r
641
MC/DC100%2/2
$dx or $dy
$dx $dy
Truth table100%3/3
A or B
A= $dxB= $dy
ABresult
1X1
011
000
74 10 ▶ my ($first, $second) = $dx ? (0, 1) : (1, 0);
Branch: 1 branch
BranchTrueFalseTotal
$dx ? : 6 4 10
75 my @order = sort {
76 48 ▶ $points->[$a][$first] <=> $points->[$b][$first]
Condition50%3/6
$points->[$a][$first] <=> $points->[$b][$first] || $points->[$a][$second] <=> $points->[$b][$second] || $a <=> $b
l!l&&r!l&&!r
4800
$points->[$a][$first] <=> $points->[$b][$first] or $points->[$a][$second] <=> $points->[$b][$second]
l!l&&r!l&&!r
32160
MC/DC0%0/3
$points->[$a][$first] <=> $points->[$b][$first] || $points->[$a][$second] <=> $points->[$b][$second] || $a <=> $b
$points->[$a][$first] <=> $points->[$b][$first] $points->[$a][$second] <=> $points->[$b][$second] $a <=> $b
Truth table50%2/4
A or B || C
A= $points->[$a][$first] <=> $points->[$b][$first]B= $points->[$a][$second] <=> $points->[$b][$second]C= $a <=> $b
ABCresult
1XX1
01X1
0011
0000
77 || $points->[$a][$second] <=> $points->[$b][$second]
78 || $a <=> $b
79 10 } 0 .. $#{$points};
80 10 my ($where) = grep { $order[$_] == $at } 0 .. $#order;
81 10 ▶ return $at unless defined $where;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $where 0 10 10
82 10 ▶ $where += ($dx || $dy) > 0 ? 1 : -1;
Branch: 1 branch
BranchTrueFalseTotal
($dx || $dy) > 0 ? : 8 2 10
Condition66%2/3
$dx || $dy
l!l&&r!l&&!r
640
MC/DC0%0/2
$dx || $dy
$dx $dy
Truth table66%2/3
A || B
A= $dxB= $dy
ABresult
1X1
011
000
83 10 ▶ return $where >= 0 && $where <= $#order ? $order[$where] : $at;
Branch: 1 branch
BranchTrueFalseTotal
$where >= 0 && $where <= $#order ? : 7 3 10
Condition100%3/3
$where >= 0 and $where <= $#order
!ll&&!rl&&r
127
MC/DC100%2/2
$where >= 0 and $where <= $#order
$where >= 0 $where <= $#order
Truth table100%3/3
A and B
A= $where >= 0B= $where <= $#order
ABresult
0X0
100
111
84 }
85  
86 74 ▶sub rest {
Subroutine rest: called CC=6 SCAR=17.9
Pod documented
87 74 my ($items, $prefer) = @_;
88 74 ▶ my @open = grep { !(ref $items->[$_] eq 'HASH' && $items->[$_]{skip}) } 0 .. $#{$items};
Condition100%3/3
ref $items->[$_] eq 'HASH' && $items->[$_]{'skip'}
!ll&&!rl&&r
8215428
MC/DC100%2/2
ref $items->[$_] eq 'HASH' && $items->[$_]{'skip'}
ref $items->[$_] eq 'HASH' $items->[$_]{'skip'}
Truth table100%3/3
A && B
A= ref $items->[$_] eq 'HASH'B= $items->[$_]{'skip'}
ABresult
0X0
100
111
89 74 ▶ return 0 unless @open;
Branch: 1 branch
BranchTrueFalseTotal
unless @open 6 68 74
90 68 ▶ if ($prefer) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prefer) 5 63 68
91 5 for my $index (@open) {
92 14 ▶ return $index if $prefer->($items->[$index], $index);
Branch: 1 branch
BranchTrueFalseTotal
if &$prefer($items->[$index], $index) 3 11 14
93 }
94 }
95 65 return $open[0];
96 }
97  
98 6 1;
99  
100 __END__
« Kit/Options.pm ↑ Summary Kit/Canvas.pm »