File Coverage

blib/lib/Git/PurePerl/Pack/WithIndex.pm
Criterion Covered Total %
statement 27 28 96.4
branch 4 6 66.6
condition 1 3 33.3
subroutine 5 5 100.0
pod 0 2 0.0
total 37 44 84.0


line stmt bran cond sub pod time code
1             package Git::PurePerl::Pack::WithIndex;
2 4     4   18 use Moose;
  4         5  
  4         38  
3 4     4   16591 use MooseX::StrictConstructor;
  4         6  
  4         26  
4 4     4   7591 use namespace::autoclean;
  4         5  
  4         28  
5              
6             extends 'Git::PurePerl::Pack';
7              
8             has 'index_filename' =>
9             ( is => 'rw', isa => 'Path::Class::File', required => 0, coerce => 1 );
10             has 'index' =>
11             ( is => 'rw', isa => 'Git::PurePerl::PackIndex', required => 0 );
12              
13             sub BUILD {
14 3     3 0 6 my $self = shift;
15 3         88 my $index_filename = $self->filename;
16 3         6 $index_filename =~ s/\.pack/.idx/;
17 3         210 $self->index_filename($index_filename);
18              
19 3   33     16 my $index_fh = IO::File->new($index_filename) || confess($!);
20 3         176 $index_fh->binmode();
21 3         53 $index_fh->read( my $signature, 4 );
22 3         42 $index_fh->read( my $version, 4 );
23 3         19 $version = unpack( 'N', $version );
24 3         11 $index_fh->close;
25              
26 3 100       32 if ( $signature eq "\377tOc" ) {
27 1 50       6 if ( $version == 2 ) {
28 1         44 $self->index(
29             Git::PurePerl::PackIndex::Version2->new(
30             filename => $index_filename
31             )
32             );
33             } else {
34 0         0 confess("Unknown version");
35             }
36             } else {
37 2         89 $self->index(
38             Git::PurePerl::PackIndex::Version1->new(
39             filename => $index_filename
40             )
41             );
42             }
43             }
44              
45             sub get_object {
46 2284     2284 0 2529 my ( $self, $want_sha1 ) = @_;
47 2284         57668 my $offset = $self->index->get_object_offset($want_sha1);
48 2284 50       3276 return unless $offset;
49 2284         5258 return $self->unpack_object($offset);
50             }
51              
52             __PACKAGE__->meta->make_immutable;
53