File Coverage

blib/lib/Astro/Coord/ECI/Mixin.pm
Criterion Covered Total %
statement 56 58 96.5
branch 14 18 77.7
condition 3 3 100.0
subroutine 12 12 100.0
pod 4 4 100.0
total 89 95 93.6


line stmt bran cond sub pod time code
1             package Astro::Coord::ECI::Mixin;
2              
3 16     16   1450 use 5.006002;
  16         63  
4              
5 16     16   89 use strict;
  16         27  
  16         481  
6 16     16   81 use warnings;
  16         62  
  16         836  
7              
8 16     16   101 use Carp;
  16         41  
  16         1367  
9              
10 16         2014 use Astro::Coord::ECI::Utils qw{ __default_station
11             ARRAY_REF PIOVER2 SECSPERDAY
12             @CARP_NOT
13 16     16   105 };
  16         42  
14 16     16   106 use Exporter ();
  16         26  
  16         442  
15 16     16   74 use POSIX qw{ floor };
  16         51  
  16         130  
16              
17             our $VERSION = '0.134';
18              
19             our @EXPORT_OK = qw{
20             almanac almanac_hash
21             next_quarter next_quarter_hash
22             };
23              
24             our %EXPORT_TAGS = (
25             almanac => [ qw{ almanac almanac_hash } ],
26             quarter => [ qw{ next_quarter next_quarter_hash } ],
27             );
28              
29             BEGIN {
30             # Because 5.6.2's Exporter does not export 'import()'.
31 16     16   14293 *import = \&Exporter::import;
32             }
33              
34             sub almanac {
35 7     7 1 32 my ( $self, $station, $start, $end ) = __default_station( @_ );
36 7 50       53 defined $start
37             or $start = $self->universal();
38 7 50       25 defined $end
39             or $end = $start + SECSPERDAY;
40              
41 7         12 my @almanac;
42              
43 7         36 my $iterator = $self->__almanac_event_type_iterator( $station );
44              
45 7         227 while ( my ( $obj, $method, $args, $event, $descr ) = $iterator->() ) {
46              
47 21         79 $obj->universal( $start );
48 21         33 while ( 1 ) {
49 51         300 my ( $time, $which ) = $obj->$method ( @$args );
50 51 100 100     485 defined $time # Thanks to JohnDenker
51             and $time < $end
52             or last;
53 30 50       270 defined ( my $text = ARRAY_REF eq ref $descr ?
    100          
54             $descr->[ $which ] : $self->$descr( $which ) )
55             or next;
56 25         132 push @almanac, [ $time, $event, $which, $text ];
57             }
58             }
59              
60 7         69 return (sort {$a->[0] <=> $b->[0]} @almanac);
  33         256  
61             }
62              
63             sub almanac_hash {
64 3     3 1 18 my ( $self, $station, $start, $end ) = __default_station( @_ );
65 3         16 return map {
66             body => $self,
67             station => $station,
68             time => $_->[0],
69             almanac => {
70             event => $_->[1],
71             detail => $_->[2],
72             description => $_->[3],
73             }
74             }, $self->almanac( $station, $start, $end );
75             }
76              
77             sub next_quarter {
78 5     5 1 17 my ( $self, $quarter ) = @_;
79 5         22 my $next_quarter_inc = $self->NEXT_QUARTER_INCREMENT();
80              
81 5 100       27 $quarter = ( defined $quarter ? $quarter :
82             floor( $self->__next_quarter_coordinate() / PIOVER2 ) + 1 ) % 4;
83 5         9 my $begin;
84 5         94 while ( floor( $self->__next_quarter_coordinate() / PIOVER2 ) == $quarter ) {
85 0         0 $begin = $self->dynamical();
86 0         0 $self->dynamical( $begin + $next_quarter_inc );
87             }
88 5         14 while ( floor( $self->__next_quarter_coordinate() / PIOVER2 ) != $quarter ) {
89 12         39 $begin = $self->dynamical();
90 12         34 $self->dynamical($begin + $next_quarter_inc);
91             }
92 5         19 my $end = $self->dynamical();
93              
94 5         23 while ( $end - $begin > 1 ) {
95 95         232 my $mid = floor( ( $begin + $end ) / 2 );
96 95         264 my $qq = floor( $self->dynamical($mid )->__next_quarter_coordinate() /
97             PIOVER2 );
98 95 100       418 ( $begin, $end ) = $qq == $quarter ?
99             ( $begin, $mid ) : ( $mid, $end );
100             }
101              
102 5         26 $self->dynamical( $end );
103              
104             return wantarray ? (
105 5 100       69 $self->universal, $quarter, $self->__quarter_name( $quarter ),
106             ) : $self->universal();
107             }
108              
109             sub next_quarter_hash {
110 1     1 1 3 my ( $self, @args ) = @_;
111 1         5 my ( $time, $quarter, $desc ) = $self->next_quarter( @args );
112 1         10 my %hash = (
113             body => $self,
114             almanac => {
115             event => 'quarter',
116             detail => $quarter,
117             description => $desc,
118             },
119             time => $time,
120             );
121 1 50       9 return wantarray ? %hash : \%hash;
122             }
123              
124             1;
125              
126             __END__