cd8b599ca25c60e248bd206527503f28ac913643
[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 sub handler : Chained('/base') PathPart('legacy') Args() {
9     my ( $self, $c, $repos ) = @_;
10     my ($action, @captures);
11     if (my $a = $c->req->param('a')) {
12         $a eq 'opml' && do { $action = '/opml/opml'; };
13         $a eq 'project_index' && do { $action = '/legacyuri/project_index'; };
14         $a =~ /^(summary|heads|tags)$/ && do { $action = "/repository/$1"; push(@captures, $repos); };
15     }
16     die("Not supported") unless $action;
17     $c->res->redirect($c->uri_for_action($action, \@captures));
18     $c->res->status(301);
19 }
20
21 sub project_index : Chained('/base') Args(0) {
22       my ( $self, $c ) = @_;
23
24       $c->response->content_type('text/plain');
25       $c->response->body(
26           join "\n", map $_->name, $c->model()->repositories->flatten
27       ) or die 'No repositories found in '. $c->model->repo_dir;
28 }
29
30 __PACKAGE__->meta->make_immutable;