File Coverage

blib/lib/CXC/Types/Astro/Coords.pm
Criterion Covered Total %
statement 48 48 100.0
branch 1 2 50.0
condition n/a
subroutine 15 15 100.0
pod 1 1 100.0
total 65 66 98.4


line stmt bran cond sub pod time code
1             package CXC::Types::Astro::Coords;
2              
3             # ABSTRACT: type definitions for Coordinates
4              
5 2     2   478595 use v5.28; # for POSIX::copysign
  2         12  
6              
7 2     2   17 use strict;
  2         4  
  2         84  
8 2     2   17 use warnings;
  2         4  
  2         146  
9              
10 2     2   871 use experimental 'signatures', 'postderef', 'declared_refs';
  2         2076  
  2         15  
11              
12             our $VERSION = '0.12';
13              
14 2     2   2124 use CXC::Types::Astro::Coords::Util 'mkSexagesimal';
  2         8  
  2         37  
15              
16             use Type::Library
17 2         36 -base,
18             -declare => qw(
19             Degrees
20              
21             LatitudeArray
22             LatitudeDegrees
23             LatitudeSexagesimal
24              
25             LongitudeArray
26             LongitudeDegrees
27             LongitudeSexagesimal
28              
29             RightAscensionArray
30             RightAscensionDegrees
31             RightAscensionSexagesimal
32              
33             DeclinationArray
34             DeclinationDegrees
35             DeclinationSexagesimal
36              
37             SexagesimalArray
38             SexagesimalDegrees
39             SexagesimalHMS
40             SexagesimalDMS
41 2     2   1982 );
  2         54697  
42              
43 2     2   11039 use Types::Standard qw( Any Int Num StrMatch Tuple );
  2         233661  
  2         56  
44 2     2   9476 use Types::Common::Numeric qw( IntRange NumRange );
  2         56600  
  2         38  
45 2     2   2392 use Types::Common::String qw( NonEmptyStr );
  2         89342  
  2         20  
46 2     2   2137 use Regexp::Common;
  2         4  
  2         19  
47 2     2   2730 use Type::Utils -all;
  2         11448  
  2         24  
48 2     2   5447 use POSIX qw( fmod copysign );
  2         5  
  2         17  
