SymlinkTree.pm

filter: Statementstmt 53.6% 134 / 250 Branchbran 38.5% 47 / 122 Conditioncond 36.9% 17 / 46 MC/DCmcdc 10.3% 3 / 29 Subroutinesub 60.9% 25 / 41 Podpod 0.0% 0 / 7 totaltotal 45.6% 226 / 495 CC 79 SCAR 38.3
CC
79
Cov
47%
SPLICE
210.0
STORE
93.1
DELETE
56.0
CRAP 46.2
« Indexer.pm ↑ Summary
1 package Tie::SymlinkTree;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Encode;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Tie::Indexer;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.1';
8  
9 {
10 package Tie::SymlinkTree::Array;
11 0 ▶ sub id { tied(@{shift()})->id(@_) }
Subroutine id: not called CC=1 SCAR=6.9
12 0 ▶ sub search { tied(@{shift()})->search(@_) }
Subroutine search: not called CC=1 SCAR=6.9
13 }
14  
15 {
16 1 package Tie::SymlinkTree::Hash;
17 0 ▶ sub id { tied(%{shift()})->id(@_) }
Subroutine id: not called CC=1 SCAR=6.9
18 0 ▶ sub search { tied(%{shift()})->search(@_) }
Subroutine search: not called CC=1 SCAR=6.9
19 }
20  
21 1 ▶sub encode_value {
Subroutine encode_value: called CC=3 SCAR=11.1
Pod undocumented
22 1 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 my $val = shift;
24 2 ▶ return undef if !defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 2 2
25 2 $val =~ s#\x{feff}#\x{feff}feff#g;
26 2 $val =~ s#\x{0000}#\x{feff}0000#g;
27 2 ▶ $val = "\x{feff}" if (length($val) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $val == 0 0 2 2
28 2 $val = encode_utf8($val);
29 2 return $val;
30 }
31  
32 3 ▶sub decode_value {
Subroutine decode_value: called CC=3 SCAR=11.0
Pod undocumented
33 1 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 3 my $val = shift;
35 3 ▶ return undef if !defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 1 2 3
36 2 $val = decode_utf8($val);
37 2 ▶ $val = "" if ($val eq "\x{feff}");
Branch: 1 branch
BranchTrueFalseTotal
if $val eq "\x{feff}" 0 2 2
38 2 $val =~ s#\x{feff}0000#\x{0000}#g;
39 2 $val =~ s#\x{feff}feff#\x{feff}#g;
40 2 return $val;
41 }
42  
43 10 ▶sub encode_key {
Subroutine encode_key: called CC=3 SCAR=11.0
Pod undocumented
44 1 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 10 my $key = shift;
46 10 ▶ $key = '' if !defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 10 10
47 10 $key =~ s#\x{feff}#\x{feff}feff#g;
48 10 $key =~ s#\x{0000}#\x{feff}0000#g;
49 10 $key =~ s#/#\x{feff}002f#g;
50 10 $key =~ s#^\.#\x{feff}002e#g;
51 10 ▶ $key = "\x{feff}" if (length($key) == 0);
Branch: 1 branch
BranchTrueFalseTotal
if length $key == 0 1 9 10
52 10 $key = encode_utf8($key);
53 10 return $key;
54 }
55  
56 3 ▶sub decode_key {
Subroutine decode_key: called CC=3 SCAR=11.0
Pod undocumented
57 1 ▶ no bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 3 my $key = shift;
59 3 ▶ return undef if !defined $key;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $key 0 3 3
60 3 $key = decode_utf8($key);
61 3 ▶ $key = "" if ($key eq "\x{feff}");
Branch: 1 branch
BranchTrueFalseTotal
if $key eq "\x{feff}" 0 3 3
62 3 $key =~ s#\x{feff}002e#.#g;
63 3 $key =~ s#\x{feff}002f#/#g;
64 3 $key =~ s#\x{feff}0000#\x{0000}#g;
65 3 $key =~ s#\x{feff}feff#\x{feff}#g;
66 3 return $key;
67 }
68  
69 0 ▶sub TIEARRAY {
Subroutine TIEARRAY: not called CC=2 SCAR=17.9
70 0 my ($package, $path) = @_;
71 0 ▶ my $self = (ref $package?$package:bless {}, $package);
Branch: 1 branch
BranchTrueFalseTotal
ref $package ? : 0 0 0
72 0 $self->{ARRAY} = 1;
73 0 return $self->TIEHASH($path);
74 }
75  
76 3 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=12 SCAR=28.8
77 3 my ($package, $path) = @_;
78 3 ▶ die "usage: tie(%hash, 'Tie::SymlinkTree', \$path)" if @_ != 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ != 2 0 3 3
79 3 ▶ my $self = (ref $package?$package:bless {}, $package);
Branch: 1 branch
BranchTrueFalseTotal
ref $package ? : 0 3 3
80
81 3 $path =~ s#/*$#/#;
82 3 ▶ die "$path is invalid" if $path =~ m#/\.\.?(/|$)#;
Branch: 1 branch
BranchTrueFalseTotal
if $path =~ m[/\.\.?(/|$)] 0 3 3
83 3 ▶ die "$path is not a directory" if -e $path and -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -e $path and -l $path 0 3 3
Condition66%2/3
-e $path and -l $path
!ll&&!rl&&r
210
MC/DC0%0/2
-e $path and -l $path
-e $path -l $path
Truth table66%2/3
A and B
A= -e $pathB= -l $path
ABresult
0X0
100
111
84 3 ▶ if (! -e $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $path) 2 1 3
85 2 ▶ mkdir $path or -d $path or die "Can't create $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $path or -d $path or die "Can't create ${path}: $!" 2 0 2
Condition33%1/3
mkdir $path or -d $path
l!l&&r!l&&!r
200
MC/DC0%0/2
mkdir $path or -d $path
mkdir $path -d $path
Truth table33%1/3
A or B
A= mkdir $pathB= -d $path
ABresult
1X1
011
000
86 2 ▶ symlink(".",$path.".array") if $self->{ARRAY};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ARRAY"} 0 2 2
87 } # race condition: assigning array and hash to one location at the same time
88 3 ▶ die "$path has wrong type" if (-e $path.".array" xor $self->{ARRAY});
Branch: 1 branch
BranchTrueFalseTotal
if -e $path . '.array' xor $self->{"ARRAY"} 0 3 3
Condition25%1/4
-e $path . '.array' xor $self->{"ARRAY"}
l&&rl&&!r!l&&r!l&&!r
0003
MC/DC0%0/2
-e $path . '.array' xor $self->{"ARRAY"}
-e $path . '.array' $self->{"ARRAY"}
Truth table25%1/4
A xor B
A= -e $path . '.array'B= $self->{"ARRAY"}
ABresult
110
101
011
000
89 3 $self->{PATH} = $path;
90
91 3 return $self;
92 }
93  
94 4 ▶sub FETCH {
Subroutine FETCH: called CC=3 SCAR=11.5
95 4 my ($self, $key) = @_;
96 4 $key = encode_key($key);
97 4 ▶ if (-d $self->{PATH}.$key) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $self->{'PATH'} . $key) { } 1 3 4
98 1 ▶ if (-e $self->{PATH}.$key."/.array") {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->{'PATH'} . $key . '/.array') { } 0 1 1
99 0 my @tmp;
100 0 tie @tmp, ref($self), $self->{PATH}.$key;
101 0 return bless \@tmp, 'Tie::SymlinkTree::Array';
102 } else {
103 1 my %tmp;
104 1 tie %tmp, ref($self), $self->{PATH}.$key;
105 1 return bless \%tmp, 'Tie::SymlinkTree::Hash';
106 }
107 } else {
108 3 return decode_value(readlink($self->{PATH}.$key));
109 }
110 }
111  
112  
113 3 ▶sub STORE {
Subroutine STORE: called CC=18 SCAR=45.3
114 3 my ($self, $key, $val, $recursion) = @_;
115 3 $key = encode_key($key);
116 3 ▶ die "no objects allowed" if ref($val) && ref($val) ne 'HASH' && ref($val) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $val and ref $val ne "HASH" and ref $val ne "ARRAY" 0 3 3
Condition50%3/6
ref $val and ref $val ne "HASH" and ref $val ne "ARRAY"
!ll&&!rl&&r
300
ref $val and ref $val ne "HASH"
!ll&&!rl&&r
210
MC/DC0%0/3
ref $val and ref $val ne "HASH" and ref $val ne "ARRAY"
ref $val ref $val ne "HASH" ref $val ne "ARRAY"
Truth table50%2/4
A and B and C
A= ref $valB= ref $val ne "HASH"C= ref $val ne "ARRAY"
ABCresult
0XX0
10X0
1100
1111
117 3 Tie::Indexer::deindex_node($self,$val,$key);
118 3 ▶ if (!defined($val)) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $val) { } 0 3 3
elsif (not ref $val) { } 2 1 3
elsif (ref $val eq 'ARRAY' or ref $val eq 'Tie::SymlinkTree::Array') { } 0 1 1
119 0 ▶ open(my $fh,'>',$self->{PATH}.".$$~".$key) || die "Error while storing: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->{"PATH"} . ".${$}~" . $key or die "Error while storing: $!" 0 0 0
120 0 close($fh);
121 0 ▶ rename($self->{PATH}.".$$~".$key,$self->{PATH}.$key) or $recursion or do {$self->DELETE($_[1]);$self->STORE($_[1],$val,1);};
Branch: 1 branch
BranchTrueFalseTotal
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion or do { $self->DELETE($_[1]); $self->STORE($_[1], $val, 1) } 0 0 0
Condition0%0/3
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion
l!l&&r!l&&!r
000
MC/DC0%0/2
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key $recursion
Truth table0%0/3
A or B
A= rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $keyB= $recursion
ABresult
1X1
011
000
122 } elsif (!ref($val)) {
123 2 ▶ symlink(encode_value($val),$self->{PATH}.".$$~".$key) || die "Error while storing: $!";
Branch: 1 branch
BranchTrueFalseTotal
symlink encode_value($val), $self->{"PATH"} . ".${$}~" . $key or die "Error while storing: $!" 2 0 2
124 0 ▶ rename($self->{PATH}.".$$~".$key,$self->{PATH}.$key) or $recursion or do {$self->DELETE($_[1]);$self->STORE($_[1],$val,1);};
Branch: 1 branch
BranchTrueFalseTotal
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion or do { $self->DELETE($_[1]); $self->STORE($_[1], $val, 1) } 2 0 2
Condition33%1/3
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion
l!l&&r!l&&!r
200
MC/DC0%0/2
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key or $recursion
rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $key $recursion
Truth table33%1/3
A or B
A= rename $self->{"PATH"} . ".${$}~" . $key, $self->{"PATH"} . $keyB= $recursion
ABresult
1X1
011
000
125 ▶ } elsif (ref($val) eq 'ARRAY' || ref($val) eq 'Tie::SymlinkTree::Array') {
Condition33%1/3
ref $val eq "ARRAY" or ref $val eq "Tie::SymlinkTree::Array"
l!l&&r!l&&!r
001
MC/DC0%0/2
ref $val eq "ARRAY" or ref $val eq "Tie::SymlinkTree::Array"
ref $val eq "ARRAY" ref $val eq "Tie::SymlinkTree::Array"
Truth table33%1/3
A or B
A= ref $val eq "ARRAY"B= ref $val eq "Tie::SymlinkTree::Array"
ABresult
1X1
011
000
126 0 my @tmp = @$val;
127 0 eval { tie @$val, ref($self), $self->{PATH}.$key; };
128 0 ▶ if (!$recursion && $@) {$self->DELETE($key);$self->STORE($_[1],$val,1);}
Branch: 1 branch
BranchTrueFalseTotal
if (not $recursion and $@) 0 0 0
Condition0%0/3
not $recursion and $@
!ll&&!rl&&r
000
MC/DC0%0/2
not $recursion and $@
not $recursion $@
Truth table0%0/3
not(A) and B
A= not $recursionB= $@
ABresult
0X0
100
111
129 0 @$val = @tmp;
130 } else {
131 1 my %tmp = %$val;
132 1 eval { tie %$val, ref($self), $self->{PATH}.$key; };
133 0 ▶ if (!$recursion && $@) {$self->DELETE($key);$self->STORE($_[1],$val,1);}
Branch: 1 branch
BranchTrueFalseTotal
if (not $recursion and $@) 0 1 1
Condition33%1/3
not $recursion and $@
!ll&&!rl&&r
010
MC/DC0%0/2
not $recursion and $@
not $recursion $@
Truth table33%1/3
not(A) and B
A= not $recursionB= $@
ABresult
0X0
100
111
134 1 %$val = %tmp;
135 }
136 3 Tie::Indexer::index_node($self,$val,$key);
137 }
138  
139  
140 0 ▶sub DELETE {
Subroutine DELETE: not called CC=7 SCAR=40.3
141 0 my ($self, $key) = @_;
142 0 $key = encode_key($key);
143 0 my $val = $self->FETCH($key);
144 0 Tie::Indexer::deindex_node($self,$val,$key);
145 0 ▶ if (UNIVERSAL::isa($val,'ARRAY')) {
Branch: 2 branches
BranchTrueFalseTotal
if (UNIVERSAL::isa($val, 'ARRAY')) { } 0 0 0
elsif (UNIVERSAL::isa($val, 'HASH')) { } 0 0 0
146 0 my @tmp = @$val;
147 0 for my $i (0..$#tmp) {
148 0 $tmp[$i] = delete $val->[$i];
149 }
150 0 $val = \@tmp;
151 0 unlink $self->{PATH}.$key."/.array";
152 } elsif (UNIVERSAL::isa($val,'HASH')) {
153 0 my %tmp = %$val;
154 0 for my $k (keys %tmp) {
155 0 $tmp{$k} = delete $val->{$k};
156 }
157 0 $val = \%tmp;
158 } else {
159 0 ▶ if (substr($self->id,0,1) ne '.' && -d $self->{PATH}."../.index-$key") {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($self->id, 0, 1) ne "." and -d $self->{"PATH"} . "../.index-$key") 0 0 0
Condition0%0/3
substr($self->id, 0, 1) ne "." and -d $self->{"PATH"} . "../.index-$key"
!ll&&!rl&&r
000
MC/DC0%0/2
substr($self->id, 0, 1) ne "." and -d $self->{"PATH"} . "../.index-$key"
substr($self->id, 0, 1) ne "." -d $self->{"PATH"} . "../.index-$key"
Truth table0%0/3
A and B
A= substr($self->id, 0, 1) ne "."B= -d $self->{"PATH"} . "../.index-$key"
ABresult
0X0
100
111
160 0 my $path = $self->{PATH};
161 0 $path =~ s#[^/]*/$##;
162 0 tie my %index, ref($self), $path.".index-$key/";
163 0 delete $index{$val}{$self->id};
164 }
165 }
166 0 unlink $self->{PATH}.$key;
167 0 rmdir $self->{PATH}.$key;
168 0 return $val;
169 }
170  
171 2 ▶sub _clear {
Subroutine _clear: called CC=6 SCAR=18.3
172 2 my ($dir) = @_;
173 2 ▶ die "empty directory" unless $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless $dir 0 2 2
174 2 my $dh;
175 2 opendir($dh,$dir);
176 2 ▶ while (defined (my $subdir = readdir($dh))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $subdir = readdir $dh)) 6 2 8
177 6 ▶ next if ($subdir eq '.' || $subdir eq '..');
Branch: 1 branch
BranchTrueFalseTotal
if $subdir eq "." or $subdir eq ".." 4 2 6
Condition100%3/3
$subdir eq "." or $subdir eq ".."
l!l&&r!l&&!r
222
MC/DC100%2/2
$subdir eq "." or $subdir eq ".."
$subdir eq "." $subdir eq ".."
Truth table100%3/3
A or B
A= $subdir eq "."B= $subdir eq ".."
ABresult
1X1
011
000
178 2 ▶ unlink($dir.$subdir) or do {
Branch: 1 branch
BranchTrueFalseTotal
unlink $dir . $subdir or do { _clear($dir . $subdir . '/'); rmdir $dir . $subdir } 2 0 2
179 0 _clear($dir.$subdir."/");
180 0 rmdir($dir.$subdir);
181 }
182 }
183 2 closedir($dh);
184 }
185  
186 2 ▶sub CLEAR {
Subroutine CLEAR: called CC=1 SCAR=0.0
187 2 my ($self) = @_;
188 2 $self->lock;
189 2 _clear($self->{PATH});
190 2 $self->unlock;
191 }
192  
193 3 ▶sub EXISTS {
Subroutine EXISTS: called CC=2 SCAR=7.0
194 3 my ($self, $key) = @_;
195 3 $key = encode_key($key);
196 3 ▶ return -e $self->{PATH}.$key || -l $self->{PATH}.$key;
Condition66%2/3
-e $self->{'PATH'} . $key || -l $self->{'PATH'} . $key
l!l&&r!l&&!r
012
MC/DC50%1/2
-e $self->{'PATH'} . $key || -l $self->{'PATH'} . $key
-e $self->{'PATH'} . $key -l $self->{'PATH'} . $key
Truth table66%2/3
A || B
A= -e $self->{'PATH'} . $keyB= -l $self->{'PATH'} . $key
ABresult
1X1
011
000
197 }
198  
199  
200 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
201 }
202  
203  
204 2 ▶sub FIRSTKEY {
Subroutine FIRSTKEY: called CC=3 SCAR=11.0
205 2 my ($self) = @_;
206
207 2 my $dh;
208 2 opendir($dh,$self->{PATH});
209 2 $self->{HANDLE} = $dh;
210 2 my $entry;
211 2 ▶ while (defined ($entry = readdir($self->{HANDLE}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($entry = readdir $self->{"HANDLE"})) 5 1 6
212 5 ▶ return decode_key($entry) unless (substr($entry,0,1) eq '.');
Branch: 1 branch
BranchTrueFalseTotal
unless substr($entry, 0, 1) eq "." 1 4 5
213 }
214 1 return;
215 }
216  
217  
218 3 ▶sub NEXTKEY {
Subroutine NEXTKEY: called CC=3 SCAR=11.0
219 3 my ($self) = @_;
220 3 my $entry;
221 3 ▶ while (defined ($entry = readdir($self->{HANDLE}))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($entry = readdir $self->{"HANDLE"})) 2 1 3
222 2 ▶ return decode_key($entry) unless (substr($entry,0,1) eq '.');
Branch: 1 branch
BranchTrueFalseTotal
unless substr($entry, 0, 1) eq "." 2 0 2
223 }
224 1 return;
225 }
226  
227 0 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: not called CC=4 SCAR=30.0
228 0 my ($self) = @_;
229 0 my $dh;
230 0 opendir($dh,$self->{PATH});
231 0 my $max = -1;
232 0 my $entry;
233 0 ▶ while (defined ($entry = readdir($dh))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($entry = readdir $dh)) 0 0 0
234 0 ▶ next if substr($entry,0,1) eq '.';
Branch: 1 branch
BranchTrueFalseTotal
if substr($entry, 0, 1) eq "." 0 0 0
235 0 ▶ $max = int($entry) if $entry > $max;
Branch: 1 branch
BranchTrueFalseTotal
if $entry > $max 0 0 0
236 }
237 0 return $max+1;
238 }
239  
240 0 ▶sub STORESIZE {
Subroutine STORESIZE: not called CC=2 SCAR=17.9
241 0 my ($self, $size) = @_;
242 0 $self->lock;
243 0 $size = int($size);
244 0 ▶ while (-e $self->{PATH}.$size) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->{"PATH"} . $size) 0 0 0
245 0 $self->DELETE($size);
246 0 $size++;
247 }
248 0 $self->unlock;
249 }
250  
251 0 ▶sub EXTEND { }
Subroutine EXTEND: not called CC=1 SCAR=0.0
252 0 ▶sub UNSHIFT { scalar shift->SPLICE(0,0,@_) }
Subroutine UNSHIFT: not called CC=1 SCAR=6.9
253 0 ▶sub SHIFT { shift->SPLICE(0,1) }
Subroutine SHIFT: not called CC=1 SCAR=6.9
254  
255 0 ▶sub PUSH {
Subroutine PUSH: not called CC=1 SCAR=6.9
256 0 my ($self, $value) = @_;
257 0 $self->lock;
258 0 my $key = $self->FETCHSIZE;
259 0 $self->STORE($key,$value);
260 0 $self->unlock;
261 0 return $key+1;
262 }
263  
264 0 ▶sub POP {
Subroutine POP: not called CC=1 SCAR=6.9
265 0 my ($self, $value) = @_;
266 0 $self->lock;
267 0 my $key = $self->FETCHSIZE-1;
268 0 my $val = $self->FETCH($key);
269 0 $self->DELETE($key);
270 0 $self->unlock;
271 0 return $val;
272 }
273  
274 0 ▶sub SPLICE {
Subroutine SPLICE: not called CC=14 SCAR=53.5
275 0 my $self = shift;
276 0 $self->lock;
277 0 my $size = $self->FETCHSIZE;
278 0 ▶ my $off = (@_) ? shift : 0;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
279 0 ▶ $off += $size if ($off < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $off < 0 0 0 0
280 0 ▶ my $len = (@_) ? shift : $size - $off;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
281 0 ▶ $len += $size - $off if $len < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $len < 0 0 0 0
282 0 my @result;
283 0 ▶ for (my $i = 0; $i < $len; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
284 0 push(@result,$self->FETCH($off+$i));
285 }
286 0 ▶ $off = $size if $off > $size;
Branch: 1 branch
BranchTrueFalseTotal
if $off > $size 0 0 0
287 0 ▶ $len -= $off + $len - $size if $off + $len > $size;
Branch: 1 branch
BranchTrueFalseTotal
if $off + $len > $size 0 0 0
288 0 ▶ if (@_ > $len) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ > $len) { } 0 0 0
elsif (@_ < $len) { } 0 0 0
289 # Move items up to make room
290 0 my $d = @_ - $len;
291 0 my $e = $off+$len;
292 0 ▶ for (my $i=$size-1; $i >= $e; $i--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i >= $e) 0 0 0
293 0 rename($self->{PATH}.$i,$self->{PATH}.($i+$d));
294 }
295 }
296 elsif (@_ < $len) {
297 # Move items down to close the gap
298 0 my $d = $len - @_;
299 0 my $e = $off+$len;
300 0 ▶ for (my $i=$off+$len; $i < $size; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $size) 0 0 0
301 0 rename($self->{PATH}.$i,$self->{PATH}.($i-$d));
302 }
303 }
304 0 ▶ for (my $i=0; $i < @_; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 0 0 0
305 0 $self->STORE($off+$i,$_[$i]);
306 }
307 0 $self->unlock;
308 0 ▶ return wantarray ? @result : pop @result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
309 }
310  
311 2 ▶sub lock {
Subroutine lock: called CC=4 SCAR=16.4
Pod undocumented
312 2 my ($self) = @_;
313 2 ▶ if (!$self->{locked}++) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"locked"}++) 2 0 2
314 2 my $i = 0;
315 2 ▶ while (!symlink($$,$self->{PATH}.".lock") && $i++ < 40) {
Branch: 1 branch
BranchTrueFalseTotal
if (not symlink($$, $self->{"PATH"} . '.lock') and $i++ < 40) 0 2 2
Condition33%1/3
not symlink($$, $self->{"PATH"} . '.lock') and $i++ < 40
!ll&&!rl&&r
200
MC/DC0%0/2
not symlink($$, $self->{"PATH"} . '.lock') and $i++ < 40
not symlink($$, $self->{"PATH"} . '.lock') $i++ < 40
Truth table33%1/3
not(A) and B
A= not symlink($$, $self->{"PATH"} . '.lock')B= $i++ < 40
ABresult
0X0
100
111
316 0 select('','','',.25);
317 }
318 }
319 }
320  
321 2 ▶sub unlock {
Subroutine unlock: called CC=2 SCAR=7.1
Pod undocumented
322 2 my ($self) = @_;
323 2 ▶ if (!--$self->{locked}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not --$self->{"locked"}) 2 0 2
324 2 unlink($self->{PATH}.".lock");
325 }
326 }
327  
328 0 ▶sub id {
Subroutine id: not called CC=1 SCAR=6.9
Pod undocumented
329 0 my ($self) = @_;
330 0 return ($self->{PATH} =~ m{/([^/]+)/$})[0];
331 }
332  
333 6 ▶sub _get_index {
Subroutine _get_index: called CC=3 SCAR=15.1
334 6 my ($tie, $create) = @_;
335 6 ▶ return undef if (!$create && ! -d $tie->{PATH}.".index/");
Branch: 1 branch
BranchTrueFalseTotal
unless $create or -d $tie->{"PATH"} . '.index/' 6 0 6
Condition33%1/3
$create or -d $tie->{"PATH"} . '.index/'
l!l&&r!l&&!r
006
MC/DC0%0/2
$create or -d $tie->{"PATH"} . '.index/'
$create -d $tie->{"PATH"} . '.index/'
Truth table33%1/3
A or B
A= $createB= -d $tie->{"PATH"} . '.index/'
ABresult
1X1
011
000
336 0 tie my %index, ref($tie), $tie->{PATH}.".index/";
337 0 return \%index;
338 }
339  
340 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
341 1 *search = \&Tie::Indexer::search;
342 }
343  
344 1 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
345 1 "Dahut!";
346 __END__
« Indexer.pm ↑ Summary