Astro-DSS-JPEG

 view release on metacpan or  search on metacpan

lib/Astro/DSS/JPEG.pm  view on Meta::CPAN

        my $simbad = $self->_get_simbad(%opts);
        %opts = (
            %opts,
            %$simbad
        );
    }

    my $res = $self->_get_dss(_process_options(%opts));
    if ($res->is_success) {
        return $res if $opts{filename};
        return $res->decoded_content;
    } else {
        die "*ERROR* Could not access DSS at: ".$res->request->uri
            ."\nHTTP Response:\n".$res->status_line;
    }
}

sub _get_dss {
    my ($self, %opts) = @_;

    my @request = (

lib/Astro/DSS/JPEG.pm  view on Meta::CPAN

    return %opts;
}

sub _get_simbad {
    my ($self, %opts) = @_;

    my $res = $self->{ua}->get(
        $self->{simbad_url}."?output.format=ASCII&Ident=".$opts{target}
    );
    if ($res->is_success) {
        my $simbad = $res->decoded_content;
        if ($simbad =~ /\(ICRS,ep=J2000,eq=2000\): (\S+ \S+ \S+)\s+(\S+ \S+ \S+)/) {
            $opts{ra}  = $1;
            $opts{dec} = $2;
        } else {
            die "*ERROR* Could not parse SIMBAD output:\n$simbad";
        }
        if ($simbad =~ /Angular size:\s*([0-9.]+)/) { # Get only largest dimension
            $opts{angular_size} = min($1 * 1.5, 600); # Get 50% extra for framing, max out at 10 degrees
        }
    } else {

t/simple.t  view on Meta::CPAN

eval { $dss->get_image(target => 'M1', ra => 1) };
like( $@, qr/Could not access SIMBAD/, "Tried to access SIMBAD" );

eval { $dss->get_image(target => 'M1', ra => 1, dec => 1) };
like( $@, qr/Could not access DSS/, "Tried to access DSS" );

$dss = Astro::DSS::JPEG->new();

my $mock_result = Test::MockObject->new();
$mock_result->set_true( 'is_success' );
$mock_result->set_true( 'decoded_content' );
my $mock = Test2::Mock->new(
    class => 'LWP::UserAgent',
    override => [
        get => sub { $mock_result },
    ],
);

eval { $dss->_get_simbad(target => 'M1') };
like( $@, qr/Could not parse SIMBAD/, "Tried to parse SIMBAD" );

my $SIMBAD = '
Coordinates(ICRS,ep=J2000,eq=2000): 06 43 14.6852097640  +65 40 38.949836611 (Opt ) C [1.5736 2.7083 90] 2018yCat.1345....0G
Coordinates(FK4,ep=B1950,eq=1950): 06 38 15.3137510911  +65 43 36.219401450
';

$mock_result->mock( 'decoded_content', sub { $SIMBAD } );
is(
    $dss->_get_simbad( target => 'M1' ),
    { ra => '06 43 14.6852097640', dec => '+65 40 38.949836611', target => 'M1' },
    'Parsed SIMBAD coordinates'
);

$SIMBAD .= 'Angular size: 0.417 0.317  30 (NIR )  C 2006AJ....131.1163S';
my $sim_result = { ra => '06 43 14.6852097640', dec => '+65 40 38.949836611', angular_size => 0.417*1.5, target => 'M1' };
$mock_result->mock( 'decoded_content', sub { $SIMBAD } );
is(
    $dss->_get_simbad( target => 'M1' ),
    $sim_result,
    'Parsed SIMBAD coordinates'
);

my $mock2 = Test2::Mock->new(
    class => 'Astro::DSS::JPEG',
    override => [
        _get_simbad => sub { $sim_result },
    ],
);

$mock_result->mock( 'decoded_content', sub { 'data' } );
my $img = $dss->get_image(target => 'M1', ra => 1);
is($img, 'data', 'Got image from decoded_content');
my $file = 'M1.jpg';
my $res = $dss->get_image(ra => 1, dec => 1, filename => $file);
is($res->is_success, T(), 'Got HTTP response');
unlink ($file) if -f $file;

# For Devel::Cover
$mock = Test2::Mock->new(
    class => 'LWP::UserAgent',
    override => [
        new => sub { undef },



( run in 0.307 second using v1.01-cache-2.11-cpan-26ccb49234f )