Commit | Line | Data |
---|---|---|
7e7f9335 | 1 | use MooseX::Declare; |
2 | ||
cd169152 | 3 | class Gitalist::Git::CollectionOfRepositories::FromDirectory |
4 | with Gitalist::Git::CollectionOfRepositories { | |
7e7f9335 | 5 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
84f31a44 | 6 | use MooseX::Types::Path::Class qw/Dir/; |
38b9e5c8 | 7 | |
84f31a44 | 8 | has repo_dir => ( |
9 | isa => Dir, | |
10 | is => 'ro', | |
11 | required => 1, | |
12 | coerce => 1, | |
13 | ); | |
7e7f9335 | 14 | |
ca6e3675 | 15 | method BUILD { |
16 | # Make sure repo_dir is an absolute path so that | |
17 | # ->contains() works correctly. | |
18 | $self->repo_dir->resolve; | |
19 | } | |
20 | ||
82bc0f05 | 21 | method _get_path_for_repository_name (NonEmptySimpleStr $name) { |
ca6e3675 | 22 | my $path = $self->repo_dir->subdir($name)->resolve; |
23 | die "Directory traversal prohibited" | |
24 | unless $self->repo_dir->contains($path); | |
6b3c0b76 | 25 | return $path; |
3bbb1202 | 26 | } |
27 | ||
52d3a5d0 | 28 | method _get_repo_from_name (NonEmptySimpleStr $name) { |
29 | return Gitalist::Git::Repository->new($self->_get_path_for_repository_name($name)); | |
30 | } | |
31 | ||
bba40bd5 | 32 | ## Builders |
82bc0f05 | 33 | method _build_repositories { |
cea99b3a | 34 | my $dh = $self->repo_dir->open || die "Could not open repo_dir"; |
84f31a44 | 35 | my @ret; |
cea99b3a | 36 | while (my $dir_entry = $dh->read) { |
82bc0f05 | 37 | # try to get a repository for each entry in repo_dir |
cea99b3a | 38 | eval { |
b5ce0e6a | 39 | my $p = $self->get_repository($dir_entry); |
cea99b3a | 40 | push @ret, $p; |
41 | }; | |
42 | } | |
6b3c0b76 | 43 | return \@ret; |
3bbb1202 | 44 | } |
775e96e0 | 45 | } # end class |
3bbb1202 | 46 | |
775e96e0 | 47 | __END__ |
3bbb1202 | 48 | |
bba40bd5 | 49 | =head1 NAME |
50 | ||
271f6b46 | 51 | Gitalist::Git::CollectionOfRepositories::FromDirectory - Model of a directory containing git repositories |
bba40bd5 | 52 | |
53 | =head1 SYNOPSIS | |
54 | ||
cd169152 | 55 | my $repo = Gitalist::Git::CollectionOfRepositories::FromDirectory->new( repo_dir => $Dir ); |
82bc0f05 | 56 | my $repository_list = $repo->repositories; |
57 | my $first_repository = $repository_list->[0]; | |
58 | my $named_repository = $repo->get_repository('Gitalist'); | |
bba40bd5 | 59 | |
60 | =head1 DESCRIPTION | |
61 | ||
87581f05 | 62 | This class provides a list of Repositories found in the given directory. |
bba40bd5 | 63 | |
64 | =head1 ATTRIBUTES | |
65 | ||
8ba87261 | 66 | =head2 repo_dir (C<Path::Class::Dir>) |
bba40bd5 | 67 | |
b90f633a | 68 | The filesystem root of the C<Repo>. |
bba40bd5 | 69 | |
3bbb1202 | 70 | =head1 SEE ALSO |
71 | ||
271f6b46 | 72 | L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository> |
8ba87261 | 73 | |
775e96e0 | 74 | =head1 AUTHORS |
3bbb1202 | 75 | |
775e96e0 | 76 | See L<Gitalist> for authors. |
3bbb1202 | 77 | |
78 | =head1 LICENSE | |
79 | ||
775e96e0 | 80 | See L<Gitalist> for the license. |
3bbb1202 | 81 | |
82 | =cut |