3 role Gitalist::Git::CollectionOfRepositories {
4 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
5 use MooseX::Types::Moose qw/ArrayRef/;
7 use aliased 'Gitalist::Git::Repository';
11 isa => ArrayRef['Gitalist::Git::Repository'],
21 method get_repository (NonEmptySimpleStr $name) {
22 my $path = $self->_get_path_for_repository_name($name);
23 die "Couldn't get_repository '$name' - not a valid git repository."
24 unless $self->_is_git_repo($path);
25 return Repository->new( $path );
27 # Determine whether a given directory is a git repo.
28 # http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html
29 method _is_git_repo ($dir) {
30 my $has_head = -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
31 my $eok_file = $self->export_ok
33 my $is_visible = $eok_file
34 && (-f $dir->file($eok_file) || -f $dir->file('.git', $eok_file));
36 return $has_head && $is_visible;
40 _get_path_for_repository_name
43 around _build_repositories {
44 [sort { $a->name cmp $b->name } $self->$orig->flatten];
52 Gitalist::Git::CollectionOfRepositories - Interface and partial implementation of a collection of git repositories
56 package My::Example::CollectionOfRepositories;
58 use namespace::autoclean;
60 with 'Gitalist::Git::CollectionOfRepositories';
62 sub _build_repositories {
64 [ $self->get_repository('Gitalist') ];
66 sub _get_path_for_repository_name {
67 my ($self, $name) = @_;
68 '/var/example/' . $name . '.git';
71 my $collection = My::Example::CollectionOfRepositories->new
72 my $repository_list = $collection->repositories;
73 my $only_repository = $repository_list->[0];
74 my $named_repository = $repo->get_repository('Gitalist');
78 This role provides an abstraction for a list of Repository directories.
84 An array of all L<Gitalist::Git::Repository>s.
88 =head2 get_repository (Str $name)
90 Returns a L<Gitalist::Git::Repository> for the given name.
91 If C<$name> is not a valid git repository an exception will be thrown.
95 L<Gitalist::Git::CollectionOfRepositories::FromListOfDirectories>,
96 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>,
97 L<Gitalist::Git::Repository>.
101 See L<Gitalist> for authors.
105 See L<Gitalist> for the license.