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   17 use Moose;
  4         4  
  4         22  
3 4     4   15738 use MooseX::StrictConstructor;
  4         7  
  4         24  
4 4     4   7213 use Moose::Util::TypeConstraints;
  4         4  
  4         29  
5 4     4   4752 use namespace::autoclean;
  4         5  
  4         31  
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 377 my $self = shift;
20 403         10267 my $content = $self->content;
21 403 50       593 return unless $content;
22 403         356 my @directory_entries;
23 403         562 while ($content) {
24 1721         1993 my $space_index = index( $content, ' ' );
25 1721         2155 my $mode = substr( $content, 0, $space_index );
26 1721         1985 $content = substr( $content, $space_index + 1 );
27 1721         1469 my $null_index = index( $content, "\0" );
28 1721         1625 my $filename = substr( $content, 0, $null_index );
29 1721         1557 $content = substr( $content, $null_index + 1 );
30 1721         3305 my $sha1 = unpack( 'H*', substr( $content, 0, 20 ) );
31 1721         1823 $content = substr( $content, 20 );
32 1721         41152 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         11318 $self->directory_entries( \@directory_entries );
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44