| 1 | |||||||||||
| 2 | package Statistics::Basic::ComputedVector; | ||||||||||
| 3 | |||||||||||
| 4 | 33 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 33 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 33 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 33 | our $tag_number = 0; | |||||||||
| 9 | |||||||||||
| 10 | 33 | ▶ | use Statistics::Basic; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 33 | ▶ | use base 'Statistics::Basic::Vector'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | # new {{{ | ||||||||||
| 14 | 13 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||
| 15 | 13 | my $class = shift; | |||||||||
| 16 | 13 | ▶ | my $that = eval { Statistics::Basic::Vector->new(@_) } or croak $@; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 17 | 13 | ▶ | croak "input vector must be supplied to ComputedVector" unless defined $that; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 18 | |||||||||||
| 19 | 13 | my $this = bless { tag=>(--$tag_number), c=>{}, input_vector=>$that, output_vector=>Statistics::Basic::Vector->new() }, $class; | |||||||||
| 20 | 13 | $this->_recalc_needed; | |||||||||
| 21 | |||||||||||
| 22 | 13 | return $this; | |||||||||
| 23 | } | ||||||||||
| 24 | # }}} | ||||||||||
| 25 | # copy {{{ | ||||||||||
| 26 | 0 | ▶ | sub copy { | ||||||||
|
Subroutine
copy: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 27 | 0 | my $this = shift; | |||||||||
| 28 | 0 | my $that = __PACKAGE__->new( $this->{input_vector} ); | |||||||||
| 29 | 0 | $that->{computer} = $this->{computer}; | |||||||||
| 30 | |||||||||||
| 31 | 0 | ▶ | warn "copied computedvector($this -> $that)\n" if $Statistics::Basic::DEBUG >= 3; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | |||||||||||
| 33 | 0 | return $that; | |||||||||
| 34 | } | ||||||||||
| 35 | # }}} | ||||||||||
| 36 | # set_filter {{{ | ||||||||||
| 37 | 12 | ▶ | sub set_filter { | ||||||||
|
Subroutine
set_filter: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||
| 38 | 12 | my $this = shift; | |||||||||
| 39 | 12 | ▶ | my $cref = shift; croak "cref should be a code reference" unless ref($cref) eq "CODE"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 12 | $this->{computer} = $cref; | |||||||||
| 42 | |||||||||||
| 43 | 12 | my $a = Scalar::Util::refaddr($this); | |||||||||
| 44 | 12 | $this->{input_vector}->_set_computer( "cvec_$a" => $this ); # sets recalc needed in this object | |||||||||
| 45 | |||||||||||
| 46 | 12 | return $this; | |||||||||
| 47 | } | ||||||||||
| 48 | # }}} | ||||||||||
| 49 | # _recalc {{{ | ||||||||||
| 50 | 18 | ▶ | sub _recalc { | ||||||||
|
Subroutine
_recalc: called CC=3 SCAR=11.0
| |||||||||||
| 51 | 18 | my $this = shift; | |||||||||
| 52 | |||||||||||
| 53 | 18 | delete $this->{recalc_needed}; | |||||||||
| 54 | |||||||||||
| 55 | 18 | ▶ | if( ref( my $c = $this->{computer} ) eq "CODE" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | 15 | $this->{output_vector}->set_vector( [$c->($this->{input_vector}->query)] ); | |||||||||
| 57 | |||||||||||
| 58 | } else { | ||||||||||
| 59 | 3 | $this->{output_vector}->set_vector( [$this->{input_vector}->query] ); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 18 | ▶ | warn "[recalc " . ref($this) . "]\n" if $Statistics::Basic::DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 18 | $this->_inform_computers_of_change; | |||||||||
| 64 | |||||||||||
| 65 | 18 | return; | |||||||||
| 66 | } | ||||||||||
| 67 | # }}} | ||||||||||
| 68 | # _recalc_needed {{{ | ||||||||||
| 69 | 33 | ▶ | sub _recalc_needed { | ||||||||
|
Subroutine
_recalc_needed: called CC=2 SCAR=7.0
| |||||||||||
| 70 | 33 | my $this = shift; | |||||||||
| 71 | 33 | $this->{recalc_needed} = 1; | |||||||||
| 72 | |||||||||||
| 73 | 33 | ▶ | warn "[recalc_needed " . ref($this) . "]\n" if $Statistics::Basic::DEBUG; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | |||||||||||
| 75 | 33 | return; | |||||||||
| 76 | } | ||||||||||
| 77 | # }}} | ||||||||||
| 78 | # query_size {{{ | ||||||||||
| 79 | 18 | ▶ | sub query_size { | ||||||||
|
Subroutine
query_size: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 18 | my $this = shift; | |||||||||
| 81 | |||||||||||
| 82 | 18 | ▶ | $this->_recalc if $this->{recalc_needed}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 83 | |||||||||||
| 84 | 18 | return $this->{output_vector}->query_size; | |||||||||
| 85 | } | ||||||||||
| 86 | |||||||||||
| 87 | # maybe deprecate this later | ||||||||||
| 88 | 33 | ▶ | *size = \&query_size unless $ENV{TEST_AUTHOR}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 89 | |||||||||||
| 90 | # }}} | ||||||||||
| 91 | # query {{{ | ||||||||||
| 92 | 35 | ▶ | sub query { | ||||||||
|
Subroutine
query: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 93 | 35 | my $this = shift; | |||||||||
| 94 | |||||||||||
| 95 | 35 | ▶ | $this->_recalc if $this->{recalc_needed}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | |||||||||||
| 97 | 35 | return $this->{output_vector}->query; | |||||||||
| 98 | } | ||||||||||
| 99 | # }}} | ||||||||||
| 100 | |||||||||||
| 101 | 0 | ▶ | sub query_vector { return $_[0]{input_vector} } | ||||||||
|
Subroutine
query_vector: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 102 | |||||||||||
| 103 | # query_filled {{{ | ||||||||||
| 104 | 12 | ▶ | sub query_filled { | ||||||||
|
Subroutine
query_filled: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||
| 105 | 12 | my $this = shift; | |||||||||
| 106 | |||||||||||
| 107 | # even though this makes little sense, imo, we need to provide it since so many other objects call it | ||||||||||
| 108 | |||||||||||
| 109 | 12 | ▶ | $this->_recalc if $this->{recalc_needed}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 110 | |||||||||||
| 111 | 12 | return $this->{input_vector}->query_filled; | |||||||||
| 112 | } | ||||||||||
| 113 | # }}} | ||||||||||
| 114 | |||||||||||
| 115 | 0 | ▶ | sub _fix_size { croak "fix_size() makes no sense on computed vectors" } | ||||||||
|
Subroutine
_fix_size: not called CC=1 SCAR=6.9
| |||||||||||
| 116 | 0 | ▶ | sub set_size { my $this = shift; $this->{input_vector}->set_size (@_); return $this } | ||||||||
|
Subroutine
set_size: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 117 | 1 | ▶ | sub insert { my $this = shift; $this->{input_vector}->insert (@_); return $this } | ||||||||
|
Subroutine
insert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 118 | 1 | ▶ | sub ginsert { my $this = shift; $this->{input_vector}->ginsert (@_); return $this } | ||||||||
|
Subroutine
ginsert: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 119 | 0 | ▶ | sub append { my $this = shift; $this->{input_vector}->append (@_); return $this } | ||||||||
|
Subroutine
append: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 120 | 2 | ▶ | sub set_vector { my $this = shift; $this->{input_vector}->set_vector(@_); return $this } | ||||||||
|
Subroutine
set_vector: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 121 | |||||||||||
| 122 | 33 | 1; | |||||||||