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         6  
  4         27  
3 4     4   20252 use MooseX::StrictConstructor;
  4         7  
  4         35  
4 4     4   9383 use Moose::Util::TypeConstraints;
  4         9  
  4         34  
5 4     4   5778 use namespace::autoclean;
  4         9  
  4         37  
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 493 my $self = shift;
20 403         11213 my $content = $self->content;
21 403 50       705 return unless $content;
22 403         510 my @directory_entries;
23 403         771 while ($content) {
24 1721         2505 my $space_index = index( $content, ' ' );
25 1721         2396 my $mode = substr( $content, 0, $space_index );
26 1721         2231 $content = substr( $content, $space_index + 1 );
27 1721         1922 my $null_index = index( $content, "\0" );
28 1721         1826 my $filename = substr( $content, 0, $null_index );
29 1721         1791 $content = substr( $content, $null_index + 1 );
30 1721         4174 my $sha1 = unpack( 'H*', substr( $content, 0, 20 ) );
31 1721         2008 $content = substr( $content, 20 );
32 1721         45935 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         13083 $self->directory_entries( \@directory_entries );
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44