File Coverage

blib/lib/Statistics/Basic/_OneVectorBase.pm
Criterion Covered Total %
statement 50 51 98.0
branch 12 18 66.6
condition n/a
subroutine 17 18 94.4
pod 7 7 100.0
total 86 94 91.4


line stmt bran cond sub pod time code
1             package Statistics::Basic::_OneVectorBase;
2              
3 33     33   1646 use strict;
  33         45  
  33         1052  
4 33     33   130 use warnings;
  33         40  
  33         713  
5 33     33   130 use Carp;
  33         34  
  33         1612  
6              
7 33     33   529 use Statistics::Basic; # make sure all the basic classes are loaded
  33         34  
  33         251  
8              
9             use overload
10 84 50   84   2875 '""' => sub { defined( my $v = $_[0]->query ) or return "n/a"; $Statistics::Basic::fmt->format_number("$v", $Statistics::Basic::IPRES) },
  84         486  
11 68     68   243 '0+' => sub { $_[0]->query },
12 0     0   0 ( defined($Statistics::Basic::TOLER) ? ('==' => sub { abs($_[0]-$_[1])<=$Statistics::Basic::TOLER }) : () ),
13 34     34   3633 'eq' => sub { "$_[0]" eq "$_[1]" },
14 400     400   853 'bool' => sub { 1 },
15 33 100   33   175 fallback => 1; # tries to do what it would have done if this wasn't present.
  33         48  
  33         404  
16              
17             # _recalc_needed {{{
18             sub _recalc_needed {
19 335     335   418 my $this = shift;
20 335         429 $this->{recalc_needed} = 1;
21              
22 335 100       540 warn "[recalc_needed " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
23              
24 335         1374 return;
25             }
26             # }}}
27             # query {{{
28             sub query {
29 402     402 1 914 my $this = shift;
30              
31 402 100       1094 $this->_recalc if $this->{recalc_needed};
32              
33 402 50       620 warn "[query " . ref($this) . " $this->{_value}]\n" if $Statistics::Basic::DEBUG;
34              
35 402         1047 return $this->{_value};
36             }
37             # }}}
38             # query_vector {{{
39             sub query_vector {
40 43     43 1 1112 my $this = shift;
41              
42 43         130 return $this->{v};
43             }
44             # }}}
45              
46             # query_size {{{
47             sub query_size {
48 4     4 1 12 my $this = shift;
49              
50 4         11 return $this->{v}->query_size;
51             }
52              
53             # maybe deprecate this later
54             *size = \&query_size unless $ENV{TEST_AUTHOR};
55              
56             # }}}
57             # set_size {{{
58             sub set_size {
59 5     5 1 11 my $this = shift;
60 5         10 my $size = shift;
61 5         9 my $nofl = shift;
62              
63 5 50       10 eval { $this->{v}->set_size($size, $nofl) } or croak $@;
  5         34  
64              
65 5         14 return $this;
66             }
67             # }}}
68             # set_vector {{{
69             sub set_vector {
70 10     10 1 43 my $this = shift;
71              
72 10 50       35 warn "[set_vector " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
73              
74 10         37 $this->{v}->set_vector(@_);
75              
76 10         15 return $this;
77             }
78             # }}}
79             # insert {{{
80             sub insert {
81 10     10 1 21 my $this = shift;
82              
83 10 50       35 warn "[insert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
84              
85 10         45 $this->{v}->insert(@_);
86              
87 10         20 return $this;
88             }
89             # }}}
90             # ginsert {{{
91             sub ginsert {
92 7     7 1 13 my $this = shift;
93              
94 7 50       23 warn "[ginsert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
95              
96 7         39 $this->{v}->ginsert(@_);
97              
98 7         15 return $this;
99             }
100              
101             *append = \&ginsert;
102             # }}}
103              
104             1;