File Coverage

blib/lib/Astro/FluxColor.pm
Criterion Covered Total %
statement 51 59 86.4
branch 8 16 50.0
condition 1 3 33.3
subroutine 13 13 100.0
pod 6 6 100.0
total 79 97 81.4


line stmt bran cond sub pod time code
1             package Astro::FluxColor;
2              
3             =head1 NAME
4              
5             Astro::FluxColor - Class for handling astronomical color quantities.
6              
7             =head1 SYNOPSIS
8              
9             use Astro::FluxColor;
10              
11             $color = new Astro::FluxColor( lower => $lower_waveband,
12             upper => $upper_waveband,
13             quantity => $quantity,
14             datetime => new DateTime );
15              
16             $quantity = $color->quantity;
17              
18             =head1 DESCRIPTION
19              
20             Class for handling astronomical color quantities.
21              
22             =cut
23              
24 3     3   11518 use 5.006;
  3         254  
  3         129  
25 3     3   18 use strict;
  3         4  
  3         101  
26 3     3   15 use warnings;
  3         6  
  3         89  
27 3     3   16 use warnings::register;
  3         7  
  3         503  
28 3     3   17 use Carp;
  3         4  
  3         189  
29              
30 3     3   17 use Astro::WaveBand;
  3         418  
  3         100  
31 3     3   994 use Number::Uncertainty;
  3         5038  
  3         2462  
32              
33             our $VERSION = '0.01';
34              
35             =head1 METHODS
36              
37             =head2 Constructor
38              
39             =over 4
40              
41             =item B
42              
43             Create a new instance of an C object.
44              
45             $color = new Astro::FluxColor( lower => $lower_waveband,
46             upper => $upper_waveband,
47             quantity => $quantity,
48             datetime => new DateTime );
49              
50             The three named parameters are mandatory. F and F
51             denote the lower and upper wavebands for the colour, and
52             must be C objects. F is a numerical
53             value in magnitudes.
54              
55             =cut
56              
57             sub new {
58 9     9 1 1963 my $proto = shift;
59 9   33     47 my $class = ref( $proto ) || $proto;
60              
61 9         38 my %args = @_;
62              
63 9 50       59 if( ! defined( $args{'lower'} ) ) {
    50          
64 0         0 croak "Lower waveband must be defined";
65             } elsif( ! UNIVERSAL::isa( $args{'lower'}, "Astro::WaveBand" ) ) {
66 0         0 $args{'lower'} = new Astro::WaveBand( Filter => $args{'lower'} );
67             }
68              
69 9 50       55 if( ! defined( $args{'upper'} ) ) {
    50          
70 0         0 croak "Upper waveband must be defined";
71             } elsif( ! UNIVERSAL::isa( $args{'upper'}, "Astro::WaveBand" ) ) {
72 0         0 $args{'upper'} = new Astro::WaveBand( Filter => $args{'upper'} );
73             }
74              
75 9         12 my $quantity;
76 9 50       43 if( ! defined( $args{'quantity'} ) ) {
    100          
77 0         0 croak "Color quantity must be defined";
78             } elsif ( ! UNIVERSAL::isa($args{'quantity'}, "Number::Uncertainty" ) ) {
79 5         25 $quantity = new Number::Uncertainty( Value => $args{'quantity'} );
80             } else {
81 4         7 $quantity = $args{'quantity'};
82             }
83 9         211 my $color = {};
84              
85 9         22 $color->{LOWER} = $args{'lower'};
86 9         18 $color->{UPPER} = $args{'upper'};
87 9         14 $color->{QUANTITY} = $quantity;
88            
89 9 50       28 if( defined( $args{'datetime'} ) ) {
90 0 0       0 unless ( UNIVERSAL::isa( $args{'datetime'}, "DateTime" ) ) {
91 0         0 croak "Time stamp must be a DateTime object\n";
92             } else {
93 0         0 $color->{TIME} = $args{'datetime'};
94             }
95             }
96            
97 9         19 bless( $color, $class );
98 9         32 return $color;
99              
100             }
101              
102             =back
103              
104             =head2 Accessor Methods
105              
106             =over 4
107              
108             =item B
109              
110             Returns the actual color value.
111              
112             my $value = $color->quantity;
113              
114             There are no parameters.
115              
116             =cut
117              
118             sub quantity {
119 9     9 1 686 my $self = shift;
120              
121 9         33 my $number = $self->{QUANTITY};
122 9         27 my $value = $number->value();
123 9         67 return $value;
124             }
125              
126             =item B
127              
128             Returns the actual uncertainty in the cerror.
129              
130             my $e = $color->error;
131              
132             There are no parameters.
133              
134             =cut
135              
136             sub error {
137 4     4 1 7 my $self = shift;
138              
139 4         41 my $number = $self->{QUANTITY};
140 4         48 my $error = $number->error();
141 4         82 return $error;
142             }
143              
144             =item B
145              
146             Returns the lower waveband.
147              
148             my $lower = $color->lower;
149              
150             There are no parameters. An C object is returned.
151              
152             =cut
153              
154             sub lower {
155 13     13 1 131 my $self = shift;
156 13         82 return $self->{LOWER};
157             }
158              
159             =item B
160              
161             Returns the upper waveband.
162              
163             my $upper = $color->upper;
164              
165             There are no parameters. An C object is returned.
166              
167             =cut
168              
169             sub upper {
170 12     12 1 786 my $self = shift;
171 12         40 return $self->{UPPER};
172             }
173              
174              
175             =item B
176              
177             Returns the datetime stamp for the given flux object.
178              
179             my $datetime = $flux->datetime;
180              
181             Returns an C object if defined. If not, returns undef.
182              
183             =cut
184              
185             sub datetime {
186 4     4 1 5 my $self = shift;
187              
188 4         16 return $self->{TIME};
189             }
190              
191             =back
192              
193             =head1 REVISION
194              
195             $Id: FluxColor.pm,v 1.6 2005/06/15 01:14:01 allan Exp $
196              
197             =head1 AUTHORS
198              
199             Brad Cavanagh Eb.cavanagh@jach.hawaii.eduE,
200             Alasdair Allan Eaa@astro.ex.ac.ukE
201              
202             =head1 COPYRIGHT
203              
204             Copyright (C) 2004 Particle Physics and Astronomy Research
205             Council. All Rights Reserved.
206              
207             This program is free software; you can redistribute it and/or
208             modify it under the same terms as Perl itself.
209              
210             =cut
211              
212             1;