| 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
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
$deg =~ /^\d+$/ or $deg =~ /^\d+\.\d+$/
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+$/
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
$deg < 0 or $deg > 360
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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||