blib/lib/Ref/Store/Attribute.pm

filter: Statementstmt 52.5% 72 / 137 Branchbran 11.1% 2 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.8% 23 / 36 Podpod 0.0% 0 / 11 totaltotal 48.0% 97 / 202 CC 14 SCAR 17.8
CC
14
Cov
48%
DESTROY
20.7
ithread_postdup
12.0
DESTROY
12.0
CRAP 5.9
« blib/lib/Ref/Store/PP.pm ↑ Summary blib/lib/Ref/Store/Feature/KeyTyped.pm »
1 package Ref::Store::Attribute;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Scalar::Util qw(weaken isweak);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Ref::Store::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Log::Fu;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
11 4 my ($cls,$scalar,$ref,$table) = @_;
12 4 my $self = [];
13 4 $#{$self} = HR_KFLD_ATTRHASH;
14
15 4 bless $self, $cls;
16
17 4 @{$self}[HR_KFLD_STRSCALAR, HR_KFLD_REFSCALAR,
18 HR_KFLD_TABLEREF, HR_KFLD_ATTRHASH] =
19 ($scalar, $ref, $table, {});
20
21 4 return $self;
22 }
23  
24 400 ▶sub link_value {
Subroutine link_value: called CC=1 SCAR=0.0
Pod undocumented
25 400 my ($self,$value) = @_;
26
27 400 $self->[HR_KFLD_TABLEREF]->dref_add_ptr(
28 $value,
29 $self->[HR_KFLD_ATTRHASH],
30 $value + 0
31 );
32 }
33  
34 0 ▶sub unlink_value {
Subroutine unlink_value: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ($self,$value) = @_;
36
37 0 $self->[HR_KFLD_TABLEREF]->dref_del_ptr(
38 $value,
39 $self->[HR_KFLD_ATTRHASH],
40 $value + 0
41 );
42
43 0 delete $self->[HR_KFLD_ATTRHASH]->{$value+0};
44 }
45  
46 4 ▶sub weaken_encapsulated {
Subroutine weaken_encapsulated: called CC=1 SCAR=0.0
Pod undocumented
47 }
48  
49 400 ▶sub store_weak {
Subroutine store_weak: called CC=1 SCAR=0.0
Pod undocumented
50 400 my ($self,$k,$v) = @_;
51 400 weaken($self->[HR_KFLD_ATTRHASH]->{$k} = $v);
52 }
53  
54 0 ▶sub store_strong {
Subroutine store_strong: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my ($self,$k,$v) = @_;
56 0 $self->[HR_KFLD_ATTRHASH]->{$k} = $v;
57 }
58  
59 404 ▶sub get_hash {
Subroutine get_hash: called CC=1 SCAR=0.0
Pod undocumented
60 404 $_[0]->[HR_KFLD_ATTRHASH];
61 }
62  
63 0 ▶sub kstring {
Subroutine kstring: not called CC=1 SCAR=6.9
Pod undocumented
64 0 my $self = shift;
65 0 $self->[HR_KFLD_STRSCALAR];
66 }
67  
68 0 ▶sub dump {
Subroutine dump: not called CC=2 SCAR=17.9
Pod undocumented
69 0 my ($self,$hrd) = @_;
70 0 my $h = $self->[HR_KFLD_ATTRHASH];
71 0 foreach my $v (values %$h) {
72 0 $hrd->iprint("V: %s", $hrd->fmt_ptr($v));
73 }
74 }
75  
76 2 ▶use Ref::Store::ThreadUtil;
Subroutine BEGIN: called CC=1 SCAR=0.0
77 0 ▶sub ithread_predup { }
Subroutine ithread_predup: not called CC=1 SCAR=0.0
Pod undocumented
78 0 ▶sub ithread_postdup {
Subroutine ithread_postdup: not called CC=3 SCAR=24.8
Pod undocumented
79 0 my ($self,$newtable,$ptr_map,$old_taddr) = @_;
80 0 my $attrhash = $self->[HR_KFLD_ATTRHASH];
81 0 my @old_keys = keys %$attrhash;
82 0 foreach my $vaddr (@old_keys) {
83 0 my $new_v = $ptr_map->{$vaddr};
84 0 $newtable->dref_del_ptr($new_v, $attrhash, $vaddr);
85 0 $newtable->dref_add_str($new_v, $attrhash, $new_v + 0);
86 0 my $was_weak = isweak($attrhash->{$vaddr});
87 0 $attrhash->{$new_v+0} = $new_v;
88 0 ▶ if($was_weak) {
Branch: 1 branch
BranchTrueFalseTotal
if ($was_weak) 0 0 0
89 0 weaken($attrhash->{$new_v+0});
90 }
91 0 delete $attrhash->{$vaddr};
92 }
93 }
94  
95 4 ▶sub DESTROY {
Subroutine DESTROY: called CC=7 SCAR=30.3
96 4 my $self = shift;
97 4 my $attrhash = $self->[HR_KFLD_ATTRHASH];
98 4 my $table = $self->[HR_KFLD_TABLEREF];
99 4 ▶ return unless $table;
Branch: 1 branch
BranchTrueFalseTotal
unless $table 0 4 4
100 #log_err("Will iterate over contained values..");
101 4 foreach my $v (values %$attrhash) {
102 4 ▶ next unless defined $v;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $v 4 0 4
103 0 $table->dref_del_ptr($v, $attrhash, $v+0);
104
105 0 my $vhash = $table->reverse->{$v+0};
106 0 my $vaddr = $v+0;
107 0 ▶ next unless defined $vhash;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vhash 0 0 0
108 0 delete $vhash->{$self+0};
109
110 0 ▶ if(! %$vhash) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$vhash) 0 0 0
111 0 delete $table->reverse->{$vaddr};
112 0 ▶ if(defined $v) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $v) 0 0 0
113 0 $table->dref_del_ptr($v, $table->reverse, $vaddr);
114 }
115 }
116 }
117
118 4 delete $table->attr_lookup->{ $self->[HR_KFLD_STRSCALAR] };
119 }
120  
121 package Ref::Store::Attribute::Encapsulating;
122 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
123 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
124 2 ▶use base qw(Ref::Store::Attribute);
Subroutine BEGIN: called CC=1 SCAR=0.0
125 2 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
126 2 ▶use Ref::Store::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
127 2 ▶use Log::Fu;
Subroutine BEGIN: called CC=1 SCAR=0.0
128 2 ▶use Ref::Store::ThreadUtil;
Subroutine BEGIN: called CC=1 SCAR=0.0
129 2 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
130 2 ▶use Devel::GlobalDestruction;
Subroutine BEGIN: called CC=1 SCAR=0.0
131  
132  
133 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
134 0 my ($cls,$astr,$encapsulated,$table) = @_;
135 0 my $self = $cls->SUPER::new($astr, $encapsulated, $table);
136 0 $table->dref_add($encapsulated, \&_encap_destroy_hook, $self);
137 0 return $self;
138 }
139  
140  
141 0 ▶sub weaken_encapsulated {
Subroutine weaken_encapsulated: not called CC=1 SCAR=6.9
142 0 my $self = shift;
143 0 weaken($self->[HR_KFLD_REFSCALAR]);
144 }
145  
146 0 ▶sub dump {
Subroutine dump: not called CC=1 SCAR=6.9
147 0 my ($self,$hrd) = @_;
148 0 $hrd->iprint("ENCAP: %s", $self->[HR_KFLD_REFSCALAR]);
149 0 $self->SUPER::dump($hrd);
150 }
151  
152 0 ▶sub ithread_predup {
Subroutine ithread_predup: not called CC=1 SCAR=6.9
153 0 my ($self,$table,$ptr_map) = @_;
154 0 hr_thrutil_store_kinfo(HR_THR_AENCAP_PREFIX, $self->[HR_KFLD_STRSCALAR],
155 $ptr_map, [ $self->[HR_KFLD_REFSCALAR]+0, $self + 0 ] );
156 }
157  
158 0 ▶sub ithread_postdup {
Subroutine ithread_postdup: not called CC=2 SCAR=17.9
159 0 my ($self,$table,$ptr_map,$old_taddr) = @_;
160 0 my $old = hr_thrutil_get_kinfo(HR_THR_AENCAP_PREFIX,
161 $self->[HR_KFLD_STRSCALAR], $ptr_map);
162 0 my ($old_encap_addr,$old_self_addr) = @$old;
163  
164 0 my $new_encap_addr = $self->[HR_KFLD_REFSCALAR]+0;
165  
166 0 $self->[HR_KFLD_STRSCALAR] =~ s/\Q$old_encap_addr\E/$new_encap_addr/gi;
167  
168 0 $table->dref_del_ptr($self->[HR_KFLD_REFSCALAR],
169 $table->attr_lookup, $self->[HR_KFLD_STRSCALAR]);
170  
171 0 my $attrhash = $self->[HR_KFLD_ATTRHASH];
172 0 foreach my $v (values %$attrhash) {
173 0 my $vhash = $table->reverse->{$v+0};
174 0 $table->dref_del_ptr($self->[HR_KFLD_REFSCALAR],
175 $vhash, $old_self_addr);
176 0 $table->dref_add_str($self->[HR_KFLD_REFSCALAR],
177 $vhash, $self + 0);
178 }
179 0 $self->SUPER::ithread_postdup($table,$ptr_map,$old_taddr);
180 }
181  
182 2 ▶use Carp qw(cluck);
Subroutine BEGIN: called CC=1 SCAR=0.0
183 0 ▶sub _encap_destroy_hook {
Subroutine _encap_destroy_hook: not called CC=2 SCAR=17.9
184 0 my ($encapped, $attr) = @_;
185 0 ▶ return if in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if &in_global_destruction() 0 0 0
186 0 $attr->DESTROY();
187 }
188  
189 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=3 SCAR=24.8
190 0 my $self = shift;
191 0 ▶ return if in_global_destruction;
Branch: 1 branch
BranchTrueFalseTotal
if &in_global_destruction() 0 0 0
192 0 $self->SUPER::DESTROY();
193 0 my $table = $self->[HR_KFLD_TABLEREF];
194
195 0 ▶ if($self->[HR_KFLD_REFSCALAR]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->[1]) 0 0 0
196 0 $table->dref_del_ptr(
197 $self->[HR_KFLD_REFSCALAR],
198 \&_encap_destroy_hook,
199 $self
200 );
201 0 $self->[HR_KFLD_REFSCALAR] = undef;
202 }
203 }
204 2 1;
« blib/lib/Ref/Store/PP.pm ↑ Summary blib/lib/Ref/Store/Feature/KeyTyped.pm »