Commit | Line | Data |
---|---|---|
7e7f9335 | 1 | use MooseX::Declare; |
2 | ||
6b3c0b76 | 3 | class Gitalist::Git::Repo with Gitalist::Git::CollectionOfProjects { |
7e7f9335 | 4 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
84f31a44 | 5 | use MooseX::Types::Path::Class qw/Dir/; |
38b9e5c8 | 6 | |
84f31a44 | 7 | has repo_dir => ( |
8 | isa => Dir, | |
9 | is => 'ro', | |
10 | required => 1, | |
11 | coerce => 1, | |
12 | ); | |
7e7f9335 | 13 | |
ca6e3675 | 14 | method BUILD { |
15 | # Make sure repo_dir is an absolute path so that | |
16 | # ->contains() works correctly. | |
17 | $self->repo_dir->resolve; | |
18 | } | |
19 | ||
6b3c0b76 | 20 | method _get_path_for_project_name (NonEmptySimpleStr $name) { |
ca6e3675 | 21 | my $path = $self->repo_dir->subdir($name)->resolve; |
22 | die "Directory traversal prohibited" | |
23 | unless $self->repo_dir->contains($path); | |
6b3c0b76 | 24 | return $path; |
3bbb1202 | 25 | } |
26 | ||
bba40bd5 | 27 | ## Builders |
84f31a44 | 28 | method _build_projects { |
cea99b3a | 29 | my $dh = $self->repo_dir->open || die "Could not open repo_dir"; |
84f31a44 | 30 | my @ret; |
cea99b3a | 31 | while (my $dir_entry = $dh->read) { |
32 | # try to get a project for each entry in repo_dir | |
33 | eval { | |
34 | my $p = $self->get_project($dir_entry); | |
35 | push @ret, $p; | |
36 | }; | |
37 | } | |
6b3c0b76 | 38 | return \@ret; |
3bbb1202 | 39 | } |
775e96e0 | 40 | } # end class |
3bbb1202 | 41 | |
775e96e0 | 42 | __END__ |
3bbb1202 | 43 | |
bba40bd5 | 44 | =head1 NAME |
45 | ||
46 | Gitalist::Git::Repo - Model of a repository directory | |
47 | ||
48 | =head1 SYNOPSIS | |
49 | ||
50 | my $repo = Gitalist::Git::Repo->new( repo_dir => $Dir ); | |
51 | my $project_list = $repo->projects; | |
b90f633a | 52 | my $first_project = $project_list->[0]; |
ca6e3675 | 53 | my $named_project = $repo->get_project('Gitalist'); |
bba40bd5 | 54 | |
55 | =head1 DESCRIPTION | |
56 | ||
57 | This class models a Gitalist Repo, which is a collection of | |
58 | Projects (git repositories). It is used for creating Project | |
59 | objects to work with. | |
60 | ||
bba40bd5 | 61 | |
62 | =head1 ATTRIBUTES | |
63 | ||
8ba87261 | 64 | =head2 repo_dir (C<Path::Class::Dir>) |
bba40bd5 | 65 | |
b90f633a | 66 | The filesystem root of the C<Repo>. |
bba40bd5 | 67 | |
68 | =head2 projects | |
69 | ||
b90f633a | 70 | An array of all L<Gitalist::Git::Project>s found in C<repo_dir>. |
bba40bd5 | 71 | |
bba40bd5 | 72 | |
73 | ||
74 | =head1 METHODS | |
75 | ||
ca6e3675 | 76 | =head2 get_project (Str $name) |
bba40bd5 | 77 | |
b90f633a | 78 | Returns a L<Gitalist::Git::Project> for the given name. |
79 | If C<$name> is not a valid git repository under C<$repo_dir>, an exception | |
80 | will be thrown. | |
81 | ||
bba40bd5 | 82 | |
bba40bd5 | 83 | |
3bbb1202 | 84 | =head1 SEE ALSO |
85 | ||
86 | L<Gitalist::Git::Project> | |
87 | ||
8ba87261 | 88 | |
775e96e0 | 89 | =head1 AUTHORS |
3bbb1202 | 90 | |
775e96e0 | 91 | See L<Gitalist> for authors. |
3bbb1202 | 92 | |
93 | =head1 LICENSE | |
94 | ||
775e96e0 | 95 | See L<Gitalist> for the license. |
3bbb1202 | 96 | |
97 | =cut |