blib/lib/Ref/Store/PP.pm

filter: Statementstmt 77.8% 130 / 167 Branchbran 27.7% 5 / 18 Conditioncond 22.2% 2 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 80.0% 36 / 45 Podpod 0.0% 0 / 4 totaltotal 69.7% 173 / 248 CC 13 SCAR 18.5
CC
13
Cov
71%
DESTROY
30.1
ithread_postdup
12.0
dref_add
2.0
CRAP 6.4
« blib/lib/Ref/Store/Sweeping.pm ↑ Summary blib/lib/Ref/Store/Attribute.pm »
1 package Ref::Store::PP::Key;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Scalar::Util qw(weaken refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Ref::Store::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp::Heavy;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Ref::Store::PP::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base qw(Ref::Store::Key);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 100 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
12 100 my ($cls,$scalar,$table) = @_;
13
14 100 my $self = [];
15 100 @{$self}[HR_KFLD_STRSCALAR, HR_KFLD_REFSCALAR, HR_KFLD_TABLEREF] =
16 ("$scalar", $scalar, $table);
17 100 bless $self, $cls;
18
19 100 $table->scalar_lookup->{$scalar} = $self;
20 100 weaken($table->scalar_lookup->{$scalar});
21
22 100 hr_pp_trigger_register($self,$table->forward,"$scalar");
23 100 hr_pp_trigger_register($self,$table->scalar_lookup,"$scalar");
24 100 return $self;
25 }
26  
27 0 ▶sub ithread_predup {
Subroutine ithread_predup: not called CC=1 SCAR=0.0
28 #Perl data structures are still valid here..
29 }
30  
31 0 ▶sub ithread_postdup {
Subroutine ithread_postdup: not called CC=1 SCAR=0.0
32 #PP::Magic information is dup'd as well, nothing for us here. Key is static
33 }
34  
35 package Ref::Store::PP::Key::Encapsulating;
36 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 1 ▶use base qw(Ref::Store::PP::Key);
Subroutine BEGIN: called CC=1 SCAR=0.0
39 1 ▶use Ref::Store::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
40 1 ▶use Ref::Store::Common qw(:pp_constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
41 1 ▶use Ref::Store::PP::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 1 ▶use Scalar::Util qw(weaken isweak);
Subroutine BEGIN: called CC=1 SCAR=0.0
43 1 ▶use Log::Fu;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 1 ▶use Ref::Store::ThreadUtil;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 ▶use Devel::GlobalDestruction;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 1 ▶use constant HR_KFLD_VHREF => HR_KFLD_AVAILABLE() + 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
48  
49 1 ▶use Devel::Peek qw(Dump);
Subroutine BEGIN: called CC=1 SCAR=0.0
50  
51 100 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
52 100 my ($cls,$obj,$table) = @_;
53 100 my $self = [];
54 100 @{$self}[HR_KFLD_STRSCALAR, HR_KFLD_REFSCALAR, HR_KFLD_TABLEREF] =
55 ($obj+0, $obj, $table);
56
57 #log_err("Creating new encapsulating key for object", $obj+0);
58 100 hr_pp_trigger_register($obj, $table->scalar_lookup,$obj+0);
59
60 100 weaken($table->scalar_lookup->{$obj+0} = $self);
61
62 100 bless $self, $cls;
63 100 return $self;
64 }
65  
66  
67 0 ▶sub ithread_predup {
Subroutine ithread_predup: not called CC=1 SCAR=6.9
68 0 my ($self,$table,$ptr_map,$value) = @_;
69 0 hr_thrutil_store_kinfo(HR_THR_KENCAP_PREFIX,
70 $self->[HR_KFLD_STRSCALAR], $ptr_map, $value+0);
71 }
72  
73 0 ▶sub ithread_postdup {
Subroutine ithread_postdup: not called CC=3 SCAR=24.8
74 0 my ($self,$new_table,$ptr_map,$old_taddr) = @_;
75
76 0 my $obj = $self->[HR_KFLD_REFSCALAR];
77 0 my $old_objaddr = $self->[HR_KFLD_STRSCALAR];
78
79 0 hr_pp_trigger_replace_key(
80 $obj, $old_objaddr, $self->[HR_KFLD_TABLEREF]->scalar_lookup,
81 $obj + 0);
82
83 0 my $old_vaddr = hr_thrutil_get_kinfo(
84 HR_THR_KENCAP_PREFIX, $old_objaddr, $ptr_map);
85 0 ▶ if(!$old_vaddr) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($old_vaddr) 0 0 0
86 0 print Dumper($ptr_map);
87 0 die("Couldn't find old value for key");
88 }
89 my $vhash = $ptr_map->{
90 0 HR_THR_LINFO_PREFIX . $old_taddr}->reverse->{$old_vaddr};
91 0 ▶ if(!$vhash) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($vhash) 0 0 0
92 0 print Dumper($ptr_map->{HR_THR_LINFO_PREFIX.$old_taddr});
93 0 die("Couldn't find old vhash! ($old_vaddr)");
94 }
95 hr_pp_trigger_replace_key(
96 0 $obj, $old_objaddr, $vhash,
97 $obj + 0);
98  
99 0 $self->[HR_KFLD_STRSCALAR] = $obj + 0;
100 }
101  
102 100 ▶sub link_value {
Subroutine link_value: called CC=1 SCAR=0.0
103 100 my ($self,$value) = @_;
104 100 my $obj = $self->[HR_KFLD_REFSCALAR];
105 100 my $stored_privhash = $self->[HR_KFLD_TABLEREF]->reverse->{$value+0};
106 100 hr_pp_trigger_register($obj, $stored_privhash, $obj+0);
107 }
108  
109 0 ▶sub unlink_value {
Subroutine unlink_value: not called CC=1 SCAR=6.9
110 0 my ($self,$value) = @_;
111 0 my $obj = $self->[HR_KFLD_REFSCALAR];
112 hr_pp_trigger_unregister($obj,
113 0 $self->[HR_KFLD_TABLEREF]->reverse->{$value+0},
114 $obj + 0
115 );
116 }
117  
118 0 ▶sub exchange_value {
Subroutine exchange_value: not called CC=1 SCAR=6.9
119 0 my ($self,$old,$new) = @_;
120 0 $self->unlink_value($old);
121 0 $self->link_value($new);
122 }
123  
124  
125 100 ▶sub weaken_encapsulated {
Subroutine weaken_encapsulated: called CC=1 SCAR=0.0
126 100 my $self = shift;
127 100 weaken($self->[HR_KFLD_REFSCALAR]);
128 }
129  
130  
131 200 ▶sub kstring {
Subroutine kstring: called CC=1 SCAR=0.0
132 200 my $self = shift;
133 200 $self->[HR_KFLD_STRSCALAR];
134 }
135  
136 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
137 0 my ($self,$hrd) = @_;
138 0 $hrd->iprint("ENCAP: %s", $hrd->fmt_ptr($self->[HR_KFLD_REFSCALAR]));
139 }
140  
141 #This is called:
142  
143 # 1) When the reverse value entry is deleted:
144 # ACTION: clean up encapsulated object magic
145 #
146 # 2) When the object itself has triggered
147 # A deletion from the value's reverse entry.
148 # ACTION:
149  
150 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
151  
152 100 ▶sub DESTROY {
Subroutine DESTROY: called CC=9 SCAR=34.1
153 100 ▶ return if in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if &in_global_destruction() 0 100 100
154 100 my $self = shift;
155 100 my $table = $self->[HR_KFLD_TABLEREF];
156 100 my $obj = $self->[HR_KFLD_REFSCALAR];
157 100 my $obj_s = $self->[HR_KFLD_STRSCALAR];
158
159 100 delete $table->scalar_lookup->{$obj_s};
160 100 my $value = delete $table->forward->{$obj_s};
161
162 100 ▶ if($obj) {
Branch: 1 branch
BranchTrueFalseTotal
if ($obj) 100 0 100
163 100 hr_pp_trigger_unregister($obj, $table->scalar_lookup, $obj_s);
164 }
165
166 #log_info("Found stored.. $stored", $stored+0);
167
168 100 ▶ return unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 100 0 100
169 0 my $vhash = $table->reverse->{$value+0};
170
171 0 ▶ if(defined $value && defined $obj && defined $vhash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value and defined $obj and defined $vhash) 0 0 0
Condition0%0/6
defined $value and defined $obj and defined $vhash
!ll&&!rl&&r
000
defined $value and defined $obj
!ll&&!rl&&r
000
MC/DC0%0/3
defined $value and defined $obj and defined $vhash
defined $value defined $obj defined $vhash
Truth table0%0/4
A and B and C
A= defined $valueB= defined $objC= defined $vhash
ABCresult
0XX0
10X0
1100
1111
172 0 hr_pp_trigger_unregister($obj, $vhash, $obj_s);
173 }
174
175 0 ▶ if(defined $vhash) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $vhash) 0 0 0
176 0 delete $vhash->{$self->[HR_KFLD_STRSCALAR]};
177 0 ▶ if(!%$vhash) {
Branch: 1 branch
BranchTrueFalseTotal
if (not %$vhash) 0 0 0
178 #log_info("Table empty!");
179 0 delete $table->reverse->{$value+0};
180 0 hr_pp_trigger_unregister($value, $table->reverse, $obj_s);
181 }
182 }
183 }
184  
185  
186  
187 package Ref::Store::PP;
188 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 1 ▶use Scalar::Util qw(weaken refaddr);
Subroutine BEGIN: called CC=1 SCAR=0.0
191 1 ▶use base qw(Ref::Store);
Subroutine BEGIN: called CC=1 SCAR=0.0
192 1 ▶use Ref::Store::PP::Magic;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 1 ▶use Ref::Store::Common qw(:pp_constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
194 1 ▶use Ref::Store::ThreadUtil;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196  
197 1 ▶use Log::Fu { level => "debug" };
Subroutine BEGIN: called CC=1 SCAR=0.0
198  
199 200 ▶sub new_key {
Subroutine new_key: called CC=2 SCAR=6.9
Pod undocumented
200 200 my ($self,$ukey) = @_;
201 200 ▶ my $cls = ref $ukey ? 'Ref::Store::PP::Key::Encapsulating' :
Branch: 1 branch
BranchTrueFalseTotal
ref $ukey ? : 100 100 200
202 'Ref::Store::PP::Key';
203 200 $cls->new($ukey, $self);
204 }
205  
206 1400 ▶sub dref_add {
Subroutine dref_add: called CC=2 SCAR=7.0
Pod undocumented
207 1400 my ($self,$value,$target,$key) = @_;
208 1400 ▶ $key ||= $value+0;
Condition66%2/3
$key ||= $value + 0
l!l&&r!l&&!r
40010000
MC/DC0%0/2
$key ||= $value + 0
$key $value + 0
Truth table66%2/3
A ||= B
A= $keyB= $value + 0
ABresult
1X1
011
000
209 1400 hr_pp_trigger_register($value,$target,$key);
210 }
211  
212 0 ▶sub dref_del {
Subroutine dref_del: not called CC=1 SCAR=6.9
Pod undocumented
213 0 my ($self,$value,$target,$key) = @_;
214 0 hr_pp_trigger_unregister($value, $target, $key);
215 }
216  
217 1 *dref_add_str = \&dref_add;
218 1 *dref_add_ptr = \&dref_add;
219  
220 1 *dref_del_ptr = \&dref_del;
221  
222 #sub dref_add_str {
223 # my ($self,$value,$target,$key) = @_;
224 # hr_pp_trigger_register($value, $key, $target);
225 #}
226 #
227 #sub dref_add_ptr {
228 # my ($self,$value,$target) = @_;
229 # hr_pp_trigger_register($value, $value+0, $target);
230 #}
231 #
232 #sub dref_del_ptr {
233 # my ($self,$value,$target,$mkey) = @_;
234 # hr_pp_trigger_unregister($value,$target,$mkey);
235 #}
236  
237 0 ▶sub ithread_store_lookup_info {
Subroutine ithread_store_lookup_info: not called CC=1 SCAR=6.9
Pod undocumented
238 0 my ($self,$ptr_map) = @_;
239 0 my $Linfo = Ref::Store::ThreadUtil::OldLookups->new($self);
240 0 $ptr_map->{HR_THR_LINFO_PREFIX . ($self + 0) } = $Linfo;
241 }
242  
243 1 1;
« blib/lib/Ref/Store/Sweeping.pm ↑ Summary blib/lib/Ref/Store/Attribute.pm »