| 1 | package Cogit::Pack::WithIndex; | ||||||||||||
| 2 | 4 | $Cogit::Pack::WithIndex::VERSION = '0.001001'; | |||||||||||
| 3 | 4 | ▶ | use Moo; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 4 | ▶ | use Cogit::PackIndex::Version1; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 4 | ▶ | use Cogit::PackIndex::Version2; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 4 | ▶ | use MooX::Types::MooseLike::Base 'InstanceOf'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 4 | ▶ | use Path::Class; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 4 | ▶ | use Check::ISA; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | 4 | ▶ | use namespace::clean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | |||||||||||||
| 11 | 4 | extends 'Cogit::Pack'; | |||||||||||
| 12 | |||||||||||||
| 13 | has index_filename => ( | ||||||||||||
| 14 | is => 'rw', | ||||||||||||
| 15 | 2 | ▶ | coerce => sub { file($_[0]) if !obj($_[0], 'Path::Class::File'); $_[0]; }, | ||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||
| 16 | #isa => InstanceOf['Path::Class::File'], | ||||||||||||
| 17 | 4 | ); | |||||||||||
| 18 | |||||||||||||
| 19 | 4 | has index => ( | |||||||||||
| 20 | is => 'rw', | ||||||||||||
| 21 | isa => InstanceOf['Cogit::PackIndex'], | ||||||||||||
| 22 | ); | ||||||||||||
| 23 | |||||||||||||
| 24 | 2 | ▶ | sub BUILD { | ||||||||||
|
Subroutine
BUILD: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||
| 25 | 2 | my $self = shift; | |||||||||||
| 26 | 2 | my $index_filename = $self->filename; | |||||||||||
| 27 | 2 | $index_filename =~ s/\.pack/.idx/; | |||||||||||
| 28 | 2 | $self->index_filename($index_filename); | |||||||||||
| 29 | |||||||||||||
| 30 | 2 | ▶ | my $index_fh = IO::File->new($index_filename) || confess($!); | ||||||||||
|
Condition50%1/2
'IO::File'->new($index_filename) || confess($!)
MC/DC0%0/1
'IO::File'->new($index_filename) || confess($!)
'IO::File'->new($index_filename)
Truth table50%1/2
A
A= 'IO::File'->new($index_filename)
| |||||||||||||
| 31 | 2 | $index_fh->binmode(); | |||||||||||
| 32 | 2 | $index_fh->read( my $signature, 4 ); | |||||||||||
| 33 | 2 | $index_fh->read( my $version, 4 ); | |||||||||||
| 34 | 2 | $version = unpack( 'N', $version ); | |||||||||||
| 35 | 2 | $index_fh->close; | |||||||||||
| 36 | |||||||||||||
| 37 | 2 | ▶ | if ( $signature eq "\377tOc" ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 1 | ▶ | if ( $version == 2 ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 39 | 1 | $self->index( | |||||||||||
| 40 | Cogit::PackIndex::Version2->new( | ||||||||||||
| 41 | filename => $index_filename | ||||||||||||
| 42 | ) | ||||||||||||
| 43 | ); | ||||||||||||
| 44 | } else { | ||||||||||||
| 45 | 0 | confess("Unknown version"); | |||||||||||
| 46 | } | ||||||||||||
| 47 | } else { | ||||||||||||
| 48 | 1 | $self->index( | |||||||||||
| 49 | Cogit::PackIndex::Version1->new( | ||||||||||||
| 50 | filename => $index_filename | ||||||||||||
| 51 | ) | ||||||||||||
| 52 | ); | ||||||||||||
| 53 | } | ||||||||||||
| 54 | } | ||||||||||||
| 55 | |||||||||||||
| 56 | 48 | ▶ | sub get_object { | ||||||||||
|
Subroutine
get_object: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 57 | 48 | my ( $self, $want_sha1 ) = @_; | |||||||||||
| 58 | 48 | my $offset = $self->index->get_object_offset($want_sha1); | |||||||||||
| 59 | 48 | ▶ | return unless $offset; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 60 | 48 | return $self->unpack_object($offset); | |||||||||||
| 61 | } | ||||||||||||
| 62 | |||||||||||||
| 63 | 4 | 1; | |||||||||||
| 64 | |||||||||||||
| 65 | __END__ | ||||||||||||