Astro-SIMBAD
view release on metacpan or search on metacpan
Query/Query.pm view on Meta::CPAN
${$self->{LOOKUP}}{"Sy1"} = "Seyfert 1 Galaxy";
${$self->{LOOKUP}}{"Sy2"} = "Seyfert 2 Galaxy";
${$self->{LOOKUP}}{"Bla"} = "Blazar";
${$self->{LOOKUP}}{"BLL"} = "BL Lac - type object";
${$self->{LOOKUP}}{"OVV"} = "Optically Violently Variable object";
${$self->{LOOKUP}}{"QSO"} = "Quasar";
# CONFIGURE FROM ARGUMENTS
# -------------------------
# 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, note
# that due to the order these are called in supplying both and RA and Dec
# and an object Identifier (e.g. HT Cas) will cause the query to default
# to using the identifier rather than the supplied co-ordinates.
for my $key (qw / RA Dec Target Error Units Frame Epoch Equinox
Proxy Timeout URL / ) {
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 SIMBAD 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->queryurl();
# build request
my $request = new HTTP::Request('GET', $URL);
# grab page from web
my $reply = $ua->request($request);
if ( ${$reply}{"_rc"} eq 200 ) {
# stuff the page contents into the buffer
$self->{BUFFER} = ${$reply}{"_content"};
} else {
$self->{BUFFER} = undef;
croak("Error ${$reply}{_rc}: Failed to establish network connection");
}
}
=item B<_parse_query>
Private function used to parse the results returned in an SIMBAD query. Should
not be called directly. Instead use the querydb() assessor method to make and
parse the results.
=cut
sub _parse_query {
my $self = shift;
my $tree = HTML::TreeBuilder->new_from_content($self->{BUFFER});
$tree->elementify();
my $result;
if ($self->use_list_query()) {
$result = $self->_parse_list_query($tree);
} else {
$result = $self->_parse_object_query($tree);
}
$tree->delete(); # yes, this is necessary
return $result;
}
=item B<_parse_list_query>
Private method to parse the results of a list query. Should not be called
directly. Instead use the querydb() assessor method to make and parse the
results.
=cut
sub _parse_list_query {
my $self = shift;
my $tree = shift;
my $pretag = $tree->find_by_tag_name('pre'); # find the <pre> element
my $idtext = decode_entities($pretag->as_HTML());
chomp($idtext);
my @buffer = split( /\n/, $idtext);
# create an Astro::SIMBAD::Result object to hold the search results
my $result = new Astro::SIMBAD::Result();
# loop round the returned buffer
foreach my $linepos (2 .. $#buffer-1) {
my $starline = $buffer[$linepos];
( run in 0.540 second using v1.01-cache-2.11-cpan-39bf76dae61 )