Fix a warning
[catagits/Gitalist.git] / lib / Gitalist / Controller / Root.pm
1 package Gitalist::Controller::Root;
2
3 use Moose;
4 use Moose::Autobox;
5
6 use Gitalist::Utils qw/ age_string /;
7
8 use namespace::autoclean;
9
10 BEGIN { extends 'Gitalist::Controller' }
11
12 __PACKAGE__->config(namespace => '');
13
14 sub root : Chained('/') PathPart('') CaptureArgs(0) {}
15
16 sub index : Chained('base') PathPart('') Args(0) {
17     my ( $self, $c ) = @_;
18     $c->stash( search_text => $c->req->param('s') || '' ) # FIXME - XSS?
19 }
20
21 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
22   my($self, $c) = @_;
23
24   my $git_version = `git --version`;
25   chomp($git_version);
26   $c->stash(
27     git_version => $git_version,
28     version     => $Gitalist::VERSION,
29
30     time_since => sub {
31       return 'never' unless $_[0];
32       return age_string(time - $_[0]->epoch);
33     },
34     short_cmt => sub {
35       my $cmt = shift;
36       my($line) = split /\n/, $cmt;
37       $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/;
38       return $line;
39     },
40     abridged_description => sub {
41         join(' ', grep { defined } (split / /, shift)[0..10]);
42     },
43   );
44 }
45
46 =head2 search_help
47
48 Provides some help for the search form.
49
50 =cut
51
52 sub search_help : Chained('base') Args(0) {}
53
54 sub end : ActionClass('RenderView') {}
55
56 sub error_404 : Action {
57     my ($self, $c) = @_;
58     $c->response->status(404);
59     $c->response->body('Page not found');
60 }
61
62 __PACKAGE__->meta->make_immutable;
63
64 __END__
65
66 =head1 NAME
67
68 Gitalist::Controller::Root - Root controller for the application
69
70 =head1 DESCRIPTION
71
72 This controller handles all of the root level paths for the application
73
74 =head1 METHODS
75
76 =head2 root
77
78 Root of chained actions
79
80 =head2 base
81
82 Populate the header and footer. Perhaps not the best location.
83
84 =head2 index
85
86 Provides the repository listing.
87
88 =head2 end
89
90 Attempt to render a view, if needed.
91
92 =head2 error_404
93
94 =head1 AUTHORS
95
96 See L<Gitalist> for authors.
97
98 =head1 LICENSE
99
100 See L<Gitalist> for the license.
101
102 =cut