line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gzip::RandomAccess; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
63207
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
114
|
|
4
|
3
|
|
|
3
|
|
15
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
97
|
|
5
|
3
|
|
|
3
|
|
12
|
use Carp; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
199
|
|
6
|
3
|
|
|
3
|
|
13
|
use XSLoader; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
1232
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.92'; |
9
|
|
|
|
|
|
|
XSLoader::load 'Gzip::RandomAccess', $VERSION; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
my $DEFAULT_INDEX_SPAN = 1024 * 1024; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub new { |
14
|
7
|
|
|
7
|
1
|
8526
|
my $class = shift; |
15
|
7
|
|
|
|
|
26
|
my $args = $class->_parse_arguments(@_); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = _new( |
18
|
|
|
|
|
|
|
$args->{file}, |
19
|
|
|
|
|
|
|
$args->{index_file}, |
20
|
|
|
|
|
|
|
$args->{index_span} || $DEFAULT_INDEX_SPAN, |
21
|
7
|
|
33
|
|
|
189
|
$args->{cleanup} || 0, |
|
|
|
100
|
|
|
|
|
22
|
|
|
|
|
|
|
); |
23
|
7
|
|
|
|
|
12
|
bless $self, $class; |
24
|
|
|
|
|
|
|
|
25
|
7
|
100
|
|
|
|
769
|
if (!$self->index_available) { |
26
|
5
|
|
|
|
|
224412
|
$self->build_index; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
7
|
|
|
|
|
76
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _parse_arguments { |
33
|
7
|
|
|
7
|
|
9
|
my $class = shift; |
34
|
7
|
50
|
100
|
|
|
70
|
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
|
7
|
50
|
|
|
|
22
|
exists $args->{file} or croak "Missing filename"; |
40
|
7
|
50
|
|
|
|
20
|
defined $args->{file} or croak "Undefined filename"; |
41
|
7
|
50
|
|
|
|
16
|
!ref $args->{file} or croak "Filename must be a scalar"; |
42
|
|
|
|
|
|
|
|
43
|
7
|
|
|
|
|
15
|
my %valid = map { $_ => 1 } qw(file index_file index_span cleanup); |
|
28
|
|
|
|
|
49
|
|
44
|
|
|
|
|
|
|
|
45
|
7
|
|
|
|
|
23
|
for my $key (keys %$args) { |
46
|
15
|
50
|
|
|
|
28
|
croak "Invalid argument '$key'" if !$valid{$key}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
7
|
|
|
|
|
13
|
return $args; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub DESTROY { |
53
|
7
|
|
|
7
|
|
49203
|
my $self = shift; |
54
|
7
|
|
|
|
|
38
|
my $index = $self->index_file; |
55
|
7
|
|
|
|
|
21
|
my $cleanup = $self->cleanup; |
56
|
7
|
|
|
|
|
207
|
$self->_free; |
57
|
7
|
100
|
|
|
|
30
|
if ($cleanup) { |
58
|
2
|
|
|
|
|
150
|
unlink($index); |
59
|
|
|
|
|
|
|
} |
60
|
7
|
|
|
|
|
94
|
return; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
1; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__END__ |