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 "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 method _is_git_repo ($dir) {
23 return -f $dir->file('HEAD') || -f $dir->file('.git', 'HEAD');
27 _get_path_for_repository_name
30 around _build_repositories {
31 [sort { $a->name cmp $b->name } $self->$orig->flatten];
39 Gitalist::Git::CollectionOfRepositories - Interface and partial implementation of a collection of git repositories
43 package My::Example::CollectionOfRepositories;
45 use namespace::autoclean;
47 with 'Gitalist::Git::CollectionOfRepositories';
49 sub _build_repositories {
51 [ $self->get_repository('Gitalist') ];
53 sub _get_path_for_repository_name {
54 my ($self, $name) = @_;
55 '/var/example/' . $name . '.git';
58 my $collection = My::Example::CollectionOfRepositories->new
59 my $repository_list = $collection->repositories;
60 my $only_repository = $repository_list->[0];
61 my $named_repository = $repo->get_repository('Gitalist');
65 This role provides an abstraction for a list of Repository directories.
71 An array of all L<Gitalist::Git::Repository>s.
75 =head2 get_repository (Str $name)
77 Returns a L<Gitalist::Git::Repository> for the given name.
78 If C<$name> is not a valid git repository an exception will be thrown.
82 L<Gitalist::Git::CollectionOfRepositories::FromListOfDirectories>,
83 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>,
84 L<Gitalist::Git::Repository>.
88 See L<Gitalist> for authors.
92 See L<Gitalist> for the license.