1 package Gitalist::Model::CollectionOfRepos;
4 use Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive;
5 use Gitalist::Git::CollectionOfRepositories::FromListOfDirectories;
6 use Gitalist::Git::CollectionOfRepositories::FromDirectory::WhiteList;
7 use MooseX::Types::Moose qw/Maybe ArrayRef/;
8 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
9 use Moose::Util::TypeConstraints;
11 use namespace::autoclean;
13 extends 'Catalyst::Model';
15 with 'Catalyst::Component::InstancePerContext';
17 my $repo_dir_t = subtype NonEmptySimpleStr,
19 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' };
21 my $arrayof_repos_dir_t = subtype ArrayRef[$repo_dir_t],
23 message { 'Cannot find repository directories listed in config - these are invalid directories: ' . join(', ', $_->flatten) };
25 coerce $arrayof_repos_dir_t,
26 from NonEmptySimpleStr,
29 has config_repo_dir => (
30 isa => NonEmptySimpleStr,
32 init_arg => 'repo_dir',
33 predicate => 'has_config_repo_dir',
43 isa => $arrayof_repos_dir_t,
45 default => sub { [] },
48 _repos_count => 'count',
54 isa => NonEmptySimpleStr,
61 default => sub { {} },
64 has search_recursively => (
82 $ENV{GITALIST_REPO_DIR} ?
83 $ENV{GITALIST_REPO_DIR}
84 : $self->has_config_repo_dir
85 ? $self->config_repo_dir
91 # Explode loudly at app startup time if there is no list of
92 # repositories or repos dir, rather than on first hit
93 $self->_repos_count || $self->repo_dir;
96 sub _default_model_class {
99 if($self->whitelist && -f $self->whitelist) {
100 return 'FromDirectory::WhiteList';
101 } elsif ($self->_repos_count && !$self->search_recursively) {
102 return 'FromListOfDirectories';
103 } elsif($self->search_recursively) {
104 return 'FromDirectoryRecursive';
107 return 'FromDirectory';
110 sub build_per_context_instance {
111 my ($self, $app) = @_;
114 export_ok => $self->export_ok || '',
118 my $class = $self->class;
119 Class::MOP::load_class($class) if $class;
121 my $default = $self->_default_model_class;
123 $args{whitelist} = $self->whitelist if $default eq 'FromDirectory::WhiteList';
124 $args{repos} = $self->repos if $default eq 'FromListOfDirectories';
125 $args{repo_dir} = $self->repo_dir if $default =~ /\b(?:WhiteList|FromDirectory(?:Recursive)?)$/;
127 $class ||= "Gitalist::Git::CollectionOfRepositories::$default";
129 $app->log->debug("Using class '$class'");
131 return $class->new(%args);
134 __PACKAGE__->meta->make_immutable;
142 Gitalist::Model::CollectionOfRepos - Model::CollectionOfRepos module for Gitalist
146 See L<Gitalist> for authors.
150 See L<Gitalist> for the license.