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',
70 # Simple directory of repositories (for list)
75 builder => '_build_repos_dir',
79 # Directory containing list of one or more repositories
82 isa => ArrayRefOfDirs,
86 sub _build_repos_dir {
88 my $dir = $self->_application->run_options->{repo_dir} || $ENV{GITALIST_REPO_DIR } || undef;
94 if ($self->repos_dir) { $self->repos_dir->resolve }
97 sub build_per_context_instance {
98 my ($self, $app) = @_;
101 export_ok => $self->export_ok || '',
102 $self->_has_whitelist ? (whitelist => $self->whitelist) : (),
103 repos => $self->repos,
104 repo_dir => $self->repos_dir,
108 my $class = $self->class;
110 $app->log->debug("Using class '$class'");
112 return $class->new(%args);
115 __PACKAGE__->meta->make_immutable;
123 Gitalist::Model::CollectionOfRepos - Model::CollectionOfRepos module for Gitalist
127 This Model is a factory for an object implementing the L<Gitalist::Git::CollectionOfRepositories>
130 The simple options passed on the command line (like C<--repos_dir>), a class will by picked by default
131 L<Gitalist::Git::CollectionOfRepositories::FromDirectory>.
133 This can be overridden from config by explicitly passing in a class name and args for that class
136 <Model::CollectionOfRepos>
141 </Model::CollectionOfRepos>
145 See L<Gitalist> for authors.
149 See L<Gitalist> for the license.