X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FRepo.pm;h=4a5d491db8b95bee5bad56006cd3fb4a1ecdddb1;hb=468e883470dc48d46e84de2218d8524311a32b04;hp=3348bddb7954c1c67bfd5ac1d41188dc83b0b71a;hpb=38b9e5c8f6eb41f89cc6c13f2c4942149e593020;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Repo.pm b/lib/Gitalist/Git/Repo.pm index 3348bdd..4a5d491 100644 --- a/lib/Gitalist/Git/Repo.pm +++ b/lib/Gitalist/Git/Repo.pm @@ -1,16 +1,38 @@ use MooseX::Declare; -class Gitalist::Git::Repo with Gitalist::Git::HasUtils { +=head1 NAME + +Gitalist::Git::Repo - Model of a repository directory + +=head1 SYNOPSIS + + my $repo = Gitalist::Git::Repo->new( repo_dir => $Dir ); + my $project_list = $repo->projects; + my $first_project = @$project_list[0]; + my $named_project = $repo->project('Gitalist'); + +=head1 DESCRIPTION + +This class models a Gitalist Repo, which is a collection of +Projects (git repositories). It is used for creating Project +objects to work with. + +=cut + + +class Gitalist::Git::Repo { use MooseX::Types::Common::String qw/NonEmptySimpleStr/; use MooseX::Types::Path::Class qw/Dir/; use MooseX::Types::Moose qw/ArrayRef/; use aliased 'Gitalist::Git::Project'; - # FIXME - this is nasty as we build the Git::Utils thing without a project name - # should refactor or something? - method _build__util { - Gitalist::Git::Util->new(); - } +=head1 ATTRIBUTES + +=head2 repo_dir + +L for the root of the Repo. + +=cut has repo_dir => ( isa => Dir, @@ -19,37 +41,36 @@ class Gitalist::Git::Repo with Gitalist::Git::HasUtils { coerce => 1, ); - method project (NonEmptySimpleStr $project) { - return Project->new( - name => $project, - path => $self->repo_dir->subdir($project), - ); - } +=head2 projects +An array of L for each valid git repo +found in repo_dir. -=head2 _is_git_repo +=cut -Determine whether a given directory (as a L object) is a -C repo. + has projects => ( + is => 'ro', + isa => ArrayRef['Gitalist::Git::Project'], + required => 1, + lazy_build => 1, + ); -=cut - method _is_git_repo ($dir) { - return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); - } +=head1 METHODS -=head2 list_projects +=head2 project -For the C specified in the config return an array of projects where -each item will contain the contents of L. +Returns a L for the specified project +name. =cut - has projects => ( - isa => ArrayRef['Gitalist::Git::Project'], - reader => 'list_projects', - lazy_build => 1, - ); + method project (NonEmptySimpleStr $project) { + my $path = $self->repo_dir->subdir($project); + die "Not a valid Project" unless $self->_is_git_repo($path); + return Project->new( $self->repo_dir->subdir($project) ); + } + method _build_projects { my $base = $self->repo_dir; @@ -67,4 +88,25 @@ each item will contain the contents of L. return [sort { $a->name cmp $b->name } @ret]; } + + # Determine whether a given directory is a git repo. + method _is_git_repo ($dir) { + return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); + } } # end class + +__END__ + +=head1 SEE ALSO + +L + +=head1 AUTHORS + +See L for authors. + +=head1 LICENSE + +See L for the license. + +=cut