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::ApplicationAttribute';
16 with 'Catalyst::Component::InstancePerContext';
18 my $repo_dir_t = subtype NonEmptySimpleStr,
20 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' };
22 my $arrayof_repos_dir_t = subtype ArrayRef[$repo_dir_t],
24 message { 'Cannot find repository directories listed in config - these are invalid directories: ' . join(', ', $_->flatten) };
26 coerce $arrayof_repos_dir_t,
27 from NonEmptySimpleStr,
30 has config_repo_dir => (
31 isa => NonEmptySimpleStr,
33 init_arg => 'repo_dir',
34 predicate => 'has_config_repo_dir',
44 isa => $arrayof_repos_dir_t,
46 default => sub { [] },
49 _repos_count => 'count',
55 isa => NonEmptySimpleStr,
62 default => sub { {} },
65 has search_recursively => (
83 my $repo_dir = $self->_application->run_options->{repo_dir};
87 : $self->has_config_repo_dir
88 ? $self->config_repo_dir
94 # Explode loudly at app startup time if there is no list of
95 # repositories or repos dir, rather than on first hit
96 $self->_repos_count || $self->repo_dir;
99 sub _default_model_class {
102 if($self->whitelist && -f $self->whitelist) {
103 return 'FromDirectory::WhiteList';
104 } elsif ($self->_repos_count && !$self->search_recursively) {
105 return 'FromListOfDirectories';
106 } elsif($self->search_recursively) {
107 return 'FromDirectoryRecursive';
110 return 'FromDirectory';
113 sub build_per_context_instance {
114 my ($self, $app) = @_;
117 export_ok => $self->export_ok || '',
121 my $class = $self->class;
122 Class::MOP::load_class($class) if $class;
124 my $default = $self->_default_model_class;
126 $args{whitelist} = $self->whitelist if $default eq 'FromDirectory::WhiteList';
127 $args{repos} = $self->repos if $default eq 'FromListOfDirectories';
128 $args{repo_dir} = $self->repo_dir if $default =~ /\b(?:WhiteList|FromDirectory(?:Recursive)?)$/;
130 $class ||= "Gitalist::Git::CollectionOfRepositories::$default";
132 $app->log->debug("Using class '$class'");
134 return $class->new(%args);
137 __PACKAGE__->meta->make_immutable;
145 Gitalist::Model::CollectionOfRepos - Model::CollectionOfRepos module for Gitalist
149 See L<Gitalist> for authors.
153 See L<Gitalist> for the license.