| 1 | package Astro::Catalog::Query::Sesame; | ||||||||||
| 2 | |||||||||||
| 3 | =head1 NAME | ||||||||||
| 4 | |||||||||||
| 5 | Astro::Catalog::Query::Sesame - Object name resolution via SIMBAD | ||||||||||
| 6 | |||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||
| 8 | |||||||||||
| 9 | my $sesame = new Astro::Catalog::Query::Sesame(Target => "EX Hya"); | ||||||||||
| 10 | my $catalog = $sesame->querydb(); | ||||||||||
| 11 | |||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||
| 13 | |||||||||||
| 14 | Simple wrapper object for the CDS SIMBAD Name Resolver serbice (Sesame), see | ||||||||||
| 15 | http://cdsweb.u-strasbg.fr/cdsws.gml for details of the service. | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | use base qw/Astro::Catalog::Transport::WebService/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 2 | ▶ | use Data::Dumper; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 2 | ▶ | use POSIX qw/ceil/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | use Astro::Coords; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | 2 | ▶ | use Astro::Catalog; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 2 | ▶ | use Astro::Catalog::Item; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | 2 | our $VERSION = '4.38'; | |||||||||
| 32 | 2 | our $DEBUG = 0; | |||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 Constructor | ||||||||||
| 37 | |||||||||||
| 38 | =over 4 | ||||||||||
| 39 | |||||||||||
| 40 | =item B<new> | ||||||||||
| 41 | |||||||||||
| 42 | Create a new instance from a hash of options | ||||||||||
| 43 | |||||||||||
| 44 | $query = new Astro::Catalog::Query::WebService(Object => $target); | ||||||||||
| 45 | |||||||||||
| 46 | returns a reference to an query object. | ||||||||||
| 47 | =cut | ||||||||||
| 48 | |||||||||||
| 49 | =item B<querydb> | ||||||||||
| 50 | |||||||||||
| 51 | Returns an Astro::Catalog object resulting from the specific query. | ||||||||||
| 52 | |||||||||||
| 53 | $catalog = $query->querydb(); | ||||||||||
| 54 | |||||||||||
| 55 | =cut | ||||||||||
| 56 | |||||||||||
| 57 | 2 | ▶ | sub querydb { | ||||||||
|
Subroutine
querydb: called CC=3 SCAR=17.7
Pod
documented
| |||||||||||
| 58 | 2 | my $self = shift; | |||||||||
| 59 | |||||||||||
| 60 | # clean out buffer | ||||||||||
| 61 | 2 | $self->_set_raw(""); | |||||||||
| 62 | |||||||||||
| 63 | 2 | my $endpoint = $self->endpoint(); | |||||||||
| 64 | 2 | my %options = $self->_translate_options(); | |||||||||
| 65 | |||||||||||
| 66 | # return unless we haev a target, set it otherwise | ||||||||||
| 67 | 2 | ▶ | return undef unless $self->query_options("object"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 68 | |||||||||||
| 69 | # make sesame query | ||||||||||
| 70 | 2 | my $service = SOAP::Lite->service($self->endpoint()); | |||||||||
| 71 | |||||||||||
| 72 | 0 | my $ident = $self->query_options("object"); | |||||||||
| 73 | 0 | $ident =~ s/\+/ /g; | |||||||||
| 74 | |||||||||||
| 75 | 0 | my $buffer; | |||||||||
| 76 | 0 | eval { $buffer = $service->sesame( $ident, "u" ); }; | |||||||||
| 77 | 0 | ▶ | if ($@) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 78 | 0 | my $status = $service->transport()->status(); | |||||||||
| 79 | 0 | croak("Error ($status): $@"); | |||||||||
| 80 | 0 | return; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | # parse results & return | ||||||||||
| 84 | 0 | $self->_set_raw($buffer); | |||||||||
| 85 | 0 | my $catalog = $self->_parse_query(); | |||||||||
| 86 | 0 | return $catalog; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | =back | ||||||||||
| 90 | |||||||||||
| 91 | =begin __PRIVATE_METHODS__ | ||||||||||
| 92 | |||||||||||
| 93 | =head2 Private methods | ||||||||||
| 94 | |||||||||||
| 95 | These methods are for internal use only. | ||||||||||
| 96 | |||||||||||
| 97 | =over 4 | ||||||||||
| 98 | |||||||||||
| 99 | =item B<_default_endpoint> | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 4 | ▶ | sub _default_endpoint { | ||||||||
|
Subroutine
_default_endpoint: called CC=1 SCAR=0.0
| |||||||||||
| 104 | 4 | return "http://cdsws.u-strasbg.fr/axis/services/Sesame?wsdl"; | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | =item B<_default_urn> | ||||||||||
| 108 | |||||||||||
| 109 | =cut | ||||||||||
| 110 | |||||||||||
| 111 | 0 | ▶ | sub _default_urn { | ||||||||
|
Subroutine
_default_urn: not called CC=1 SCAR=6.9
| |||||||||||
| 112 | 0 | return undef; | |||||||||
| 113 | } | ||||||||||
| 114 | |||||||||||
| 115 | =item B<_is_service> | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||
| 118 | |||||||||||
| 119 | 0 | ▶ | sub _is_service { | ||||||||
|
Subroutine
_is_service: not called CC=1 SCAR=6.9
| |||||||||||
| 120 | 0 | return 1; | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | =item B<_get_allowed_options> | ||||||||||
| 124 | |||||||||||
| 125 | Returns a hash with keys, being the internal options supported | ||||||||||
| 126 | by this subclass, and values being the key name actually required | ||||||||||
| 127 | by the remote system (and to be included in the query). | ||||||||||
| 128 | |||||||||||
| 129 | =cut | ||||||||||
| 130 | |||||||||||
| 131 | 14 | ▶ | sub _get_allowed_options { | ||||||||
|
Subroutine
_get_allowed_options: called CC=1 SCAR=0.0
| |||||||||||
| 132 | 14 | my $self = shift; | |||||||||
| 133 | return ( | ||||||||||
| 134 | 14 | object => 'object' | |||||||||
| 135 | ); | ||||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | =item B<_get_supported_init> | ||||||||||
| 139 | |||||||||||
| 140 | Uses base class options. | ||||||||||
| 141 | |||||||||||
| 142 | =cut | ||||||||||
| 143 | |||||||||||
| 144 | =item B<_set_default_options> | ||||||||||
| 145 | |||||||||||
| 146 | Set the default query state. | ||||||||||
| 147 | |||||||||||
| 148 | =cut | ||||||||||
| 149 | |||||||||||
| 150 | 2 | ▶ | sub _set_default_options { | ||||||||
|
Subroutine
_set_default_options: called CC=1 SCAR=0.0
| |||||||||||
| 151 | return ( | ||||||||||
| 152 | 2 | object => undef, | |||||||||
| 153 | ); | ||||||||||
| 154 | } | ||||||||||
| 155 | |||||||||||
| 156 | |||||||||||
| 157 | =item B<_get_supported_init> | ||||||||||
| 158 | |||||||||||
| 159 | Return the list of initialization methods supported by this catalog. | ||||||||||
| 160 | This is not the same as the allowed options since some methods are | ||||||||||
| 161 | not related to options and other methods that are related to options | ||||||||||
| 162 | use different names. | ||||||||||
| 163 | |||||||||||
| 164 | =cut | ||||||||||
| 165 | |||||||||||
| 166 | 0 | ▶ | sub _get_supported_init { | ||||||||
|
Subroutine
_get_supported_init: not called CC=1 SCAR=6.9
| |||||||||||
| 167 | 0 | return (qw/Target URN Endpoint Proxy/); | |||||||||
| 168 | } | ||||||||||
| 169 | |||||||||||
| 170 | =item B<_parse_query> | ||||||||||
| 171 | |||||||||||
| 172 | Private function used to parse the results returned in an USNO-A2.0 query. | ||||||||||
| 173 | Should not be called directly. Instead use the querydb() assessor method to | ||||||||||
| 174 | make and parse the results. | ||||||||||
| 175 | |||||||||||
| 176 | =cut | ||||||||||
| 177 | |||||||||||
| 178 | 0 | ▶ | sub _parse_query { | ||||||||
|
Subroutine
_parse_query: not called CC=5 SCAR=34.0
| |||||||||||
| 179 | 0 | my $self = shift; | |||||||||
| 180 | |||||||||||
| 181 | # create an Astro::Catalog object to hold the search results | ||||||||||
| 182 | 0 | my $catalog = new Astro::Catalog(); | |||||||||
| 183 | |||||||||||
| 184 | # create a temporary object to hold stars | ||||||||||
| 185 | 0 | my $star = new Astro::Catalog::Item(); | |||||||||
| 186 | |||||||||||
| 187 | # get a local copy of the current BUFFER | ||||||||||
| 188 | 0 | my @result = $self->_dump_raw(); | |||||||||
| 189 | 0 | chomp @result; | |||||||||
| 190 | |||||||||||
| 191 | 0 | ▶ | print Dumper(@result) if $DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 192 | |||||||||||
| 193 | # Grab Coordinates | ||||||||||
| 194 | |||||||||||
| 195 | # grab line from return result | ||||||||||
| 196 | 0 | my $coord_line = undef; | |||||||||
| 197 | 0 | foreach my $i (0 ... $#result) { | |||||||||
| 198 | 0 | ▶ | if ($result[$i] =~ /^%J /) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 199 | 0 | $coord_line = $i; | |||||||||
| 200 | 0 | last; | |||||||||
| 201 | } | ||||||||||
| 202 | } | ||||||||||
| 203 | |||||||||||
| 204 | 0 | ▶ | croak "Can not understand response, no co-ordinate line found " | ||||||||
|
Branch: 1 branch
| |||||||||||
| 205 | unless defined $coord_line; | ||||||||||
| 206 | 0 | my $line = $result[$coord_line]; | |||||||||
| 207 | |||||||||||
| 208 | # split it on \s+ | ||||||||||
| 209 | 0 | my @coords = split /\s+/, $line; | |||||||||
| 210 | |||||||||||
| 211 | # GRAB DEC | ||||||||||
| 212 | |||||||||||
| 213 | # create an Astro::Coords::Angle for coordinate conversion | ||||||||||
| 214 | 0 | my $ang = new Astro::Coords::Angle($coords[2], units => 'deg'); | |||||||||
| 215 | 0 | my $objdec = $ang->string; | |||||||||
| 216 | |||||||||||
| 217 | # GRAB RA | ||||||||||
| 218 | 0 | $ang = new Astro::Coords::Angle($coords[1]/15.0, units => 'deg'); | |||||||||
| 219 | 0 | my $objra = $ang->string; | |||||||||
| 220 | |||||||||||
| 221 | 0 | $star->coords(new Astro::Coords( | |||||||||
| 222 | ra => $objra, | ||||||||||
| 223 | dec => $objdec, | ||||||||||
| 224 | units => 'sex', | ||||||||||
| 225 | type => 'J2000', | ||||||||||
| 226 | name => $self->query_options("object"), | ||||||||||
| 227 | )); | ||||||||||
| 228 | |||||||||||
| 229 | |||||||||||
| 230 | # Push the star into the catalog | ||||||||||
| 231 | 0 | $catalog->pushstar( $star ); | |||||||||
| 232 | |||||||||||
| 233 | # return | ||||||||||
| 234 | 0 | return $catalog; | |||||||||
| 235 | } | ||||||||||
| 236 | |||||||||||
| 237 | 2 | 1; | |||||||||
| 238 | |||||||||||
| 239 | __END__ | ||||||||||