Get sane debugging info for the setup of everything
[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 {
31d3c368 5 use MooseX::Types::Moose qw/ HashRef Str /;
84a21009 6 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
7 use MooseX::Types::Path::Class qw/Dir/;
31d3c368 8 use Moose::Util::TypeConstraints;
9
10 sub BUILDARGS { # FIXME - This is fuck ugly!
11 my ($class, @args) = @_;
12 my $args = $class->next::method(@args);
13 my %collections = %{ delete $args->{collections} };
14 foreach my $name (keys %collections) {
15 my %args = %{$collections{$name}};
16 my $class = delete $args{class};
17 Class::MOP::load_class($class);
18 $collections{$name} = $class->new(%args);
19 }
20 my $ret = { %$args, collections => \%collections };
21 return $ret;
22 }
84a21009 23
24 has vhost_dispatch => (
25 isa => HashRef,
84a21009 26 traits => ['Hash'],
27 required => 1,
28 handles => {
29 _get_collection_name_for_vhost => 'get',
30 },
31 );
32
33 has collections => (
34 isa => HashRef,
35 traits => ['Hash'],
36 required => 1,
37 handles => {
38 _get_collection => 'get',
39 }
40 );
41
42 has vhost => (
43 is => 'ro',
44 isa => Str,
45 required => 1,
46 );
47
13c42902 48 method debug_string { 'chosen collection ' . ref($self->chosen_collection) . " " . $self->chosen_collection->debug_string }
49
31d3c368 50 role_type 'Gitalist::Git::CollectionOfRepositories';
84a21009 51 has chosen_collection => (
52 does => 'Gitalist::Git::CollectionOfRepositories',
53 handles => [qw/
54 _get_repo_from_name
55 _build_repositories
56 /],
57 default => sub {
58 my $self = shift;
31d3c368 59 $self->_get_collection($self->_get_collection_name_for_vhost($self->vhost) || $self->_get_collection_name_for_vhost('_default_'));
84a21009 60 },
61 lazy => 1,
62 );
63} # end class
64
65__END__
66
67=head1 NAME
68
69Gitalist::Git::CollectionOfRepositories::Vhost
70
71=head1 SYNOPSIS
72
73 my $repo = Gitalist::Git::CollectionOfRepositories::Vhost->new(
74 vhost_dispatch => {
75 "git.shadowcat.co.uk" => "foo",
76 "git.moose.perl.org" => "bar",
31d3c368 77 "_default_" => "foo",
84a21009 78 },
79 collections => {
31d3c368 80 foo => { class => Gitalist::Git::CollectionOfRepositories::XXX', %args },
81 bar => { class => Gitalist::Git::CollectionOfRepositories::XXX', %args },
84a21009 82 }
83 );
84 my $repository_list = $repo->repositories;
85 my $first_repository = $repository_list->[0];
86 my $named_repository = $repo->get_repository('Gitalist');
87
88=head1 DESCRIPTION
89
90=head1 SEE ALSO
91
92L<Gitalist::Git::CollectionOfRepositories>, L<Gitalist::Git::Repository>
93
94=head1 AUTHORS
95
96See L<Gitalist> for authors.
97
98=head1 LICENSE
99
100See L<Gitalist> for the license.
101
102=cut