| 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
| |||||||||||||||||||||||||||||
| 30 | 7 | ▶ | open my $fh, $mode, $file or croak "Couldn't open $file: $!\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 19 | ▶ | if ($self->EOF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 70 | : $length; | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 14 | ▶ | seek $self->{handles}[$f], $pos, 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 14 | $self->{pos} += $this_read; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 14 | ▶ | if ( $b < $this_read ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 5 | my $buf = ""; | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 5 | ▶ | if (not defined $/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
Condition66%2/3
index($buf, $/) == -1 and not $self->EOF
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
| |||||||||||||||||||||||||||||
| 108 | 3 | $self->READ($buf, 1024, length $buf); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | ▶ | if (index($buf, $/) != -1) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
MC/DC100%1/1
$offset ||= 0
$offset
Truth table100%2/2
A
A= $offset
| |||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 3 | ▶ | if ($self->EOF) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 148 | : $length; | ||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 3 | ▶ | seek $self->{handles}[$f], $pos, 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | or croak "Couldn't seek $self->{files}[$f]"; | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 3 | ▶ | print { $self->{handles}[$f] } substr($_[1], $offset, $this_write) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 154 | or return 0; | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 3 | $self->{pos} += $this_write; | |||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 3 | ▶ | if ($this_write == $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 185 | 11 | ▶ | $whence == 1 and $pos += $offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 11 | ▶ | $whence == 2 and $pos = $self->{size} + $offset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 11 | ▶ | return 0 if $pos < 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||