| 1 | package Gzip::RandomAccess; | ||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use XSLoader; | ||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.92'; | |||||||||||||||||||||||||||||||||||
| 9 | 4 | XSLoader::load 'Gzip::RandomAccess', $VERSION; | |||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||
| 11 | 4 | my $DEFAULT_INDEX_SPAN = 1024 * 1024; | |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||
| 13 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||
| 14 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 15 | 16 | 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 | ▶ | $args->{cleanup} || 0, | ||||||||||||||||||||||||||||||||||
|
Condition60%3/5
$args->{'index_span'} || $DEFAULT_INDEX_SPAN
$args->{'cleanup'} || 0
MC/DC0%0/2
$args->{'index_span'} || $DEFAULT_INDEX_SPAN
$args->{'index_span'}
$DEFAULT_INDEX_SPAN
MC/DC100%1/1
$args->{'cleanup'} || 0
$args->{'cleanup'}
Truth table33%1/3
A || B
A= $args->{'index_span'}B= $DEFAULT_INDEX_SPAN
Truth table100%2/2
A
A= $args->{'cleanup'}
| |||||||||||||||||||||||||||||||||||||
| 22 | ); | ||||||||||||||||||||||||||||||||||||
| 23 | 7 | bless $self, $class; | |||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | if (!$self->index_available) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 26 | 5 | $self->build_index; | |||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||
| 29 | 7 | return $self; | |||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||
| 32 | 16 | ▶ | sub _parse_arguments { | ||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_arguments: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||
| 33 | 16 | my $class = shift; | |||||||||||||||||||||||||||||||||||
| 34 | 16 | ▶ | my $args = (@_ == 1 && ref $_[0] eq 'HASH') ? $_[0] # Hashref | ||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC100%2/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table100%3/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||
| 35 | : (@_ == 1) ? { file => $_[0] } # Filename | ||||||||||||||||||||||||||||||||||||
| 36 | : (@_ % 2 == 0) ? { @_ } # Hash | ||||||||||||||||||||||||||||||||||||
| 37 | : croak "Pass either a filename or a hash of arguments"; | ||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||
| 39 | 15 | ▶ | exists $args->{file} or croak "Missing filename"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 40 | 12 | ▶ | defined $args->{file} or croak "Undefined filename"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 41 | 10 | ▶ | !ref $args->{file} or croak "Filename must be a scalar"; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||
| 43 | 8 | my %valid = map { $_ => 1 } qw(file index_file index_span cleanup); | |||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||
| 45 | 8 | for my $key (keys %$args) { | |||||||||||||||||||||||||||||||||||
| 46 | 17 | ▶ | croak "Invalid argument '$key'" if !$valid{$key}; | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||
| 49 | 7 | return $args; | |||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||
| 52 | 7 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||
| 53 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||
| 54 | 7 | my $index = $self->index_file; | |||||||||||||||||||||||||||||||||||
| 55 | 7 | my $cleanup = $self->cleanup; | |||||||||||||||||||||||||||||||||||
| 56 | 7 | $self->_free; | |||||||||||||||||||||||||||||||||||
| 57 | 7 | ▶ | if ($cleanup) { | ||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||
| 58 | 2 | unlink($index); | |||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||
| 60 | 7 | return; | |||||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||
| 63 | 4 | 1; | |||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||
| 65 | __END__ | ||||||||||||||||||||||||||||||||||||