Change from string to bareword types, and add a Maybe in Gitalist/Git/Project as...
[catagits/Gitalist.git] / lib / Gitalist / Git / Util.pm
1 use MooseX::Declare;
2
3 class Gitalist::Git::Util {
4     use File::Which;
5     use Git::PurePerl;
6     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
7     use MooseX::Types::Moose qw/Str/;
8     has gitdir => ( isa => Str, is => 'ro', required => 1 );
9     has _git      => ( isa => NonEmptySimpleStr, is => 'ro', lazy_build => 1 );
10     sub _build__git {
11         my $git = File::Which::which('git');
12
13         if (!$git) {
14             die <<EOR;
15 Could not find a git executable.
16 Please specify the which git executable to use in gitweb.yml
17 EOR
18         }
19
20         return $git;
21     }
22
23     has _gpp      => ( isa => 'Git::PurePerl',   is => 'rw', lazy_build => 1 );
24     method _build__gpp {
25         my $gpp = Git::PurePerl->new(gitdir => $self->gitdir);
26         return $gpp;
27     }
28
29     method run_cmd (@args) {
30         unshift @args, ( '--git-dir' => $self->gitdir );
31         print STDERR 'RUNNING: ', $self->_git, qq[ @args], $/;
32         
33         open my $fh, '-|', $self->_git, @args
34             or die "failed to run git command";
35         binmode $fh, ':encoding(UTF-8)';
36
37         my $output = do { local $/ = undef; <$fh> };
38         close $fh;
39
40         return $output;
41     }
42
43
44
45
46
47 #
48 } # end class