Commit | Line | Data |
6b3c0b76 |
1 | use MooseX::Declare; |
2 | |
cd169152 |
3 | role Gitalist::Git::CollectionOfRepositories { |
6b3c0b76 |
4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
5 | use MooseX::Types::Moose qw/ArrayRef/; |
6 | use Moose::Autobox; |
44a9ed75 |
7 | use aliased 'Gitalist::Git::Repository'; |
6b3c0b76 |
8 | |
9 | has projects => ( |
10 | is => 'ro', |
44a9ed75 |
11 | isa => ArrayRef['Gitalist::Git::Repository'], |
6b3c0b76 |
12 | required => 1, |
13 | lazy_build => 1, |
14 | ); |
b5ce0e6a |
15 | method get_repository (NonEmptySimpleStr $name) { |
6b3c0b76 |
16 | my $path = $self->_get_path_for_project_name($name); |
44a9ed75 |
17 | die "Not a valid git repository." |
6b3c0b76 |
18 | unless $self->_is_git_repo($path); |
44a9ed75 |
19 | return Repository->new( $path ); |
6b3c0b76 |
20 | } |
21 | # Determine whether a given directory is a git repo. |
22 | method _is_git_repo ($dir) { |
23 | return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); |
24 | } |
25 | requires qw/ |
26 | _build_projects |
27 | _get_path_for_project_name |
28 | /; |
29 | |
30 | around _build_projects { |
31 | [sort { $a->name cmp $b->name } $self->$orig->flatten]; |
32 | } |
33 | } |
34 | |
35 | 1; |