File Coverage

blib/lib/Astro/Catalog/Transport/WebService.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 16 16 100.0


line stmt bran cond sub pod time code
1             package Astro::Catalog::Transport::WebService;
2              
3             =head1 NAME
4              
5             Astro::Catalog::Transport::WebService - A base class for WebService querys
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 distribution (eg C).
15              
16             =cut
17              
18             # L O A D M O D U L E S --------------------------------------------------
19              
20 3     3   7063020 use 5.006;
  3         17  
  3         147  
21 3     3   17 use strict;
  3         12  
  3         294  
22 3     3   78 use warnings;
  3         23  
  3         180  
23 3     3   14 use base qw/ Astro::Catalog::Query /;
  3         6  
  3         5112  
24             use vars qw/ $VERSION /;
25              
26             use SOAP::Lite;
27             use Net::Domain qw(hostname hostdomain);
28             use File::Spec;
29             use Carp;
30              
31             # generic catalog objects
32             use Astro::Catalog;
33             use Astro::Catalog::Star;
34              
35             $VERSION = "4.31";
36              
37             =head1 REVISION
38              
39             $Id: WebService.pm,v 1.4 2003/08/03 06:18:35 timj Exp $
40              
41             =head1 METHODS
42              
43             =head2 Constructor
44              
45             =over 4
46              
47             =item B
48              
49             Create a new instance from a hash of options
50              
51             $q = new Astro::Catalog::Transport::WebService(
52             Coords => new Astro::Coords(),
53             Radius => $radius,
54             Bright => $magbright,
55             Faint => $magfaint,
56             Sort => $sort_type,
57             Number => $number_out );
58              
59             returns a reference to an query object. Must only called from
60             sub-classed constructors.
61              
62             RA and Dec are also allowed but are deprecated (since with only
63             RA/Dec the coordinates must always be supplied as J2000 space-separated
64             sexagesimal format).
65              
66             =cut
67              
68             sub new {
69             my $proto = shift;
70             my $class = ref($proto) || $proto;
71              
72             # bless the query hash into the class
73             my $block = bless { OPTIONS => {},
74             COORDS => undef,
75             URN => undef,
76             ENDPOINT => undef,
77             SERVICE => undef,
78             QUERY => undef,
79             BUFFER => undef }, $class;
80              
81             # Configure the object [even if there are no args]
82             $block->configure( @_ );
83              
84             return $block;
85              
86             }
87              
88             =item B
89              
90             Unlike C a default C method is not
91             provided by this base class, each sub-class must provide its own
92             implemetation.
93              
94             =cut
95              
96             sub querydb {
97             croak "querydb() must be provided by the subclass\n";
98             }
99              
100             =item B
101              
102             Return (or set) the current proxy for the catalog request.
103              
104             $usno->proxy( 'http://wwwcache.ex.ac.uk:8080/' );
105             $proxy_url = $usno->proxy();
106              
107             =cut
108              
109             sub proxy {
110             my $self = shift;
111              
112             # SOAP::Lite respects the HTTP_proxy environment variable
113              
114             if (@_) {
115             my $proxy_url = shift;
116             $ENV{HTTP_proxy} = $proxy_url;
117             $ENV{HTTP_PROXY} = $proxy_url;
118             }
119              
120             # return the current proxy
121             return $ENV{HTTP_proxy};
122              
123             }
124              
125             =item B
126              
127             Return the current remote urn for the query
128              
129             $host = $q->urn();
130              
131             Can also be used to set the urn.
132              
133             =cut
134              
135             sub urn {
136             my $self = shift;
137              
138             # SETTING URL
139             if (@_) {
140              
141             # set the url option
142             my $urn = shift;
143             $self->{URN} = $urn;
144             }
145              
146             return $self->{URN};
147              
148             }
149              
150             =item B
151              
152             Return the current endpoint for the query
153              
154             $host = $q->endpoint();
155             $q->endpoint( 'http://www.blah.org:8080' ););
156              
157             Can also be used to set the endpoint. If the endpoint is a wsdl file
158             the SOAP::Lite object will automagically be configured to use the
159             correct URN, e.g.
160              
161             $q->endpoint( 'http://cdsws.u-strasbg.fr/axis/Sesame.jws?wsdl' );
162              
163             =cut
164              
165             sub endpoint {
166             my $self = shift;
167              
168             # SETTING ENDPOINT
169             if (@_) {
170              
171             # set the url option
172             my $endpoint = shift;
173              
174             if( $endpoint =~ /wsdl$/ ) {
175             $self->{SERVICE} = 1;
176             }
177             $self->{ENDPOINT} = $endpoint;
178              
179             }
180              
181             if ( defined $self->{ENDPOINT} ) {
182             return $self->{ENDPOINT};
183             } else {
184             return $self->_default_endpoint();
185             }
186              
187             }
188              
189             =back
190              
191             =head2 General Methods
192              
193             =over 4
194              
195             =item B
196              
197             Configures the object, takes an options hash as an argument
198              
199             $q->configure( %options );
200              
201             Does nothing if the array is not supplied.
202              
203             =cut
204              
205             sub configure {
206             my $self = shift;
207             $self->SUPER::configure( @_ );
208             }
209              
210             # T I M E A T T H E B A R --------------------------------------------
211              
212             =back
213              
214             =begin __PRIVATE_METHODS__
215              
216             =head2 Private methods
217              
218             These methods are for internal use only.
219              
220             =over 4
221              
222             =item B<_default_urn>
223              
224             The default URN for the hostname. Must be specified in a sub-class.
225              
226             $host = $q->_default_urn();
227              
228             =cut
229              
230             sub _default_urn {
231             croak "default URN must be specified in subclass\n";
232             }
233              
234             =item B<_default_endpoint>
235              
236             The default endpoint. Must be specified in a sub-class.
237              
238             $host = $q->_default_endpoint();
239              
240             =cut
241              
242             sub _default_endpoint {
243             croak "default endpoint must be specified in subclass\n";
244             }
245              
246             =item B<_is_service>
247              
248             Whether the webservice uses a URN and $endpoint, or is
249             a service specified by a WSDL file
250              
251             $bool = $q->_is_service();
252              
253             =cut
254              
255             sub _is_service {
256             croak "decision must be made by subclass\n";
257             }
258              
259              
260             =head1 COPYRIGHT
261              
262             Copyright (C) 2001 University of Exeter. All Rights Reserved.
263             Some modifications copyright (C) 2003 Particle Physics and Astronomy
264             Research Council. All Rights Reserved.
265              
266             This program was written as part of the eSTAR project and is free software;
267             you can redistribute it and/or modify it under the terms of the GNU Public
268             License.
269              
270             =head1 AUTHORS
271              
272             Alasdair Allan Eaa@astro.ex.ac.ukE,
273             Tim Jenness Etjenness@cpan.orgE
274              
275             =cut
276              
277             # L A S T O R D E R S ------------------------------------------------------
278              
279             1;