lib/Gitalist/Controller/Root.pm untested

filter: Statementstmt 0.0% 0 / 54 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 9 totaltotal 0.0% 0 / 95 CC 6 SCAR 20.0
CC
6
Cov
0%
base
20.0
end
12.0
BEGIN
2.0
CRAP 7.4
1 package Gitalist::Controller::Root;
2  
3 use Moose;
4 use Moose::Autobox;
5 use Digest::MD5 qw(md5_hex);
6 use Gitalist::Utils qw/ age_string mode_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 # XXX Fragile much?
22 sub css : Chained('/root') PathPart('core.css') Args(0) {
23 my ( $self, $c ) = @_;
24  
25 $c->stash( template => 'static/css/core.css', content_type => 'text/css' );
26 }
27  
28 sub base : Chained('/root') PathPart('') CaptureArgs(0) {
29 my($self, $c) = @_;
30  
31 my $git_version = `git --version`;
32 chomp($git_version);
33 $c->stash(
34 git_version => $git_version,
35 version => $Gitalist::VERSION,
36  
37 time_since => sub {
38 return 'never' unless $_[0];
39 return age_string(time - $_[0]->epoch);
40 },
41 short_cmt => sub {
42 my $cmt = shift;
43 my($line) = split /\n/, $cmt;
44 $line =~ s/^(.{70,80}\b).*/$1 \x{2026}/ if defined $line;
45 return $line;
46 },
47 abridged_description => sub {
48 join(' ', grep { defined } (split / /, shift)[0..10]);
49 },
50 uri_for_gravatar => sub {
51 my $email = shift;
52 my $size = shift;
53 my $uri = 'http://www.gravatar.com/avatar/' . md5_hex($email);
54 $uri .= "?s=$size" if $size;
55 return $uri;
56 },
57 mode_string => sub {
58 return mode_string(oct shift);
59 }
60 );
61 }
62  
63 sub search : Chained('base') Args(0) {}
64  
65 =head2 search_help
66  
67 Provides some help for the search form.
68  
69 =cut
70  
71 sub search_help : Chained('base') Args(0) {}
72  
73 sub end : ActionClass('Serialize') {
74 my ($self, $c) = @_;
75 # Give repository views the current HEAD.
76 if ($c->stash->{Repository}) {
77 $c->stash->{HEAD} = $c->stash->{Repository}->head_hash;
78 }
79 if ($c->stash->{data} && blessed $c->stash->{data}) {
80 $c->stash->{rest} = $c->stash->{data}->pack;
81 }
82 }
83  
84 sub error_404 : Action {
85 my ($self, $c) = @_;
86 $c->response->status(404);
87 $c->response->body('Page not found');
88 }
89  
90 __PACKAGE__->config(
91 default => 'text/html',
92 map => {
93 'application/json' => [qw/ JSON /],
94 map { $_ => [qw/ View Default /] }
95 qw( text/css text/html text/plain
96 application/atom+xml application/rss+xml application/rss )
97 },
98 content_type_stash_key => 'content_type',
99 );
100  
101 __PACKAGE__->meta->make_immutable;
102  
103 __END__