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';
9 with 'Gitalist::Serializeable';
13 isa => ArrayRef['Gitalist::Git::Repository'],
17 method get_repository (NonEmptySimpleStr $name) {
18 my $path = $self->_get_path_for_repository_name($name);
19 die "Not a valid git repository."
20 unless $self->_is_git_repo($path);
21 return Repository->new( $path );
23 # Determine whether a given directory is a git repo.
24 method _is_git_repo ($dir) {
25 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
29 _get_path_for_repository_name
32 around _build_repositories {
33 [sort { $a->name cmp $b->name } $self->$orig->flatten];
41 Gitalist::Git::CollectionOfRepositories - Interface and partial implementation of a collection of git repositories
45 package My::Example::CollectionOfRepositories;
47 use namespace::autoclean;
49 with 'Gitalist::Git::CollectionOfRepositories';
51 sub _build_repositories {
53 [ $self->get_repository('Gitalist') ];
55 sub _get_path_for_repository_name {
56 my ($self, $name) = @_;
57 '/var/example/' . $name . '.git';
60 my $collection = My::Example::CollectionOfRepositories->new
61 my $repository_list = $collection->repositories;
62 my $only_repository = $repository_list->[0];
63 my $named_repository = $repo->get_repository('Gitalist');
67 This role provides an abstraction for a list of Repository directories.
73 An array of all L<Gitalist::Git::Repository>s.
77 =head2 get_repository (Str $name)
79 Returns a L<Gitalist::Git::Repository> for the given name.
80 If C<$name> is not a valid git repository an exception will be thrown.
84 L<Gitalist::Git::CollectionOfRepositories::FromListOfDirectories>,
85 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>,
86 L<Gitalist::Git::Repository>.
90 See L<Gitalist> for authors.
94 See L<Gitalist> for the license.