SIMBAD/Result.pm

filter: Statementstmt 88.5% 54 / 61 Branchbran 55.5% 10 / 18 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.0% 9 / 10 Podpod 100% 7 / 7 totaltotal 80.2% 81 / 101 CC 14 SCAR 12.3
CC
14
Cov
79%
objects
6.0
configure
5.1
new
3.2
CRAP 3.4
« SIMBAD/Result/Object.pm ↑ Summary SIMBAD.pm »
1 package Astro::SIMBAD::Result;
2  
3 # ---------------------------------------------------------------------------
4  
5 #+
6 # Name:
7 # Astro::SIMBAD::Result
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: Result.pm,v 1.3 2001/11/28 17:43:34 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 - Results from an SIMBAD Query
34  
35 =head1 SYNOPSIS
36  
37 $result = new Astro::SIMBAD::Result( Objects => \@objects );
38  
39 =head1 DESCRIPTION
40  
41 Stores the results returned from an SIMBAD search as a hash of
42 Astro::SIMBAD::Result::Object objects with the objects being
43 indexed by Object Name.
44  
45 =cut
46  
47 # L O A D M O D U L E S --------------------------------------------------
48  
49 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 2 ▶use vars qw/ $VERSION /;
Subroutine BEGIN: called CC=1 SCAR=0.0
51  
52 2 ▶use Astro::SIMBAD::Result::Object;
Subroutine BEGIN: called CC=1 SCAR=0.0
53  
54 2 ▶'$Revision: 1.3 $ ' =~ /.*:\s(.*)\s\$/ && ($VERSION = $1);
Branch: 1 branch
BranchTrueFalseTotal
"\$Revision: 1.3 \$ " =~ /.*:\s(.*)\s\$/ and $Astro::SIMBAD::Result::VERSION = $1 2 0 2
55  
56 # C O N S T R U C T O R ----------------------------------------------------
57  
58 =head1 REVISION
59  
60 $Id: Result.pm,v 1.3 2001/11/28 17:43:34 aa Exp $
61  
62 =head1 METHODS
63  
64 =head2 Constructor
65  
66 =over 4
67  
68 =item B<new>
69  
70 Create a new instance from a hash of options
71  
72 $result = new Astro::SIMBAD::Result( Objects => \@objects );
73  
74 returns a reference to an SIMBAD Result object.
75  
76 =cut
77  
78 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.8
Pod documented
79 1 my $proto = shift;
80 1 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
81  
82 # bless the query hash into the class
83 1 my $block = bless { RESULTS => {},
84 SIZE => 0 }, $class;
85  
86 # If we have arguments configure the object
87 1 ▶ $block->configure( @_ ) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 0 1
88  
89 1 return $block;
90  
91 }
92  
93 # A C C E S S O R --------------------------------------------------------
94  
95 =back
96  
97 =head2 Accessor Methods
98  
99 =over 4
100  
101 =item B<sizeof>
102  
103 Return the number of objects in the Astro::SIMBAD::Result object.
104  
105 $num = $result->sizeof();
106  
107 =cut
108  
109 2 ▶sub sizeof {
Subroutine sizeof: called CC=1 SCAR=0.0
Pod documented
110 2 my $self = shift;
111 2 return $self->{SIZE};
112 }
113  
114 =item B<addobject>
115  
116 Push a new Astro::SIMBAD::Result::Object object onto the end of the
117 Astro::SIMBAD::Result object
118  
119 $result->addobject( $object );
120  
121 returns the number of objects now in the Result object.
122  
123 =cut
124  
125 1 ▶sub addobject {
Subroutine addobject: called CC=3 SCAR=11.1
Pod documented
126 1 my $self = shift;
127  
128 # return unless we have arguments
129 1 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
130
131 # grab the object reference
132 1 my $new_object = shift;
133
134 # increment the sizeof counter
135 1 $self->{SIZE} = $self->{SIZE} + 1;
136
137 # get the object name as a key for $self->{RESULTS} hash
138 1 my $object_name = $new_object->name();
139 1 ▶ $object_name = "Object " . $self->{SIZE} unless defined $object_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object_name 0 1 1
140 1 ${$self->{RESULTS}}{$object_name} = $new_object;
141
142 1 return $self->{SIZE};
143  
144 }
145  
146 =item B<objects>
147  
148 Return an array of all the C<Astro::SIMBAD::Result::Object> objects
149 stored in the results object.
150  
151 @objects = $result->objects;
152  
153 =cut
154  
155 0 ▶sub objects {
Subroutine objects: not called CC=2 SCAR=17.9
Pod documented
156 0 my $self = shift;
157
158 # build the return array from the Object hash
159 0 my @array;
160 0 for my $key ( keys %{$self->{RESULTS}} ) {
161 0 push ( @array, ${$self->{RESULTS}}{$key} );
162 }
163
164 # return it
165 0 return @array;
166 }
167  
168 =item B<objectbyname>
169  
170 Returns an list of C<Astro::SIMBAD::Result::Object> objects by name
171  
172 @objects = $result->objectbyname("IP Peg");
173  
174 the name given does not have to be a full object name, only a sub-string.
175 However, if multiple matches are found an array of possible matches will be
176 returned.
177  
178 =cut
179  
180 2 ▶sub objectbyname {
Subroutine objectbyname: called CC=3 SCAR=11.0
Pod documented
181 2 my $self = shift;
182
183 2 my $search_string = shift;
184 # build the return array from the Object hash
185 2 my @array;
186 2 for my $key ( keys %{$self->{RESULTS}} ) {
187 6 ▶ push ( @array, ${$self->{RESULTS}}{$key} ) if $key =~ $search_string;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /$search_string/ 3 3 6
188 }
189
190 # return it
191 2 return @array;
192 }
193  
194  
195 =item B<listofobjects>
196  
197 Returns a list of all the stellar objects held in the Result object
198  
199 @object_name = $result->listofobjects();
200 $number = $result->listofobjects();
201  
202 if called in a scalar context it will return the number of objects in
203 the Result object.
204  
205 =cut
206  
207 1 ▶sub listofobjects{
Subroutine listofobjects: called CC=3 SCAR=11.0
Pod documented
208 1 my $self = shift;
209
210 1 my @list;
211 1 for my $key ( sort keys %{$self->{RESULTS}} ) {
212 3 push ( @list, $key);
213 }
214
215 1 ▶ return wantarray ? @list : scalar(@list);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
216  
217 }
218  
219 # C O N F I G U R E -------------------------------------------------------
220  
221 =back
222  
223 =head2 General Methods
224  
225 =over 4
226  
227 =item B<configure>
228  
229 Configures the object, takes an options hash as argument
230  
231 $result->configure( %options );
232  
233 Takes a hash as argument with the following keywords:
234  
235 =cut
236  
237 1 ▶sub configure {
Subroutine configure: called CC=5 SCAR=16.3
Pod documented
238 1 my $self = shift;
239  
240 # return unless we have arguments
241 1 ▶ return undef unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 1 1
242  
243 # grab the argument list
244 1 my %args = @_;
245  
246 1 ▶ if (defined $args{Objects}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"Objects"}) 1 0 1
247  
248 # Go through each of the supplied stellar object and add it
249 1 for my $i ( 0 ...$#{$args{Objects}} ) {
250
251 # increment the hash counter
252 2 $self->{SIZE} = $self->{SIZE} + 1;
253
254 # extract the object name and index by it
255 2 my $object_name = ${$args{Objects}}[$i]->name();
256 2 ▶ $object_name = "Object " . $self->{SIZE} unless defined $object_name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $object_name 0 2 2
257 2 ${$self->{RESULTS}}{$object_name} = ${$args{Objects}}[$i];
258  
259 }
260 }
261  
262 }
263  
264  
265 # T I M E A T T H E B A R --------------------------------------------
266  
267 =back
268  
269 =head1 COPYRIGHT
270  
271 Copyright (C) 2001 University of Exeter. All Rights Reserved.
272  
273 This program was written as part of the eSTAR project and is free software;
274 you can redistribute it and/or modify it under the terms of the GNU Public
275 License.
276  
277 =head1 AUTHORS
278  
279 Alasdair Allan E<lt>aa@astro.ex.ac.ukE<gt>,
280  
281 =cut
282  
283 # L A S T O R D E R S ------------------------------------------------------
284  
285 2 1;
« SIMBAD/Result/Object.pm ↑ Summary SIMBAD.pm »