Astro-App-Satpass2
view release on metacpan or search on metacpan
lib/Astro/App/Satpass2/FormatValue.pm view on Meta::CPAN
alias => 'gmt',
},
zulu => {
alias => 'gmt',
},
},
formatter => '_format_time',
},
);
# The following was for a utility script to generate documentation for
# the dimensions.
#
# sub __get_dimension_data {
# my ( $class, $name ) = @_;
# return $dimensions{$name};
# }
# The following hash is used for generating formatter methods, as
# a way of avoiding the replication of common code. The keys are
# the method names, and the values are hashes which specify the
# method to generate. If the named method already exists, it is
# not replaced.
#
# The hash specifying each method contains the following keys,
# which are all requited unless the documentation for the key says
# otherwise.
#
# {chain} - An optional code reference which may (but need not)
# expand the formatter to produce multiple representations of
# the same value. It takes the arguments ( $self, $name,
# $value, $arg ) where $self is the invocant, $name is the
# name of the formatter method, $value is the value being
# formatted, and $arg is the formatter arguments, which have
# already had the defaults applied. It returns at least one
# argument hash. If it returns more than one, the same value
# is formatted using each set of arguments, with the results
# made into a single string using join( ' ', ... ). The
# returned argument sets MUST keep the same field width for
# the same arguments.
#
# This is used only for azimuth(), to process the 'bearing'
# argument.
#
# {default} - A hash specifying all legal arguments, and their
# default values. You can specify undef to make the argument
# legal but give it no value (i.e. to pick up the value from
# somewhere else).
#
# {dimension} - A hash specifying the dimension of the value to be
# formatted. This must contain a {dimension} key specifying
# the name of the dimension, and may contain a {units} value
# overriding the default units.
#
# {fetch} - A code reference which returns the value to be
# formatted. It will be passed arguments ( $self, $name, $arg
# ), where $self is the invocant, $name is the name of the
# formatter method, and $arg is a refernce to the arguments
# hash, which has already had _apply_defaults() called on it.
# This code is _not_ called if the invocant was initialized
# with title => 1.
#
# {locale} - A hash specifying last-ditch localization
# information. The keys are locale, the formatter name
# (yes, this is a duplicate) and the item name.
my %formatter_data = ( # For generating formatters
almanac => {
default => {
width => 40,
},
dimension => {
dimension => 'almanac_pseudo_units',
},
fetch => sub {
my ( $self, undef, $arg ) = @_; # $name unused
my $field = $arg->{units} ||= 'description';
return $self->_get( data => almanac => $field );
},
},
altitude => {
default => {
places => 1,
width => 7,
},
dimension => {
dimension => 'length',
},
fetch => sub {
my ( $self ) = @_; # $name, $arg unused
my $value;
if ( my $body = $self->_get_eci( 'body' ) ) {
$value = ( $body->geodetic() )[2];
}
return $value;
},
},
angle => {
default => {
places => 1,
width => 5,
},
dimension => {
dimension => 'angle_units',
},
fetch => sub {
my ( $self ) = @_; # $name, $arg unused
return $self->_get( data => 'angle' );
},
},
apoapsis => {
default => {
as_altitude => 1,
places => 0,
width => 6,
},
( run in 0.537 second using v1.01-cache-2.11-cpan-39bf76dae61 )