File Coverage

blib/lib/SETI/Drake.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 2 100.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 2 2 100.0
total 31 33 93.9


line stmt bran cond sub pod time code
1             # $Id: Drake.pm 868 2008-04-20 07:24:28Z gene $
2              
3             package SETI::Drake;
4             $VERSION = 0.0201;
5 1     1   769 use strict;
  1         2  
  1         33  
6 1     1   6 use warnings;
  1         2  
  1         256  
7              
8             sub new {
9 5     5 1 769 my $class = shift;
10 5   33     23 my $proto = ref $class || $class;
11 5         39 my $self = {
12             defaults => {
13             R => 5,
14             fp => 0.5,
15             ne => 2,
16             fl => 1,
17             fi => 0.2,
18             fc => 1,
19             L => 10000,
20             },
21             @_
22             };
23 5         11 bless $self, $class;
24 5         8 $self->_init();
25 5         17 return $self;
26             }
27              
28             sub _init {
29 5     5   6 my $self = shift;
30 5         5 for( keys %{$self->{defaults}} ) {
  5         22  
31             # Make sure each equation term has a defined value.
32 35 100       76 $self->{$_} = $self->{defaults}{$_}
33             unless defined $self->{$_};
34             }
35             }
36              
37             sub N {
38 5     5 1 475 my $self = shift;
39             # Set N to the value of R.
40 5         6 my $N = $self->{R};
41             # Calculate the repeated product of every value of the object except R and the defaults.
42 5         15 $N *= $self->{$_} for grep { !/^R|defaults$/o } keys %$self;
  40         124  
43 5         25 return $N;
44             }
45              
46             1;
47              
48             __END__