lib/Gitalist/Controller/Ref.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 76 CC 2 SCAR 10.0
CC
2
Cov
0%
raw
6.0
BEGIN
2.0
base
2.0
CRAP 2.7
1 package Gitalist::Controller::Ref;
2  
3 use Moose;
4 use namespace::autoclean;
5  
6 BEGIN { extends 'Gitalist::Controller' }
7 with 'Gitalist::URIStructure::Ref';
8  
9 use File::Type;
10 use File::Type::WebImages ();
11  
12 sub base : Chained('/repository/find') PathPart('') CaptureArgs(0) {}
13  
14 after commit => sub {
15 my($self, $c) = @_;
16  
17 $c->stash->{diff_tree} = ( $c->stash->{Commit}->diff )[0];
18 };
19  
20 sub raw : Chained('find') Does('FilenameArgs') Args() {
21 my ($self, $c) = @_;
22 $c->forward('find_blob');
23  
24 if(!Gitalist::Utils::is_binary($c->stash->{blob})) {
25 $c->response->content_type('text/plain; charset=utf-8');
26 } else {
27 my $ft = File::Type->new();
28 $c->response->content_type(
29 File::Type::WebImages::mime_type($c->stash->{blob})
30 || File::Type->new->mime_type($c->stash->{blob})
31 );
32 }
33  
34 utf8::decode($c->stash->{blob});
35 $c->response->body(delete $c->stash->{blob});
36 }
37  
38 =encoding UTF-8
39  
40 =head1 NAME
41  
42 Gitalist::Controller::Ref - Controller::Ref module for Gitalist
43  
44 =head2 snapshot
45  
46 Provides a snapshot of a given commit.
47  
48 =cut
49  
50 sub snapshot : Chained('find') PathPart('snapshot') Args() {
51 my ($self, $c, $format) = @_;
52 $format ||= 'tgz';
53 my @snap = $c->stash->{Repository}->snapshot(
54 sha1 => $c->stash->{Commit}->sha1,
55 format => $format
56 );
57 $c->response->status(200);
58 $c->response->headers->header( 'Content-Disposition' =>
59 "attachment; filename=$snap[0]");
60 $c->response->body($snap[1]);
61 }
62  
63 =head2 patch
64  
65 A raw patch for a given commit.
66  
67 =cut
68  
69 sub patch : Chained('find') Args(0) {
70 my ($self, $c) = @_;
71 $c->detach('patches', [1]);
72 }
73  
74 =head2 patches
75  
76 The patcheset for a given commit ???
77  
78 =cut
79  
80 sub patches : Chained('find') Args(1) {
81 my ($self, $c, $count) = @_;
82 $count ||= Gitalist->config->{patches}{max};
83 my $commit = $c->stash->{Commit};
84 my $parent = $c->req->param('hp') || undef; # FIXME
85 my $patch = $commit->get_patch( $parent, $count );
86 $c->response->body($patch);
87 $c->response->content_type('text/plain');
88 $c->response->status(200);
89 }
90  
91 __PACKAGE__->meta->make_immutable;