Shm/Tied/HASH.pm

filter: Statementstmt 87.6% 78 / 89 Branchbran 63.3% 19 / 30 Conditioncond 55.5% 5 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 86.6% 13 / 15 Podpod 100% 1 / 1 totaltotal 77.3% 116 / 150 CC 21 SCAR 13.7
CC
21
Cov
80%
FIRSTKEY
6.0
EXISTS
6.0
SCALAR
6.0
CRAP 3.9
« Shm.pm ↑ Summary Shm/Tied/SCALAR.pm »
1 package IPC::Shm::Tied::HASH;
2 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 #
7 # Copyright (c) 2014 by Kevin Cody-Little <kcody@cpan.org>
8 #
9 # This code may be modified or redistributed under the terms
10 # of either the Artistic or GNU General Public licenses, at
11 # the modifier or redistributor's discretion.
12 #
13  
14 =head1 NAME
15  
16 IPC::Shm::Tied::HASH
17  
18 =head1 SYNOPSIS
19  
20 This class is part of the IPC::Shm implementation. You should not be using it directly.
21  
22 =cut
23  
24 # Loaded from IPC::Shm::Tied, so don't reload it
25 6 ▶use vars qw( @ISA );
Subroutine BEGIN: called CC=1 SCAR=0.0
26 6 @ISA = qw( IPC::Shm::Tied );
27  
28 6 ▶use IPC::Shm::Make;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 29 ▶sub EMPTY {
Subroutine EMPTY: called CC=1 SCAR=0.0
Pod documented
32 29 return {};
33 }
34  
35 24 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
36 24 my ( $class, $this ) = @_;
37  
38 24 return bless $this, $class;
39 }
40  
41 66 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.0
42 66 my ( $this, $key ) = @_;
43  
44 66 my $locked = $this->readlock;
45 66 $this->fetch;
46 66 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 66 0 66
47  
48 66 my $rv = $this->vcache->{$key};
49  
50 66 ▶ return ref( $rv ) ? getback( $rv ) : $rv;
Branch: 1 branch
BranchTrueFalseTotal
ref $rv ? : 1 65 66
51 }
52  
53 46 ▶sub STORE {
Subroutine STORE: called CC=4 SCAR=13.9
54 46 my ( $this, $key, $value ) = @_;
55  
56 46 makeshm( \$value );
57  
58 46 my $locked = $this->writelock;
59  
60 46 $this->fetch;
61 46 my $vcache = $this->vcache;
62 46 my $oldval = $vcache->{$key};
63  
64 46 $vcache->{$key} = $value;
65 46 $this->flush;
66  
67 46 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 42 4 46
68  
69 46 ▶ $this->standin_discard( $oldval ) if ( $oldval and ref( $oldval ) );
Branch: 1 branch
BranchTrueFalseTotal
if $oldval and ref $oldval 0 46 46
Condition66%2/3
$oldval and ref $oldval
!ll&&!rl&&r
4420
MC/DC0%0/2
$oldval and ref $oldval
$oldval ref $oldval
Truth table66%2/3
A and B
A= $oldvalB= ref $oldval
ABresult
0X0
100
111
70  
71 46 return $value;
72 }
73  
74 11 ▶sub DELETE {
Subroutine DELETE: called CC=4 SCAR=14.1
75 11 my ( $this, $key ) = @_;
76  
77 11 my $locked = $this->writelock;
78  
79 11 $this->fetch;
80 11 my $vcache = $this->vcache;
81 11 my $oldval = $vcache->{$key};
82  
83 11 delete $vcache->{$key};
84 11 $this->flush;
85  
86 11 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 11 0 11
87  
88 11 ▶ $this->standin_discard( $oldval ) if ( $oldval and ref( $oldval ) );
Branch: 1 branch
BranchTrueFalseTotal
if $oldval and ref $oldval 0 11 11
Condition66%2/3
$oldval and ref $oldval
!ll&&!rl&&r
1100
MC/DC0%0/2
$oldval and ref $oldval
$oldval ref $oldval
Truth table66%2/3
A and B
A= $oldvalB= ref $oldval
ABresult
0X0
100
111
89  
90 11 return 1;
91 }
92  
93 10 ▶sub CLEAR {
Subroutine CLEAR: called CC=5 SCAR=16.3
94 10 my ( $this ) = @_;
95  
96 10 my $locked = $this->writelock;
97  
98 10 $this->fetch;
99 10 my $vcache = $this->vcache;
100  
101 10 $this->vcache( $this->EMPTY );
102 10 $this->flush;
103  
104 10 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 3 7 10
105  
106 10 foreach my $oldval ( values %{$vcache} ) {
107 6 ▶ $this->standin_discard( $oldval ) if ( $oldval and ref( $oldval ) );
Branch: 1 branch
BranchTrueFalseTotal
if $oldval and ref $oldval 0 6 6
Condition33%1/3
$oldval and ref $oldval
!ll&&!rl&&r
060
MC/DC0%0/2
$oldval and ref $oldval
$oldval ref $oldval
Truth table33%1/3
A and B
A= $oldvalB= ref $oldval
ABresult
0X0
100
111
108 }
109  
110 10 return 1;
111 }
112  
113 0 ▶sub EXISTS {
Subroutine EXISTS: not called CC=2 SCAR=17.9
114 0 my ( $this, $key ) = @_;
115  
116 0 my $locked = $this->readlock;
117 0 $this->fetch;
118 0 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 0 0 0
119  
120 0 return exists $this->vcache->{$key};
121 }
122  
123 4 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=6 SCAR=18.0
124 4 my ( $this ) = @_;
125  
126 4 my $locked = $this->readlock;
127 4 $this->fetch;
128 4 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 4 0 4
129  
130 4 my ( %index, $first, $last );
131 4 foreach my $key ( keys %{$this->vcache} ) {
132  
133 9 ▶ unless ( defined $first ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $first) 3 6 9
134 3 $first = $last = $key;
135 3 next;
136 }
137  
138 6 $index{$last} = $key;
139 6 $last = $key;
140  
141 }
142  
143 4 ▶ return unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 1 3 4
144  
145 3 ▶ $index{$last} = undef if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 3 0 3
146  
147 3 $this->{icache} = \%index;
148  
149 3 return $first;
150 }
151  
152 9 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=2 SCAR=6.9
153 9 my ( $this, $lastkey ) = @_;
154  
155 9 my $icache = $this->{icache};
156  
157 9 ▶ return unless defined $icache->{$lastkey};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $icache->{$lastkey} 3 6 9
158  
159 6 return $icache->{$lastkey};
160 }
161  
162 0 ▶sub SCALAR {
Subroutine SCALAR: not called CC=2 SCAR=17.9
163 0 my ( $this ) = @_;
164  
165 0 my $locked = $this->readlock;
166 0 $this->fetch;
167 0 ▶ $this->unlock if $locked;
Branch: 1 branch
BranchTrueFalseTotal
if $locked 0 0 0
168  
169 0 return scalar %{$this->vcache};
170 }
171  
172  
173  
174 =head1 AUTHOR
175  
176 Kevin Cody-Little <kcody@cpan.org>
177  
178 =cut
179  
180 6 1;
« Shm.pm ↑ Summary Shm/Tied/SCALAR.pm »