File Coverage

blib/lib/Math/Business/HMA.pm
Criterion Covered Total %
statement 32 34 94.1
branch 5 8 62.5
condition 2 3 66.6
subroutine 8 10 80.0
pod 0 6 0.0
total 47 61 77.0


line stmt bran cond sub pod time code
1             package Math::Business::HMA;
2              
3 1     1   5037 use strict;
  1         9  
  1         23  
4 1     1   4 use warnings;
  1         2  
  1         19  
5 1     1   4 use Carp;
  1         1  
  1         40  
6 1     1   335 use Math::Business::WMA;
  1         5  
  1         313  
7              
8             1;
9              
10 0     0 0 0 sub tag { (shift)->[-1] }
11              
12 0     0 0 0 sub recommended { croak "no recommendation" }
13              
14             sub new {
15 1     1 0 124 my $class = shift;
16 1         3 my $this = bless [
17             undef,
18             undef,
19             undef,
20             undef
21             ], $class;
22              
23 1         3 my $days = shift;
24 1 50       3 if( defined $days ) {
25 1         6 $this->set_days( $days );
26             }
27              
28 1         4 return $this;
29             }
30              
31             sub set_days {
32 1     1 0 3 my $this = shift;
33 1         1 my $arg = int(shift);
34              
35 1 50       4 croak "days must be a positive number" if $arg <= 0;
36              
37 1         8 @$this = (
38             Math::Business::WMA->new(int($arg/2)),
39             Math::Business::WMA->new($arg),
40             Math::Business::WMA->new(int(sqrt($arg))),
41              
42             "HMA($arg)", # tag must be last
43             );
44             }
45              
46             sub insert {
47 265     265 0 18510 my $this = shift;
48 265         707 my ($po2, $p, $sqp) = @$this;
49              
50 265 50       717 croak "You must set the number of days before you try to insert" unless defined $sqp;
51 265         747 while( defined(my $P = shift) ) {
52 265         957 $po2->insert($P);
53 265         947 $p->insert($P);
54              
55 265 100 66     1112 if( defined( my $_p = $p->query ) and defined( my $_po2 = $po2->query ) ) {
56 252         884 $sqp->insert( 2*$_po2 - $_p );
57             }
58             }
59             }
60              
61             sub query {
62 265     265 0 1132 my $this = shift;
63              
64 265         790 return $this->[2]->query;
65             }
66              
67             __END__