App-SourcePlot

 view release on metacpan or  search on metacpan

lib/App/SourcePlot/Source.pm  view on Meta::CPAN


=head1 METHODS

=head2 Constructor

=over 4

=item new

Create a new Source object.

    $obs = App::SourcePlot::Source->new($planet);
    $obs = App::SourcePlot::Source->new($name, $RA, $DEC, $Epoc);

Or using an Astro::Coords object.

    $coords = Astro::Coords->new(...);
    $obs = App::SourcePlot::Source->new($coords);

=cut

sub new {
    print "Creating a new observation Source object\n" if $locateBug;

    my $proto = shift;
    my $class = ref($proto) || $proto;

    my $self = {};  # Anon hash

    bless($self, $class);
    print "New observation Source object has been blessed: $self\n" if $locateBug;

    $self->configure(@_);

    $self->active(1);

    print "Object created\n" if $locateBug;

    return $self;
}


sub configure {
    my $self = shift;

    # Special case: empty source object.
    unless (@_) {
        $self->coords(Astro::Coords->new());
        return;
    }

    my $name = shift;

    if (UNIVERSAL::isa($name, 'Astro::Coords')) {
        $self->coords($name);
    }
    elsif (@_) {
        print "Passed in paramaters are being entered\n" if $locateBug;
        my ($ra, $dec, $epoc, undef) = @_;

        # Prevent Astro::Coords guessing between radians and degrees.
        my $unit = ($ra =~ /:/ or $dec =~ /:/)
            ? 'sexagesimal'
            : 'degrees';

        if ($epoc eq 'RJ') {
            $self->coords(Astro::Coords->new(
                name => $name,
                ra => ($unit eq 'degrees') ? ($ra * 15) : $ra,
                dec => $dec,
                type => 'J2000',
                units => $unit,
            ));
        }
        elsif ($epoc eq 'RB') {
            $self->coords(Astro::Coords->new(
                name => $name,
                ra => ($unit eq 'degrees') ? ($ra * 15) : $ra,
                dec => $dec,
                type => 'B1950',
                units => $unit,
            ));
        }
        elsif ($epoc eq 'GA') {
            $self->coords(Astro::Coords->new(
                name => $name,
                long => $ra,
                lat => $dec,
                type => 'galactic',
                units => $unit,
            ));
        }
        elsif ($epoc eq 'AZ') {
            $self->coords(Astro::Coords->new(
                name => $name,
                az => $ra,
                el => $dec,
                units => $unit,
            ));
        }
        else {
            die "App::SourcePlot::Source unknown epoc " . $epoc
                . " for source " . $name;
        }
    }
    else {
        $self->coords(Astro::Coords->new(
            planet => $name,
        ));
    }
}

=back

=head2 Common data manipulation functions

=over 4

=item name

Returns and sets the name of the source.



( run in 0.524 second using v1.01-cache-2.11-cpan-39bf76dae61 )