Astro-App-Satpass2
view release on metacpan or search on metacpan
lib/Astro/App/Satpass2/Format.pm view on Meta::CPAN
$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};
};
}
my %not_part_of_config = map { $_ => 1 } qw{ parent warner };
sub config {
my ( $self, %args ) = @_;
my @data;
foreach my $name ( $self->attribute_names() ) {
$not_part_of_config{$name}
and next;
my $val = $self->$name();
$args{decode}
and ref $val
and $val = $self->decode( $name );
no warnings qw{ uninitialized };
next if $args{changes} &&
$val eq ( $original_value{$name} ?
$original_value{$name}->( $self, $name ) :
undef );
push @data, [ $name, $val ];
}
return wantarray ? @data : \@data;
}
}
{
my %decoder = (
desired_equinox_dynamical => sub {
my ( $self, $method, @args ) = @_;
my $rslt = $self->$method( @args );
@args and return $rslt;
$rslt or return $rslt;
return $self->{time_formatter}->format_datetime(
$self->{time_formatter}->ISO_8601_FORMAT(),
$rslt, 1 );
},
time_formatter => sub {
my ( $self, $method, @args ) = @_;
my $rslt = $self->$method( @args );
@args and return $rslt;
# return ref $rslt || $rslt;
return $rslt->class_name_of_record();
},
);
$decoder{value_formatter} = $decoder{time_formatter};
sub decode {
my ( $self, $method, @args ) = @_;
my $dcdr = $decoder{$method}
or return $self->$method( @args );
my $type = ref $dcdr
or $self->weep( "Decoder for $method is scalar" );
CODE_REF eq $type
or $self->weep(
"Decoder for $method is $type reference" );
return $dcdr->( $self, $method, @args );
}
}
sub format : method { ## no critic (ProhibitBuiltInHomonyms,RequireFinalReturn)
my ( $self ) = @_;
# ->weep() throws an exception.
( run in 2.412 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )