File Coverage

blib/lib/Git/PurePerl/PackIndex.pm
Criterion Covered Total %
statement 25 25 100.0
branch 1 2 50.0
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 1 0.0
total 32 36 88.8


line stmt bran cond sub pod time code
1             package Git::PurePerl::PackIndex;
2 4     4   16 use Moose;
  4         5  
  4         25  
3 4     4   12744 use MooseX::StrictConstructor;
  4         7  
  4         31  
4 4     4   8694 use IO::File;
  4         7  
  4         524  
5 4     4   18 use namespace::autoclean;
  4         5  
  4         35  
6              
7             has 'filename' =>
8             ( is => 'ro', isa => 'Path::Class::File', required => 1, coerce => 1 );
9              
10             has 'fh' => ( is => 'rw', isa => 'IO::File', required => 0 );
11              
12             has 'offsets' =>
13             ( is => 'rw', isa => 'ArrayRef[Int]', required => 0, auto_deref => 1, );
14             has 'size' => ( is => 'rw', isa => 'Int', required => 0 );
15              
16             my $FanOutCount = 256;
17             my $SHA1Size = 20;
18             my $IdxOffsetSize = 4;
19             my $OffsetSize = 4;
20             my $CrcSize = 4;
21             my $OffsetStart = $FanOutCount * $IdxOffsetSize;
22             my $SHA1Start = $OffsetStart + $OffsetSize;
23             my $EntrySize = $OffsetSize + $SHA1Size;
24             my $EntrySizeV2 = $SHA1Size + $CrcSize + $OffsetSize;
25              
26             sub BUILD {
27 3     3 0 8 my $self = shift;
28 3         107 my $filename = $self->filename;
29              
30 3   33     18 my $fh = IO::File->new($filename) || confess($!);
31 3         413 $self->fh($fh);
32              
33 3         8 my @offsets = (0);
34 3         18 $fh->seek( $self->global_offset, 0 );
35 3         29 foreach my $i ( 0 .. $FanOutCount - 1 ) {
36 768         1037 $fh->read( my $data, $IdxOffsetSize );
37 768         2719 my $offset = unpack( 'N', $data );
38 768 50       1104 confess("pack has discontinuous index") if $offset < $offsets[-1];
39 768         757 push @offsets, $offset;
40             }
41 3         146 $self->offsets( \@offsets );
42 3         165 $self->size( $offsets[-1] );
43             }
44              
45             __PACKAGE__->meta->make_immutable;
46