Kill warnings
[catagits/Gitalist.git] / lib / Gitalist / Git / Object.pm
CommitLineData
a8a8f8f9 1use MooseX::Declare;
2
3class Gitalist::Git::Object {
0617cbd0 4 use MooseX::Types::Moose qw/Str Int/;
a8a8f8f9 5 use File::Stat::ModeString qw/mode_to_string/;
54368e9d 6 # project and sha1 are required initargs
50394a3e 7 has project => ( isa => 'Gitalist::Git::Project',
8 required => 1,
9 is => 'ro',
10 handles => [ 'run_cmd' ],
11 );
8dbe8024 12 has sha1 => ( isa => Str,
54368e9d 13 required => 1,
14 is => 'ro' );
15
0617cbd0 16 has $_ => ( isa => Str,
50394a3e 17 required => 1,
18 is => 'ro',
0617cbd0 19 lazy_build => 1 )
483b98b7 20 for qw/type modestr size/;
54368e9d 21
22 # objects can't determine their mode or filename
23 has file => ( isa => Str,
24 required => 0,
25 is => 'ro' );
26 has mode => ( isa => Int,
27 required => 1,
28 default => 0,
29 is => 'ro' );
30
31 method BUILD {
32 $self->$_() for qw/type modestr size/; # Ensure to build early.
33 }
a8a8f8f9 34
50394a3e 35 method _build_type {
36 my $output = $self->run_cmd(qw/cat-file -t/, $self->{sha1});
37 chomp($output);
38 return $output;
39 }
54368e9d 40
a8a8f8f9 41 method _build_modestr {
42 my $modestr = mode_to_string($self->{mode});
43 return $modestr;
44 }
45
50394a3e 46 method _build_size {
47 my $output = $self->run_cmd(qw/cat-file -s/, $self->{sha1});
48 chomp($output);
49 return $output;
50 }
51
52=head2 contents
53
54Return the contents of a given file.
55
56=cut
a8a8f8f9 57
50394a3e 58 method contents {
59 if ( $self->type ne 'blob' ) {
60 die "object $self->sha1 is not a file\n"
61 }
62
63 my $output = $self->run_cmd(qw/cat-file -p/, $self->sha1);
64 return unless $output;
65
66 return $output;
67 }
a8a8f8f9 68
69} # end class