Massive tree action speedup
[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     method entries {
33         return $self->{_gpp_obj}->{directory_entries};
34     }
35
36 }
37
38 1;
39
40
41 1;
42
43 __END__
44
45 =head1 NAME
46
47 Gitalist::Git::Object::HasTree - Git::Object::HasTree module for Gitalist
48
49 =head1 SYNOPSIS
50
51     my $tree = Repository->get_object($tree_sha1);
52
53 =head1 DESCRIPTION
54
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
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