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->repo_dir) {
39 return 'Gitalist::Git::CollectionOfRepositories::FromDirectory';
42 return "Don't know where to get repositores from. Try a --repo_dir option, or setting up config";
49 default => sub { {} },
52 has search_recursively => (
58 ## XX What is this for?
67 predicate => '_has_whitelist',
70 # Simple directory of repositories (for list)
75 builder => '_build_repo_dir',
79 # Directory containing list of one or more repositories
82 isa => ArrayRefOfDirs,
88 return $ENV{GITALIST_REPO_DIR};
91 sub build_per_context_instance {
92 my ($self, $ctx) = @_;
96 if ($self->repo_dir) { $self->repo_dir->resolve }
99 export_ok => $self->export_ok || '',
100 $self->_has_whitelist ? (whitelist => $self->whitelist) : (),
101 repos => $self->repos,
102 repo_dir => $self->repo_dir,
103 vhost => $ctx->request->uri->host,
107 my $class = $self->class;
109 $ctx->log->debug("Building $class with " . join(", ", map { $_ . " => " . (defined($args{$_}) ? "'" . $args{$_} . "'" : 'undef') } keys %args))
111 my $model = $class->new(%args);
113 $ctx->log->debug("Using class '$class' " . $model->debug_string) if $ctx->debug;
118 __PACKAGE__->meta->make_immutable;
126 Gitalist::Model::CollectionOfRepos - Model::CollectionOfRepos module for Gitalist
130 This Model is a factory for an object implementing the L<Gitalist::Git::CollectionOfRepositories>
133 The simple options passed on the command line (like C<--repo_dir>), a class will by picked by default
134 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>.
136 This can be overridden from config by explicitly passing in a class name and args for that class
139 <Model::CollectionOfRepos>
144 </Model::CollectionOfRepos>
148 See L<Gitalist> for authors.
152 See L<Gitalist> for the license.