PurePerl/PackIndex.pm

filter: Statementstmt 100% 39 / 39 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 92.0% 46 / 50 CC 4 SCAR 9.2
CC
4
Cov
95%
BUILD
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
« PurePerl/Pack/WithIndex.pm ↑ Summary PurePerl/NewObject/Commit.pm »
1 package Git::PurePerl::PackIndex;
2 4 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 4 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 4 has 'filename' =>
8 ( is => 'ro', isa => 'Path::Class::File', required => 1, coerce => 1 );
9  
10 4 has 'fh' => ( is => 'rw', isa => 'IO::File', required => 0 );
11  
12 4 has 'offsets' =>
13 ( is => 'rw', isa => 'ArrayRef[Int]', required => 0, auto_deref => 1, );
14 4 has 'size' => ( is => 'rw', isa => 'Int', required => 0 );
15  
16 4 my $FanOutCount = 256;
17 4 my $SHA1Size = 20;
18 4 my $IdxOffsetSize = 4;
19 4 my $OffsetSize = 4;
20 4 my $CrcSize = 4;
21 4 my $OffsetStart = $FanOutCount * $IdxOffsetSize;
22 4 my $SHA1Start = $OffsetStart + $OffsetSize;
23 4 my $EntrySize = $OffsetSize + $SHA1Size;
24 4 my $EntrySizeV2 = $SHA1Size + $CrcSize + $OffsetSize;
25  
26 2 ▶sub BUILD {
Subroutine BUILD: called CC=4 SCAR=13.9
Pod undocumented
27 2 my $self = shift;
28 2 my $filename = $self->filename;
29  
30 2 ▶ my $fh = IO::File->new($filename) || confess($!);
Condition50%1/2
'IO::File'->new($filename) || confess($!)
l!l
20
MC/DC0%0/1
'IO::File'->new($filename) || confess($!)
'IO::File'->new($filename)
Truth table50%1/2
A
A= 'IO::File'->new($filename)
Aresult
11
00
31 2 $self->fh($fh);
32  
33 2 my @offsets = (0);
34 2 $fh->seek( $self->global_offset, 0 );
35 2 foreach my $i ( 0 .. $FanOutCount - 1 ) {
36 512 $fh->read( my $data, $IdxOffsetSize );
37 512 my $offset = unpack( 'N', $data );
38 512 ▶ confess("pack has discontinuous index") if $offset < $offsets[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $offset < $offsets[-1] 0 512 512
39 512 push @offsets, $offset;
40 }
41 2 $self->offsets( \@offsets );
42 2 $self->size( $offsets[-1] );
43 }
44  
45 4 __PACKAGE__->meta->make_immutable;
46  
« PurePerl/Pack/WithIndex.pm ↑ Summary PurePerl/NewObject/Commit.pm »