Commit | Line | Data |
0250a92d |
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; |
b1c8b22c |
19 | # Ignore commits, these represent submodules |
20 | next if $type eq 'commit'; |
0250a92d |
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, |
82bc0f05 |
26 | repository => $self->repository, |
0250a92d |
27 | ); |
28 | } |
29 | return \@ret; |
30 | } |
31 | |
eb8ee28a |
32 | method entries { |
33 | return $self->{_gpp_obj}->{directory_entries}; |
34 | } |
35 | |
0250a92d |
36 | } |
775e96e0 |
37 | |
38 | 1; |
39 | |
40 | |
41 | 1; |
42 | |
43 | __END__ |
44 | |
45 | =head1 NAME |
46 | |
2298d93f |
47 | Gitalist::Git::Object::HasTree - Git::Object::HasTree module for Gitalist |
775e96e0 |
48 | |
c19af0d0 |
49 | =head1 SYNOPSIS |
50 | |
44a9ed75 |
51 | my $tree = Repository->get_object($tree_sha1); |
c19af0d0 |
52 | |
775e96e0 |
53 | =head1 DESCRIPTION |
54 | |
c19af0d0 |
55 | Role for objects which have a tree - C<Commit> and C<Tree> objects. |
56 | |
57 | |
58 | =head1 ATTRIBUTES |
59 | |
60 | =head2 tree |
61 | |
62 | |
63 | =head1 METHODS |
64 | |
775e96e0 |
65 | |
66 | =head1 AUTHORS |
67 | |
68 | See L<Gitalist> for authors. |
69 | |
70 | =head1 LICENSE |
71 | |
72 | See L<Gitalist> for the license. |
73 | |
74 | =cut |