3 class Gitalist::Git::Repo {
4 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5 use MooseX::Types::Path::Class qw/Dir/;
6 use MooseX::Types::Moose qw/ArrayRef/;
7 use aliased 'Gitalist::Git::Project';
18 isa => ArrayRef['Gitalist::Git::Project'],
24 method project (NonEmptySimpleStr $project) {
25 my $path = $self->repo_dir->subdir($project)->resolve;
26 die "Directory traversal prohibited" unless $self->repo_dir->contains($path);
27 die "Not a valid Project" unless $self->_is_git_repo($path);
28 return Project->new( $self->repo_dir->subdir($project) );
32 method _build_projects {
33 my $base = $self->repo_dir;
34 my $dh = $base->open || die "Could not open $base";
36 while (my $file = $dh->read) {
37 next if $file =~ /^.{1,2}$/;
39 my $obj = $base->subdir($file);
41 next unless $self->_is_git_repo($obj);
43 push @ret, $self->project($file);
46 return [sort { $a->name cmp $b->name } @ret];
50 # Determine whether a given directory is a git repo.
51 method _is_git_repo ($dir) {
52 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
60 Gitalist::Git::Repo - Model of a repository directory
64 my $repo = Gitalist::Git::Repo->new( repo_dir => $Dir );
65 my $project_list = $repo->projects;
66 my $first_project = @$project_list[0];
67 my $named_project = $repo->project('Gitalist');
71 This class models a Gitalist Repo, which is a collection of
72 Projects (git repositories). It is used for creating Project
81 L<Path::Class::Dir> for the root of the Repo.
87 An array of L<Gitalist::Git::Project> for each valid git repo
95 =head2 project (NonEmptySimpleStr $project)
97 Returns a L<Gitalist::Git::Project> for the specified project
104 L<Gitalist::Git::Project>
108 See L<Gitalist> for authors.
112 See L<Gitalist> for the license.