Pass the vhost in as a parameter
[catagits/Gitalist.git] / lib / Gitalist / Git / CollectionOfRepositories / Vhost.pm
CommitLineData
84a21009 1use MooseX::Declare;
2
3class Gitalist::Git::CollectionOfRepositories::Vhost
4 with Gitalist::Git::CollectionOfRepositories {
5 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
6 use MooseX::Types::Path::Class qw/Dir/;
7
8 has vhost_dispatch => (
9 isa => HashRef,
10 sa => HashRef,
11 traits => ['Hash'],
12 required => 1,
13 handles => {
14 _get_collection_name_for_vhost => 'get',
15 },
16 );
17
18 has collections => (
19 isa => HashRef,
20 traits => ['Hash'],
21 required => 1,
22 handles => {
23 _get_collection => 'get',
24 }
25 );
26
27 has vhost => (
28 is => 'ro',
29 isa => Str,
30 required => 1,
31 );
32
33 has chosen_collection => (
34 does => 'Gitalist::Git::CollectionOfRepositories',
35 handles => [qw/
36 _get_repo_from_name
37 _build_repositories
38 /],
39 default => sub {
40 my $self = shift;
41 $self->_get_collection($self->_get_collection_name_for_vhost($self->vhost) || $self->_get_collection_name_for_vhost('default'));
42 },
43 lazy => 1,
44 );
45} # end class
46
47__END__
48
49=head1 NAME
50
51Gitalist::Git::CollectionOfRepositories::Vhost
52
53=head1 SYNOPSIS
54
55 my $repo = Gitalist::Git::CollectionOfRepositories::Vhost->new(
56 vhost_dispatch => {
57 "git.shadowcat.co.uk" => "foo",
58 "git.moose.perl.org" => "bar",
59 },
60 collections => {
61 foo => Gitalist::Git::CollectionOfRepositories::XXX->new(),
62 bar => Gitalist::Git::CollectionOfRepositories::XXX->new,
63 }
64 );
65 my $repository_list = $repo->repositories;
66 my $first_repository = $repository_list->[0];
67 my $named_repository = $repo->get_repository('Gitalist');
68
69=head1 DESCRIPTION
70
71=head1 SEE ALSO
72
73L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository>
74
75=head1 AUTHORS
76
77See L<Gitalist> for authors.
78
79=head1 LICENSE
80
81See L<Gitalist> for the license.
82
83=cut