Make starting gitalist pointed at somewhere settable from an environment variable...
Tomas Doran [Sun, 6 Dec 2009 14:11:10 +0000 (14:11 +0000)]
Changes
lib/Gitalist/Model/GitRepos.pm
lib/Gitalist/Script/CGI.pm [new file with mode: 0644]
lib/Gitalist/Script/FastCGI.pm
lib/Gitalist/Script/Server.pm [new file with mode: 0644]
lib/Gitalist/ScriptRole.pm [new file with mode: 0644]
t/01app.t
t/03legacy_uri.t
t/scripts.t [new file with mode: 0644]

diff --git a/Changes b/Changes
index 753186a..86218e2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,12 @@
 This file documents the revision history for Perl extension Gitalist.
 
+   - Fix so that invalid repository directory will be detected at application
+     startup and a helpful error message will be displayed.
+   - Add --repos_dir command line parameter to all of the scripts which can
+     be used to force the repository directory, overriding config and
+     environment.
+   - Add GITALIST_REPOS_DIR environment variable which will determine the
+     repository path (overriding normal config) if set.
    - Change so that no default repos path is in the config when installed from
      CPAN (when checked out of git, behavior of browsing AppDir/../ is
      maintained).
index 5d2f66b..f988d8c 100644 (file)
@@ -3,18 +3,45 @@ package Gitalist::Model::GitRepos;
 use Moose;
 use Gitalist::Git::Repo;
 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+use Moose::Util::TypeConstraints;
 use namespace::autoclean;
 
 extends 'Catalyst::Model';
 
 with 'Catalyst::Component::InstancePerContext';
 
-has repo_dir => (
+my $repo_dir_t = subtype NonEmptySimpleStr,
+    where { -d $_ },
+    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' };
+
+has config_repo_dir => (
     isa => NonEmptySimpleStr,
     is => 'ro',
-    required => 1,
+    init_arg => 'repo_dir',
+    predicate => 'has_config_repo_dir',
 );
 
+has repo_dir => (
+    isa => $repo_dir_t,
+    is => 'ro',
+    lazy_build => 1
+);
+
+sub _build_repo_dir {
+    my $self = shift;
+    $ENV{GITALIST_REPO_DIR} ?
+        $ENV{GITALIST_REPO_DIR}
+      : $self->has_config_repo_dir
+      ? $self->config_repo_dir
+        : '';
+}
+
+after BUILD => sub {
+    my $self = shift;
+    $self->repo_dir; # Explode loudly at app startup time if there is no repos
+                     # dir, rather than on first hit
+};
+
 sub build_per_context_instance {
     my ($self, $app) = @_;
 
diff --git a/lib/Gitalist/Script/CGI.pm b/lib/Gitalist/Script/CGI.pm
new file mode 100644 (file)
index 0000000..9e3e365
--- /dev/null
@@ -0,0 +1,9 @@
+package Gitalist::Script::CGI;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::Script::CGI';
+with 'Gitalist::ScriptRole';
+
+__PACKAGE__->meta->make_immutable;
+
index 778760c..8c03a33 100644 (file)
@@ -3,6 +3,7 @@ use Moose;
 use namespace::autoclean;
 
 extends 'Catalyst::Script::FastCGI';
+with 'Gitalist::ScriptRole';
 
 # Only exists so that this horrible hack can happen..
 # This should be in FCGI.pm, see:
diff --git a/lib/Gitalist/Script/Server.pm b/lib/Gitalist/Script/Server.pm
new file mode 100644 (file)
index 0000000..8e9b539
--- /dev/null
@@ -0,0 +1,9 @@
+package Gitalist::Script::Server;
+use Moose;
+use namespace::autoclean;
+
+extends 'Catalyst::Script::Server';
+with 'Gitalist::ScriptRole';
+
+__PACKAGE__->meta->make_immutable;
+
diff --git a/lib/Gitalist/ScriptRole.pm b/lib/Gitalist/ScriptRole.pm
new file mode 100644 (file)
index 0000000..ef7d37e
--- /dev/null
@@ -0,0 +1,24 @@
+package Gitalist::ScriptRole;
+use Moose::Role;
+use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+use namespace::autoclean;
+
+has repo_dir => (
+    isa => NonEmptySimpleStr, is => 'ro',
+    predicate => 'has_repo_dir'
+);
+
+before 'run' => sub {
+    my $self = shift;
+    if ($self->has_repo_dir) {
+        # FIXME - This seems gross. I should be able to pass things through
+        #         to the app instance, but the params are sent to the engine
+        #         and not actually used to construct the app.. Not that
+        #         $ENV{GITLIST_REPO_DIR} is a bad move, just that that being
+        #         the mechanism by which this works that is non optimum.
+        $ENV{GITALIST_REPO_DIR} = $self->repo_dir;
+    }
+};
+
+1;
+
index a39a128..cd20afe 100644 (file)
--- a/t/01app.t
+++ b/t/01app.t
@@ -6,6 +6,7 @@ use FindBin qw/$Bin/;
 
 BEGIN {
     $ENV{GITALIST_CONFIG} = $Bin;
+    $ENV{GITALIST_REPO_DIR} = undef;
     use_ok 'Catalyst::Test', 'Gitalist'
 }
 
index 6ff8e99..1522623 100644 (file)
@@ -6,6 +6,7 @@ use FindBin qw/$Bin/;
 
 BEGIN {
     $ENV{GITALIST_CONFIG} = $Bin;
+    $ENV{GITALIST_REPO_DIR} = undef;
     use_ok 'Catalyst::Test', 'Gitalist'
 }
 
diff --git a/t/scripts.t b/t/scripts.t
new file mode 100644 (file)
index 0000000..2402921
--- /dev/null
@@ -0,0 +1,12 @@
+use strict;
+use warnings;
+use Test::More;
+
+use_ok('Gitalist::Script::CGI');
+use_ok('Gitalist::Script::Server');
+use_ok('Gitalist::Script::FastCGI');
+
+# FIXME - Test the script role.
+
+done_testing;
+