| 1 | package Tie::Array::Boolean; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | $VERSION = '0.0.1'; | |||||||||
| 4 | 3 | @ISA = ( 'Tie::Array' ); | |||||||||
| 5 | |||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 3 | ▶ | use Tie::Array; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 1 | ▶ | sub TIEARRAY { | ||||||||
|
Subroutine
TIEARRAY: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 1 | my $class = shift; | |||||||||
| 13 | |||||||||||
| 14 | 1 | my $self = { | |||||||||
| 15 | bits => '', | ||||||||||
| 16 | size => 0, | ||||||||||
| 17 | }; | ||||||||||
| 18 | |||||||||||
| 19 | 1 | return bless $self, $class; | |||||||||
| 20 | } | ||||||||||
| 21 | |||||||||||
| 22 | 126 | ▶ | sub STORE { | ||||||||
|
Subroutine
STORE: called CC=2 SCAR=6.9
| |||||||||||
| 23 | 126 | my $self = shift; | |||||||||
| 24 | 126 | my $index = shift; | |||||||||
| 25 | 126 | my $value = !! shift; | |||||||||
| 26 | |||||||||||
| 27 | 126 | ▶ | $self->STORESIZE( 1+$index ) if 1+$index > $self->FETCHSIZE(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | |||||||||||
| 29 | 126 | vec( $self->{bits}, $index, 1 ) = $value; | |||||||||
| 30 | |||||||||||
| 31 | 126 | return; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 216 | ▶ | sub FETCH { | ||||||||
|
Subroutine
FETCH: called CC=2 SCAR=6.9
| |||||||||||
| 35 | 216 | my $self = shift; | |||||||||
| 36 | 216 | my $index = shift; | |||||||||
| 37 | |||||||||||
| 38 | 216 | ▶ | return undef if 1+$index > $self->FETCHSIZE(); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 39 | 215 | return vec( $self->{bits}, $index, 1 ); | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | 527 | ▶ | sub FETCHSIZE { | ||||||||
|
Subroutine
FETCHSIZE: called CC=1 SCAR=0.0
| |||||||||||
| 43 | 527 | my $self = shift; | |||||||||
| 44 | |||||||||||
| 45 | 527 | return $self->{size}; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 60 | ▶ | sub STORESIZE { | ||||||||
|
Subroutine
STORESIZE: called CC=3 SCAR=11.0
| |||||||||||
| 49 | 60 | my $self = shift; | |||||||||
| 50 | 60 | my $size = shift; | |||||||||
| 51 | |||||||||||
| 52 | 60 | ▶ | if ( $size < $self->{size} ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 27 | substr( $self->{bits}, int( $size / 8 ) + 1 ) = ''; | |||||||||
| 54 | 27 | vec( $self->{bits}, $_, 1 ) = 0 for $size .. $size + 8; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 60 | $self->{size} = $size; | |||||||||
| 58 | |||||||||||
| 59 | 60 | return; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 3 | ▶ | sub DELETE { | ||||||||
|
Subroutine
DELETE: called CC=2 SCAR=6.9
| |||||||||||
| 63 | 3 | my $self = shift; | |||||||||
| 64 | 3 | my $index = shift; | |||||||||
| 65 | |||||||||||
| 66 | 3 | ▶ | if ( $index == $self->FETCHSIZE() - 1 ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | 2 | $self->STORESIZE( $index ); | |||||||||
| 68 | } | ||||||||||
| 69 | else { | ||||||||||
| 70 | 1 | $self->STORE( $index, 0 ); | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 3 | return; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 1 | ▶ | sub EXISTS { | ||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||
| 77 | 1 | my $self = shift; | |||||||||
| 78 | 1 | my $index = shift; | |||||||||
| 79 | |||||||||||
| 80 | 1 | return $index < $self->FETCHSIZE(); | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 12 | ▶ | sub get_truth_count { | ||||||||
|
Subroutine
get_truth_count: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 84 | 12 | my $self = shift; | |||||||||
| 85 | |||||||||||
| 86 | 12 | return unpack '%32b*', $self->{bits}; | |||||||||
| 87 | } | ||||||||||
| 88 | |||||||||||
| 89 | 3 | 1; # Magic true value required at end of module | |||||||||
| 90 | __END__ | ||||||||||