line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gzip::RandomAccess; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
88168
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
119
|
|
4
|
3
|
|
|
3
|
|
17
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
110
|
|
5
|
3
|
|
|
3
|
|
18
|
use Carp; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
264
|
|
6
|
3
|
|
|
3
|
|
17
|
use XSLoader; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1734
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.91'; |
9
|
|
|
|
|
|
|
XSLoader::load 'Gzip::RandomAccess', $VERSION; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $DEFAULT_INDEX_SPAN = 1024 * 1024; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
10
|
|
|
10
|
1
|
23312
|
my $class = shift; |
15
|
10
|
|
|
|
|
41
|
my $args = $class->_parse_arguments(@_); |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
33
|
|
|
236
|
my $self = _new( |
|
|
|
50
|
|
|
|
|
18
|
|
|
|
|
|
|
$args->{file}, |
19
|
|
|
|
|
|
|
$args->{index_file}, |
20
|
|
|
|
|
|
|
$args->{index_span} || $DEFAULT_INDEX_SPAN, |
21
|
|
|
|
|
|
|
$args->{cleanup} || 0, |
22
|
|
|
|
|
|
|
); |
23
|
1
|
|
|
|
|
6
|
bless $self, $class; |
24
|
|
|
|
|
|
|
|
25
|
1
|
50
|
|
|
|
51
|
if (!$self->index_available) { |
26
|
1
|
|
|
|
|
55546
|
$self->build_index; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
1
|
|
|
|
|
27
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _parse_arguments { |
33
|
10
|
|
|
10
|
|
16
|
my $class = shift; |
34
|
10
|
100
|
100
|
|
|
102
|
my $args = (@_ == 1 && ref $_[0] eq 'HASH') ? $_[0] # Hashref |
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
35
|
|
|
|
|
|
|
: (@_ == 1) ? { file => $_[0] } # Filename |
36
|
|
|
|
|
|
|
: (@_ % 2 == 0) ? { @_ } # Hash |
37
|
|
|
|
|
|
|
: croak "Pass either a filename or a hash of arguments"; |
38
|
|
|
|
|
|
|
|
39
|
9
|
100
|
|
|
|
66
|
exists $args->{file} or croak "Missing filename"; |
40
|
6
|
100
|
|
|
|
39
|
defined $args->{file} or croak "Undefined filename"; |
41
|
4
|
100
|
|
|
|
29
|
!ref $args->{file} or croak "Filename must be a scalar"; |
42
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
8
|
my %valid = map { $_ => 1 } qw(file index_file index_span cleanup); |
|
8
|
|
|
|
|
152
|
|
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
26
|
for my $key (keys %$args) { |
46
|
2
|
100
|
|
|
|
26
|
croak "Invalid argument '$key'" if !$valid{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
1
|
|
|
|
|
6
|
return $args; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub DESTROY { |
53
|
1
|
|
|
1
|
|
77251
|
my $self = shift; |
54
|
1
|
|
|
|
|
7
|
my $index = $self->index_file; |
55
|
1
|
|
|
|
|
6
|
my $cleanup = $self->cleanup; |
56
|
1
|
|
|
|
|
31
|
$self->_free; |
57
|
1
|
50
|
|
|
|
7
|
if ($cleanup) { |
58
|
0
|
|
|
|
|
0
|
unlink($index); |
59
|
|
|
|
|
|
|
} |
60
|
1
|
|
|
|
|
107
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |