Commit | Line | Data |
7e7f9335 |
1 | use MooseX::Declare; |
2 | |
3 | class Gitalist::Git::Repo { |
4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
84f31a44 |
5 | use MooseX::Types::Path::Class qw/Dir/; |
6 | use MooseX::Types::Moose qw/ArrayRef/; |
7e7f9335 |
7 | use Gitalist::Git::Project; |
84f31a44 |
8 | has repo_dir => ( |
9 | isa => Dir, |
10 | is => 'ro', |
11 | required => 1, |
12 | coerce => 1, |
13 | ); |
7e7f9335 |
14 | |
ba033c36 |
15 | method project (NonEmptySimpleStr $project) { |
ba033c36 |
16 | return Gitalist::Git::Project->new( |
17 | name => $project, |
3742082a |
18 | path => $self->repo_dir->subdir($project), |
ba033c36 |
19 | ); |
20 | } |
21 | |
22 | |
7e7f9335 |
23 | =head2 _is_git_repo |
24 | |
25 | Determine whether a given directory (as a L<Path::Class::Dir> object) is a |
26 | C<git> repo. |
27 | |
28 | =cut |
29 | |
30 | method _is_git_repo ($dir) { |
255ee743 |
31 | return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); |
7e7f9335 |
32 | } |
33 | |
7e7f9335 |
34 | =head2 list_projects |
35 | |
36 | For the C<repo_dir> specified in the config return an array of projects where |
37 | each item will contain the contents of L</project_info>. |
38 | |
39 | =cut |
40 | |
84f31a44 |
41 | has projects => ( |
42 | isa => ArrayRef['Gitalist::Git::Project'], |
43 | reader => 'list_projects', |
44 | lazy_build => 1, |
45 | ); |
46 | |
47 | method _build_projects { |
48 | my $base = $self->repo_dir; |
7e7f9335 |
49 | my $dh = $base->open || die "Could not open $base"; |
84f31a44 |
50 | my @ret; |
7e7f9335 |
51 | while (my $file = $dh->read) { |
52 | next if $file =~ /^.{1,2}$/; |
53 | |
54 | my $obj = $base->subdir($file); |
55 | next unless -d $obj; |
56 | next unless $self->_is_git_repo($obj); |
57 | |
84f31a44 |
58 | push @ret, Gitalist::Git::Project->new( |
59 | name => $file, |
60 | path => $obj, |
61 | ); |
7e7f9335 |
62 | } |
63 | |
84f31a44 |
64 | return [sort { $a->name cmp $b->name } @ret]; |
7e7f9335 |
65 | } |
7e7f9335 |
66 | } # end class |