DWH_File/Kernel.pm

filter: Statementstmt 95.0% 133 / 140 Branchbran 66.6% 24 / 36 Conditioncond 38.4% 10 / 26 MC/DCmcdc 7.1% 1 / 14 Subroutinesub 100% 33 / 33 Podpod 0.0% 0 / 23 totaltotal 73.9% 201 / 272 CC 29 SCAR 13.0
CC
29
Cov
83%
save_custom_grounding
8.8
unground
6.0
ground_reference
5.6
CRAP 3.7
« DWH_File/Tie/Hash.pm ↑ Summary DWH_File/Tie/Hash/Node.pm »
1 package DWH_File::Kernel;
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 UNIVERSAL;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 ▶use DWH_File::ID_Mill;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 9 ▶use DWH_File::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use DWH_File::Registry::URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use DWH_File::Registry::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use DWH_File::Value::Factory;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 9 ▶use URI::file;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 9 @ISA = qw( );
18 9 $VERSION = 0.01;
19  
20 13 ▶sub new {
Subroutine new: called CC=5 SCAR=16.2
Pod undocumented
21 13 my $this = shift;
22 13 my $file = $_[ 0 ];
23 13 ▶ my $class = ref $this || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0130
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
24 13 my %dummy = ();
25 13 my $dbm = tie %dummy, $DWH_File::default_dbm, @_;
26 0 ▶ unless ( $dbm ) { die "Failed to create dbm file $file: $!" }
Branch: 1 branch
BranchTrueFalseTotal
unless ($dbm) 0 13 13
27 13 my $self = { dbm => $dbm,
28 file => $file,
29 cache => DWH_File::Cache->new,
30 garbage => {},
31 dummy => \%dummy,
32 alive => 1,
33 };
34 13 bless $self, $class;
35 13 $self->{ id_mill } = DWH_File::ID_Mill->new( $self, 'id_mill' );
36 13 ▶ $self->{ id_mill }{ current } ||= 0;
Condition100%2/2
$self->{"id_mill"}{"current"} ||= 0
l!l
94
MC/DC100%1/1
$self->{"id_mill"}{"current"} ||= 0
$self->{"id_mill"}{"current"}
Truth table100%2/2
A
A= $self->{"id_mill"}{"current"}
Aresult
11
00
37 13 $self->{ uri_pool } = DWH_File::Registry::URI->new( $self, 'uri_pool' );
38 13 DWH_File::Registry::URI->register( $self );
39 13 $self->{ class_pool } = DWH_File::Registry::Class->new( $self,
40 'class_pool' );
41 13 my $worker_id = $self->fetch_property( 'worker' );
42 13 ▶ if ( defined $worker_id ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $worker_id) { } 9 4 13
43 9 $self->{ work } = $self->activate_by_id( $worker_id );
44 }
45 else {
46 4 $self->{ work } = DWH_File::Value::Factory->from_input( $self, {},
47 'DWH_File::Work' );
48 4 $self->store_property( 'worker', $self->{ work }{ id } );
49 }
50 13 return $self;
51 }
52  
53 47 ▶sub uri {
Subroutine uri: called CC=1 SCAR=0.0
Pod undocumented
54 47 return URI::file->new_abs( $_[ 0 ]->{ file } );
55 }
56  
57 410 ▶sub store {
Subroutine store: called CC=1 SCAR=0.0
Pod undocumented
58 410 $_[ 0 ]->{ dbm }->STORE( @_[ 1, 2 ] );
59 }
60  
61 51 ▶sub store_property {
Subroutine store_property: called CC=1 SCAR=0.0
Pod undocumented
62 51 $_[ 0 ]->store( pack( 'La*', 0, $_[ 1 ] ), $_[ 2 ] );
63 }
64  
65 1247 ▶sub fetch {
Subroutine fetch: called CC=1 SCAR=0.0
Pod undocumented
66 1247 return $_[ 0 ]->{ dbm }->FETCH( $_[ 1 ] );
67 }
68  
69 78 ▶sub fetch_property {
Subroutine fetch_property: called CC=1 SCAR=0.0
Pod undocumented
70 78 return $_[ 0 ]->fetch( pack 'La*', 0, $_[ 1 ] );
71 }
72  
73 60 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod undocumented
74 60 $_[ 0 ]->{ dbm }->DELETE( $_[ 1 ] );
75 }
76  
77 36 ▶sub next_id {
Subroutine next_id: called CC=1 SCAR=0.0
Pod undocumented
78 36 return $_[ 0 ]->{ id_mill }->next;
79 }
80  
81 13 ▶sub save_state {
Subroutine save_state: called CC=1 SCAR=0.0
Pod undocumented
82 13 $_[ 0 ]->{ id_mill }->save;
83 13 $_[ 0 ]->{ class_pool }->save;
84 13 $_[ 0 ]->{ uri_pool }->save;
85 }
86  
87 56 ▶sub class_id {
Subroutine class_id: called CC=1 SCAR=0.0
Pod undocumented
88 56 $_[ 0 ]->{ class_pool }->class_id( $_[ 1 ] );
89 }
90  
91 69 ▶sub reference_string {
Subroutine reference_string: called CC=2 SCAR=6.9
Pod undocumented
92 69 my $tag;
93 69 ▶ if ( $_[ 1 ]->{ kernel } == $_[ 0 ] ) { $tag = 0 }
Branch: 1 branch
BranchTrueFalseTotal
if ($_[1]{'kernel'} == $_[0]) { } 48 21 69
94 21 else { $tag = $_[ 0 ]->{ uri_pool }->tag( $_[ 1 ]->{ kernel } ) }
95 69 pack "aSL", '^', $tag, $_[ 1 ]->{ id };
96 }
97  
98 1478 ▶sub activate_reference {
Subroutine activate_reference: called CC=3 SCAR=11.0
Pod undocumented
99 1478 my ( $self, $stored ) = @_;
100 1478 my ( $head, $tag, $id ) =
101 unpack "aSL", $stored;
102 1478 ▶ $head eq '^' or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$head eq "^" or return undef 295 1183 1478
103 295 ▶ if ( $tag ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag) { } 19 276 295
104 return DWH_File::Tie::Foreign->
105 19 new( $self, $self->{ uri_pool }->retrieve( $tag )->
106 activate_by_id( $id ) );
107 }
108 276 else { return $self->activate_by_id( $id ) }
109 }
110  
111 306 ▶sub activate_by_id {
Subroutine activate_by_id: called CC=4 SCAR=14.0
Pod undocumented
112 306 my ( $self, $id ) = @_;
113 306 my $val_obj;
114 306 ▶ unless ( $val_obj = $self->{ cache }->retrieve( $id ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($val_obj = $self->{"cache"}->retrieve($id)) 33 273 306
115 33 my $ground = $self->fetch( pack "L", $id );
116 33 my ( $tie_class_id, $blessing_id, $refcount, $tail )
117 = unpack "SSLa*", $ground;
118 33 my $ref;
119 33 my $tie_class = $self->{ class_pool }->fetch( $tie_class_id );
120 33 my $blessing = $self->{ class_pool }->fetch( $blessing_id );
121 33 ▶ $tie_class or die "Invalid class id: '$tie_class_id'";
Branch: 1 branch
BranchTrueFalseTotal
$tie_class or die "Invalid class id: '${tie_class_id}'" 33 0 33
122 33 $val_obj = $tie_class->tie_reference( $self, $ref, $blessing,
123 $id, $tail );
124 33 ▶ if ( UNIVERSAL::isa( $ref, 'DWH_File::Aware' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (UNIVERSAL::isa($ref, "DWH_File::Aware")) 0 33 33
125 0 $ref->dwh_activate( $val_obj );
126 }
127 }
128 306 return $val_obj;
129 }
130  
131 28 ▶sub ground_reference {
Subroutine ground_reference: called CC=4 SCAR=17.2
Pod undocumented
132 28 my ( $self, $value_obj ) = @_;
133 28 ▶ unless ( ref $value_obj and
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")) 0 28 28
Condition33%2/6
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
!ll&&!rl&&r
0028
ref $value_obj and $value_obj->isa("DWH_File::Value")
!ll&&!rl&&r
0028
MC/DC0%0/3
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
ref $value_obj $value_obj->isa("DWH_File::Value") $value_obj->isa("DWH_File::Reference")
Truth table25%1/4
A and B and C
A= ref $value_objB= $value_obj->isa("DWH_File::Value")C= $value_obj->isa("DWH_File::Reference")
ABCresult
0XX0
10X0
1100
1111
134 $value_obj->isa( 'DWH_File::Value' ) and
135 $value_obj->isa( 'DWH_File::Reference' ) ) {
136 0 die "ground_reference() called for inapproproate object";
137 }
138 28 my $ground = pack "SSLa*", $self->class_id( $value_obj ),
139 $self->class_id( $value_obj->actual_value ),
140 0, # refcount
141 $value_obj->custom_grounding;
142 28 $self->store( pack( "L", $value_obj->{ id } ), $ground );
143 }
144  
145 134 ▶sub save_custom_grounding {
Subroutine save_custom_grounding: called CC=7 SCAR=21.8
Pod undocumented
146 134 my ( $self, $value_obj ) = @_;
147 134 ▶ unless ( ref $value_obj and
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")) 0 134 134
Condition33%2/6
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
!ll&&!rl&&r
00134
ref $value_obj and $value_obj->isa("DWH_File::Value")
!ll&&!rl&&r
00134
MC/DC0%0/3
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
ref $value_obj $value_obj->isa("DWH_File::Value") $value_obj->isa("DWH_File::Reference")
Truth table25%1/4
A and B and C
A= ref $value_objB= $value_obj->isa("DWH_File::Value")C= $value_obj->isa("DWH_File::Reference")
ABCresult
0XX0
10X0
1100
1111
148 $value_obj->isa( 'DWH_File::Value' ) and
149 $value_obj->isa( 'DWH_File::Reference' ) ) {
150 0 die "save_custom_grounding() called for inapproproate object";
151 }
152 134 my $id = $value_obj->{ id };
153 134 ▶ defined $id or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $id or return 134 0 134
154 134 my $idstring = pack "L", $id;
155 134 ▶ my $ground = $self->fetch( $idstring ) or return;
Branch: 1 branch
BranchTrueFalseTotal
my $ground = $self->fetch($idstring) or return 37 97 134
156 37 my ( $pre ) = unpack "a8", $ground;
157 37 ▶ $pre or return;
Branch: 1 branch
BranchTrueFalseTotal
$pre or return 37 0 37
158 37 $self->store( $idstring, pack "a8a*", $pre,
159 $value_obj->custom_grounding );
160 }
161  
162 2 ▶sub unground {
Subroutine unground: called CC=4 SCAR=17.9
Pod undocumented
163 2 my ( $self, $value_obj ) = @_;
164 2 ▶ unless ( ref $value_obj and
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")) 0 2 2
Condition33%2/6
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
!ll&&!rl&&r
002
ref $value_obj and $value_obj->isa("DWH_File::Value")
!ll&&!rl&&r
002
MC/DC0%0/3
ref $value_obj and $value_obj->isa("DWH_File::Value") and $value_obj->isa("DWH_File::Reference")
ref $value_obj $value_obj->isa("DWH_File::Value") $value_obj->isa("DWH_File::Reference")
Truth table25%1/4
A and B and C
A= ref $value_objB= $value_obj->isa("DWH_File::Value")C= $value_obj->isa("DWH_File::Reference")
ABCresult
0XX0
10X0
1100
1111
165 $value_obj->isa( 'DWH_File::Value' ) and
166 $value_obj->isa( 'DWH_File::Reference' ) ) {
167 0 die "unground() called for inapproproate object";
168 }
169 2 $self->delete( pack( "L", $value_obj->{ id } ) );
170 }
171  
172 27 ▶sub bump_refcount {
Subroutine bump_refcount: called CC=1 SCAR=0.0
Pod undocumented
173 27 my ( $self, $id ) = @_;
174 27 my $idstring = pack "L", $id;
175 27 my ( $pre, $refcount, $post ) = unpack "a4La*", $self->fetch( $idstring );
176 27 $refcount++;
177 27 $self->store( $idstring, pack( "a4La*", $pre, $refcount, $post ) );
178 27 delete $self->{ garbage }{ $id };
179 }
180  
181 2 ▶sub cut_refcount {
Subroutine cut_refcount: called CC=3 SCAR=12.0
Pod undocumented
182 2 my ( $self, $id ) = @_;
183 2 my $idstring = pack "L", $id;
184 2 my ( $pre, $refcount, $post ) = unpack "a4La*",
185 $self->fetch( $idstring );
186 2 $refcount--;
187 2 $self->store( $idstring, pack "a4La*", $pre, $refcount, $post );
188 2 ▶ if ( $refcount == 0 ) { $self->{ garbage }{ $id } = 1 }
Branch: 2 branches
BranchTrueFalseTotal
if ($refcount == 0) { } 2 0 2
elsif ($refcount < 0) { } 0 0 0
189 0 elsif ( $refcount < 0 ) { die "Negative refcount exception! [$id]" }
190 }
191  
192 61 ▶sub tieing {
Subroutine tieing: called CC=1 SCAR=0.0
Pod undocumented
193 61 $_[ 0 ]->{ cache }->encache( $_[ 1 ] );
194 }
195  
196 61 ▶sub did_tie {
Subroutine did_tie: called CC=1 SCAR=0.0
Pod undocumented
197 }
198  
199 13 ▶sub purge_garbage {
Subroutine purge_garbage: called CC=5 SCAR=17.0
Pod undocumented
200 13 ▶ while ( my @goids = keys %{ $_[ 0 ]->{ garbage } } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@goids) = keys %{$_[0]{"garbage"};}) 2 13 15
201 2 for my $goid ( @goids ) {
202 2 my $goner = $_[ 0 ]->activate_by_id( $goid );
203 2 ▶ if ( $goner and
Branch: 1 branch
BranchTrueFalseTotal
if ($goner and UNIVERSAL::isa($goner, 'DWH_File::Reference')) { } 2 0 2
Condition33%1/3
$goner and UNIVERSAL::isa($goner, "DWH_File::Reference")
!ll&&!rl&&r
002
MC/DC0%0/2
$goner and UNIVERSAL::isa($goner, "DWH_File::Reference")
$goner UNIVERSAL::isa($goner, "DWH_File::Reference")
Truth table33%1/3
A and B
A= $gonerB= UNIVERSAL::isa($goner, "DWH_File::Reference")
ABresult
0X0
100
111
204 UNIVERSAL::isa( $goner, 'DWH_File::Reference' ) ) {
205 2 $goner->vanish;
206 2 delete $_[ 0 ]->{ garbage }{ $goid };
207 }
208 0 else { warn "Garbage anomaly: $goid ~ $goner" }
209 }
210 }
211 }
212  
213 13 ▶sub release {
Subroutine release: called CC=1 SCAR=0.0
Pod undocumented
214 13 my ( $self ) = @_;
215 13 $self->{ uri_pool }->release( $self );
216 13 delete $_[ 0 ]->{ dbm };
217 13 untie %{ $_[ 0 ]->{ dummy } };
218 13 $self->{ alive } = 0;
219 }
220  
221 13 ▶sub wipe {
Subroutine wipe: called CC=1 SCAR=0.0
Pod undocumented
222 13 my ( $self ) = @_;
223 13 $self->save_state;
224 13 $self->purge_garbage;
225 13 $self->release;
226 }
227  
228 9 1;
229  
230 __END__
« DWH_File/Tie/Hash.pm ↑ Summary DWH_File/Tie/Hash/Node.pm »