File Coverage

blib/lib/Statistics/Descriptive/Smoother.pm
Criterion Covered Total %
statement 32 32 100.0
branch 8 8 100.0
condition 7 8 87.5
subroutine 6 6 100.0
pod 3 3 100.0
total 56 57 98.2


line stmt bran cond sub pod time code
1             package Statistics::Descriptive::Smoother;
2              
3 12     12   210611 use strict;
  12         57  
  12         338  
4 12     12   61 use warnings;
  12         28  
  12         290  
5              
6 12     12   61 use Carp;
  12         32  
  12         4913  
7              
8             our $VERSION = '3.0702';
9              
10             sub instantiate {
11 16     16 1 7992 my ($class, $args) = @_;
12              
13 16         41 my $method = delete $args->{method};
14 16   100     73 my $coeff = delete $args->{coeff} || 0;
15 16         36 my $ra_samples = delete $args->{samples};
16 16         32 my $ra_data = delete $args->{data};
17              
18 16 100 100     83 if ($coeff < 0 || $coeff > 1) {
19 2         325 carp("Invalid smoothing coefficient C $coeff\n");
20 2         70 return;
21             }
22 14 100       89 if (@$ra_data < 2) {
23 1         138 carp("Need at least 2 samples to smooth the data\n");
24 1         32 return;
25             }
26 13         44 $method = ucfirst(lc($method));
27 13         43 my $sub_class = __PACKAGE__."::$method";
28 13         806 eval "require $sub_class";
29 13 100       73 die "No such class $sub_class: $@" if $@;
30              
31 12         95 return $sub_class->_new({
32             data => $ra_data,
33             samples => $ra_samples,
34             count => scalar @$ra_data,
35             coeff => $coeff,
36             });
37             }
38              
39 145     145 1 1184 sub get_smoothing_coeff { $_[0]->{coeff} }
40              
41             sub set_smoothing_coeff {
42 2     2 1 7 my ($self, $coeff) = @_;
43              
44 2 100 66     15 if ($coeff < 0 || $coeff > 1) {
45 1         88 carp("Invalid smoothing coefficient C $coeff\n");
46 1         69 return;
47             }
48              
49 1         3 $self->{coeff} = $coeff;
50 1         4 return 1;
51             }
52              
53             1;
54              
55             __END__