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 | ||
6b3c0b76 | 21 | method _get_path_for_project_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 | ||
bba40bd5 | 28 | ## Builders |
84f31a44 | 29 | method _build_projects { |
cea99b3a | 30 | my $dh = $self->repo_dir->open || die "Could not open repo_dir"; |
84f31a44 | 31 | my @ret; |
cea99b3a | 32 | while (my $dir_entry = $dh->read) { |
33 | # try to get a project for each entry in repo_dir | |
34 | eval { | |
b5ce0e6a | 35 | my $p = $self->get_repository($dir_entry); |
cea99b3a | 36 | push @ret, $p; |
37 | }; | |
38 | } | |
6b3c0b76 | 39 | return \@ret; |
3bbb1202 | 40 | } |
775e96e0 | 41 | } # end class |
3bbb1202 | 42 | |
775e96e0 | 43 | __END__ |
3bbb1202 | 44 | |
bba40bd5 | 45 | =head1 NAME |
46 | ||
cd169152 | 47 | Gitalist::Git::CollectionOfRepositories::FromDirectory - Model of a repository directory |
bba40bd5 | 48 | |
49 | =head1 SYNOPSIS | |
50 | ||
cd169152 | 51 | my $repo = Gitalist::Git::CollectionOfRepositories::FromDirectory->new( repo_dir => $Dir ); |
bba40bd5 | 52 | my $project_list = $repo->projects; |
b90f633a | 53 | my $first_project = $project_list->[0]; |
b5ce0e6a | 54 | my $named_project = $repo->get_repository('Gitalist'); |
bba40bd5 | 55 | |
56 | =head1 DESCRIPTION | |
57 | ||
87581f05 | 58 | This class provides a list of Repositories found in the given directory. |
bba40bd5 | 59 | |
60 | =head1 ATTRIBUTES | |
61 | ||
8ba87261 | 62 | =head2 repo_dir (C<Path::Class::Dir>) |
bba40bd5 | 63 | |
b90f633a | 64 | The filesystem root of the C<Repo>. |
bba40bd5 | 65 | |
66 | =head2 projects | |
67 | ||
44a9ed75 | 68 | An array of all L<Gitalist::Git::Repository>s found in C<repo_dir>. |
bba40bd5 | 69 | |
bba40bd5 | 70 | |
71 | ||
72 | =head1 METHODS | |
73 | ||
b5ce0e6a | 74 | =head2 get_repository (Str $name) |
bba40bd5 | 75 | |
44a9ed75 | 76 | Returns a L<Gitalist::Git::Repository> for the given name. |
b90f633a | 77 | If C<$name> is not a valid git repository under C<$repo_dir>, an exception |
78 | will be thrown. | |
79 | ||
bba40bd5 | 80 | |
bba40bd5 | 81 | |
3bbb1202 | 82 | =head1 SEE ALSO |
83 | ||
44a9ed75 | 84 | L<Gitalist::Git::Repository> |
3bbb1202 | 85 | |
8ba87261 | 86 | |
775e96e0 | 87 | =head1 AUTHORS |
3bbb1202 | 88 | |
775e96e0 | 89 | See L<Gitalist> for authors. |
3bbb1202 | 90 | |
91 | =head1 LICENSE | |
92 | ||
775e96e0 | 93 | See L<Gitalist> for the license. |
3bbb1202 | 94 | |
95 | =cut |