lib/Array/FileReader.pm

filter: Statementstmt 37.0% 20 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 50.0% 5 / 10 Podpod n/a totaltotal 31.6% 25 / 79 CC 7 SCAR 17.2
CC
7
Cov
30%
_getupto
12.0
TIEARRAY
6.0
FETCH
6.0
CRAP 5.6
↑ Summary
1 package Array::FileReader;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 require Exporter;
7 2 require DynaLoader;
8 2 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Tie::Array;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 @ISA = qw(Tie::Array DynaLoader);
13  
14 2 $VERSION = '0.03';
15  
16 # bootstrap Array::FileReader $VERSION;
17  
18 0 ▶sub TIEARRAY {
Subroutine TIEARRAY: not called CC=2 SCAR=17.9
19 0 my ($class, $file) = @_;
20 0 my $fh = new IO::File;
21 0 ▶ $fh->open($file) or croak "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
$fh->open($file) or croak("Can't open ${file}: $!") 0 0 0
22 0 my $self = {
23 fh => $fh,
24 offsets => [0]
25 };
26 0 bless $self, $class;
27 }
28  
29 0 ▶sub FETCH {
Subroutine FETCH: not called CC=2 SCAR=17.9
30 0 my ($self, $elem) = @_;
31 0 ▶ if ($elem > $#{$self->{offsets}} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($elem > $#{$$self{"offsets"};}) 0 0 0
32 0 &_getupto;
33 }
34 0 goto &_getit;
35 }
36  
37 0 ▶sub FETCHSIZE {
Subroutine FETCHSIZE: not called CC=2 SCAR=17.9
38 0 my $self= shift;
39 0 ▶ return $self->{size} if exists $self->{size};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"size"} 0 0 0
40 0 seek $self->{fh},0,0;
41 0 _getupto($self,-1);
42 0 return $self->{size} = $#{$self->{offsets}};
43 }
44  
45 0 ▶sub _getupto {
Subroutine _getupto: not called CC=3 SCAR=24.8
46 0 my ($self, $elem) = @_;
47 # Go to end
48 0 my $fh= $self->{fh};
49 0 seek($fh,$self->{offsets}->[-1],0);
50 0 my $out;
51 0 ▶ until (eof $fh or $#{$self->{offsets}} == $elem) {
Branch: 1 branch
BranchTrueFalseTotal
unless (eof $fh or $#{$$self{"offsets"};} == $elem) 0 0 0
Condition0%0/3
eof $fh or $#{$$self{"offsets"};} == $elem
l!l&&r!l&&!r
000
MC/DC0%0/2
eof $fh or $#{$$self{"offsets"};} == $elem
eof $fh $#{$$self{"offsets"};} == $elem
Truth table0%0/3
A or B
A= eof $fhB= $#{$$self{"offsets"};} == $elem
ABresult
1X1
011
000
52 0 $out = scalar <$fh>;
53 0 push @{$self->{offsets}}, tell($fh);
54 }
55 0 return $out;
56 }
57  
58 0 ▶sub _getit {
Subroutine _getit: not called CC=2 SCAR=17.9
59 0 my ($self, $elem) = @_;
60 0 ▶ die "ASSERTION FAILED" unless defined $self->{offsets}->[$elem];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"offsets"}[$elem] 0 0 0
61 0 seek $self->{fh}, $self->{offsets}->[$elem],0;
62 0 my $fh = $self->{fh};
63 0 my $out = <$fh>;
64 0 push @{$self->{offsets}}, tell($fh);
65 0 return $out;
66 }
67 2 1;
68 __END__
↑ Summary