X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FRepo.pm;h=c31a06a1b141870ac378496054153fb4b9239c57;hb=45881c7beb6de411e280a010f8f523613caa5d1f;hp=4146575b3b426fd38cf0aa105703c77162704b8d;hpb=3742082ae5aab55de26187993b685363a6548e80;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Repo.pm b/lib/Gitalist/Git/Repo.pm index 4146575..c31a06a 100644 --- a/lib/Gitalist/Git/Repo.pm +++ b/lib/Gitalist/Git/Repo.pm @@ -1,10 +1,39 @@ use MooseX::Declare; +=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 Gitalist::Git::Project; + use aliased 'Gitalist::Git::Project'; + +=head1 ATTRIBUTES + +=head2 repo_dir + +L for the root of the Repo. + +=cut + has repo_dir => ( isa => Dir, is => 'ro', @@ -12,37 +41,41 @@ class Gitalist::Git::Repo { coerce => 1, ); - method project (NonEmptySimpleStr $project) { - return Gitalist::Git::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 BUILD { $self->projects() } - method _is_git_repo ($dir) { - return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD'); - } -=head2 list_projects +=head1 METHODS + +=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( + name => $project, + path => $self->repo_dir->subdir($project), + ); + } + method _build_projects { my $base = $self->repo_dir; @@ -55,12 +88,39 @@ each item will contain the contents of L. next unless -d $obj; next unless $self->_is_git_repo($obj); - push @ret, Gitalist::Git::Project->new( - name => $file, - path => $obj, - ); + push @ret, $self->project($file); } 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'); + } + + +=head1 SEE ALSO + +L + +=head1 AUTHORS AND COPYRIGHT + + Catalyst application: + (C) 2009 Venda Ltd and Dan Brook + + Original gitweb.cgi from which this was derived: + (C) 2005-2006, Kay Sievers + (C) 2005, Christian Gierke + +=head1 LICENSE + +FIXME - Is this going to be GPLv2 as per gitweb? If so this is broken.. + +This library is free software. You can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut + + } # end class