File Coverage

blib/lib/Astro/SIMBAD/Result/Object.pm
Criterion Covered Total %
statement 56 93 60.2
branch 21 40 52.5
condition 1 3 33.3
subroutine 12 20 60.0
pod 18 18 100.0
total 108 174 62.0


line stmt bran cond sub pod time code
1             package Astro::SIMBAD::Result::Object;
2              
3             # ---------------------------------------------------------------------------
4              
5             #+
6             # Name:
7             # Astro::SIMBAD::Result:Object
8              
9             # Purposes:
10             # Perl wrapper for the SIMBAD database
11              
12             # Language:
13             # Perl module
14              
15             # Description:
16             # This module wraps the SIMBAD online database.
17              
18             # Authors:
19             # Alasdair Allan (aa@astro.ex.ac.uk)
20              
21             # Revision:
22             # $Id: Object.pm,v 1.3 2005/06/08 01:38:17 aa Exp $
23              
24             # Copyright:
25             # Copyright (C) 2001 University of Exeter. All Rights Reserved.
26              
27             #-
28              
29             # ---------------------------------------------------------------------------
30              
31             =head1 NAME
32              
33             Astro::SIMBAD::Result::Object - A individual astronomical object
34              
35             =head1 SYNOPSIS
36              
37             $object = new Astro::SIMBAD::Result::Object( Name => $object_name,
38             Type => $object_type,
39             Long => $long_type,
40             Frame => \@coord_frame,
41             RA => $ra,
42             Dec => $declination,
43             Spec => $spectral_type,
44             URL => $url );
45              
46             =head1 DESCRIPTION
47              
48             Stores meta-data about an individual astronomical object in the
49             Astro::SIMBAD::Result object returned by an Astro::SIMBAD::Query object.
50              
51             =cut
52              
53             # L O A D M O D U L E S --------------------------------------------------
54              
55 3     3   8565 use strict;
  3         6  
  3         204  
56 3     3   17 use vars qw/ $VERSION /;
  3         5  
  3         4277  
