1 package Gitalist::Model::CollectionOfRepos;
4 use MooseX::Types::Moose qw/Undef Maybe ArrayRef Str/;
5 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
6 use MooseX::Types::LoadableClass qw/ LoadableClass /;
7 use Gitalist::Git::Types qw/ ArrayRefOfDirs Dir DirOrUndef /;
8 use Moose::Util::TypeConstraints;
10 use Path::Class qw/ dir /;
11 use namespace::autoclean;
13 extends 'Catalyst::Model';
15 with 'Catalyst::Component::ApplicationAttribute';
16 with 'Catalyst::Component::InstancePerContext';
23 builder => '_build_class',
29 if($self->whitelist && -f $self->whitelist) {
30 return 'Gitalist::Git::CollectionOfRepositories::FromDirectory::WhiteList';
32 elsif($self->search_recursively) {
33 return 'Gitalist::Git::CollectionOfRepositories::FromDirectoryRecursive';
35 elsif ($self->repos) {
36 return 'Gitalist::Git::CollectionOfRepositories::FromListOfDirectories';
38 elsif ($self->repos_dir) {
39 return 'Gitalist::Git::CollectionOfRepositories::FromDirectory';
42 return "Don't know where to get repositores from. Try a --repos_dir option, or setting up config";
49 default => sub { {} },
52 has search_recursively => (
58 ## XX What is this for?
67 predicate => '_has_whitelist',
74 predicate => '_has_repo_dir',
77 # Simple directory of repositories (for list)
82 builder => '_build_repos_dir',
86 # Directory containing list of one or more repositories
89 isa => ArrayRefOfDirs,
93 sub _build_repos_dir {
95 my $opts = $self->_application->run_options || {};
96 return $self->_has_repo_dir && $self->repo_dir
97 || $opts->{repos_dir} || $ENV{GITALIST_REPO_DIR} || undef;
103 if ($self->repos_dir) { $self->repos_dir->resolve }
106 sub build_per_context_instance {
107 my ($self, $ctx) = @_;
110 export_ok => $self->export_ok || '',
111 $self->_has_whitelist ? (whitelist => $self->whitelist) : (),
112 repos => $self->repos,
113 repo_dir => $self->repos_dir,
114 vhost => $ctx->request->uri->host,
118 my $class = $self->class;
120 $ctx->log->debug("Using class '$class'") if $c->debug;
122 return $class->new(%args);
125 __PACKAGE__->meta->make_immutable;
133 Gitalist::Model::CollectionOfRepos - Model::CollectionOfRepos module for Gitalist
137 This Model is a factory for an object implementing the L<Gitalist::Git::CollectionOfRepositories>
140 The simple options passed on the command line (like C<--repos_dir>), a class will by picked by default
141 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>.
143 This can be overridden from config by explicitly passing in a class name and args for that class
146 <Model::CollectionOfRepos>
151 </Model::CollectionOfRepos>
155 See L<Gitalist> for authors.
159 See L<Gitalist> for the license.