Commit | Line | Data |
21336a02 |
1 | package Gitalist::Model::GitRepos; |
2 | |
3 | use Moose; |
4 | use Gitalist::Git::Repo; |
bddfb71e |
5 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
a18818fd |
6 | use Moose::Util::TypeConstraints; |
21336a02 |
7 | use namespace::autoclean; |
8 | |
bddfb71e |
9 | extends 'Catalyst::Model'; |
21336a02 |
10 | |
bddfb71e |
11 | with 'Catalyst::Component::InstancePerContext'; |
12 | |
a18818fd |
13 | my $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 | |
17 | has 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 |
24 | has repo_dir => ( |
25 | isa => $repo_dir_t, |
26 | is => 'ro', |
27 | lazy_build => 1 |
28 | ); |
29 | |
30 | sub _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 | |
39 | after 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 |
45 | sub 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 | |
57 | See L<Gitalist> for authors. |
58 | |
59 | =head1 LICENSE |
60 | |
61 | See L<Gitalist> for the license. |
62 | |
63 | =cut |