57              
58             '$Revision: 1.3 $ ' =~ /.*:\s(.*)\s\$/ && ($VERSION = $1);
59              
60             # C O N S T R U C T O R ----------------------------------------------------
61              
62             =head1 REVISION
63              
64             $Id: Object.pm,v 1.3 2005/06/08 01:38:17 aa Exp $
65              
66             =head1 METHODS
67              
68             =head2 Constructor
69              
70             =over 4
71              
72             =item B
73              
74             Create a new instance from a hash of options
75              
76             $paper = new Astro::SIMBAD::Result::Object( );
77              
78             returns a reference to an SIMBAD astronomical object.
79              
80             =cut
81              
82             sub new {
83 6     6 1 628 my $proto = shift;
84 6   33     38 my $class = ref($proto) || $proto;
85              
86             # bless the query hash into the class
87 6         93 my $block = bless { NAME => undef,
88             TARGET => undef,
89             TYPE => undef,
90             LONG => undef,
91             FRAME => [],
92             RA => undef,
93             DEC => undef,
94             SPEC => undef,
95             URL => undef,
96             BMAG => undef,
97             VMAG => undef,
98             IDENT => [],
99             PM => [],
100             PLX => undef,
101             RADIAL => undef,
102             REDSHIFT=> undef,
103             }, $class;
104              
105             # If we have arguments configure the object
106 6 50       38 $block->configure( @_ ) if @_;
107              
108 6         18 return $block;
109              
110             }
111              
112             # A C C E S S O R --------------------------------------------------------
113              
114             =back
115              
116             =head2 Accessor Methods
117              
118             =over 4
119              
120             =item B
121              
122             Return (or set) the name of the object
123              
124             $name = $object->name();
125             $object->name( $name );
126              
127             Query types: list, object
128              
129             =cut
130              
131             sub name {
132 12     12 1 23 my $self = shift;
133 12 100       34 if (@_) {
134 6         20 $self->{NAME} = shift;
135             }
136 12         39 return $self->{NAME};
137             }
138              
139             =item B
140              
141             Return (or set) the target name of the object. Available whenever a target is
142             specified in the query. The returned value is identical to the query parameter,
143             except that it is normalized (spaces replaced with '+' characters).
144             This is useful because name() may return a different designation than the
145             target that is supplied as a query parameter.
146              
147             $target = $object->target();
148             $object->target( $target );
149              
150             Query types: list, object
151              
152             =cut
153              
154             sub target {
155 0     0 1 0 my $self = shift;
156 0 0       0 if (@_) {
157 0         0 $self->{TARGET} = shift;
158             }
159 0         0 return $self->{TARGET};
160             }
161              
162             =item B
163              
164             Return (or set) the (short) type of the object
165              
166             $type = $object->type();
167             $object->type( $type );
168              
169             Query types: list
170              
171             =cut
172              
173             sub type {
174 9     9 1 15 my $self = shift;
175 9 100       25 if (@_) {
176 6         14 $self->{TYPE} = shift;
177             }
178 9         24 return $self->{TYPE};
179             }
180              
181             =item B
182              
183             Return (or set) the (long) type of the object
184              
185             $long_type = $object->long();
186             $object->long( $long_type );
187              
188             Query types: list, object
189              
190             =cut
191              
192             sub long {
193 9     9 1 14 my $self = shift;
194 9 100       25 if (@_) {
195 6         13 $self->{LONG} = shift;
196             }
197 9         22 return $self->{LONG};
198             }
199              
200             =item B
201              
202             Return (or set) the system the R.A. and DEC stored in the object are
203             defined in, e.g. Co-ordinate Frame FK5, Epoch 1950 and Equinox 2000
204              
205             @system = $object->frame();
206             $object->frame( \@system );
207              
208             where @system would be [ "FK5", 1950.0, 2000.0 ]. If called in a scalar
209             context will return a string of the form "FK5 1950/2000" to
210              
211             Query types: list, object
212              
213             =cut
214              
215             sub frame {
216 9     9 1 11 my $self = shift;
217              
218 9 100       36 if (@_) {
219             # take a local copy to avoid "copy of copy" problems
220 6         10 my $frame = shift;
221 6         18 @{$self->{FRAME}} = @{$frame};
  6         19  
  6         11  
222             }
223            
224 9         14 my $stringify =
225 9         28 "${$self->{FRAME}}[0] ${$self->{FRAME}}[1]/${$self->{FRAME}}[2]";
  9         69  
  9         37  
226            
227 9 50       35 return wantarray ? @{$self->{FRAME}} : $stringify;
  0         0  
228             }
229              
230             =item B
231              
232             Return (or set) the R.A. of the object
233              
234             $ra = $object->ra();
235             $object->ra( $ra );
236              
237             Query types: list, object
238              
239             =cut
240              
241             sub ra {
242 9     9 1 15 my $self = shift;
243 9 100       22 if (@_) {
244 6         11 $self->{RA} = shift;
245             }
246 9         31 return $self->{RA};
247             }
248              
249             =item B
250              
251             Return (or set) the Declination of the object
252              
253             $dec = $object->dec();
254             $object->dec( $dec );
255              
256             Query types: list, object
257              
258             =cut
259              
260             sub dec {
261 9     9 1 14 my $self = shift;
262 9 100       24 if (@_) {
263 6         30 $self->{DEC} = shift;
264             }
265 9         25 return $self->{DEC};
266             }
267              
268             =item B
269              
270             Return (or set) the Spectral Type of the object
271              
272             $spec_type = $object->spec();
273             $object->spec( $spec_type );
274              
275             Query types: list, object
276              
277             =cut
278              
279             sub spec {
280 9     9 1 14 my $self = shift;
281 9 100       26 if (@_) {
282 6         15 $self->{SPEC} = shift;
283             }
284 9         29 return $self->{SPEC};
285             }
286              
287             =item B
288              
289             Return (or set) the followup URL for the object where more information
290             can be found via SIMBAD, including pointers to reduced data.
291              
292             $url = $object->url();
293             $object->url( $url );
294              
295             =cut
296              
297             sub url {
298 6     6 1 8 my $self = shift;
299 6 100       24 if (@_) {
300 3         5 $self->{URL} = shift;
301             }
302 6         27 return $self->{URL};
303             }
304              
305             =item B
306              
307             Return (or set) the B-magnitude of the object
308              
309             $bmag = $object->bmag();
310             $object->bmag( $bmag );
311              
312             Query types: list, object
313              
314             =cut
315              
316             sub bmag {
317 0     0 1 0 my $self = shift;
318 0 0       0 if (@_) {
319 0         0 $self->{BMAG} = shift;
320             }
321 0         0 return $self->{BMAG};
322             }
323              
324             =item B
325              
326             Return (or set) the V-magnitude of the object
327              
328             $vmag = $object->vmag();
329             $object->vmag( $vmag );
330              
331             Query types: list, object
332              
333             =cut
334              
335             sub vmag {
336 0     0 1 0 my $self = shift;
337 0 0       0 if (@_) {
338 0         0 $self->{VMAG} = shift;
339             }
340 0         0 return $self->{VMAG};
341             }
342              
343             =item B
344              
345             Return (or append) the array of object identifiers
346              
347             @ident = $object->ident();
348             $object->ident( @ident );
349              
350             Query types: object
351              
352             =cut
353              
354             sub ident {
355 0     0 1 0 my $self = shift;
356 0 0       0 if (@_) {
357 0         0 my $idarray = shift;
358 0         0 @{$self->{IDENT}} = @{$idarray};
  0         0  
  0         0  
359             }
360 0         0 return $self->{IDENT};
361             }
362              
363             =item B
364              
365             Return (or set) the proper motion of the object in mas/year
366              
367             @pm = $object->pm();
368             $object->pm( @pm );
369              
370             Query types: object
371              
372             =cut
373              
374             sub pm {
375 0     0 1 0 my $self = shift;
376 0 0       0 if (@_) {
377 0         0 push @{$self->{PM}}, @_[0..1];
  0         0  
378             }
379 0         0 return $self->{PM};
380             }
381              
382             =item B
383              
384             Return (or set) the parallax of the object
385              
386             $plx = $object->plx();
387             $object->plx( $plx );
388              
389             Query types: object
390              
391             =cut
392              
393             sub plx {
394 0     0 1 0 my $self = shift;
395 0 0       0 if (@_) {
396 0         0 $self->{PLX} = shift;
397             }
398 0         0 return $self->{PLX};
399             }
400              
401             =item B
402              
403             Return (or set) the radial velocity (km/s) of the object
404              
405             $radial = $object->radial();
406             $object->radial( $radial );
407              
408             Query types: object
409              
410             =cut
411              
412             sub radial {
413 0     0 1 0 my $self = shift;
414 0 0       0 if (@_) {
415 0         0 $self->{RADIAL} = shift;
416             }
417 0         0 return $self->{RADIAL};
418             }
419              
420             =item B
421              
422             Return (or set) the redshift of the object
423              
424             $redshift = $object->redshift();
425             $object->redshift( $redshift );
426              
427             Query types: object
428              
429             =cut
430              
431             sub redshift {
432 0     0 1 0 my $self = shift;
433 0 0       0 if (@_) {
434 0         0 $self->{REDSHIFT} = shift;
435             }
436 0         0 return $self->{REDSHIFT};
437             }
438              
439             # C O N F I G U R E -------------------------------------------------------
440              
441             =back
442              
443             =head2 General Methods
444              
445             =over 4
446              
447             =item B
448              
449             Configures the object from multiple pieces of information.
450              
451             $object->configure( %options );
452              
453             Takes a hash as argument with the following keywords:
454              
455             =cut
456              
457             sub configure {
458 6     6 1 10 my $self = shift;
459              
460             # return unless we have arguments
461 6 50       18 return undef unless @_;
462              
463             # grab the argument list
464 6         47 my %args = @_;
465              
466             # Loop over the allowed keys storing the values
467             # in the object if they exist
468 6         14 for my $key (qw / Name Type Long Frame RA Dec Spec URL /) {
469 48         72 my $method = lc($key);
470 48 100       196 $self->$method( $args{$key} ) if exists $args{$key};
471             }
472              
473             }
474              
475              
476             # T I M E A T T H E B A R --------------------------------------------
477              
478             =back
479              
480             =head1 COPYRIGHT
481              
482             Copyright (C) 2001 University of Exeter. All Rights Reserved.
483              
484             This program was written as part of the eSTAR project and is free software;
485             you can redistribute it and/or modify it under the terms of the GNU Public
486             License.
487              
488              
489             =head1 AUTHORS
490              
491             Alasdair Allan Eaa@astro.ex.ac.ukE,
492              
493             =cut
494              
495             # L A S T O R D E R S ------------------------------------------------------
496              
497             1;