blib/lib/Gzip/RandomAccess.pm

filter: Statementstmt 100% 40 / 40 Branchbran 100% 18 / 18 Conditioncond 75.0% 6 / 8 MC/DCmcdc 60.0% 3 / 5 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 94.9% 75 / 79 CC 14 SCAR 18.3
CC
14
Cov
97%
_parse_arguments
10.0
new
4.0
DESTROY
2.0
CRAP 6.2
↑ Summary RandomAccess.xs »
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
l!l&&r!l&&!r
070
$args->{'cleanup'} || 0
l!l
25
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
ABresult
1X1
011
000
Truth table100%2/2
A
A= $args->{'cleanup'}
Aresult
11
00
22 );
23 7 bless $self, $class;
24  
25 7 ▶ if (!$self->index_available) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->index_available) 5 2 7
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
BranchTrueFalseTotal
@_ == 1 && ref $_[0] eq 'HASH' ? : 4 12 16
@_ == 1 ? : 3 9 12
@_ % 2 == 0 ? : 8 1 9
Condition100%3/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
934
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"
ABresult
0X0
100
111
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
BranchTrueFalseTotal
exists $args->{"file"} or croak("Missing filename") 12 3 15
40 12 ▶ defined $args->{file} or croak "Undefined filename";
Branch: 1 branch
BranchTrueFalseTotal
defined $args->{"file"} or croak("Undefined filename") 10 2 12
41 10 ▶ !ref $args->{file} or croak "Filename must be a scalar";
Branch: 1 branch
BranchTrueFalseTotal
ref $args->{"file"} and croak("Filename must be a scalar") 2 8 10
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
BranchTrueFalseTotal
unless $valid{$key} 1 16 17
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
BranchTrueFalseTotal
if ($cleanup) 2 5 7
58 2 unlink($index);
59 }
60 7 return;
61 }
62  
63 4 1;
64  
65 __END__
↑ Summary RandomAccess.xs »