File Coverage

blib/lib/Git/PurePerl/Object/Tree.pm
Criterion Covered Total %
statement 27 27 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 33 35 94.2


line stmt bran cond sub pod time code
1             package Git::PurePerl::Object::Tree;
2 4     4   19 use Moose;
  4         7  
  4         27  
3 4     4   17345 use MooseX::StrictConstructor;
  4         6  
  4         27  
4 4     4   7391 use Moose::Util::TypeConstraints;
  4         6  
  4         32  
5 4     4   4750 use namespace::autoclean;
  4         7  
  4         29  
6              
7             extends 'Git::PurePerl::Object';
8              
9             has 'kind' =>
10             ( is => 'ro', isa => 'ObjectKind', required => 1, default => 'tree' );
11             has 'directory_entries' => (
12             is => 'rw',
13             isa => 'ArrayRef[Git::PurePerl::DirectoryEntry]',
14             required => 0,
15             auto_deref => 1,
16             );
17              
18             sub BUILD {
19 403     403 0 379 my $self = shift;
20 403         10386 my $content = $self->content;
21 403 50       1051 return unless $content;
22 403         346 my @directory_entries;
23 403         663 while ($content) {
24 1721         2130 my $space_index = index( $content, ' ' );
25 1721         1981 my $mode = substr( $content, 0, $space_index );
26 1721         2092 $content = substr( $content, $space_index + 1 );
27 1721         1414 my $null_index = index( $content, "\0" );
28 1721         1640 my $filename = substr( $content, 0, $null_index );
29 1721         1605 $content = substr( $content, $null_index + 1 );
30 1721         3130 my $sha1 = unpack( 'H*', substr( $content, 0, 20 ) );
31 1721         1665 $content = substr( $content, 20 );
32 1721         41211 push @directory_entries,
33             Git::PurePerl::DirectoryEntry->new(
34             mode => $mode,
35             filename => $filename,
36             sha1 => $sha1,
37             git => $self->git,
38             );
39             }
40 403         11487 $self->directory_entries( \@directory_entries );
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44