blib/lib/Geo/Compass/Direction.pm

filter: Statementstmt 100% 28 / 28 Branchbran 100% 6 / 6 Conditioncond 83.3% 5 / 6 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 85.7% 6 / 7 Podpod 100% 1 / 1 totaltotal 94.2% 49 / 52 CC 6 SCAR 12.5
CC
6
Cov
98%
direction
6.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
↑ Summary
1 package Geo::Compass::Direction;
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  
7 2 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '1.01';
11  
12 2 our @ISA = qw(Exporter);
13 2 our @EXPORT_OK = qw(direction);
14  
15 2 my @DIRECTIONS = qw(
16 N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW N
17 );
18  
19 1681 ▶sub direction {
Subroutine direction: called CC=6 SCAR=17.9
Pod documented
20 1681 my ($deg) = @_;
21  
22 1681 ▶ if (! defined $deg) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $deg) 1 1680 1681
23 1 croak("direction() must have an integer or float as its only parameter");
24 }
25 1680 ▶ if ($deg !~ /^\d+$/ && $deg !~ /^\d+\.\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($deg =~ /^\d+$/ or $deg =~ /^\d+\.\d+$/) 1002 678 1680
Condition100%3/3
$deg =~ /^\d+$/ or $deg =~ /^\d+\.\d+$/
l!l&&r!l&&!r
67351002
MC/DC100%2/2
$deg =~ /^\d+$/ or $deg =~ /^\d+\.\d+$/
$deg =~ /^\d+$/ $deg =~ /^\d+\.\d+$/
Truth table100%3/3
A or B
A= $deg =~ /^\d+$/B= $deg =~ /^\d+\.\d+$/
ABresult
1X1
011
000
26 1002 croak("The degree parameter for direction() must be an int or float");
27 }
28 678 ▶ if ($deg < 0 || $deg > 360) {
Branch: 1 branch
BranchTrueFalseTotal
if ($deg < 0 or $deg > 360) 640 38 678
Condition66%2/3
$deg < 0 or $deg > 360
l!l&&r!l&&!r
064038
MC/DC50%1/2
$deg < 0 or $deg > 360
$deg < 0 $deg > 360
Truth table66%2/3
A or B
A= $deg < 0B= $deg > 360
ABresult
1X1
011
000
29 640 croak("The degree parameter must be an int or float between 0-360");
30 }
31  
32 38 my $calc = (($deg % 360) / 22.5) + .5;
33  
34 38 return $DIRECTIONS[$calc];
35 }
36 0 ▶sub __placeholder {}
Subroutine __placeholder: not called CC=1 SCAR=0.0
37  
38 2 1;
39 __END__
↑ Summary