lib/Gitalist/URIStructure/Ref.pm untested

filter: Statementstmt 0.0% 0 / 41 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 99 CC 6 SCAR 19.3
CC
6
Cov
0%
find_blob
20.0
_set_diff_args
12.0
find
2.0
CRAP 6.9
1 package Gitalist::URIStructure::Ref;
2 use MooseX::MethodAttributes::Role;
3 use Moose::Autobox;
4 use namespace::autoclean;
5  
6 use Git::Gitalist::Types qw/SHA1/;
7  
8 requires 'base';
9  
10 with qw/
11 Gitalist::URIStructure::WithLog
12 /;
13  
14 after 'base' => sub {
15 my ($self, $c) = @_;
16 confess("No repository in the stash")
17 unless $c->stash->{Repository};
18 };
19  
20 sub find : Chained('base') PathPart('') CaptureArgs(1) {
21 my ($self, $c, $sha1part) = @_;
22 # FIXME - Should not be here!
23 $c->stash->{Commit} = $c->stash->{Repository}->get_object($sha1part)
24 or $c->detach('/error404', "Couldn't find a object for '$sha1part' in XXXX!");
25 $c->stash->{data} = $c->stash->{Commit};
26 }
27  
28 sub diff : Chained('find') CaptureArgs(0) {}
29  
30 sub _set_diff_args {
31 my($self, $c, @rest) = @_;
32  
33 # FIXME - This ain't pretty
34 $c->stash(parent => shift @rest)
35 if @rest == 2
36 # Check that the single arg is unlikely to be a path.
37 or @rest && to_SHA1($rest[0]) && $c->stash->{Repository}->get_object($rest[0]);
38 $c->stash(filename => $rest[-1])
39 if @rest;
40 }
41  
42 sub diff_fancy : Chained('diff') PathPart('') Args() {
43 my($self, $c, @rest) = @_;
44  
45 $self->_set_diff_args($c, @rest);
46 }
47  
48 sub diff_plain : Chained('diff') PathPart('plain') Args() {
49 my($self, $c, $comparison, @rest) = @_;
50  
51 $self->_set_diff_args($c, @rest);
52  
53 $c->stash(no_wrapper => 1);
54 $c->response->content_type('text/plain; charset=utf-8');
55 }
56  
57 sub commit : Chained('find') PathPart('commit') Args(0) {}
58  
59 sub file_commit_info : Chained('find') Does('FilenameArgs') Args() {}
60  
61 sub tree : Chained('find') Does('FilenameArgs') Args() {}
62  
63 sub find_blob : Action {
64 my ($self, $c) = @_;
65 my($repo, $object) = @{$c->{stash}}{qw(Repository Commit)};
66  
67 # FIXME - Eugh!
68 my $blob;
69 if ($object->isa('Git::Gitalist::Object::Commit')) {
70 $blob = $object->sha_by_path($c->stash->{filename});
71 } elsif ($object->isa('Git::Gitalist::Object::Blob')) {
72 $blob = $object;
73 } else {
74 die "Unknown object type for '${\$object->sha1}'";
75 }
76 die "No file or sha1 provided."
77 unless $blob;
78  
79 $c->stash(blob => $blob->content);
80 }
81  
82 sub blob : Chained('find') Does('FilenameArgs') Args() {
83 my ($self, $c) = @_;
84 $c->forward('find_blob');
85 }
86  
87 sub blame : Chained('find') Does('FilenameArgs') Args() {}
88  
89 sub history : Chained('find') Does('FilenameArgs') Args() {}
90  
91 1;