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             $Statistics::Descriptive::Smoother::VERSION = '3.0801';
3 11     11   222317 use strict;
  11         54  
  11         336  
4 11     11   77 use warnings;
  11         37  
  11         408  
5              
6 11     11   70 use Carp qw/ carp /;
  11         23  
  11         4329  
7              
8             ## no critic (ProhibitExplicitReturnUndef)
9              
10             sub instantiate
11             {
12 16     16 1 6459 my ( $class, $args ) = @_;
13              
14 16         72 my $method = delete $args->{method};
15 16   100     90 my $coeff = delete $args->{coeff} || 0;
16 16         41 my $ra_samples = delete $args->{samples};
17 16         32 my $ra_data = delete $args->{data};
18              
19 16 100 100     89 if ( $coeff < 0 || $coeff > 1 )
20             {
21 2         331 carp("Invalid smoothing coefficient C $coeff\n");
22 2         74 return;
23             }
24 14 100       44 if ( @$ra_data < 2 )
25             {
26 1         98 carp("Need at least 2 samples to smooth the data\n");
27 1         30 return;
28             }
29 13         46 $method = ucfirst( lc($method) );
30 13         38 my $sub_class = __PACKAGE__ . "::$method";
31             ## no critic
32 13         792 eval "require $sub_class";
33             ## use critic
34 13 100       72 die "No such class $sub_class: $@" if $@;
35              
36 12         129 return $sub_class->_new(
37             {
38             data => $ra_data,
39             samples => $ra_samples,
40             count => scalar @$ra_data,
41             coeff => $coeff,
42             }
43             );
44             }
45              
46 145     145 1 943 sub get_smoothing_coeff { $_[0]->{coeff} }
47              
48             sub set_smoothing_coeff
49             {
50 2     2 1 12 my ( $self, $coeff ) = @_;
51              
52 2 100 66     13 if ( $coeff < 0 || $coeff > 1 )
53             {
54 1         86 carp("Invalid smoothing coefficient C $coeff\n");
55 1         41 return;
56             }
57              
58 1         3 $self->{coeff} = $coeff;
59 1         2 return 1;
60             }
61              
62             1;
63              
64             __END__