« blib/lib/Astro/App/Satpass2/ParseTime/Date/Manip/v5.pm
↑ Summary
blib/lib/Astro/App/Satpass2/Geocode.pm »
| 1 | package Astro::App::Satpass2::ParseTime::Date::Manip::v6; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Astro::Coord::ECI::Utils 0.112 qw{ looks_like_number }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use parent qw{ Astro::App::Satpass2::ParseTime::Date::Manip }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Astro::App::Satpass2::Utils qw{ load_package @CARP_NOT }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | our $VERSION = '0.059'; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | my $invalid; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=9 SCAR=37.9
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | eval { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | load_package( 'Date::Manip' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | or return; | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | load_package( 'Date::Manip::Date' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | or return; | ||||||||||||||||||||||||||||
| 22 | 0 | my $ver = Date::Manip->VERSION(); | |||||||||||||||||||||||||||
| 23 | 0 | $ver =~ s/ _ //smxg; | |||||||||||||||||||||||||||
| 24 | $ver >= 6 | ||||||||||||||||||||||||||||
| 25 | 0 | ▶ | and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$ver >= 6 and do {
"Date::Manip"->import;
1
}
MC/DC0%0/2
$ver >= 6 and do {
"Date::Manip"->import;
1
}
$ver >= 6
do {
"Date::Manip"->import;
1
}
Truth table0%0/3
A and B
A= $ver >= 6B= do {
"Date::Manip"->import;
1
}
| |||||||||||||||||||||||||||||
| 26 | 0 | Date::Manip->import(); | |||||||||||||||||||||||||||
| 27 | 0 | 1; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | or $invalid = sprintf | ||||||||||||||||||||||||||||
| 30 | '%s assumes a Date::Manip version >= 6. You have %s', | ||||||||||||||||||||||||||||
| 31 | __PACKAGE__, Date::Manip->VERSION(); | ||||||||||||||||||||||||||||
| 32 | $ver >= 6.49 | ||||||||||||||||||||||||||||
| 33 | 0 | ▶ | and *_normalize_zone = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 34 | 0 | $_[0] =~ s/ \A (?: gmt | ut ) \z /UT/smxi; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | 1; | ||||||||||||||||||||||||||
|
Condition50%1/2
$@ || 'Unable to load Date::Manip'
MC/DC0%0/1
$@ || 'Unable to load Date::Manip'
$@
Truth table50%1/2
A
A= $@
| |||||||||||||||||||||||||||||
| 37 | } or $invalid = ( $@ || 'Unable to load Date::Manip' ); | ||||||||||||||||||||||||||||
| 38 | __PACKAGE__->can( '_normalize_zone' ) | ||||||||||||||||||||||||||||
| 39 | 1 | ▶ | or *_normalize_zone = sub{}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub delegate { | ||||||||||||||||||||||||||
|
Subroutine
delegate: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 0 | return __PACKAGE__; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub dmd_err { | ||||||||||||||||||||||||||
|
Subroutine
dmd_err: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | return $self->_get_dm_field( 'object' )->err(); | |||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub dmd_zone { | ||||||||||||||||||||||||||
|
Subroutine
dmd_zone: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 52 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 53 | 0 | return scalar $self->_get_dm_field( 'object' )->tz->zone(); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub parse_time_absolute { | ||||||||||||||||||||||||||
|
Subroutine
parse_time_absolute: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 57 | 0 | my ( $self, $string ) = @_; | |||||||||||||||||||||||||||
| 58 | 0 | ▶ | $invalid and $self->wail( $invalid ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 0 | my $dm = $self->_get_dm_field( 'object' ); | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | $dm->parse( $string ) and return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | return $dm->secs_since_1970_GMT() - $self->__epoch_offset(); | |||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub use_perltime { | ||||||||||||||||||||||||||
|
Subroutine
use_perltime: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | return 0; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | ▶ | sub tz { | ||||||||||||||||||||||||||
|
Subroutine
tz: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 69 | 0 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | $invalid and $self->wail( $invalid ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | if ( @args ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 0 | my $zone = $args[0]; | |||||||||||||||||||||||||||
| 73 | 0 | my $dm = $self->_get_dm_field( 'object' ); | |||||||||||||||||||||||||||
| 74 | 0 | ▶ | defined $zone and '' ne $zone | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $zone and "" ne $zone
MC/DC0%0/2
defined $zone and "" ne $zone
defined $zone
"" ne $zone
Truth table0%0/3
A and B
A= defined $zoneB= "" ne $zone
| |||||||||||||||||||||||||||||
| 75 | or $zone = $self->_get_dm_field( 'default_zone' ); | ||||||||||||||||||||||||||||
| 76 | 0 | _normalize_zone( $zone ); | |||||||||||||||||||||||||||
| 77 | 0 | $dm->config( setdate => "zone,$zone" ); | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | 0 | return $self->SUPER::tz( @args ); | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | sub __back_end_validate { | ||||||||||||||||||||||||||
|
Subroutine
__back_end_validate: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 83 | 0 | my ( $self, $cls ) = @_; | |||||||||||||||||||||||||||
| 84 | 0 | ▶ | $cls->can( 'parse' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | or $self->wail( "$cls does not have a parse() method" ); | ||||||||||||||||||||||||||||
| 86 | 0 | return; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub __set_back_end_location { | ||||||||||||||||||||||||||
|
Subroutine
__set_back_end_location: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 90 | 0 | my ( $self, $location ) = @_; | |||||||||||||||||||||||||||
| 91 | 0 | ▶ | if ( my $dm = $self->_get_dm_field( 'object' ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | # NOTE that we have no way to introspect Date::Manip::Date (or | ||||||||||||||||||||||||||||
| 93 | # any other back end) to see if it has the 'location' config, so | ||||||||||||||||||||||||||||
| 94 | # since Date::Manip uses warn() to report errors, we just | ||||||||||||||||||||||||||||
| 95 | # blindly set it and swallow the possible warning. | ||||||||||||||||||||||||||||
| 96 | 0 | ▶ | local $SIG{__WARN__} = sub {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | 0 | $dm->config( location => $location ); | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | return; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | sub _get_dm_field { | ||||||||||||||||||||||||||
|
Subroutine
_get_dm_field: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 103 | 0 | my ( $self, $field ) = @_; | |||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $info = $self->{+__PACKAGE__} ||= $self->_make_dm_hash(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"Astro::App::Satpass2::ParseTime::Date::Manip::v6"} ||= $self->_make_dm_hash
MC/DC0%0/2
$self->{"Astro::App::Satpass2::ParseTime::Date::Manip::v6"} ||= $self->_make_dm_hash
$self->{"Astro::App::Satpass2::ParseTime::Date::Manip::v6"}
$self->_make_dm_hash
Truth table0%0/3
A ||= B
A= $self->{"Astro::App::Satpass2::ParseTime::Date::Manip::v6"}B= $self->_make_dm_hash
| |||||||||||||||||||||||||||||
| 105 | 0 | return $info->{$field}; | |||||||||||||||||||||||||||
| 106 | } | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _make_dm_hash { | ||||||||||||||||||||||||||
|
Subroutine
_make_dm_hash: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 109 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | # Workaround for bug (well, _I_ think it's a bug) introduced into | ||||||||||||||||||||||||||||
| 112 | # Date::Manip with 6.34, while fixing RT #78566. My bug report is RT | ||||||||||||||||||||||||||||
| 113 | # #80435. | ||||||||||||||||||||||||||||
| 114 | 0 | my $path = $ENV{PATH}; | |||||||||||||||||||||||||||
| 115 | 0 | local $ENV{PATH} = $path; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $back_end = $self->back_end() || 'Date::Manip::Date'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$self->back_end || 'Date::Manip::Date'
MC/DC0%0/1
$self->back_end || 'Date::Manip::Date'
$self->back_end
Truth table0%0/2
A
A= $self->back_end
| |||||||||||||||||||||||||||||
| 118 | 0 | my $dm = $back_end->new(); | |||||||||||||||||||||||||||
| 119 | return { | ||||||||||||||||||||||||||||
| 120 | 0 | default_zone => scalar $dm->tz->zone(), | |||||||||||||||||||||||||||
| 121 | object => $dm, | ||||||||||||||||||||||||||||
| 122 | }; | ||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 1 | 1; | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | =head1 NAME | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Astro::App::Satpass2::ParseTime::Date::Manip::v6 - Astro::App::Satpass2 wrapper for Date::Manip v6 or greater | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | No user-serviceable parts inside. | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | =head1 DETAILS | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | This class wraps the L<Date::Manip::Date|Date::Manip::Date> object from | ||||||||||||||||||||||||||||
| 138 | L<Date::Manip|Date::Manip> version 6.0 or higher, and uses it to parse | ||||||||||||||||||||||||||||
| 139 | dates. It ignores the C<perltime> mechanism. | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | B<Caveat:> the L<Date::Manip|Date::Manip> configuration mechanism (used | ||||||||||||||||||||||||||||
| 142 | to set the time zone) reports errors using the C<warn> built-in, rather | ||||||||||||||||||||||||||||
| 143 | than by returning a bad status or throwing an exception. Yes, I could | ||||||||||||||||||||||||||||
| 144 | use the C<$SIG{__WARN__}> hook to trap this, but I would rather hope | ||||||||||||||||||||||||||||
| 145 | that Mr. Beck will provide a more friendly mechanism. | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | =head1 METHODS | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | This class supports the following public methods over and above those | ||||||||||||||||||||||||||||
| 150 | documented in its superclass | ||||||||||||||||||||||||||||
| 151 | L<Astro::App::Satpass2::ParseTime|Astro::App::Satpass2::ParseTime>. | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | =head2 dmd_err | ||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | my $error_string = $pt->dmd_err(); | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | This method wraps the L<Date::Manip::Date|Date::Manip::Date> object's | ||||||||||||||||||||||||||||
| 158 | C<err()> method, and returns whatever that method | ||||||||||||||||||||||||||||
| 159 | returns. | ||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | =head2 dmd_zone | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | my $zone_name = $pt->dmd_zone(); | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | This method wraps the L<Date::Manip::TZ|Date::Manip::TZ> object's | ||||||||||||||||||||||||||||
| 166 | C<zone()> method, calling it in scalar context to | ||||||||||||||||||||||||||||
| 167 | get the default zone name, and returning the result. | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | Note that unlike the inherited C<tz()> method, this is an accessor | ||||||||||||||||||||||||||||
| 170 | only, and, it is possible that C<< $pt->dmd_zone() >> will not return | ||||||||||||||||||||||||||||
| 171 | the same thing that C<< $pt->tz() >> does. For example, | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | $pt->tz( 'EST5EDT' ); | ||||||||||||||||||||||||||||
| 174 | print '$pt->tz(): ', $pt->tz(), "\n"; | ||||||||||||||||||||||||||||
| 175 | print '$pt->dmd_zone(): ', $pt->dmd_zone(), "\n"; | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | prints | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | $pt->tz(): EST5EDT | ||||||||||||||||||||||||||||
| 180 | $pt->dmd_zone(): America/New_York | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | This is because C<< $pt->tz() >> returns the last setting, whereas C<< | ||||||||||||||||||||||||||||
| 183 | $pt->dmd_zone() >> returns the name of the time zone in the Olson | ||||||||||||||||||||||||||||
| 184 | zoneinfo database, which is typically something like C<Continent/City>, | ||||||||||||||||||||||||||||
| 185 | even though the time zone was set using an alias, abbreviation or | ||||||||||||||||||||||||||||
| 186 | offset. See L<Date::Manip::TZ|Date::Manip::TZ> for the gory details. | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Another difference is the if the time zone has never been set, | ||||||||||||||||||||||||||||
| 189 | C<< $pt->tz() >> will return C<undef>, whereas | ||||||||||||||||||||||||||||
| 190 | C<< $pt->dmd_zone() >> will actually return the name of the default | ||||||||||||||||||||||||||||
| 191 | zone. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | Support is by the author. Please file bug reports at | ||||||||||||||||||||||||||||
| 196 | L<https://github.com/trwyant/perl-Astro-App-Satpass2/issues> or in | ||||||||||||||||||||||||||||
| 197 | electronic mail to the author. | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | Thomas R. Wyant, III F<harryfmudd at comcast dot net> | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Copyright (C) 2009-2026 by Thomas R. Wyant, III | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 208 | under the same terms as Perl 5.10.0. For more details, see the full text | ||||||||||||||||||||||||||||
| 209 | of the licenses in the files F<LICENSE-Artistic> and F<LICENSE-GPL>. | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | This program is distributed in the hope that it will be useful, but | ||||||||||||||||||||||||||||
| 212 | without any warranty; without even the implied warranty of | ||||||||||||||||||||||||||||
| 213 | merchantability or fitness for a particular purpose. | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | __END__ | ||||||||||||||||||||||||||||