Commit | Line | Data |
576d59a0 |
1 | use MooseX::Declare; |
2 | |
3 | class Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive |
4 | with Gitalist::Git::CollectionOfRepositories { |
411e6add |
5 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
6 | use MooseX::Types::Path::Class qw/Dir/; |
576d59a0 |
7 | |
cf7ff3ce |
8 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
9 | use MooseX::Types::Path::Class qw/Dir/; |
10 | |
11 | use Moose::Autobox; |
12 | use List::Util 'first'; |
13 | |
14 | has repo_dir => ( |
576d59a0 |
15 | isa => Dir, |
16 | is => 'ro', |
17 | required => 1, |
18 | coerce => 1, |
cf7ff3ce |
19 | ); |
576d59a0 |
20 | |
21 | method BUILD { |
411e6add |
22 | # Make sure repo_dir is an absolute path so that |
23 | # ->contains() works correctly. |
24 | $self->repo_dir->resolve; |
576d59a0 |
25 | } |
26 | |
cf7ff3ce |
27 | method _find_repos(Dir $dir) { |
28 | return map { |
29 | $self->_is_git_repo($_) ? $_ : $self->_find_repos($_) |
30 | } grep $_->is_dir, $dir->children; |
31 | } |
32 | |
576d59a0 |
33 | method _get_path_for_repository_name (NonEmptySimpleStr $name) { |
cf7ff3ce |
34 | my $repo = first { $_->name eq $name } $self->repositories->flatten |
35 | or return; |
36 | return $repo->path; |
576d59a0 |
37 | } |
38 | |
39 | ## Builders |
40 | method _build_repositories { |
cf7ff3ce |
41 | return [ |
42 | map Gitalist::Git::Repository->new($_), $self->_find_repos( $self->repo_dir ) |
43 | ]; |
576d59a0 |
44 | } |
e473ebf6 |
45 | } # end class |
576d59a0 |
46 | |
47 | __END__ |
48 | |
49 | =head1 NAME |
50 | |
51 | Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive - Model of recursive directories containing git repositories |
52 | |
53 | =head1 SYNOPSIS |
54 | |
55 | my $repo = Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive->new( repo_dir => $Dir ); |
56 | my $repository_list = $repo->repositories; |
57 | my $first_repository = $repository_list->[0]; |
58 | my $named_repository = $repo->get_repository('Gitalist'); |
59 | |
60 | =head1 DESCRIPTION |
61 | |
62 | This class provides a list of Repositories recursively found in the given directory. |
63 | |
64 | =head1 ATTRIBUTES |
65 | |
66 | =head2 repo_dir (C<Path::Class::Dir>) |
67 | |
68 | The filesystem root of the C<Repo>. |
69 | |
70 | =head1 SEE ALSO |
71 | |
72 | L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository> |
73 | |
74 | =head1 AUTHORS |
75 | |
76 | See L<Gitalist> for authors. |
77 | |
78 | =head1 LICENSE |
79 | |
80 | See L<Gitalist> for the license. |
81 | |
82 | =cut |