Initial refactoring to pull a collectionofprojects role out of ::Git::Repo.
[catagits/Gitalist.git] / lib / Gitalist / Model / GitRepos.pm
CommitLineData
21336a02 1package Gitalist::Model::GitRepos;
2
3use Moose;
4use Gitalist::Git::Repo;
bddfb71e 5use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
a18818fd 6use Moose::Util::TypeConstraints;
21336a02 7use namespace::autoclean;
8
bddfb71e 9extends 'Catalyst::Model';
21336a02 10
bddfb71e 11with 'Catalyst::Component::InstancePerContext';
12
a18818fd 13my $repo_dir_t = subtype NonEmptySimpleStr,
14 where { -d $_ },
15 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' };
16
17has config_repo_dir => (
bddfb71e 18 isa => NonEmptySimpleStr,
19 is => 'ro',
a18818fd 20 init_arg => 'repo_dir',
21 predicate => 'has_config_repo_dir',
bddfb71e 22);
23
a18818fd 24has repo_dir => (
25 isa => $repo_dir_t,
26 is => 'ro',
27 lazy_build => 1
28);
29
30sub _build_repo_dir {
31 my $self = shift;
32 $ENV{GITALIST_REPO_DIR} ?
33 $ENV{GITALIST_REPO_DIR}
34 : $self->has_config_repo_dir
35 ? $self->config_repo_dir
36 : '';
37}
38
39after BUILD => sub {
40 my $self = shift;
41 $self->repo_dir; # Explode loudly at app startup time if there is no repos
42 # dir, rather than on first hit
43};
44
bddfb71e 45sub build_per_context_instance {
46 my ($self, $app) = @_;
47
48 Gitalist::Git::Repo->new(repo_dir => $self->repo_dir);
21336a02 49}
50
51__PACKAGE__->meta->make_immutable;
bddfb71e 52
775e96e0 53__END__
54
55=head1 AUTHORS
56
57See L<Gitalist> for authors.
58
59=head1 LICENSE
60
61See L<Gitalist> for the license.
62
63=cut