78d26f288f7bbfb327f5302159b169ee1dc4c76e
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
1 package Gitalist::Controller::Root;
2 use Moose;
3 use namespace::autoclean;
4
5 BEGIN { extends 'Catalyst::Controller' }
6
7 #
8 # Sets the actions in this controller to be registered with no prefix
9 # so they function identically to actions created in MyApp.pm
10 #
11 __PACKAGE__->config->{namespace} = '';
12
13 =head1 NAME
14
15 Gitalist::Controller::Root - Root Controller for Gitalist
16
17 =head1 DESCRIPTION
18
19 [enter your description here]
20
21 =head1 METHODS
22
23 =cut
24
25 =head2 index
26
27 =cut
28
29 use IO::Capture::Stdout;
30 use File::Slurp qw(slurp);
31
32 sub default :Path {
33   my ( $self, $c ) = @_;
34
35   my $capture = IO::Capture::Stdout->new();
36   $capture->start();
37   eval {
38     my $action = gitweb::main($c);
39     $action->();
40   };
41   $capture->stop();
42
43   gitweb::git_header_html();
44   gitweb::git_footer_html();
45   my $output = join '', $capture->read;
46   $c->stash->{content} = $output
47     unless $c->stash->{content};
48   $c->stash->{template} = 'default.tt2';
49 }
50
51 sub index :Path :Args(0) {
52     my ( $self, $c ) = @_;
53
54   my $order = $c->req->param('order');
55   if($order && $order !~ m/none|project|descr|owner|age/) {
56     die "Unknown order parameter";
57   }
58
59   my @list = $c->model('Git')->projects;
60   if (!@list) {
61     die "No projects found";
62   }
63
64   if (-f $c->config->{home_text}) {
65     print "<div class=\"index_include\">\n";
66     print slurp($c->config->{home_text});
67     print "</div>\n";
68   }
69
70   my $cgi;
71   print $cgi->startform(-method => "get") .
72     "<p class=\"projsearch\">Search:\n" .
73     $cgi->textfield(-name => "s", -value => $c->req->param('searchtext')) . "\n" .
74     "</p>" .
75     $cgi->end_form() . "\n";
76
77   git_project_list_body(\@list, $order);
78 }
79
80 =head2 end
81
82 Attempt to render a view, if needed.
83
84 =cut
85
86 sub end : ActionClass('RenderView') {}
87
88 =head1 AUTHOR
89
90 Dan Brook,,,
91
92 =head1 LICENSE
93
94 This library is free software. You can redistribute it and/or modify
95 it under the same terms as Perl itself.
96
97 =cut
98
99 __PACKAGE__->meta->make_immutable;