blib/lib/File/LinearRaid.pm

filter: Statementstmt 90.8% 99 / 109 Branchbran 74.0% 37 / 50 Conditioncond 85.7% 6 / 7 MC/DCmcdc 75.0% 3 / 4 Subroutinesub 83.3% 15 / 18 Podpod 0.0% 0 / 1 totaltotal 84.6% 160 / 189 CC 30 SCAR 16.9
CC
30
Cov
86%
READ
9.0
WRITE
8.1
READLINE
7.3
CRAP 5.4
↑ Summary
1 package File::LinearRaid;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Symbol;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 $VERSION = '0.11_1';
10  
11 sub new {
12 3 ▶ my $pkg = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
13
14 3 my $sym = gensym;
15 3 tie *$sym, $pkg, @_;
16  
17 3 return bless $sym, $pkg;
18 }
19  
20 sub TIEHANDLE {
21 3 ▶ my $pkg = shift;
Subroutine TIEHANDLE: called CC=3 SCAR=11.0
22 3 my $mode = shift;
23
24 3 my @files;
25 my @sizes;
26 3 my @handles;
27 3 my $length = 0;
28
29 3 ▶ while (my ($file, $size) = splice @_, 0, 2) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = splice(@_, 0, 2)) 7 3 10
30 7 ▶ open my $fh, $mode, $file or croak "Couldn't open $file: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, $mode, $file or croak("Couldn't open ${file}: $!\n") 0 7 7
31
32 7 push @handles, $fh;
33 7 push @files, $file;
34 7 push @sizes, $size;
35 7 $length += $size;
36 }
37
38 bless {
39 3 pos => 0,
40 files => \@files,
41 sizes => \@sizes,
42 handles => \@handles,
43 length => $length,
44 last_file => $#files
45 }, $pkg;
46 }
47  
48 sub READ {
49 19 ▶ my ($self, undef, $length, $offset) = @_;
Subroutine READ: called CC=9 SCAR=22.0
50
51 19 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
910
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
52
53 19 ▶ if ($self->EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->EOF) 5 14 19
54 5 substr($_[1], $offset) = "";
55 5 return 0;
56 }
57
58 14 my $pos = $self->{pos};
59  
60 14 my $f = 0;
61 14 ▶ while ($pos >= $self->{sizes}[$f]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= $self->{"sizes"}[$f]) 9 14 23
62 9 $pos -= $self->{sizes}[$f];
63 9 $f++;
64 }
65
66 14 my $b;
67
68 my $this_read = ($pos + $length > $self->{sizes}[$f])
69 14 ▶ ? $self->{sizes}[$f] - $pos
Branch: 1 branch
BranchTrueFalseTotal
$pos + $length > $self->{'sizes'}[$f] ? : 9 5 14
70 : $length;
71
72 14 ▶ seek $self->{handles}[$f], $pos, 0
Branch: 1 branch
BranchTrueFalseTotal
seek $self->{"handles"}[$f], $pos, 0 or croak(qq[Couldn't seek $self->{"files"}[$f]]) 0 14 14
73 or croak "Couldn't seek $self->{files}[$f]";
74
75 14 $b = read $self->{handles}[$f], $_[1], $this_read, $offset;
76  
77 14 ▶ defined $b or croak "Error reading from $self->{files}[$f]: $!";
Branch: 1 branch
BranchTrueFalseTotal
defined $b or croak(qq[Error reading from $self->{"files"}[$f]: $!]) 0 14 14
78  
79 14 $self->{pos} += $this_read;
80
81 14 ▶ if ( $b < $this_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($b < $this_read) 2 12 14
82 # pad out rest of chunk with nulls
83 2 substr($_[1], $offset + $b) = "\x0" x ($this_read - $b);
84 }
85  
86 14 ▶ if ($this_read == $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_read == $length) { } 5 9 14
87 5 return $length;
88 } else {
89 9 return $this_read + $self->READ($_[1], $length - $this_read, $offset + $this_read);
90 }
91 }
92  
93 sub READLINE {
94 6 ▶ my $self = shift;
Subroutine READLINE: called CC=7 SCAR=19.9
95 6 my $oldpos = $self->{pos};
96  
97 6 ▶ return undef if $self->EOF;
Branch: 1 branch
BranchTrueFalseTotal
if $self->EOF 1 5 6
98
99 5 my $buf = "";
100
101 5 ▶ if (not defined $/) {
Branch: 2 branches
BranchTrueFalseTotal
if (not defined $/) { } 2 3 5
elsif (ref $/) { } 0 3 3
102 2 $self->READ($buf, $self->{length} - $oldpos);
103 } elsif (ref $/) {
104 0 $self->READ($buf, ${$/});
105 } else {
106
107 3 ▶ while (index($buf, $/) == -1 and not $self->EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($buf, $/) == -1 and not $self->EOF) 3 3 6
Condition66%2/3
index($buf, $/) == -1 and not $self->EOF
!ll&&!rl&&r
303
MC/DC50%1/2
index($buf, $/) == -1 and not $self->EOF
index($buf, $/) == -1 not $self->EOF
Truth table66%2/3
A and not(B)
A= index($buf, $/) == -1B= not $self->EOF
ABresult
0X0
100
111
108 3 $self->READ($buf, 1024, length $buf);
109 }
110
111 3 ▶ if (index($buf, $/) != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($buf, $/) != -1) 3 0 3
112 3 substr($buf, index($buf, $/) + length($/)) = "";
113 3 $self->{pos} = $oldpos + length $buf;
114 }
115 }
116
117 5 return $buf;
118
119 }
120  
121 sub GETC {
122 0 ▶ my $c;
Subroutine GETC: not called CC=1 SCAR=6.9
123 0 $_[0]->READ($c, 1);
124 0 return $c;
125 }
126  
127  
128  
129 sub WRITE {
130 3 ▶ my ($self, undef, $length, $offset) = @_;
Subroutine WRITE: called CC=8 SCAR=21.0
131
132 3 ▶ $offset ||= 0;
Condition100%2/2
$offset ||= 0
l!l
12
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
Aresult
11
00
133
134 3 ▶ if ($self->EOF) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->EOF) 0 3 3
135 0 return 0;
136 }
137
138 3 my $pos = $self->{pos};
139  
140 3 my $f = 0;
141 3 ▶ while ($pos >= $self->{sizes}[$f]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pos >= $self->{"sizes"}[$f]) 1 3 4
142 1 $pos -= $self->{sizes}[$f];
143 1 $f++;
144 }
145
146 my $this_write = ($pos + $length > $self->{sizes}[$f])
147 3 ▶ ? $self->{sizes}[$f] - $pos
Branch: 1 branch
BranchTrueFalseTotal
$pos + $length > $self->{'sizes'}[$f] ? : 1 2 3
148 : $length;
149
150 3 ▶ seek $self->{handles}[$f], $pos, 0
Branch: 1 branch
BranchTrueFalseTotal
seek $self->{"handles"}[$f], $pos, 0 or croak(qq[Couldn't seek $self->{"files"}[$f]]) 0 3 3
151 or croak "Couldn't seek $self->{files}[$f]";
152
153 3 ▶ print { $self->{handles}[$f] } substr($_[1], $offset, $this_write)
Branch: 1 branch
BranchTrueFalseTotal
print {$self->{"handles"}[$f];} substr($_[1], $offset, $this_write) or return 0 0 3 3
154 or return 0;
155  
156 3 $self->{pos} += $this_write;
157  
158 3 ▶ if ($this_write == $length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this_write == $length) { } 2 1 3
159 2 return 1;
160 } else {
161 1 return $self->WRITE($_[1], $length - $this_write, $offset + $this_write);
162 }
163 }
164  
165 sub PRINT {
166 2 ▶ my $self = shift;
Subroutine PRINT: called CC=2 SCAR=7.1
167 2 ▶ my $buf = join +(defined $, ? $, : "") => @_;
Branch: 1 branch
BranchTrueFalseTotal
defined $, ? : 0 2 2
168 2 $self->WRITE($buf, length($buf), 0);
169 }
170  
171 sub PRINTF {
172 0 ▶ my $self = shift;
Subroutine PRINTF: not called CC=1 SCAR=6.9
173 0 my $fmt = shift;
174 0 $self->PRINT( sprintf $fmt, @_ );
175 }
176  
177  
178  
179 sub SEEK {
180 11 ▶ my ($self, $offset, $whence) = @_;
Subroutine SEEK: called CC=5 SCAR=16.8
181
182 11 my $pos = $self->{pos};
183
184 11 ▶ $whence == 0 and $pos = $offset;
Branch: 1 branch
BranchTrueFalseTotal
$whence == 0 and $pos = $offset 11 0 11
185 11 ▶ $whence == 1 and $pos += $offset;
Branch: 1 branch
BranchTrueFalseTotal
$whence == 1 and $pos += $offset 0 11 11
186 11 ▶ $whence == 2 and $pos = $self->{size} + $offset;
Branch: 1 branch
BranchTrueFalseTotal
$whence == 2 and $pos = $self->{"size"} + $offset 0 11 11
187  
188 11 ▶ return 0 if $pos < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 11 11
189 11 $self->{pos} = $pos;
190 11 return 1;
191 }
192  
193 sub TELL {
194 13 ▶ $_[0]->{pos};
Subroutine TELL: called CC=1 SCAR=0.0
195 }
196  
197 sub EOF {
198 32 ▶ my $self = shift;
Subroutine EOF: called CC=1 SCAR=0.0
199 32 return $self->{pos} == $self->{length};
200 }
201  
202 sub CLOSE {
203 1 ▶ close $_ for @{ $_[0]->{handles} };
Subroutine CLOSE: called CC=2 SCAR=6.9
204 1 $_[0] = undef;
205 }
206  
207 sub OPEN {
208 0 ▶ croak "OPEN Unimplemented";
Subroutine OPEN: not called CC=1 SCAR=6.9
209 }
210 1 1;
211  
212 __END__
↑ Summary