| 1 | package Astro::Nova::DMS; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Astro::Nova; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | # basic stuff is in Astro::Nova's XS! | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 9 | ▶ | sub members { | ||||||||||||||||||||||||||
|
Subroutine
members: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | 9 | return qw/neg degrees minutes seconds/ | |||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 3 | my $FLOAT = qr/(?:[+-]?)(?=\d|\.\d)\d*(?:\.\d*)?(?:[Ee]([+-]?\d+))?/; | |||||||||||||||||||||||||||
| 16 | 2 | ▶ | sub from_string { | ||||||||||||||||||||||||||
|
Subroutine
from_string: called CC=12 SCAR=26.7
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 2 | my $class = shift; | |||||||||||||||||||||||||||
| 18 | 2 | ▶ | my $self = ref($class) ? $class : $class->new(); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 2 | my $string = shift; | |||||||||||||||||||||||||||
| 20 | 2 | ▶ | $string =~ m{ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | ^\s* | ||||||||||||||||||||||||||||
| 22 | ([+-]?)\s* | ||||||||||||||||||||||||||||
| 23 | (?:(\d+)\s*°)? | ||||||||||||||||||||||||||||
| 24 | \s* | ||||||||||||||||||||||||||||
| 25 | (?:(\d+)\s*')? | ||||||||||||||||||||||||||||
| 26 | \s* | ||||||||||||||||||||||||||||
| 27 | (?:($FLOAT)\s*'')? | ||||||||||||||||||||||||||||
| 28 | \s*(?:([eEwWnNsS]))?\s*$ | ||||||||||||||||||||||||||||
| 29 | }x or return(); | ||||||||||||||||||||||||||||
| 30 | 2 | my ($sign, $deg, $min, $sec, $dir) = ($1, $2, $3, $4, $5); | |||||||||||||||||||||||||||
| 31 | 2 | ▶ | if (not grep {defined($_)} ($deg, $min, $sec)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 0 | return(); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 2 | ▶ | $sign = 1 if not defined $sign; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 2 | ▶ | $sign = ($sign eq '-' ? -1 : 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | $sign *= -1 if $dir and $dir =~ /^[wW]$/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$dir and $dir =~ /^[wW]$/
MC/DC0%0/2
$dir and $dir =~ /^[wW]$/
$dir
$dir =~ /^[wW]$/
Truth table33%1/3
A and B
A= $dirB= $dir =~ /^[wW]$/
| |||||||||||||||||||||||||||||
| 37 | 2 | ▶ | $self->set_neg($sign < 0 ? 1 : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 2 | ▶ | $self->set_degrees(defined $deg ? $deg : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | 2 | ▶ | $self->set_minutes(defined $min ? $min : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 2 | ▶ | $self->set_seconds(defined $sec ? $sec : 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | 2 | return $self; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 0 | ▶ | sub as_ascii { | ||||||||||||||||||||||||||
|
Subroutine
as_ascii: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 45 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 46 | 0 | my $template = <<'HERE'; | |||||||||||||||||||||||||||
| 47 | Negative: %d | ||||||||||||||||||||||||||||
| 48 | Degrees: %d | ||||||||||||||||||||||||||||
| 49 | Minutes: %d | ||||||||||||||||||||||||||||
| 50 | Seconds: %f | ||||||||||||||||||||||||||||
| 51 | HERE | ||||||||||||||||||||||||||||
| 52 | 0 | return sprintf($template, $self->get_all()); | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 6 | ▶ | sub get_all { | ||||||||||||||||||||||||||
|
Subroutine
get_all: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 6 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 6 | return(map $self->$_(), map "get_$_", $self->members()); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | sub set_all { | ||||||||||||||||||||||||||
|
Subroutine
set_all: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 2 | foreach my $member (map "set_$_", $self->members) { | |||||||||||||||||||||||||||
| 63 | 5 | ▶ | last if not @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 4 | my $value = shift @_; | |||||||||||||||||||||||||||
| 65 | 4 | ▶ | next if not defined $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | 2 | $self->$member($value); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | 2 | return 1; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | sub to_degrees { | ||||||||||||||||||||||||||
|
Subroutine
to_degrees: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | 0 | Astro::Nova::dms_to_deg(shift) | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub to_radians { | ||||||||||||||||||||||||||
|
Subroutine
to_radians: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 0 | Astro::Nova::dms_to_rad(shift) | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub to_hms { | ||||||||||||||||||||||||||
|
Subroutine
to_hms: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 80 | 1 | Astro::Nova::deg_to_hms(Astro::Nova::dms_to_deg(shift)) | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub from_degrees { | ||||||||||||||||||||||||||
|
Subroutine
from_degrees: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 85 | 0 | my $obj = Astro::Nova::deg_to_dms(shift); | |||||||||||||||||||||||||||
| 86 | 0 | ▶ | return $obj if not ref $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 0 | $class->set_all($obj->get_all()); | |||||||||||||||||||||||||||
| 88 | 0 | return $class; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub from_radians { | ||||||||||||||||||||||||||
|
Subroutine
from_radians: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 93 | 0 | my $obj = Astro::Nova::rad_to_dms(shift); | |||||||||||||||||||||||||||
| 94 | 0 | ▶ | return $obj if not ref $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 95 | 0 | $class->set_all($obj->get_all()); | |||||||||||||||||||||||||||
| 96 | 0 | return $class; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub from_hms { | ||||||||||||||||||||||||||
|
Subroutine
from_hms: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $class = shift; | |||||||||||||||||||||||||||
| 101 | 0 | my $obj = shift->to_dms(); | |||||||||||||||||||||||||||
| 102 | 0 | ▶ | return $obj if not ref $class; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | 0 | $class->set_all($obj->get_all()); | |||||||||||||||||||||||||||
| 104 | 0 | return $class; | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 3 | 1; | |||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||