DWH_File/Tie/Array.pm

filter: Statementstmt 89.8% 124 / 138 Branchbran 57.5% 23 / 40 Conditioncond 61.1% 11 / 18 MC/DCmcdc 30.0% 3 / 10 Subroutinesub 92.3% 24 / 26 Podpod 0.0% 0 / 8 totaltotal 77.0% 185 / 240 CC 33 SCAR 18.2
CC
33
Cov
81%
SPLICE
17.1
shove
6.4
tie_reference
5.5
CRAP 6.2
« DWH_File/Value/Factory.pm ↑ Summary DWH_File/Tie/Hash.pm »
1 package DWH_File::Tie::Array;
2  
3 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use vars qw( @ISA $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use DWH_File::Subscript;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 ▶use DWH_File::Value::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 9 ▶use DWH_File::Tie::Subscripted;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use DWH_File::Tie::Array::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 @ISA = qw( DWH_File::Tie::Subscripted );
13 9 $VERSION = 0.01;
14  
15 28 ▶sub TIEARRAY {
Subroutine TIEARRAY: called CC=1 SCAR=0.0
16 28 my $this = shift;
17 28 my $self = $this->perform_tie( @_ );
18 #$self->{ cache } = DWH_File::Cache->new;
19 }
20  
21 125 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: called CC=2 SCAR=6.9
22 125 my ( $self ) = @_;
23 125 ▶ return $self->{ size } || 0;
Condition100%2/2
$self->{'size'} || 0
l!l
11114
MC/DC100%1/1
$self->{'size'} || 0
$self->{'size'}
Truth table100%2/2
A
A= $self->{'size'}
Aresult
11
00
24 }
25  
26 68 ▶sub STORESIZE {
Subroutine STORESIZE: called CC=4 SCAR=16.3
27 68 my ( $self, $size ) = @_;
28 68 ▶ my $oldsize = $self->{ size } || 0;
Condition100%2/2
$self->{'size'} || 0
l!l
5414
MC/DC100%1/1
$self->{'size'} || 0
$self->{'size'}
Truth table100%2/2
A
A= $self->{'size'}
Aresult
11
00
29 68 $self->{ size } = $size;
30 68 my $kernel = $self->{ kernel };
31 # make lazy
32 68 $kernel->save_custom_grounding( $self );
33 68 my $nc = $self->node_class;
34 68 ▶ for ( my $i = $size; $i < $oldsize; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $oldsize) 0 68 68
35 0 my $subscript = DWH_File::Subscript->from_input( $self, $i );
36 0 my $data = $kernel->delete( $subscript );
37 0 ▶ if ( $data ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($data) 0 0 0
38 0 $nc->from_stored( $kernel, $data )->release;
39 }
40 }
41 }
42  
43 0 ▶sub CLEAR { $_[ 0 ]->STORESIZE( 0 ) }
Subroutine CLEAR: not called CC=1 SCAR=6.9
44  
45 2 ▶sub POP {
Subroutine POP: called CC=2 SCAR=7.0
46 2 my ( $self ) = @_;
47 2 ▶ $self->{ size } or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->{"size"} or return undef 2 0 2
48 2 my $value = $self->DELETE( $self->{ size } - 1 );
49 2 $self->{ size }--;
50 2 $self->{ kernel }->save_custom_grounding( $self );
51 2 return $value;
52 }
53  
54 3 ▶sub PUSH {
Subroutine PUSH: called CC=3 SCAR=11.0
55 3 my $self = shift; # @_ contains data to be pushed
56 3 ▶ @_ or return;
Branch: 1 branch
BranchTrueFalseTotal
@_ or return 3 0 3
57 3 my $i = $self->{ size };
58 3 my $kernel = $self->{ kernel };
59 3 my $nc = $self->node_class;
60 3 $self->STORESIZE( $i + @_ );
61 3 for my $v ( @_ ) {
62 11 my $subscript = DWH_File::Subscript->from_input( $self, $i );
63 11 my $value = DWH_File::Value::Factory->from_input( $kernel, $v );
64 11 my $node = $nc->new;
65 11 $node->set_value( $value );
66 # make lazy
67 11 $kernel->store( $subscript, $node );
68 11 $i++;
69 }
70 }
71  
72 3 ▶sub SHIFT {
Subroutine SHIFT: called CC=1 SCAR=0.0
73 3 my ( $self ) = @_;
74 3 return $self->SPLICE( 0, 1 );
75 }
76  
77 3 ▶sub UNSHIFT {
Subroutine UNSHIFT: called CC=1 SCAR=0.0
78 3 my $self = shift; # @_ contains data to be unshifted
79 3 return $self->SPLICE( 0, 0, @_ );
80 }
81  
82 11 ▶sub SPLICE {
Subroutine SPLICE: called CC=13 SCAR=28.4
83 11 my $self = shift;
84 11 my $offset = shift;
85 11 my $length = shift;
86 # @_ contains data to be inserted
87 11 my $insert_length = @_;
88  
89 0 ▶ if ( $offset > $self->{ size } ) { $offset = $self->{ size } }
Branch: 2 branches
BranchTrueFalseTotal
if ($offset > $self->{'size'}) { } 0 11 11
elsif ($self->{'size'} == 0) { } 0 11 11
90 0 elsif ( $self->{ size } == 0 ) { $offset = 0 }
91 0 ▶ else { while ( $offset < 0 ) { $offset += $self->{ size } } }
Branch: 1 branch
BranchTrueFalseTotal
if ($offset < 0) 0 11 11
92  
93 11 my $last = $offset + $length - 1;
94 0 ▶ if ( $last >= $self->{ size } ) { $last = $self->{ size } - 1 }
Branch: 1 branch
BranchTrueFalseTotal
if ($last >= $self->{"size"}) 0 11 11
95 11 $length = $last - $offset + 1;
96 11 my @return = map { $self->DELETE( $_ ) } ( $offset..$last );
97  
98 11 ▶ if ( $insert_length ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($insert_length) { } 6 5 11
elsif ($length) { } 5 0 5
99 6 ▶ if ( $last < $self->{ size } - 1
Branch: 1 branch
BranchTrueFalseTotal
if ($last < $self->{"size"} - 1 and $offset < $self->{"size"} and $insert_length != $length) 6 0 6
Condition33%2/6
$last < $self->{"size"} - 1 and $offset < $self->{"size"} and $insert_length != $length
!ll&&!rl&&r
006
$last < $self->{"size"} - 1 and $offset < $self->{"size"}
!ll&&!rl&&r
006
MC/DC0%0/3
$last < $self->{"size"} - 1 and $offset < $self->{"size"} and $insert_length != $length
$last < $self->{"size"} - 1 $offset < $self->{"size"} $insert_length != $length
Truth table25%1/4
A and B and C
A= $last < $self->{"size"} - 1B= $offset < $self->{"size"}C= $insert_length != $length
ABCresult
0XX0
10X0
1100
1111
100 and $offset < $self->{ size }
101 and $insert_length != $length ) {
102 6 $self->shove( $last + 1, $insert_length - $length );
103 6 $self->{ size } += $insert_length - $length;
104 # make lazy
105 6 $self->{ kernel }->save_custom_grounding( $self );
106 }
107 6 for my $v ( @_ ) {
108 14 $self->STORE( $offset++, $v );
109 }
110 }
111 elsif ( $length ) {
112 5 ▶ if ( $last < $self->{ size } - 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last < $self->{"size"} - 1) 5 0 5
113 5 $self->shove( $last + 1, -$length );
114 }
115 5 $self->{ size } -= $length;
116 # make lazy
117 5 $self->{ kernel }->save_custom_grounding( $self );
118 }
119  
120 11 ▶ wantarray and return @return;
Branch: 1 branch
BranchTrueFalseTotal
wantarray and return @return 1 10 11
121 10 return $return[ 0 ];
122 }
123  
124 15 ▶sub DELETE {
Subroutine DELETE: called CC=2 SCAR=7.1
125 15 my ( $self, $index ) = @_;
126 # check semantics. In this interpretation deleting never
127 # affects the size of the array - it only differs from
128 # the assignment of undef in terms of the way EXISTS()
129 # responds (and as a side effect, in terms of space
130 # complexity).
131 15 my $subscript = DWH_File::Subscript->from_input( $self, $index );
132 15 ▶ if ( my $node = $self->get_node( $subscript ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $node = $self->get_node($subscript)) { } 15 0 15
133 15 my $value = $node->{ value }->actual_value;
134 15 $node->release;
135 15 $self->{ kernel }->delete( $subscript );
136 15 return $value;
137 }
138 0 else { return undef }
139 }
140  
141 0 ▶sub EXTEND {
Subroutine EXTEND: not called CC=1 SCAR=6.9
142 0 my ( $self, $count ) = @_;
143 # no-op in this class
144 }
145  
146 11 ▶sub shove {
Subroutine shove: called CC=6 SCAR=18.5
Pod undocumented
147 11 my ( $self, $start, $amount ) = @_;
148 0 ▶ if ( $start + $amount < 0 ) { die "anomalous invocation of shove" }
Branch: 1 branch
BranchTrueFalseTotal
if ($start + $amount < 0) 0 11 11
149 11 ▶ if ( $amount < 0 ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($amount < 0) { } 6 5 11
elsif ($amount > 0) { } 5 0 5
150 6 for my $i ( $start .. ( $self->{ size } - 1 ) ) {
151 22 $self->move( $i, $amount );
152 }
153 }
154 elsif ( $amount > 0 ) {
155 5 for my $i ( 0 .. ( $self->{ size } - 1 - $start ) ) {
156 15 $self->move( $self->{ size } - 1 - $i, $amount );
157 }
158 }
159 }
160  
161 37 ▶sub move {
Subroutine move: called CC=1 SCAR=0.0
Pod undocumented
162 37 my ( $self, $from, $amount ) = @_;
163 37 my $subscript = DWH_File::Subscript->from_input( $self, $from );
164 37 my $node_string = $self->{ kernel }->fetch( $subscript );
165 37 $self->{ kernel }->delete( $subscript );
166 37 $subscript = DWH_File::Subscript->from_input( $self, $from + $amount );
167 37 $self->{ kernel }->store( $subscript, $node_string );
168 }
169  
170 28 ▶sub tie_reference {
Subroutine tie_reference: called CC=5 SCAR=17.1
Pod undocumented
171 28 ▶ $_[ 2 ] ||= [];
Condition100%2/2
$_[2] ||= []
l!l
1414
MC/DC100%1/1
$_[2] ||= []
$_[2]
Truth table100%2/2
A
A= $_[2]
Aresult
11
00
172 28 my ( $this, $kernel, $ref, $blessing, $id, $tail ) = @_;
173 28 ▶ my $class = ref $this || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0280
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
174 28 ▶ $blessing ||= ref $ref;
Condition66%2/3
$blessing ||= ref $ref
l!l&&r!l&&!r
14140
MC/DC0%0/2
$blessing ||= ref $ref
$blessing ref $ref
Truth table66%2/3
A ||= B
A= $blessingB= ref $ref
ABresult
1X1
011
000
175 28 my $instance = tie @$ref, $class,
176 $kernel, $ref, $id, $tail;
177 0 ▶ if ( $blessing ne 'ARRAY' ) { bless $ref, $blessing }
Branch: 1 branch
BranchTrueFalseTotal
if ($blessing ne "ARRAY") 0 28 28
178 28 return $instance;
179 }
180  
181 14 ▶sub wake_up_call {
Subroutine wake_up_call: called CC=2 SCAR=7.6
Pod undocumented
182 14 my ( $self, $tail ) = @_;
183 0 ▶ unless ( defined $tail ) { die "Tail anomaly" }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $tail) 0 14 14
184 14 $self->{ size } = int $tail;
185 }
186  
187 14 ▶sub sign_in_first_time {
Subroutine sign_in_first_time: called CC=2 SCAR=6.9
Pod undocumented
188 14 my ( $self ) = @_;
189 14 my $i = 0;
190 14 for my $v ( @{ $self->{ content } } ) {
191 64 $self->STORE( $i, $v );
192 64 $i++;
193 }
194 }
195  
196 313 ▶sub node_class { 'DWH_File::Tie::Array::Node' }
Subroutine node_class: called CC=1 SCAR=0.0
Pod undocumented
197  
198 80 ▶sub handle_new_node {
Subroutine handle_new_node: called CC=2 SCAR=6.9
Pod undocumented
199 80 my ( $self, $node, $subscript ) = @_;
200 80 my $index = $subscript->actual;
201 80 ▶ if ( $index >= $self->FETCHSIZE ) { $self->STORESIZE( $index + 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($index >= $self->FETCHSIZE) 65 15 80
202 }
203  
204 31 ▶sub custom_grounding {
Subroutine custom_grounding: called CC=1 SCAR=0.0
Pod undocumented
205 31 return $_[ 0 ]->FETCHSIZE;
206 }
207  
208 9 1;
209  
210 __END__
« DWH_File/Value/Factory.pm ↑ Summary DWH_File/Tie/Hash.pm »