line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Array::FileReader; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
24533
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
4
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
118
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
require DynaLoader; |
8
|
1
|
|
|
1
|
|
1252
|
use IO::File; |
|
1
|
|
|
|
|
11653
|
|
|
1
|
|
|
|
|
207
|
|
9
|
1
|
|
|
1
|
|
998
|
use Tie::Array; |
|
1
|
|
|
|
|
1416
|
|
|
1
|
|
|
|
|
29
|
|
10
|
1
|
|
|
1
|
|
8
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
523
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
@ISA = qw(Tie::Array DynaLoader); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '0.03'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# bootstrap Array::FileReader $VERSION; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub TIEARRAY { |
19
|
0
|
|
|
0
|
|
|
my ($class, $file) = @_; |
20
|
0
|
|
|
|
|
|
my $fh = new IO::File; |
21
|
0
|
0
|
|
|
|
|
$fh->open($file) or croak "Can't open $file: $!"; |
22
|
0
|
|
|
|
|
|
my $self = { |
23
|
|
|
|
|
|
|
fh => $fh, |
24
|
|
|
|
|
|
|
offsets => [0] |
25
|
|
|
|
|
|
|
}; |
26
|
0
|
|
|
|
|
|
bless $self, $class; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub FETCH { |
30
|
0
|
|
|
0
|
|
|
my ($self, $elem) = @_; |
31
|
0
|
0
|
|
|
|
|
if ($elem > $#{$self->{offsets}} ) { |
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
&_getupto; |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
goto &_getit; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub FETCHSIZE { |
38
|
0
|
|
|
0
|
|
|
my $self= shift; |
39
|
0
|
0
|
|
|
|
|
return $self->{size} if exists $self->{size}; |
40
|
0
|
|
|
|
|
|
seek $self->{fh},0,0; |
41
|
0
|
|
|
|
|
|
_getupto($self,-1); |
42
|
0
|
|
|
|
|
|
return $self->{size} = $#{$self->{offsets}}; |
|
0
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _getupto { |
46
|
0
|
|
|
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
|
|
0
|
|
|
|
until (eof $fh or $#{$self->{offsets}} == $elem) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$out = scalar <$fh>; |
53
|
0
|
|
|
|
|
|
push @{$self->{offsets}}, tell($fh); |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
} |
55
|
0
|
|
|
|
|
|
return $out; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub _getit { |
59
|
0
|
|
|
0
|
|
|
my ($self, $elem) = @_; |
60
|
0
|
0
|
|
|
|
|
die "ASSERTION FAILED" unless defined $self->{offsets}->[$elem]; |
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); |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return $out; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
1; |
68
|
|
|
|
|
|
|
__END__ |