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   1387 use 5.006002;
  16         52  
4              
5 16     16   60 use strict;
  16         22  
  16         295  
6 16     16   53 use warnings;
  16         27  
  16         615  
7              
8 16     16   94 use Carp;
  16         46  
  16         1041  
9              
10 16         1698 use Astro::Coord::ECI::Utils qw{ __default_station
11             ARRAY_REF PIOVER2 SECSPERDAY
12             @CARP_NOT
13 16     16   102 };
  16         28  
14 16     16   74 use Exporter ();
  16         20  
  16         284  
15 16     16   46 use POSIX qw{ floor };
  16         47  
  16         94  
16              
17             our $VERSION = '0.134_01';
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   10720 *import = \&Exporter::import;
32             }
33              
34             sub almanac {
35 7     7 1 41 my ( $self, $station, $start, $end ) = __default_station( @_ );
36 7 50       47 defined $start
37             or $start = $self->universal();
38 7 50       23 defined $end
39             or $end = $start + SECSPERDAY;
40              
41 7         10 my @almanac;
42              
43 7         27 my $iterator = $self->__almanac_event_type_iterator( $station );
44              
45 7         1532 while ( my ( $obj, $method, $args, $event, $descr ) = $iterator->() ) {
46              
47 21         55 $obj->universal( $start );
48 21         27 while ( 1 ) {
49 51         217 my ( $time, $which ) = $obj->$method ( @$args );
50 51 100 100     332 defined $time # Thanks to JohnDenker
51             and $time < $end
52             or last;
53 30 50       364 defined ( my $text = ARRAY_REF eq ref $descr ?
    100          
54             $descr->[ $which ] : $self->$descr( $which ) )
55             or next;
56 25         91 push @almanac, [ $time, $event, $which, $text ];
57             }
58             }
59              
60 7         56 return (sort {$a->[0] <=> $b->[0]} @almanac);
  33         199  
61             }
62              
63             sub almanac_hash {
64 3     3 1 14 my ( $self, $station, $start, $end ) = __default_station( @_ );
65 3         39 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 10 my ( $self, $quarter ) = @_;
79 5         17 my $next_quarter_inc = $self->NEXT_QUARTER_INCREMENT();
80              
81 5 100       19 $quarter = ( defined $quarter ? $quarter :
82             floor( $self->__next_quarter_coordinate() / PIOVER2 ) + 1 ) % 4;
83 5         27 my $begin;
84 5         57 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         11 while ( floor( $self->__next_quarter_coordinate() / PIOVER2 ) != $quarter ) {
89 12         24 $begin = $self->dynamical();
90 12         25 $self->dynamical($begin + $next_quarter_inc);
91             }
92 5         25 my $end = $self->dynamical();
93              
94 5         17 while ( $end - $begin > 1 ) {
95 95         163 my $mid = floor( ( $begin + $end ) / 2 );
96 95         177 my $qq = floor( $self->dynamical($mid )->__next_quarter_coordinate() /
97             PIOVER2 );
98 95 100       289 ( $begin, $end ) = $qq == $quarter ?
99             ( $begin, $mid ) : ( $mid, $end );
100             }
101              
102 5         14 $self->dynamical( $end );
103              
104             return wantarray ? (
105 5 100       21 $self->universal, $quarter, $self->__quarter_name( $quarter ),
106             ) : $self->universal();
107             }
108              
109             sub next_quarter_hash {
110 1     1 1 2 my ( $self, @args ) = @_;
111 1         3 my ( $time, $quarter, $desc ) = $self->next_quarter( @args );
112 1         8 my %hash = (
113             body => $self,
114             almanac => {
115             event => 'quarter',
116             detail => $quarter,
117             description => $desc,
118             },
119             time => $time,
120             );
121 1 50       6 return wantarray ? %hash : \%hash;
122             }
123              
124             1;
125              
126             __END__