Merge branch 'project_list'
[catagits/Gitalist.git] / lib / Gitalist / Git / CollectionOfProjects / FromDirectory.pm
CommitLineData
7e7f9335 1use MooseX::Declare;
2
2a16bfc4 3class Gitalist::Git::CollectionOfProjects::FromDirectory
4 with Gitalist::Git::CollectionOfProjects {
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 {
35 my $p = $self->get_project($dir_entry);
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
2a16bfc4 47Gitalist::Git::CollectionOfProjects::FromDirectory - Model of a repository directory
bba40bd5 48
49=head1 SYNOPSIS
50
2a16bfc4 51 my $repo = Gitalist::Git::CollectionOfProjects::FromDirectory->new( repo_dir => $Dir );
bba40bd5 52 my $project_list = $repo->projects;
b90f633a 53 my $first_project = $project_list->[0];
ca6e3675 54 my $named_project = $repo->get_project('Gitalist');
bba40bd5 55
56=head1 DESCRIPTION
57
58This class models a Gitalist Repo, which is a collection of
59Projects (git repositories). It is used for creating Project
60objects to work with.
61
bba40bd5 62
63=head1 ATTRIBUTES
64
8ba87261 65=head2 repo_dir (C<Path::Class::Dir>)
bba40bd5 66
b90f633a 67The filesystem root of the C<Repo>.
bba40bd5 68
69=head2 projects
70
b90f633a 71An array of all L<Gitalist::Git::Project>s found in C<repo_dir>.
bba40bd5 72
bba40bd5 73
74
75=head1 METHODS
76
ca6e3675 77=head2 get_project (Str $name)
bba40bd5 78
b90f633a 79Returns a L<Gitalist::Git::Project> for the given name.
80If C<$name> is not a valid git repository under C<$repo_dir>, an exception
81will be thrown.
82
bba40bd5 83
bba40bd5 84
3bbb1202 85=head1 SEE ALSO
86
87L<Gitalist::Git::Project>
88
8ba87261 89
775e96e0 90=head1 AUTHORS
3bbb1202 91
775e96e0 92See L<Gitalist> for authors.
3bbb1202 93
94=head1 LICENSE
95
775e96e0 96See L<Gitalist> for the license.
3bbb1202 97
98=cut