Work correctly with latest Catalyst
[catagits/Gitalist.git] / lib / Gitalist.pm
1 package Gitalist;
2 use Moose;
3 BEGIN { require 5.008006; }
4 use Catalyst::Runtime 5.80;
5 use namespace::autoclean;
6
7 extends 'Catalyst';
8
9 use Catalyst qw/
10                 ConfigLoader
11                 Unicode::Encoding
12                 Static::Simple
13                 StackTrace
14                 SubRequest
15 /;
16
17 our $VERSION = '0.001007';
18 $VERSION = eval $VERSION;
19
20 __PACKAGE__->config(
21     name => 'Gitalist',
22     default_view => 'Default',
23     default_model => 'CollectionOfRepos',
24     use_request_uri_for_path => 1,
25     disable_component_resolution_regex_fallback => 1,
26 );
27
28 __PACKAGE__->setup();
29
30 after prepare_path => sub {
31     my ($ctx) = @_;
32     if ($ctx->req->param('a')) {
33         $ctx->request->uri->path('/legacy' . $ctx->request->uri->path);
34     }
35 };
36
37 around uri_for => sub {
38   my ($orig, $c) = (shift, shift);
39   my $uri = $c->$orig(@_);
40   $$uri =~ tr[&][;] if defined $uri;
41   return $uri;
42 };
43
44 around uri_for_action => sub {
45   my ($orig, $c) = (shift, shift);
46   my $uri = $c->$orig(@_);
47   $$uri =~ s[/fragment\b][] if defined $uri;
48   return $uri;
49 };
50
51 sub uri_with {
52   my ($self, @args) = @_;
53   my $uri = $self->request->uri_with(@args);
54   # Wow this awful.
55   $uri =~ s[/fragment\b][];
56   return $uri;  
57 }
58
59 1;
60
61 __END__
62
63 =head1 NAME
64
65 Gitalist - A modern git web viewer
66
67 =head1 SYNOPSIS
68
69     script/gitalist_server.pl --repo_dir /home/me/code/git
70
71 =head1 INSTALL
72
73 As Gitalist follows the usual Perl module format the usual approach
74 for installation should work e.g.
75
76   perl Makefile.PL
77   make
78   make test
79   make install
80
81 or
82
83   cpan -i Gitalist
84
85 You can also check gitalist out from git and run it, in this case you'll additionally
86 need the author modules, but no configuration will be needed as it will default to looking
87 for repositories the directory above the checkout.
88
89 =head1 DESCRIPTION
90
91 Gitalist is a web frontend for git repositories based on gitweb.cgi
92 and backed by Catalyst.
93
94 =head2 History
95
96 This project started off as an attempt to port gitweb.cgi to a
97 Catalyst app in a piecemeal fashion. As it turns out, thanks largely
98 to Florian Ragwitz's earlier effort, it was easier to use gitweb.cgi
99 as a template for building a new Catalyst application.
100
101 =head1 GETTING GITALIST
102
103 You can install Gitalist from CPAN in the usual way:
104
105     cpan -i Gitalist
106
107 Alternatively, you can get Gitalist using git.
108
109 The canonical repository for the master branch is:
110
111     git://git.shadowcat.co.uk/catagits/Gitalist.git
112
113 Gitalist is also mirrored to github, and a number of people have active forks
114 with branches and/or new features in the master branch.
115
116 =head1 INITIAL CONFIGURATION
117
118 Gitalist is configured using L<Catalyst::Plugin::Configloader>. The supplied sample
119 configuration is in L<Config::General> format, however it is possible to configure
120 Gitalist using other config file formats (such as YAML) if you prefer.
121
122 =head2 WHEN CHECKING GITALIST OUT OF GIT
123
124 Gitalist from git includes a minimal C<gitalist_local.conf>, which sets the repository
125 directory to one directory higher than the Gitalist repository.
126
127 This means that if you check Gitalist out next to your other git checkouts, then starting
128 the demo server needs no parameters at all:
129
130     Gitalist [master]$ ./script/gitalist_server.pl
131     You can connect to your server at http://localhost:3000
132
133 =head2 FOR CPAN INSTALLS
134
135 Gitalist can be supplied with a config file by setting the C<< GITALIST_CONFIG >>
136 environment variable to point to a configuration file.
137
138 If you install Gitalist from CPAN, a default configuration is installed along with gitalist,
139 which is complete except for a repository directory. You can get a copy of this configuration
140 by running:
141
142   cp `perl -Ilib -MGitalist -e'print Gitalist->path_to("gitalist.conf")'` gitalist.conf
143
144 You can then edit this confg, adding a repo_dir path and customising other settings as desired.
145
146 You can then start the Gitalist demo server by setting C<< GITALIST_CONFIG >>. For example:
147
148     GITALIST_CONFIG=/usr/local/etc/gitalist.conf gitalist_server.pl
149
150 Alternatively, if you only want to set a repository directory and are otherwise happy with
151 the default configuration, then you can set the C<< GITALIST_REPO_DIR >> environment
152 variable, or pass the C<< --repo_dir >> flag to any of the scripts.
153
154     GITALIST_REPO_DIR=/home/myuser/code/git gitalist_server.pl
155     gitalist_server.pl --repo_dir home/myuser/code/git
156
157 The C<< GITALIST_REPO_DIR >> environment variable will override the repository directory set
158 in configuration, and will itself be overridden by he C<< --repo_dir >> flag.
159
160 =head1 RUNNING
161
162 Once you have followed the instructions above to install and configure Gitalist, you may want
163 to run it in a more production facing environment than using the single threaded developement
164 server.
165
166 The recommended deployment method for Gitalist is FastCGI, although Gitalist can also be run
167 under mod_perl or as pure perl with L<Catalyst::Engine::PreFork>.
168
169 Assuming that you have installed Gitalist's dependencies into a L<local::lib>, and you
170 are running from a git checkout, adding a trivial FCGI script as C<script/gitalist.fcgi>
171 (this file is specifically in C<.gitignore> so you can have your own copy):
172
173     #!/bin/sh
174     export PERL5LIB=/home/t0m/public_html/Gitalist/lib:/home/t0m/perl5/lib/perl5:$PERL5LIB
175     exec /home/t0m/public_html/Gitalist/script/gitalist_fastcgi.pl
176
177 This example can be seen live here:
178
179     http://goatse.co.uk/~bobtfish/Gitalist/script/gitalist.fcgi/
180
181 =head1 CONTRIBUTING
182
183 Patches are welcome, please feel free to fork on github and send pull requests, send patches
184 from git format-patch to the bug tracker, or host your own copy of gitalist somewhere and
185 ask us to pull from it.
186
187 =head1 SUPPORT
188
189 Gitalist has an active irc community in C<#gitalist> on irc.perl.org, please feel free to stop
190 by and ask questions, report bugs or installation issues or generally for a chat about where
191 we plan to go with the project.
192
193 =head1 SEE ALSO
194
195 L<Gitalist::Controller::Root>
196
197 L<Gitalist::Git::Repository>
198
199 L<Catalyst>
200
201 =head1 AUTHORS AND COPYRIGHT
202
203   Catalyst application:
204     (C) 2009 Venda Ltd and Dan Brook <broq@cpan.org>
205     (C) 2009, Tom Doran <bobtfish@bobtfish.net>
206     (C) 2009, Zac Stevens <zts@cryptocracy.com>
207
208   Original gitweb.cgi from which this was derived:
209     (C) 2005-2006, Kay Sievers <kay.sievers@vrfy.org>
210     (C) 2005, Christian Gierke
211
212   Model based on http://github.com/rafl/gitweb
213     (C) 2008, Florian Ragwitz
214
215 =head1 LICENSE
216
217 Licensed under GNU GPL v2
218
219 =cut