Untabify recent changes.
[catagits/Gitalist.git] / lib / Gitalist / Controller / LegacyURI.pm
1 package Gitalist::Controller::LegacyURI;
2 use Moose;
3 use Moose::Autobox;
4 use namespace::autoclean;
5
6 BEGIN { extends 'Gitalist::Controller' }
7
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];
14     },
15     blob => sub {
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');
19     },
20 );
21
22 sub _legacy_uri {
23     my($self, $c, $repos, $action) = @_;
24
25     return
26         unless $action;
27
28     my @result  = grep { $action =~ /^$_$/ } keys %LEGACY_DISPATCH;
29     die "Matched too many actions for '$a' - @result"
30         if @result > 1;
31
32     return $LEGACY_DISPATCH{$result[0]}->($c, $action, $repos)
33         if $result[0];
34 }
35
36 sub handler : Chained('/base') PathPart('legacy') Args() {
37     my ( $self, $c, $repos ) = @_;
38
39     my ($action, $captures, @args) = $self->_legacy_uri($c, $repos, $c->req->param('a'));
40
41     die("Not supported")
42         unless $action;
43
44     $c->res->redirect($c->uri_for_action($action, $captures || [], @args));
45     $c->res->status(301);
46 }
47
48 sub project_index : Chained('/base') Args(0) {
49       my ( $self, $c ) = @_;
50
51       $c->response->content_type('text/plain');
52       $c->response->body(
53           join "\n", map $_->name, $c->model()->repositories->flatten
54       ) or die 'No repositories found in '. $c->model->repo_dir;
55 }
56
57 __PACKAGE__->meta->make_immutable;