49              
50             my sub croak {
51             require Carp;
52             goto \&Carp::croak;
53             }
54              
55              
56              
57              
58              
59              
60              
61              
62              
63              
64              
65              
66              
67              
68             BEGIN {
69 2     2   4489 my @parameters = qw[ -any -optws -optsep -optunits -trim ];
70 2         11 my %default = mkSexagesimal( @parameters )->%*;
71              
72 12     12 1 99 sub methods ( %attr ) {
  12         47  
  12         19  
73             return {
74             ## no critic (BuiltinFunctions::ProhibitComplexMappings)
75             map {
76 12         38 my $value = $attr{$_};
  72         117  
77 30     30   2151 $_ => sub { $value },
78 72         374 }
79             keys %attr,
80             };
81             }
82              
83             __PACKAGE__->meta->add_type(
84             name => 'Sexagesimal',
85             constraint_generator => sub ( @args ) {
86 10 50       75 croak( 'Sexagesimal requires parameters' )
87             unless @args;
88 10         52 my %parameterized = mkSexagesimal( @args )->%*;
89             return Type::Tiny->new(
90             display_name => 'Sexagesimal[' . join( q{,}, sort @args ) . ']',
91             constraint => $parameterized{constraint},
92 10         109 parameters => [@args],
93             parent => Any, # required to avoid an oops; see https://github.com/tobyink/p5-type-tiny/issues/151
94             my_methods => methods( %parameterized ),
95             );
96             },
97             constraint => $default{constraint},
98 2         27 my_methods => methods( %default ),
99             );
100             }
101              
102              
103              
104              
105              
106              
107              
108              
109              
110              
111              
112              
113              
114             declare SexagesimalArray, as Tuple [ Int, IntRange [ 0, 59 ], NumRange [ 0, 60, 0, 1 ] ];
115              
116              
117              
118              
119              
120              
121              
122              
123              
124             declare SexagesimalDegrees, as Num;
125              
126             coerce SexagesimalArray, from NonEmptyStr, Sexagesimal->my_Str_toArrayRef;
127             coerce SexagesimalDegrees, from NonEmptyStr, Sexagesimal->my_Str_toDegrees;
128             coerce SexagesimalDegrees, from SexagesimalArray, Sexagesimal->my_ArrayRef_toDegrees;
129              
130              
131              
132              
133              
134              
135              
136             declare Degrees, as NumRange [ 0, 360, 0, 1 ];
137             coerce Degrees, from Num, q{ POSIX::fmod( 360 + POSIX::fmod( $_, 360 ), 360 ) };
138              
139              
140              
141              
142              
143              
144              
145              
146              
147              
148              
149              
150              
151             declare LongitudeArray,
152             as Tuple [ IntRange [ 0, 359 ], IntRange [ 0, 59 ], NumRange [ 0, 60, 0, 1 ] ];
153              
154              
155              
156              
157              
158              
159              
160              
161              
162              
163             declare LongitudeDegrees, as NumRange [ 0, 360, 0, 1 ];
164              
165              
166              
167              
168              
169              
170              
171              
172              
173              
174              
175              
176              
177              
178              
179              
180              
181              
182              
183              
184              
185              
186              
187              
188              
189              
190              
191              
192              
193              
194              
195             declare LongitudeSexagesimal, as Sexagesimal [ -long, -trim, -optws, -optunits, -optsep ];
196              
197             coerce LongitudeArray, from NonEmptyStr, LongitudeSexagesimal->my_Str_toArrayRef;
198             coerce LongitudeDegrees, from NonEmptyStr, LongitudeSexagesimal->my_Str_toDegrees;
199             coerce LongitudeDegrees, from LongitudeArray, LongitudeSexagesimal->my_ArrayRef_toDegrees;
200              
201              
202              
203              
204              
205              
206              
207              
208              
209              
210              
211              
212              
213              
214              
215              
216              
217              
218              
219             declare LatitudeArray,
220             as Tuple [ IntRange [ -90, 90 ], IntRange [ 0, 59 ], NumRange [ 0, 60, 0, 1 ] ], where sub {
221             abs( $_->[0] ) + $_->[1] / 60 + $_->[2] / 3600 <= 90;
222             }, inline_as {
223             my $V = $_[1];
224             return ( undef, qq{abs( $V\->[0] ) + $V\->[1] / 60 + $V\->[2] / 3600 <= 90} );
225             };
226              
227              
228              
229              
230              
231              
232              
233              
234              
235              
236             declare LatitudeDegrees, as NumRange [ -90, 90 ];
237              
238              
239              
240              
241              
242              
243              
244              
245              
246              
247              
248              
249              
250              
251              
252              
253              
254              
255              
256              
257              
258              
259              
260              
261              
262              
263              
264              
265              
266              
267              
268              
269              
270              
271             declare LatitudeSexagesimal, as Sexagesimal [ -lat, -trim, -optws, -optunits, -optsep ];
272             coerce LatitudeArray, from NonEmptyStr, LatitudeSexagesimal->my_Str_toArrayRef;
273             coerce LatitudeDegrees, from NonEmptyStr, LatitudeSexagesimal->my_Str_toDegrees;
274             coerce LatitudeDegrees, from LatitudeArray, LatitudeSexagesimal->my_ArrayRef_toDegrees;
275              
276              
277              
278              
279              
280              
281              
282              
283              
284              
285              
286              
287              
288             declare RightAscensionArray,
289             as Tuple [ IntRange [ 0, 23 ], IntRange [ 0, 59 ], NumRange [ 0, 60, 0, 1 ] ];
290              
291              
292              
293              
294              
295              
296              
297              
298              
299              
300             declare RightAscensionDegrees, as NumRange [ 0, 360 ];
301              
302              
303              
304              
305              
306              
307              
308              
309              
310              
311              
312              
313              
314              
315              
316              
317              
318              
319              
320              
321              
322              
323              
324              
325              
326              
327              
328              
329              
330              
331             declare RightAscensionSexagesimal, as Sexagesimal [ -ra, -trim, -optws, -optunits, -optsep ];
332             coerce RightAscensionArray, from NonEmptyStr, RightAscensionSexagesimal->my_Str_toArrayRef;
333             coerce RightAscensionDegrees, from NonEmptyStr, RightAscensionSexagesimal->my_Str_toDegrees;
334             coerce RightAscensionDegrees, from RightAscensionArray,
335             RightAscensionSexagesimal->my_ArrayRef_toDegrees;
336              
337              
338              
339              
340              
341              
342              
343              
344              
345              
346              
347              
348              
349              
350              
351              
352              
353             declare DeclinationArray, as LatitudeArray, coercion => 1;
354              
355              
356              
357              
358              
359              
360              
361              
362              
363             declare DeclinationDegrees, as LatitudeDegrees, coercion => 1;
364              
365              
366              
367              
368              
369              
370              
371              
372              
373              
374              
375              
376              
377              
378              
379              
380              
381              
382              
383              
384              
385              
386              
387              
388              
389              
390              
391              
392              
393              
394              
395              
396              
397              
398             declare DeclinationSexagesimal, as LatitudeSexagesimal, coercible => 1;
399              
400             coerce DeclinationArray, from NonEmptyStr, DeclinationSexagesimal->my_Str_toArrayRef;
401             coerce DeclinationDegrees, from NonEmptyStr, DeclinationSexagesimal->my_Str_toDegrees;
402             coerce DeclinationDegrees, from DeclinationArray, DeclinationSexagesimal->my_ArrayRef_toDegrees;
403              
404              
405              
406              
407              
408              
409              
410              
411              
412              
413              
414              
415              
416              
417              
418             declare SexagesimalHMS, as Sexagesimal [ -ra, -trim, -optws, -units ];
419              
420              
421              
422              
423              
424              
425              
426              
427              
428              
429              
430              
431              
432              
433              
434              
435             declare SexagesimalDMS, as Sexagesimal [ -deg, -trim, -optws, -units ];
436              
437             1;
438              
439             #
440             # This file is part of CXC-Types-Astro-Coords
441             #
442             # This software is Copyright (c) 2018 by Smithsonian Astrophysical Observatory.
443             #
444             # This is free software, licensed under:
445             #
446             # The GNU General Public License, Version 3, June 2007
447             #
448              
449             __END__