9421c771944b0f9302666f851aee3d97fd44a324
[catagits/Gitalist.git] / lib / Gitalist / Git / Object / HasTree.pm
1 package Gitalist::Git::Object::HasTree;
2 use MooseX::Declare;
3
4 role Gitalist::Git::Object::HasTree {
5     has tree => ( isa => 'ArrayRef[Gitalist::Git::Object]',
6                   required => 0,
7                   is => 'ro',
8                   lazy_build => 1 );
9
10
11 ## Builders
12     method _build_tree {
13         my $output = $self->_run_cmd(qw/ls-tree -z/, $self->sha1);
14         return unless defined $output;
15
16         my @ret;
17         for my $line (split /\0/, $output) {
18             my ($mode, $type, $object, $file) = split /\s+/, $line, 4;
19             # Ignore commits, these represent submodules
20             next if $type eq 'commit';
21             my $class = 'Gitalist::Git::Object::' . ucfirst($type);
22             push @ret, $class->new( mode => oct $mode,
23                                     type => $type,
24                                     sha1 => $object,
25                                     file => $file,
26                                     repository => $self->repository,
27                                   );
28         }
29         return \@ret;
30     }
31
32 }
33
34 1;
35
36
37 1;
38
39 __END__
40
41 =head1 NAME
42
43 Gitalist::Git::Object::HasTree - Git::Object::HasTree module for Gitalist
44
45 =head1 SYNOPSIS
46
47     my $tree = Repository->get_object($tree_sha1);
48
49 =head1 DESCRIPTION
50
51 Role for objects which have a tree - C<Commit> and C<Tree> objects.
52
53
54 =head1 ATTRIBUTES
55
56 =head2 tree
57
58
59 =head1 METHODS
60
61
62 =head1 AUTHORS
63
64 See L<Gitalist> for authors.
65
66 =head1 LICENSE
67
68 See L<Gitalist> for the license.
69
70 =cut