Astro-Coords
view release on metacpan or search on metacpan
lib/Astro/Coords.pm view on Meta::CPAN
C<datetime_is_unsafe> method to indicate this to the module.
=cut
sub datetime {
my $self = shift;
if (@_) {
my $time = shift;
# undef is okay
croak "datetime: Argument does not have an mjd() method [class="
. ( ref($time) ? ref($time) : $time) ."]"
if (defined $time && !UNIVERSAL::can($time, "mjd"));
$self->{DateTime} = _clone_time( $time );
$self->usenow(0);
# Changing usenow will have forced a recalculation of the cache key
# so no update is required here
# $self->_calc_cache_key;
}
if (defined $self->{DateTime} && ! $self->usenow) {
return $self->{DateTime};
} else {
return DateTime->now( time_zone => UTC );
}
}
=item B<has_datetime>
Returns true if a specific time is stored in the object, returns
false if no time is stored. (The value of C<usenow> is
ignored).
This is required because C<datetime> always returns a time.
=cut
sub has_datetime {
my $self = shift;
return (defined $self->{DateTime});
}
=item B<usenow>
Flag to indicate whether the current time should be used for calculations
regardless of whether an explicit time object is stored in C<datetime>.
This is useful when trying to determine the current position of a target
without affecting previous settings.
$c->usenow( 1 );
$usenow = $c->usenow;
Defaults to false.
=cut
sub usenow {
my $self = shift;
if (@_) {
$self->{UseNow} = shift;
# Since this affects caching we need to force a key check if this value
# is updated
$self->_calc_cache_key();
}
return $self->{UseNow};
}
=item B<datetime_is_unsafe>
If true, indicates that the DateTime object stored in this object is
not guranteed to be immutable by the externally user. This effectively
turns off the internal cache.
$c->datetime_is_unsafe();
=cut
sub datetime_is_unsafe {
my $self = shift;
if (@_) {
$self->{DATETIME_IS_UNSAFE} = shift;
$self->_calc_cache_key;
}
return $self->{DATETIME_IS_UNSAFE};
}
=item B<comment>
A textual comment associated with the coordinate (optional).
Defaults to the empty string.
$comment = $c->comment;
$c->comment("An inaccurate coordinate");
Always returns an empty string if undefined.
=cut
sub comment {
my $self = shift;
if (@_) {
$self->{Comment} = shift;
}
my $com = $self->{Comment};
$com = '' unless defined $com;
return $com;
}
=item B<native>
Returns the name of the method that should be called to return the
coordinates in a form as close as possible to those that were supplied
to the constructor. This method is useful if, say, the object is created
from Galactic coordinates but internally represented in a different
coordinate frame.
$native_method = $c->native;
This method can then be called to retrieve the coordinates:
($c1, $c2) = $c->$native_method();
( run in 0.482 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )