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