Basic/_TwoVectorBase.pm

filter: Statementstmt 100% 69 / 69 Branchbran 56.6% 17 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 17 / 17 Podpod 100% 6 / 6 totaltotal 89.3% 109 / 122 CC 19 SCAR 11.2
CC
19
Cov
87%
ginsert
5.2
set_vector
5.2
insert
4.1
CRAP 3.1
« Basic/Mean.pm ↑ Summary Basic.pm »
1 package Statistics::Basic::_TwoVectorBase;
2  
3 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 33 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 33 ▶use Statistics::Basic; # make sure all the basic classes are loaded
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 use overload
10 8 ▶ '""' => sub { defined( my $v = $_[0]->query ) || return "n/a"; $Statistics::Basic::fmt->format_number("$v", $Statistics::Basic::IPRES) },
Subroutine BEGIN: called CC=2 SCAR=6.9
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined(my $v = $_[0]->query) or return "n/a" 8 0 8
11 10 ▶ '0+' => sub { $_[0]->query },
Subroutine __ANON__: called CC=1 SCAR=0.0
12 11 ▶ ( defined($Statistics::Basic::TOLER) ? ('==' => sub { abs($_[0]-$_[1])<=$Statistics::Basic::TOLER }) : () ),
Subroutine __ANON__: called CC=1 SCAR=0.0
13 4 ▶ 'eq' => sub { "$_[0]" eq "$_[1]" },
Subroutine __ANON__: called CC=1 SCAR=0.0
14 24 ▶ 'bool' => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
15 33 ▶ fallback => 1; # tries to do what it would have done if this wasn't present.
Branch: 1 branch
BranchTrueFalseTotal
defined $Statistics::Basic::TOLER ? : 4 29 33
16  
17 # query {{{
18 45 ▶sub query {
Subroutine query: called CC=3 SCAR=11.0
Pod documented
19 45 my $this = shift;
20  
21 45 ▶ $this->_recalc if $this->{recalc_needed};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"recalc_needed"} 43 2 45
22  
23 45 ▶ warn "[query " . ref($this) . " $this->{_value}]\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 45 45
24  
25 45 return $this->{_value};
26 }
27 # }}}
28 # query_size {{{
29 18 ▶sub query_size {
Subroutine query_size: called CC=1 SCAR=0.0
Pod documented
30 18 my $this = shift;
31  
32 18 my @v = @{$this->{_vectors}};
33 18 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 33 ▶*size = \&query_size unless $ENV{TEST_AUTHOR};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{"TEST_AUTHOR"} 33 0 33
38  
39 # }}}
40 # set_size {{{
41 1 ▶sub set_size {
Subroutine set_size: called CC=3 SCAR=11.0
Pod documented
42 1 my $this = shift;
43 1 my $size = shift;
44 1 my $nofl = shift;
45  
46 1 ▶ eval { $_->set_size($size, $nofl) for @{$this->{_vectors}}; 1 } or croak $@;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $_->set_size($size, $nofl) foreach (@{$$this{"_vectors"};}); 1 } } or croak($@) 1 0 1
47  
48 1 return $this;
49 }
50 # }}}
51 # insert {{{
52 6 ▶sub insert {
Subroutine insert: called CC=4 SCAR=14.1
Pod documented
53 6 my $this = shift;
54  
55 6 ▶ warn "[insert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 6 6
56  
57 6 ▶ croak ref($this) . "-insert() takes precisely two arguments. They can be arrayrefs if you like." unless 2 == int @_;
Branch: 1 branch
BranchTrueFalseTotal
unless 2 == int @_ 0 6 6
58  
59 6 my $c = 0;
60 6 $_->insert( $_[$c++] ) for @{$this->{_vectors}};
61  
62 6 return $this;
63 }
64 # }}}
65 # ginsert {{{
66 12 ▶sub ginsert {
Subroutine ginsert: called CC=5 SCAR=16.5
Pod documented
67 12 my $this = shift;
68  
69 12 ▶ warn "[ginsert " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 12 12
70  
71 12 ▶ croak "" . ref($this) . "-ginsert() takes precisely two arguments. They can be arrayrefs if you like."
Branch: 1 branch
BranchTrueFalseTotal
unless 2 == int @_ 0 12 12
72 unless 2 == int @_;
73  
74 12 my $c = 0;
75 12 $_->ginsert( $_[$c++] ) for @{$this->{_vectors}};
76  
77 12 my @s = $this->query_size;
78 12 ▶ croak "Uneven ginsert detected, the two vectors in a " . ref($this) . " object must remain the same length."
Branch: 1 branch
BranchTrueFalseTotal
unless $s[0] == $s[1] 0 12 12
79 unless $s[0] == $s[1];
80  
81 12 return $this;
82 }
83 33 *append = \&ginsert;
84 # }}}
85 # set_vector {{{
86 6 ▶sub set_vector {
Subroutine set_vector: called CC=5 SCAR=16.5
Pod documented
87 6 my $this = shift;
88  
89 6 ▶ warn "[set_vector " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 6 6
90  
91 6 ▶ croak "this set_vector() takes precisely two arguments. They can be arrayrefs if you like."
Branch: 1 branch
BranchTrueFalseTotal
unless 2 == int @_ 0 6 6
92 unless 2 == int @_;
93  
94 6 my $c = 0;
95 6 $_->set_vector( $_[$c++] ) for @{$this->{_vectors}};
96  
97 6 my @s = $this->query_size;
98 6 ▶ croak "Uneven set_vector detected, the two vectors in a " . ref($this) . " object must remain the same length."
Branch: 1 branch
BranchTrueFalseTotal
unless $s[0] == $s[1] 0 6 6
99 unless $s[0] == $s[1];
100  
101 6 return $this;
102 }
103 # }}}
104 # _recalc_needed {{{
105 156 ▶sub _recalc_needed {
Subroutine _recalc_needed: called CC=2 SCAR=7.0
106 156 my $this = shift;
107 156 $this->{recalc_needed} = 1;
108  
109 156 ▶ warn "[recalc_needed " . ref($this) . "]\n" if $Statistics::Basic::DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Statistics::Basic::DEBUG 0 156 156
110  
111 156 return;
112 }
113 # }}}
114  
115 33 1;
« Basic/Mean.pm ↑ Summary Basic.pm »