lib/Astro/Montenbruck/RiseSet.pm

filter: Statementstmt 68.1% 92 / 135 Branchbran 28.5% 4 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 61.5% 24 / 39 Podpod 100% 3 / 3 totaltotal 64.4% 123 / 191 CC 10 SCAR 10.4
CC
10
Cov
64%
__ANON__
9.3
__ANON__
6.0
__ANON__
6.0
CRAP 2.8
« lib/Astro/Montenbruck/Ephemeris/Pert.pm ↑ Summary lib/Astro/Montenbruck/Time.pm »
1 package Astro::Montenbruck::RiseSet;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶no warnings qw/experimental/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use feature qw/switch/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Exporter qw/import/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Readonly;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Memoize;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 memoize qw/_get_obliquity/;
12  
13 3 ▶use Math::Trig qw/:pi deg2rad/;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use Astro::Montenbruck::MathUtils qw/frac/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 ▶use Astro::Montenbruck::Time qw/jd_cent/;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶use Astro::Montenbruck::CoCo qw/ecl2equ/;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Astro::Montenbruck::NutEqu qw/obliquity/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 3 ▶use Astro::Montenbruck::Ephemeris qw/iterator/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 3 ▶use Astro::Montenbruck::Ephemeris::Planet qw/:ids/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 use Astro::Montenbruck::RiseSet::Constants
21 3 ▶ qw/:altitudes :twilight :events :states/;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 3 ▶use Astro::Montenbruck::RiseSet::Plarise qw/rst_func/;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 3 ▶use Astro::Montenbruck::RiseSet::Sunset qw/riseset_func/;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 3 our %EXPORT_TAGS = ( all => [qw/rst riseset twilight/], );
26 3 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
27 3 our $VERSION = 0.02;
28  
29 3 Readonly::Array our @TWILIGHT_TYPES =>
30 ( $TWILIGHT_ASTRO, $TWILIGHT_NAUTICAL, $TWILIGHT_CIVIL );
31  
32 466 ▶sub _get_obliquity { obliquity( $_[0] ) }
Subroutine _get_obliquity: called CC=1 SCAR=0.0
33  
34 674 ▶sub _get_equatorial {
Subroutine _get_equatorial: called CC=1 SCAR=0.0
35 674 my ( $id, $jd ) = @_;
36 674 my $t = jd_cent($jd);
37 674 my $iter = iterator( $t, [$id] );
38 674 my $res = $iter->();
39 674 my @ecl = @{ $res->[1] }[ 0 .. 1 ];
40 674 map { deg2rad($_) } ecl2equ( @ecl, _get_obliquity($t) );
41 }
42  
43 11 ▶sub twilight {
Subroutine twilight: called CC=3 SCAR=14.2
Pod documented
44 my %arg = (
45 type => $TWILIGHT_NAUTICAL,
46 0 ▶ on_event => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
47 0 ▶ on_noevent => sub { },
Subroutine __ANON__: not called CC=1 SCAR=0.0
48 @_
49 11 );
50 11 my $type = delete $arg{type};
51 11 ▶ die "Unknown twilight type: \"$type\"" unless exists $H0_TWL{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $Astro::Montenbruck::RiseSet::H0_TWL{$type} 0 11 11
52 11 my $on_event = delete $arg{on_event};
53 11 my $on_noevent = delete $arg{on_noevent};
54  
55 11 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 11 11
56 0 my %res;
57 riseset_func(%arg)->(
58 0 ▶ on_event => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
59 0 my ( $evt, $jd ) = @_;
60 0 $res{$evt} = $jd;
61 0 $on_event->(@_);
62 },
63 0 ▶ on_noevent => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
64 0 $on_noevent->(@_);
65 },
66 %arg,
67 0 ▶ get_position => sub { _get_equatorial( $SU, $_[0] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
68 0 sin_h0 => sin( deg2rad( $H0_TWL{$type} ) ),
69 );
70 0 return %res;
71 }
72  
73 riseset_func(%arg)->(
74 %arg,
75 247 ▶ get_position => sub { _get_equatorial( $SU, $_[0] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
76 11 sin_h0 => sin( deg2rad( $H0_TWL{$type} ) ),
77 on_event => $on_event,
78 on_noevent => $on_noevent
79 );
80 }
81  
82 0 ▶sub riseset {
Subroutine riseset: not called CC=1 SCAR=6.9
Pod documented
83 0 my %arg = @_;
84 0 my $pla = delete $arg{planet};
85 0 my $h0 = do {
86 0 given ($pla) {
87 0 $H0_SUN when $SU;
88 0 $H0_MOO when $MO;
89 0 default { $H0_PLA }
90 }
91 };
92 0 my $func = riseset_func(%arg);
93 0 ▶ sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
94 0 ▶ my %arg = ( on_event => sub { }, on_noevent => sub { }, @_ );
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
95  
96 0 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 0 0
97  
98 # if caller asks for a result, collect events to %res hash
99 0 my %res;
100 $func->(
101 0 ▶ get_position => sub { _get_equatorial( $pla, $_[0] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
102 sin_h0 => sin( deg2rad($h0) ),
103 0 ▶ on_event => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
104 0 my ( $evt, $jd ) = @_;
105 0 $arg{on_event}->(@_);
106 0 $res{$evt} = { ok => 1, jd => $jd };
107 },
108 0 ▶ on_noevent => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
109 0 my ($state) = shift;
110 0 $arg{on_noevent}->(@_);
111 0 ▶ my $evt =
Branch: 1 branch
BranchTrueFalseTotal
$state eq $Astro::Montenbruck::RiseSet::STATE_NEVER_RISES ? : 0 0 0
112 $state eq $STATE_NEVER_RISES ? $EVT_RISE : $EVT_SET;
113 0 $res{$evt} = { ok => 0, state => $state };
114 }
115 0 );
116 0 return %res;
117 }
118  
119 # if caller doesn't ask for a result, just call the function with the callbacks
120 $func->(
121 0 ▶ get_position => sub { _get_equatorial( $pla, $_[0] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
122 sin_h0 => sin( deg2rad($h0) ),
123 on_event => $arg{on_event},
124 on_noevent => $arg{on_noevent},
125 0 );
126 }
127 0 }
128  
129 1 ▶sub rst {
Subroutine rst: called CC=1 SCAR=0.7
Pod documented
130  
131 # build top-level function for any event and any celestial object
132 # for given time and place
133 1 my $rst = rst_func(@_);
134  
135 9 ▶ sub {
Subroutine __ANON__: called CC=6 SCAR=22.3
136 9 my $obj = shift;
137 9 ▶ my %arg = ( on_event => sub { }, on_noevent => sub { }, @_ );
Subroutine __ANON__: not called CC=1 SCAR=0.0
Subroutine __ANON__: not called CC=1 SCAR=0.0
138  
139 9 my $h0 = do {
140 9 given ($obj) {
141 9 $H0_SUN when $SU;
142 8 $H0_MOO when $MO;
143 8 default { $H0_PLA }
144 }
145 };
146  
147 # build second level functon for calculating any event for given object
148 my $evt_func = $rst->(
149 18 ▶ get_position => sub { _get_equatorial( $obj, $_[0] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
150 9 sin_h0 => sin( deg2rad($h0) )
151 );
152  
153 9 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 0 9 9
154  
155 # if caller asks for a result, collect events to %res hash
156 0 my %res;
157 0 for (@RS_EVENTS) {
158 0 my ( $state, $jd ) = $evt_func->($_);
159 0 ▶ if ( $state eq $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq $_) { } 0 0 0
160 0 $arg{on_event}->( $_, $jd );
161 0 $res{$_} = { ok => 1, jd => $jd };
162 }
163 else {
164 0 $arg{on_noevent}->( $_, $state );
165 0 $res{$_} = { ok => 0, state => $state };
166 }
167 }
168 0 return %res;
169 }
170  
171 # if caller doesn't ask for a result, just call the function with the callbacks
172 9 for (@RS_EVENTS) {
173 27 my ( $state, $jd ) = $evt_func->($_);
174 27 ▶ if ( $state eq $_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state eq $_) { } 27 0 27
175 27 $arg{on_event}->( $_, $jd );
176 }
177 else {
178 0 $arg{on_noevent}->( $_, $state );
179 }
180 }
181 }
182 1 }
183  
184 3 1;
185 __END__
« lib/Astro/Montenbruck/Ephemeris/Pert.pm ↑ Summary lib/Astro/Montenbruck/Time.pm »