| 1 | package Astro::Catalog::Transport::WebService; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | Astro::Catalog::Transport::WebService - A base class for WebService queries | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | use base qw/Astro::Catalog::Transport::WebService/; | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 DESCRIPTION | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | This class forms a base class for all the WebService based query classes | ||||||||||||||||||||
| 14 | in the C<Astro::Catalog> distribution (eg C<Astro::Catalog::Query::Sesame>). | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =cut | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | 3 | ▶ | use base qw/Astro::Catalog::Query/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 3 | ▶ | use SOAP::Lite; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 23 | 3 | ▶ | use Net::Domain qw/hostname hostdomain/; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 3 | ▶ | use File::Spec; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 3 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 3 | ▶ | use Astro::Catalog; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 3 | ▶ | use Astro::Catalog::Item; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 3 | our $VERSION = '4.38'; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 METHODS | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | =head2 Constructor | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =over 4 | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =item B<new> | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | Create a new instance from a hash of options | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | $q = new Astro::Catalog::Transport::WebService( | ||||||||||||||||||||
| 43 | Coords => new Astro::Coords(), | ||||||||||||||||||||
| 44 | Radius => $radius, | ||||||||||||||||||||
| 45 | Bright => $magbright, | ||||||||||||||||||||
| 46 | Faint => $magfaint, | ||||||||||||||||||||
| 47 | Sort => $sort_type, | ||||||||||||||||||||
| 48 | Number => $number_out); | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | returns a reference to an query object. Must only called from | ||||||||||||||||||||
| 51 | sub-classed constructors. | ||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | RA and Dec are also allowed but are deprecated (since with only | ||||||||||||||||||||
| 54 | RA/Dec the coordinates must always be supplied as J2000 space-separated | ||||||||||||||||||||
| 55 | sexagesimal format). | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =cut | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | 2 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||
| 60 | 2 | my $proto = shift; | |||||||||||||||||||
| 61 | 2 | ▶ | my $class = ref($proto) || $proto; | ||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | # bless the query hash into the class | ||||||||||||||||||||
| 64 | 2 | my $block = bless { | |||||||||||||||||||
| 65 | OPTIONS => {}, | ||||||||||||||||||||
| 66 | COORDS => undef, | ||||||||||||||||||||
| 67 | URN => undef, | ||||||||||||||||||||
| 68 | ENDPOINT => undef, | ||||||||||||||||||||
| 69 | SERVICE => undef, | ||||||||||||||||||||
| 70 | QUERY => undef, | ||||||||||||||||||||
| 71 | BUFFER => undef, | ||||||||||||||||||||
| 72 | }, $class; | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | # Configure the object [even if there are no args] | ||||||||||||||||||||
| 75 | 2 | $block->configure(@_); | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | 2 | return $block; | |||||||||||||||||||
| 78 | } | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =item B<querydb> | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Unlike C<Astro::Transport::REST> a default C<querydb()> method is not | ||||||||||||||||||||
| 83 | provided by this base class, each sub-class must provide its own | ||||||||||||||||||||
| 84 | implemetation. | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | sub querydb { | ||||||||||||||||||
|
Subroutine
querydb: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 89 | 0 | croak "querydb() must be provided by the subclass\n"; | |||||||||||||||||||
| 90 | } | ||||||||||||||||||||
| 91 | |||||||||||||||||||||
| 92 | =item B<proxy> | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | Return (or set) the current proxy for the catalog request. | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | $usno->proxy('http://wwwcache.ex.ac.uk:8080/'); | ||||||||||||||||||||
| 97 | $proxy_url = $usno->proxy(); | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =cut | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | sub proxy { | ||||||||||||||||||
|
Subroutine
proxy: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 102 | 0 | my $self = shift; | |||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | # SOAP::Lite respects the HTTP_proxy environment variable | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 107 | 0 | my $proxy_url = shift; | |||||||||||||||||||
| 108 | 0 | $ENV{HTTP_proxy} = $proxy_url; | |||||||||||||||||||
| 109 | 0 | $ENV{HTTP_PROXY} = $proxy_url; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | # return the current proxy | ||||||||||||||||||||
| 113 | 0 | return $ENV{HTTP_proxy}; | |||||||||||||||||||
| 114 | } | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =item B<urn> | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | Return the current remote urn for the query | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | $host = $q->urn(); | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Can also be used to set the urn. | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =cut | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | 0 | ▶ | sub urn { | ||||||||||||||||||
|
Subroutine
urn: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 127 | 0 | my $self = shift; | |||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | # SETTING URL | ||||||||||||||||||||
| 130 | 0 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 131 | # set the url option | ||||||||||||||||||||
| 132 | 0 | my $urn = shift; | |||||||||||||||||||
| 133 | 0 | $self->{URN} = $urn; | |||||||||||||||||||
| 134 | } | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 0 | return $self->{URN}; | |||||||||||||||||||
| 137 | } | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =item B<endpoint> | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | Return the current endpoint for the query | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | $host = $q->endpoint(); | ||||||||||||||||||||
| 144 | $q->endpoint('http://www.blah.org:8080'); | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | Can also be used to set the endpoint. If the endpoint is a wsdl file | ||||||||||||||||||||
| 147 | the SOAP::Lite object will automagically be configured to use the | ||||||||||||||||||||
| 148 | correct URN, e.g. | ||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | $q->endpoint('http://cdsws.u-strasbg.fr/axis/Sesame.jws?wsdl'); | ||||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | =cut | ||||||||||||||||||||
| 153 | |||||||||||||||||||||
| 154 | 4 | ▶ | sub endpoint { | ||||||||||||||||||
|
Subroutine
endpoint: called CC=4 SCAR=20.1
Pod
documented
| |||||||||||||||||||||
| 155 | 4 | my $self = shift; | |||||||||||||||||||
| 156 | |||||||||||||||||||||
| 157 | # SETTING ENDPOINT | ||||||||||||||||||||
| 158 | 4 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 159 | # set the url option | ||||||||||||||||||||
| 160 | 0 | my $endpoint = shift; | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | 0 | ▶ | if ($endpoint =~ /wsdl$/) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 163 | 0 | $self->{SERVICE} = 1; | |||||||||||||||||||
| 164 | } | ||||||||||||||||||||
| 165 | 0 | $self->{ENDPOINT} = $endpoint; | |||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | } | ||||||||||||||||||||
| 168 | |||||||||||||||||||||
| 169 | 4 | ▶ | if (defined $self->{ENDPOINT}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 170 | 0 | return $self->{ENDPOINT}; | |||||||||||||||||||
| 171 | } | ||||||||||||||||||||
| 172 | else { | ||||||||||||||||||||
| 173 | 4 | return $self->_default_endpoint(); | |||||||||||||||||||
| 174 | } | ||||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | =back | ||||||||||||||||||||
| 178 | |||||||||||||||||||||
| 179 | =head2 General Methods | ||||||||||||||||||||
| 180 | |||||||||||||||||||||
| 181 | =over 4 | ||||||||||||||||||||
| 182 | |||||||||||||||||||||
| 183 | =item B<configure> | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | Configures the object, takes an options hash as an argument | ||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | $q->configure(%options); | ||||||||||||||||||||
| 188 | |||||||||||||||||||||
| 189 | Does nothing if the array is not supplied. | ||||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | =cut | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 2 | ▶ | sub configure { | ||||||||||||||||||
|
Subroutine
configure: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 194 | 2 | my $self = shift; | |||||||||||||||||||
| 195 | 2 | $self->SUPER::configure(@_); | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | =back | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =begin __PRIVATE_METHODS__ | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | =head2 Private methods | ||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | These methods are for internal use only. | ||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | =over 4 | ||||||||||||||||||||
| 207 | |||||||||||||||||||||
| 208 | =item B<_default_urn> | ||||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | The default URN for the hostname. Must be specified in a sub-class. | ||||||||||||||||||||
| 211 | |||||||||||||||||||||
| 212 | $host = $q->_default_urn(); | ||||||||||||||||||||
| 213 | |||||||||||||||||||||
| 214 | =cut | ||||||||||||||||||||
| 215 | |||||||||||||||||||||
| 216 | 0 | ▶ | sub _default_urn { | ||||||||||||||||||
|
Subroutine
_default_urn: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 217 | 0 | croak "default URN must be specified in subclass\n"; | |||||||||||||||||||
| 218 | } | ||||||||||||||||||||
| 219 | |||||||||||||||||||||
| 220 | =item B<_default_endpoint> | ||||||||||||||||||||
| 221 | |||||||||||||||||||||
| 222 | The default endpoint. Must be specified in a sub-class. | ||||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | $host = $q->_default_endpoint(); | ||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | =cut | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | 0 | ▶ | sub _default_endpoint { | ||||||||||||||||||
|
Subroutine
_default_endpoint: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 229 | 0 | croak "default endpoint must be specified in subclass\n"; | |||||||||||||||||||
| 230 | } | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | =item B<_is_service> | ||||||||||||||||||||
| 233 | |||||||||||||||||||||
| 234 | Whether the webservice uses a URN and $endpoint, or is | ||||||||||||||||||||
| 235 | a service specified by a WSDL file | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | $bool = $q->_is_service(); | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | =back | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | =cut | ||||||||||||||||||||
| 242 | |||||||||||||||||||||
| 243 | 0 | ▶ | sub _is_service { | ||||||||||||||||||
|
Subroutine
_is_service: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 244 | 0 | croak "decision must be made by subclass\n"; | |||||||||||||||||||
| 245 | } | ||||||||||||||||||||
| 246 | |||||||||||||||||||||
| 247 | 3 | 1; | |||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | __END__ | ||||||||||||||||||||