Astro-satpass
view release on metacpan or search on metacpan
lib/Astro/Coord/ECI/TLE/Set.pm view on Meta::CPAN
this.
Optionally, the first argument may be a hash reference. The hash
contains options that modify the function of this method. The only
option at the moment is
select => $time
which causes the object best representing the given time to be selected
in any Astro::Coord::ECI::TLE::Set objects.
=cut
our $Singleton = 0;
sub aggregate {
my ($class, @args) = @_;
$class = ref $class if ref $class;
my $opt = HASH_REF eq ref $args[0] ? shift @args : {};
my %data;
my @rslt;
foreach my $tle ( @args ) {
my $model = $tle->get( 'model' );
my $id = $tle->get ('id');
if ( '' eq $id && 'null' eq $model ) {
push @rslt, $tle;
} else {
$data{$id} ||= [];
push @{$data{$id}}, $tle;
}
}
my $limit = $Singleton ? 0 : 1;
foreach my $id (sort keys %data) {
my $items = @{$data{$id}};
if ($items > $limit) {
my $set = $class->new(@{$data{$id}});
exists $opt->{select}
and $set->select($opt->{select});
push @rslt, $set;
} else {
push @rslt, @{$data{$id}};
}
}
return @rslt;
}
=item $set->can ($method);
This method checks to see if the object can execute the given method.
If so, it returns a code reference to the subroutine; otherwise it
returns undef.
This override to UNIVERSAL::can is necessary because we want to return
true for member class methods, but we execute them by autoloading, so
they are not in our namespace.
=cut
sub can {
my ($self, $method) = @_;
my $rslt = eval {$self->SUPER::can($method)};
$@ and return;
$rslt and return $rslt;
return eval { ## no critic (RequireCheckingReturnValueOfEval)
$self->{current}->can($method)
};
}
=item $set->clear ();
This method removes all members from the set, allowing it to be
reloaded with a different NORAD ID.
=cut
sub clear {
my $self = shift;
$self->{current} = undef;
@{$self->{members}} = ();
return $self;
}
=item $value = $set->get( $name );
This method returns the value of the named attribute.
If the attribute name is C<'tle'>, it returns the concatenated TLE data
of all TLEs in the set. Otherwise it simply returns the named attribute
of the selected C<Astro::Coord::ECI::TLE> object.
=cut
{
my %override = (
tle => sub {
## my ( $self, $name ) = @_;
my ( $self ) = @_; # Name unused
my $output;
foreach my $body ( $self->members() ) {
$output .= $body->get( 'tle' );
}
return $output;
},
);
sub get {
my ( $self, $name ) = @_;
$override{$name}
and return $override{$name}->( $self, $name );
return $self->select()->get( $name );
}
}
=item $time = $set->max_effective_date(...);
This method extends the L<Astro::Coord::ECI::TLE|Astro::Coord::ECI::TLE>
C<max_effective_date()> method appropriately for sets of elements.
If there are arguments, their maximum is taken, the appropriate member
element is set, and C<max_effective_date()> is called on that element,
( run in 0.455 second using v1.01-cache-2.11-cpan-98e64b0badf )