1 package Gitalist::Controller::LegacyURI;
4 use namespace::autoclean;
6 BEGIN { extends 'Gitalist::Controller' }
8 my %LEGACY_DISPATCH = (
9 opml => sub { '/opml/opml' },
10 project_index => sub { '/legacyuri/project_index' },
11 '(?:summary|heads|tags)' => sub {
12 my($c, $action, $repos) = @_;
13 return "/repository/$action", [$repos];
16 my($c, $action, $repos) = @_;
17 my $ref = $c->req->param('hb') || $c->req->param('h');
18 return '/ref/blob', [$repos, $ref], $c->req->param('f');
21 my($c, $action, $repos) = @_;
22 my $ref = $c->req->param('hb') || $c->req->param('h');
23 return '/ref/raw', [$repos, $ref], $c->req->param('f');
26 my($c, $action, $repos) = @_;
27 my $ref = $c->req->param('hb') || $c->req->param('h');
28 my $compare = $c->req->param('hbp') || $c->req->param('hp');
29 return '/ref/diff', [$repos, $ref], $compare, $c->req->param('f');
31 blobdiff_plain => sub {
32 my($c, $action, $repos) = @_;
33 my $ref = $c->req->param('hb') || $c->req->param('h');
34 my $compare = $c->req->param('hbp') || $c->req->param('hp');
35 return '/ref/diff_plain', [$repos, $ref], $compare, $c->req->param('f');
40 my($self, $c, $repos, $action) = @_;
45 my @result = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH;
46 die "Matched too many actions for '$a' - @result"
49 return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos)
53 sub handler : Chained('/base') PathPart('legacy') Args() {
54 my ( $self, $c, $repos ) = @_;
56 my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a'));
61 $c->res->redirect($c->uri_for_action($action, $captures || [], @args));
65 sub project_index : Chained('/base') Args(0) {
66 my ( $self, $c ) = @_;
68 $c->response->content_type('text/plain');
70 join "\n", map $_->name, $c->model()->repositories->flatten
71 ) or die 'No repositories found in '. $c->model->repo_dir;
74 __PACKAGE__->meta->make_immutable;