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'],
15 method get_repository (NonEmptySimpleStr $name) {
16 my $path = $self->_get_path_for_repository_name($name);
17 die "Couldn't get_repository '$name' - not a valid git repository."
18 unless $self->_is_git_repo($path);
19 return Repository->new( $path );
21 # Determine whether a given directory is a git repo.
22 # http://www.kernel.org/pub/software/scm/git/docs/gitrepository-layout.html
23 method _is_git_repo ($dir) {
24 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
28 _get_path_for_repository_name
31 around _build_repositories {
32 [sort { $a->name cmp $b->name } $self->$orig->flatten];
40 Gitalist::Git::CollectionOfRepositories - Interface and partial implementation of a collection of git repositories
44 package My::Example::CollectionOfRepositories;
46 use namespace::autoclean;
48 with 'Gitalist::Git::CollectionOfRepositories';
50 sub _build_repositories {
52 [ $self->get_repository('Gitalist') ];
54 sub _get_path_for_repository_name {
55 my ($self, $name) = @_;
56 '/var/example/' . $name . '.git';
59 my $collection = My::Example::CollectionOfRepositories->new
60 my $repository_list = $collection->repositories;
61 my $only_repository = $repository_list->[0];
62 my $named_repository = $repo->get_repository('Gitalist');
66 This role provides an abstraction for a list of Repository directories.
72 An array of all L<Gitalist::Git::Repository>s.
76 =head2 get_repository (Str $name)
78 Returns a L<Gitalist::Git::Repository> for the given name.
79 If C<$name> is not a valid git repository an exception will be thrown.
83 L<Gitalist::Git::CollectionOfRepositories::FromListOfDirectories>,
84 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>,
85 L<Gitalist::Git::Repository>.
89 See L<Gitalist> for authors.
93 See L<Gitalist> for the license.