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 | |
411e6add |
8 | has repo_dir => ( |
576d59a0 |
9 | isa => Dir, |
10 | is => 'ro', |
11 | required => 1, |
12 | coerce => 1, |
411e6add |
13 | ); |
576d59a0 |
14 | |
15 | method BUILD { |
411e6add |
16 | # Make sure repo_dir is an absolute path so that |
17 | # ->contains() works correctly. |
18 | $self->repo_dir->resolve; |
576d59a0 |
19 | } |
20 | |
21 | method _get_path_for_repository_name (NonEmptySimpleStr $name) { |
411e6add |
22 | my $path = Path::Class::Dir->new( $name )->resolve; |
23 | die "Directory traversal prohibited: $path" |
24 | unless $self->repo_dir->contains($path); |
25 | return $path; |
576d59a0 |
26 | } |
27 | |
28 | ## Builders |
29 | method _build_repositories { |
411e6add |
30 | my @ret; |
31 | $self->repo_dir->recurse( |
32 | callback => sub { |
33 | my ( $dir ) = @_; |
34 | if ( $dir->is_dir ) { |
35 | for my $repo ( @ret ) { |
36 | # no need to go further if parent is git dir |
37 | # never have a git repo in a git repo? |
38 | return if ( $repo->path->contains( $dir ) ); |
576d59a0 |
39 | } |
411e6add |
40 | eval { |
41 | # pass directory as string |
42 | my $p = $self->get_repository("$dir"); |
43 | push @ret, $p; |
44 | }; |
45 | } |
46 | return; |
47 | } |
48 | ); |
49 | return \@ret; |
576d59a0 |
50 | } |
e473ebf6 |
51 | } # end class |
576d59a0 |
52 | |
53 | __END__ |
54 | |
55 | =head1 NAME |
56 | |
57 | Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive - Model of recursive directories containing git repositories |
58 | |
59 | =head1 SYNOPSIS |
60 | |
61 | my $repo = Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive->new( repo_dir => $Dir ); |
62 | my $repository_list = $repo->repositories; |
63 | my $first_repository = $repository_list->[0]; |
64 | my $named_repository = $repo->get_repository('Gitalist'); |
65 | |
66 | =head1 DESCRIPTION |
67 | |
68 | This class provides a list of Repositories recursively found in the given directory. |
69 | |
70 | =head1 ATTRIBUTES |
71 | |
72 | =head2 repo_dir (C<Path::Class::Dir>) |
73 | |
74 | The filesystem root of the C<Repo>. |
75 | |
76 | =head1 SEE ALSO |
77 | |
78 | L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository> |
79 | |
80 | =head1 AUTHORS |
81 | |
82 | See L<Gitalist> for authors. |
83 | |
84 | =head1 LICENSE |
85 | |
86 | See L<Gitalist> for the license. |
87 | |
88 | =cut |