File Coverage

blib/lib/Statistics/Basic/_TwoVectorBase.pm
Criterion Covered Total %
statement 66 66 100.0
branch 16 28 57.1
condition n/a
subroutine 17 17 100.0
pod 6 6 100.0
total 105 117 89.7


line stmt bran cond sub pod time code
1             package Statistics::Basic::_TwoVectorBase;
2              
3 33     33   200 use strict;
  33         69  
  33         1229  
4 33     33   166 use warnings;
  33         55  
  33         886  
5 33     33   150 use Carp;
  33         47  
  33         1919  
6              
7 33     33   173 use Statistics::Basic; # make sure all the basic classes are loaded
  33         59  
  33         323  
8              
9             use overload
10 11 50   11   891 '""' => sub { defined( my $v = $_[0]->query ) || return "n/a"; $Statistics::Basic::fmt->format_number("$v", $Statistics::Basic::IPRES) },
  11         118  
11 10     10   48 '0+' => sub { $_[0]->query },
12 11     11   5773 ( defined($Statistics::Basic::TOLER) ? ('==' => sub { abs($_[0]-$_[1])<=$Statistics::Basic::TOLER }) : () ),
13 4     4   203 'eq' => sub { "$_[0]" eq "$_[1]" },
14 52     52   169 'bool' => sub { 1 },
15 33 100   33   214 fallback => 1; # tries to do what it would have done if this wasn't present.
  33         59  
  33         689  
16              
17             # query {{{
18             sub query {
19 48     48 1 141 my $this = shift;
20              
21 48 100       232 $this->_recalc if $this->{recalc_needed};
22              
23 48 50       103 warn "[query " . ref($this) . " $this->{_value}]\n" if $Statistics::Basic::DEBUG;
24              
25 48         230 return $this->{_value};
26             }
27             # }}}
28             # query_size {{{
29             sub query_size {
30 18     18 1 28 my $this = shift;
31              
32 18         17 my @v = @{$this->{_vectors}};
  18         54  
33 18         66 return ($v[0]->query_size, $v[1]->query_size); # list rather than map{} so this can be a scalar
34             }
35              
36             # maybe deprecate this later
37             *size = \&query_size unless $ENV{TEST_AUTHOR};
38              
39             # }}}
40             # set_size {{{
41             sub set_size {
42 1     1 1 3 my $this = shift;
43 1         8 my $size = shift;
44 1         2 my $nofl = shift;
45              
46 1 50       2 eval { $_->set_size($size, $nofl) for @{$this->{_vectors}}; 1 } or croak $@;
  1         2  
  1         11  
  1         6  
47              
48 1         3 return $this;
49             }
50             # }}}
51             # insert {{{
52             sub insert {
53 6     6 1 585 my $this = shift;
54              
55 6 50       21 warn "[insert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
56              
57 6 50       21 croak ref($this) . "-insert() takes precisely two arguments. They can be arrayrefs if you like." unless 2 == int @_;
58              
59 6         18 my $c = 0;
60 6         10 $_->insert( $_[$c++] ) for @{$this->{_vectors}};
  6         57  
61              
62 6         16 return $this;
63             }
64             # }}}
65             # ginsert {{{
66             sub ginsert {
67 12     12 1 94 my $this = shift;
68              
69 12 50       36 warn "[ginsert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
70              
71 12 50       32 croak "" . ref($this) . "-ginsert() takes precisely two arguments. They can be arrayrefs if you like."
72             unless 2 == int @_;
73              
74 12         17 my $c = 0;
75 12         12 $_->ginsert( $_[$c++] ) for @{$this->{_vectors}};
  12         71  
76              
77 12         28 my @s = $this->query_size;
78 12 50       33 croak "Uneven ginsert detected, the two vectors in a " . ref($this) . " object must remain the same length."
79             unless $s[0] == $s[1];
80              
81 12         27 return $this;
82             }
83             *append = \&ginsert;
84             # }}}
85             # set_vector {{{
86             sub set_vector {
87 6     6 1 29 my $this = shift;
88              
89 6 50       22 warn "[set_vector " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
90              
91 6 50       26 croak "this set_vector() takes precisely two arguments. They can be arrayrefs if you like."
92             unless 2 == int @_;
93              
94 6         13 my $c = 0;
95 6         12 $_->set_vector( $_[$c++] ) for @{$this->{_vectors}};
  6         57  
96              
97 6         43 my @s = $this->query_size;
98 6 50       23 croak "Uneven set_vector detected, the two vectors in a " . ref($this) . " object must remain the same length."
99             unless $s[0] == $s[1];
100              
101 6         17 return $this;
102             }
103             # }}}
104             # _recalc_needed {{{
105             sub _recalc_needed {
106 156     156   174 my $this = shift;
107 156         216 $this->{recalc_needed} = 1;
108              
109 156 50       281 warn "[recalc_needed " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
110              
111 156         469 return;
112             }
113             # }}}
114              
115             1;