Astro-DSS
view release on metacpan or search on metacpan
# CONFIGURE DEFAULTS
# ------------------
# define the default base URL
$self->{URL} = "archive.eso.org";
# define the query URLs
my $default_url = $self->{URL};
$self->{QUERY} = "http://$default_url/dss/dss/image?";
# Setup the LWP::UserAgent
my $HOST = hostname();
my $DOMAIN = hostdomain();
$self->{USERAGENT} = new LWP::UserAgent( timeout => 30 );
$self->{USERAGENT}->agent("Astro::DDS/$VERSION ($HOST.$DOMAIN)");
# Grab Proxy details from local environment
$self->{USERAGENT}->env_proxy();
# Grab something for DATA directory
if ( defined $ENV{"ESTAR_DATA"} ) {
if ( opendir (DIR, File::Spec->catdir($ENV{"ESTAR_DATA"}) ) ) {
# default to the ESTAR_DATA directory
$self->{DATADIR} = File::Spec->catdir($ENV{"ESTAR_DATA"});
closedir DIR;
} else {
# Shouldn't happen?
croak("Cannot open $ENV{ESTAR_DATA} for incoming files.");
}
} elsif ( opendir(TMP, File::Spec->tmpdir() ) ) {
# fall back on the /tmp directory
$self->{DATADIR} = File::Spec->tmpdir();
closedir TMP;
} else {
# Shouldn't happen?
croak("Cannot open any directory for incoming files.");
}
# configure the default options
${$self->{OPTIONS}}{"ra"} = undef;
${$self->{OPTIONS}}{"dec"} = undef;
${$self->{OPTIONS}}{"name"} = undef;
${$self->{OPTIONS}}{"equinox"} = 2000;
${$self->{OPTIONS}}{"x"} = 10;
${$self->{OPTIONS}}{"y"} = 10;
${$self->{OPTIONS}}{"Sky-Survey"} = "DSS1";
${$self->{OPTIONS}}{"mime-type"} = "download-gif";
# CONFIGURE FROM ARGUEMENTS
# -------------------------
# return unless we have arguments
return undef unless @_;
# grab the argument list
my %args = @_;
# Loop over the allowed keys and modify the default query options
for my $key (qw / RA Dec Target Equinox Xsize Ysize Survey Format
URL Timeout Proxy / ) {
my $method = lc($key);
$self->$method( $args{$key} ) if exists $args{$key};
}
}
# T I M E A T T H E B A R --------------------------------------------
=back
=begin __PRIVATE_METHODS__
=head2 Private methods
These methods are for internal use only.
=over 4
=item B<_make_query>
Private function used to make an DSS query. Should not be called directly,
since it does not parse the results. Instead use the querydb() assessor method.
=cut
sub _make_query {
my $self = shift;
# grab the user agent
my $ua = $self->{USERAGENT};
# clean out the buffer
$self->{BUFFER} = "";
# grab the base URL
my $URL = $self->{QUERY};
my $options = "";
# loop round all the options keys and build the query
foreach my $key ( keys %{$self->{OPTIONS}} ) {
$options = $options .
"&$key=${$self->{OPTIONS}}{$key}" if defined ${$self->{OPTIONS}}{$key};
}
# build final query URL
$URL = $URL . $options;
# build request
my $request = new HTTP::Request('GET', $URL);
# grab page from web
my $reply = $ua->request($request);
# declare file name
my $file_name;
if ( ${$reply}{"_rc"} eq 200 ) {
if ( ${${$reply}{"_headers"}}{"content-type"}
eq "application/octet-stream" ) {
( run in 1.682 second using v1.01-cache-2.11-cpan-39bf76dae61 )