1 package Gitalist::Model::CollectionOfRepos;
4 use Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive;
5 use Gitalist::Git::CollectionOfRepositories::FromListOfDirectories;
6 use MooseX::Types::Moose qw/Maybe ArrayRef/;
7 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
8 use Moose::Util::TypeConstraints;
10 use namespace::autoclean;
12 extends 'Catalyst::Model';
14 with 'Catalyst::Component::InstancePerContext';
16 my $repo_dir_t = subtype NonEmptySimpleStr,
18 message { 'Cannot find repository dir: "' . $_ . '", please set up gitalist.conf, or set GITALIST_REPO_DIR environment or pass the --repo_dir parameter when starting the application' };
20 my $arrayof_repos_dir_t = subtype ArrayRef[$repo_dir_t],
22 message { 'Cannot find repository directories listed in config - these are invalid directories: ' . join(', ', $_->flatten) };
24 coerce $arrayof_repos_dir_t,
25 from NonEmptySimpleStr,
28 has config_repo_dir => (
29 isa => NonEmptySimpleStr,
31 init_arg => 'repo_dir',
32 predicate => 'has_config_repo_dir',
42 isa => $arrayof_repos_dir_t,
44 default => sub { [] },
47 _repos_count => 'count',
54 $ENV{GITALIST_REPO_DIR} ?
55 $ENV{GITALIST_REPO_DIR}
56 : $self->has_config_repo_dir
57 ? $self->config_repo_dir
63 # Explode loudly at app startup time if there is no list of
64 # repositories or repos dir, rather than on first hit
65 $self->_repos_count || $self->repo_dir;
68 sub build_per_context_instance {
69 my ($self, $app) = @_;
70 if ($self->_repos_count) {
71 Gitalist::Git::CollectionOfRepositories::FromListOfDirectories->new(repos => $self->repos);
74 Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive->new(repo_dir => $self->repo_dir);
78 __PACKAGE__->meta->make_immutable;
84 See L<Gitalist> for authors.
88 See L<Gitalist> for the license.