Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Git / PurePerl / Object / Tree.pm
1 package Git::PurePerl::Object::Tree;
2 use Moose;
3 use MooseX::StrictConstructor;
4 use Moose::Util::TypeConstraints;
5 use namespace::autoclean;
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     my $self    = shift;
20     my $content = $self->content;
21     return unless $content;
22     my @directory_entries;
23     while ($content) {
24         my $space_index = index( $content, ' ' );
25         my $mode = substr( $content, 0, $space_index );
26         $content = substr( $content, $space_index + 1 );
27         my $null_index = index( $content, "\0" );
28         my $filename = substr( $content, 0, $null_index );
29         $content = substr( $content, $null_index + 1 );
30         my $sha1 = unpack( 'H*', substr( $content, 0, 20 ) );
31         $content = substr( $content, 20 );
32         push @directory_entries,
33             Git::PurePerl::DirectoryEntry->new(
34             mode     => $mode,
35             filename => $filename,
36             sha1     => $sha1,
37             git      => $self->git,
38             );
39     }
40     $self->directory_entries( \@directory_entries );
41 }
42
43 __PACKAGE__->meta->make_immutable;
44