From: Tomas Doran Date: Wed, 20 Jul 2011 11:17:27 +0000 (+0100) Subject: Vhost based repository chooser. X-Git-Tag: 0.003007~15 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=commitdiff_plain;h=84a21009cd9d5c180946d6328afd046db0101012 Vhost based repository chooser. --- diff --git a/lib/Gitalist/Git/CollectionOfRepositories/Vhost.pm b/lib/Gitalist/Git/CollectionOfRepositories/Vhost.pm new file mode 100644 index 0000000..d8499ed --- /dev/null +++ b/lib/Gitalist/Git/CollectionOfRepositories/Vhost.pm @@ -0,0 +1,83 @@ +use MooseX::Declare; + +class Gitalist::Git::CollectionOfRepositories::Vhost + with Gitalist::Git::CollectionOfRepositories { + use MooseX::Types::Common::String qw/NonEmptySimpleStr/; + use MooseX::Types::Path::Class qw/Dir/; + + has vhost_dispatch => ( + isa => HashRef, + sa => HashRef, + traits => ['Hash'], + required => 1, + handles => { + _get_collection_name_for_vhost => 'get', + }, + ); + + has collections => ( + isa => HashRef, + traits => ['Hash'], + required => 1, + handles => { + _get_collection => 'get', + } + ); + + has vhost => ( + is => 'ro', + isa => Str, + required => 1, + ); + + has chosen_collection => ( + does => 'Gitalist::Git::CollectionOfRepositories', + handles => [qw/ + _get_repo_from_name + _build_repositories + /], + default => sub { + my $self = shift; + $self->_get_collection($self->_get_collection_name_for_vhost($self->vhost) || $self->_get_collection_name_for_vhost('default')); + }, + lazy => 1, + ); +} # end class + +__END__ + +=head1 NAME + +Gitalist::Git::CollectionOfRepositories::Vhost + +=head1 SYNOPSIS + + my $repo = Gitalist::Git::CollectionOfRepositories::Vhost->new( + vhost_dispatch => { + "git.shadowcat.co.uk" => "foo", + "git.moose.perl.org" => "bar", + }, + collections => { + foo => Gitalist::Git::CollectionOfRepositories::XXX->new(), + bar => Gitalist::Git::CollectionOfRepositories::XXX->new, + } + ); + my $repository_list = $repo->repositories; + my $first_repository = $repository_list->[0]; + my $named_repository = $repo->get_repository('Gitalist'); + +=head1 DESCRIPTION + +=head1 SEE ALSO + +L, L + +=head1 AUTHORS + +See L for authors. + +=head1 LICENSE + +See L for the license. + +=cut