Further work on sorting out the style and content.
[catagits/Gitalist.git] / lib / Gitalist.pm
CommitLineData
89de6a33 1package Gitalist;
42fe5d11 2use Moose;
3use namespace::autoclean;
89de6a33 4
5use Catalyst::Runtime 5.80;
6
42fe5d11 7extends 'Catalyst';
89de6a33 8
43d4a724 9use Catalyst qw/
89de6a33 10 ConfigLoader
d5cc37a4 11 Static::Simple
61b56ed6 12 StackTrace/;
13
89de6a33 14our $VERSION = '0.01';
15
4666d5c7 16# Bring in the libified gitweb.cgi.
17use gitweb;
18
d3feefcf 19__PACKAGE__->config(
61b56ed6 20 name => 'Gitalist',
21 default_view => 'Default',
887260eb 22 default_model => 'Git', # Yes, we are going to be changing this.
dd3c4caf 23 # Set to 1 to make your fcgi die the request after you push :)
24 exit_at_end_of_request_if_updated => 0,
d3feefcf 25);
89de6a33 26
dd3c4caf 27{
28 my $version;
29 my $get_version = sub {
30 my $gitdir = shift->path_to('.git');
31 my $version = qx{cat "$gitdir/`cut -d' ' -f2 .git/HEAD`"};
32 chomp $version;
33 return $version;
34 };
35
36 after setup_finalize => sub {
37 my $c = shift;
38 $version = $c->$get_version
39 if $c->config->{exit_at_end_of_request_if_updated};
40 };
41 after handle_request => sub {
42 my $c = shift;
43 if ($version) {
44 my $new = $c->$get_version;
45 exit 0 unless $new eq $version;
46 }
47 };
48}
49
50
89de6a33 51# Start the application
52__PACKAGE__->setup();
53
4df2f62f 54around uri_for => sub {
55 my ($orig, $c) = (shift, shift);
63b77209 56 local $c->stash->{current_model}; # FIXME - for zts..
c1f608c8 57 my $hash = ref($_[-1]) eq 'HASH' ? pop @_ : {};
4df2f62f 58 my $params = Catalyst::Utils::merge_hashes(
c1f608c8 59 { p => $hash->{p} || $c->model()->project },
60 $hash,
4df2f62f 61 );
62 (my $uri = $c->$orig(@_, $params))
63 =~ tr[&][;];
64 return $uri;
65};
61b56ed6 66
89de6a33 67=head1 NAME
68
69Gitalist - Catalyst based application
70
71=head1 SYNOPSIS
72
73 script/gitalist_server.pl
74
75=head1 DESCRIPTION
76
77[enter your description here]
78
79=head1 SEE ALSO
80
81L<Gitalist::Controller::Root>, L<Catalyst>
82
42fe5d11 83=head1 AUTHORS AND COPYRIGHT
89de6a33 84
42fe5d11 85 Catalyst application:
86 (C) 2009 Venda Ltd and Dan Brook <dbrook@venda.com>
87
88 Original gitweb.cgi from which this was derived:
89 (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
90 (C) 2005, Christian Gierke
89de6a33 91
92=head1 LICENSE
93
42fe5d11 94FIXME - Is this going to be GPLv2 as per gitweb? If so this is broken..
95
89de6a33 96This library is free software. You can redistribute it and/or modify
97it under the same terms as Perl itself.
98
99=cut
100
1011;