Astro-App-Satpass2
view release on metacpan or search on metacpan
lib/Astro/App/Satpass2/Format.pm view on Meta::CPAN
package Astro::App::Satpass2::Format;
use strict;
use warnings;
use parent qw{ Astro::App::Satpass2::Copier };
use Clone ();
use Astro::App::Satpass2::FormatTime;
use Astro::App::Satpass2::Utils qw{
instance
load_package __parse_class_and_args
CODE_REF
@CARP_NOT
};
use Scalar::Util 1.26 qw{ weaken };
our $VERSION = '0.057';
use constant DEFAULT_LOCAL_COORD => 'azel_rng';
# Note that the fact that new() works when called from
# My::Module::Test::App is unsupported and undocumented, and
# the functionality may be revoked or changed without warning.
my %static = (
desired_equinox_dynamical => 0,
gmt => 0,
local_coord => DEFAULT_LOCAL_COORD,
provider => 'Astro::App::Satpass2',
value_formatter => 'Astro::App::Satpass2::FormatValue',
);
sub new {
my ( $class, %args ) = @_;
ref $class and $class = ref $class;
my $self = { %static };
bless $self, $class;
$self->warner( delete $args{warner} );
$class eq __PACKAGE__
and 'My::Module::Test::App' ne caller
and $self->wail( __PACKAGE__,
' may not be instantiated. Use a subclass' );
$self->{parent} = delete $args{parent};
# FIXME the below is verbatim from
# Astro::App::Satpass2::Macro->init(), ca. line 63.
defined $self->{parent}
or $self->wail( q{Attribute 'parent' is required} );
instance( $self->{parent}, 'Astro::App::Satpass2' )
or $self->wail( q{Attribute 'parent' must be an Astro::App::Satpass2} );
weaken( $self->{parent} );
exists $args{tz} or $args{tz} = $ENV{TZ};
$self->time_formatter( delete $args{time_formatter} );
$self->time_formatter()->warner( $self->warner() );
$args{date_format}
or $self->date_format( $self->time_formatter()->DATE_FORMAT() );
$args{time_format}
or $self->time_format( $self->time_formatter()->TIME_FORMAT() );
exists $args{round_time}
or $self->round_time( $self->time_formatter()->ROUND_TIME() );
$self->value_formatter( delete $args{value_formatter} ||
$static{value_formatter} );
$self->value_formatter()->warner( $self->warner() );
$self->init( %args );
return $self;
}
sub round_time {
my ( $self, @arg ) = @_;
if ( @arg ) {
$self->time_formatter()->round_time( @arg );
$self->{round_time} = $arg[0];
return $self;
} else {
return $self->time_formatter()->round_time();
}
}
sub attribute_names {
my ( $self ) = @_;
return ( $self->SUPER::attribute_names(),
qw{ date_format desired_equinox_dynamical gmt
local_coord parent provider round_time
time_format time_formatter tz
value_formatter
} );
}
{
my %original_value = (
date_format => sub {
return $_[0]->time_formatter()->DATE_FORMAT()
},
round_time => sub {
return $_[0]->time_formatter()->ROUND_TIME()
},
time_format => sub {
return $_[0]->time_formatter()->TIME_FORMAT()
},
);
foreach my $key ( keys %static ) {
$original_value{ $key } ||= sub {
return $static{$key};
( run in 1.021 second using v1.01-cache-2.11-cpan-437f7b0c052 )