use MooseX::Declare;
-role Gitalist::Git::CollectionOfRepositories with Gitalist::Git::Serializable {
+role Gitalist::Git::CollectionOfRepositories
+ with Gitalist::Git::Serializable
+ with Gitalist::Git::CollectionOfRepositories::Role::Context {
use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
use MooseX::Types::Moose qw/ArrayRef/;
use Moose::Autobox;
--- /dev/null
+use MooseX::Declare;
+
+role Gitalist::Git::CollectionOfRepositories::Role::Context {
+ requires qw/
+ implementation_class
+ ACCEPT_CONTEXT
+ /;
+
+ method implementation_class {
+ $self->meta->name
+ }
+
+ method ACCEPT_CONTEXT($ctx) {
+ return $self;
+ }
+}
use MooseX::Declare;
class Gitalist::Git::CollectionOfRepositories::Vhost
- with Gitalist::Git::CollectionOfRepositories {
- use MooseX::Types::Moose qw/ HashRef Str /;
- use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
- use MooseX::Types::Path::Class qw/Dir/;
- use Moose::Util::TypeConstraints;
+ with Gitalist::Git::CollectionOfRepositoriesWithRequestState {
+ use MooseX::Types::Moose qw/HashRef/;
sub BUILDARGS { # FIXME - This is fuck ugly!
my ($class, @args) = @_;
my $args = $class->next::method(@args);
return $ret;
}
+ has collections => (
+ is => 'ro',
+ isa => HashRef,
+ required => 1,
+ );
+
+ has vhost_dispatch => (
+ isa => HashRef,
+ traits => ['Hash'],
+ required => 1,
+ handles => {
+ _get_collection_name_for_vhost => 'get',
+ },
+ );
+
+ method implementation_class { 'Gitalist::Git::CollectionOfRepositories::VhostImpl' }
+ method extract_request_state ($ctx) {
+ return (vhost => $ctx->uri->host);
+ }
+}
+
+class Gitalist::Git::CollectionOfRepositories::VhostImpl
+ with Gitalist::Git::CollectionOfRepositories {
+ use MooseX::Types::Moose qw/ HashRef Str /;
+ use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
+ use MooseX::Types::Path::Class qw/Dir/;
+ use Moose::Util::TypeConstraints;
+
has vhost_dispatch => (
isa => HashRef,
traits => ['Hash'],
role_type 'Gitalist::Git::CollectionOfRepositories';
has chosen_collection => (
+ is => 'ro',
does => 'Gitalist::Git::CollectionOfRepositories',
handles => [qw/
_get_repo_from_name
--- /dev/null
+use MooseX::Declare;
+
+role Gitalist::Git::CollectionOfRepositoriesWithRequestState {
+ requires qw/
+ implementation_class
+ extract_request_state
+ /;
+
+ method ACCEPT_CONTEXT($c) {
+ $self->implementation_class->new(%$self, $self->extract_request_state($c))->chosen_collection;
+ }
+}
+
use Moose::Autobox;
use Path::Class qw/ dir /;
use namespace::autoclean;
+use Carp qw/croak/;
extends 'Catalyst::Model';
-with 'Catalyst::Component::ApplicationAttribute';
-with 'Catalyst::Component::InstancePerContext';
-
has class => (
isa => LoadableClass,
is => 'ro',
return 'Gitalist::Git::CollectionOfRepositories::FromDirectory';
}
else {
- return "Don't know where to get repositores from. Try a --repo_dir option, or setting up config";
+ croak "Don't know where to get repositores from. Try a --repo_dir option, or setting up config";
}
}
return $ENV{GITALIST_REPO_DIR};
}
-sub build_per_context_instance {
- my ($self, $ctx) = @_;
+sub BUILD {
+ my($self) = @_;
$self->class();
if ($self->repo_dir) { $self->repo_dir->resolve }
+}
+
+sub COMPONENT {
+ my($class, $ctx, @args) = @_;
+
+ my $self = $class->new($ctx, @args);
my %args = (
export_ok => $self->export_ok || '',
+ repos => $self->repos,
+ repo_dir => $self->repo_dir,
$self->_has_whitelist ? (whitelist => $self->whitelist) : (),
- repos => $self->repos,
- repo_dir => $self->repo_dir,
- vhost => $ctx->request->uri->host,
%{ $self->args }
);
- my $class = $self->class;
+ my $model_class = $self->class;
- $ctx->log->debug("Building $class with " . join(", ", map { $_ . " => " . (defined($args{$_}) ? "'" . $args{$_} . "'" : 'undef') } keys %args))
+ $ctx->log->debug("Building $model_class with " . join(", ", map { $_ . " => " . (defined($args{$_}) ? "'" . $args{$_} . "'" : 'undef') } keys %args))
if $ctx->debug;
- my $model = $class->new(%args);
- $ctx->log->debug("Using class '$class' " . $model->debug_string) if $ctx->debug;
+ my $model = $model_class->new(\%args);
+
+ $ctx->log->debug("Using class '$model_class' " . $model->debug_string) if $ctx->debug;
return $model;
}
around run => sub {
my $orig = shift;
my $self = shift;
- warn("Script repo dir" . $self->repo_dir);
local $ENV{GITALIST_REPO_DIR} = $self->repo_dir;
$self->$orig(@_);
};
+++ /dev/null
-Subproject commit 1516bf4a4e8b4ebc4e7b3bd07d42a68d7a6f406a
--- /dev/null
+ref: refs/heads/master
--- /dev/null
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
--- /dev/null
+A fake Catalyst repo based on repo1 for Vhost testing.
--- /dev/null
+# git-ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
--- /dev/null
+0710a7c8ee11c73e8098d08f9384c2a839c65e4e
--- /dev/null
+d6ddf8b26be63066e01d96a0922c87cd8d6e2270
--- /dev/null
+36c6c6708b8360d7023e8a1649c45bcf9b3bd818
+++ /dev/null
-Subproject commit 5731b027a3fcf44db136fb06def7c3049e8c7dc6
--- /dev/null
+ref: refs/heads/master
--- /dev/null
+[core]
+ repositoryformatversion = 0
+ filemode = true
+ bare = true
--- /dev/null
+A fake Moose repo based on repo1 for Vhost testing.
--- /dev/null
+# git-ls-files --others --exclude-from=.git/info/exclude
+# Lines that start with '#' are comments.
+# For a project mostly in C, the following would be a good set of
+# exclude patterns (uncomment them if you want to use them):
+# *.[oa]
+# *~
--- /dev/null
+0710a7c8ee11c73e8098d08f9384c2a839c65e4e
--- /dev/null
+d6ddf8b26be63066e01d96a0922c87cd8d6e2270
--- /dev/null
+36c6c6708b8360d7023e8a1649c45bcf9b3bd818
my $logger = $mock_log->name->new;
$mock_ctx_meta->add_method('log' => sub { $logger });
-my $host = "example.gitalist.com";
+my $host = "git.shadowcat.co.uk";
+$mock_ctx_meta->add_method('uri' => sub { URI->new("http://$host/") });
our $ctx_gen = sub {
my ($cb, %args) = @_;
my $ctx = $mock_ctx_meta->new_object(
};
local %ENV = %ENV;
+delete $ENV{GITALIST_CONFIG};
delete $ENV{GITALIST_REPO_DIR};
throws_ok { my $i = Gitalist::Model::CollectionOfRepos->COMPONENT($ctx_gen->(), {}); $i->{_application} = $mock_ctx_meta->name; }
});
}
-my $c_name = "$FindBin::Bin/lib/repositories_sets/catgit/Catalyst-Runtime/.git";
-my $m_name = "$FindBin::Bin/lib/repositories_sets/moose/Moose/.git";
+my $c_name = "$FindBin::Bin/lib/repositories_sets/catgit/Catalyst-Runtime";
+my $m_name = "$FindBin::Bin/lib/repositories_sets/moose/Moose";
{
my $i = test_vhost_instance();
is scalar($i->repositories->flatten), 2, 'Found 2 repos on test vhost';
ok $m, 'Has model';
my $i = $m->ACCEPT_CONTEXT($ctx);
ok $i, 'Has model instance from ACCEPT_CONTEXT';
- isnt $i, $m, 'Model instance returned from ACCEPT_CONTEXT not same as model';
- is $i, $m->ACCEPT_CONTEXT($ctx), 'Same model instance for same context';
- isnt $i, $m->ACCEPT_CONTEXT($ctx_gen->()), 'Different model instance for different context';
return $i;
}
+++ /dev/null
-use FindBin qw/$Bin/;
-BEGIN {
- my $env = "$FindBin::Bin/../script/env";
- if (-r $env) {
- do $env or die $@;
- }
-}
-
-
-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;
-