Commit | Line | Data |
a8a8f8f9 |
1 | use MooseX::Declare; |
2 | |
3 | class Gitalist::Git::Object { |
0617cbd0 |
4 | use MooseX::Types::Moose qw/Str Int/; |
a8a8f8f9 |
5 | use File::Stat::ModeString qw/mode_to_string/; |
50394a3e |
6 | has project => ( isa => 'Gitalist::Git::Project', |
7 | required => 1, |
8 | is => 'ro', |
9 | handles => [ 'run_cmd' ], |
10 | ); |
0617cbd0 |
11 | has $_ => ( isa => Str, |
50394a3e |
12 | required => 1, |
0617cbd0 |
13 | is => 'ro' ) |
14 | for qw/sha1 file/; |
15 | has $_ => ( isa => Str, |
50394a3e |
16 | required => 1, |
17 | is => 'ro', |
0617cbd0 |
18 | lazy_build => 1 ) |
19 | for qw/type modestr/; |
20 | has $_ => ( isa => Int, |
50394a3e |
21 | required => 1, |
0617cbd0 |
22 | is => 'ro' ) |
23 | for qw/mode size/; |
a8a8f8f9 |
24 | |
50394a3e |
25 | method _build_type { |
26 | my $output = $self->run_cmd(qw/cat-file -t/, $self->{sha1}); |
27 | chomp($output); |
28 | return $output; |
29 | } |
30 | |
a8a8f8f9 |
31 | method _build_modestr { |
32 | my $modestr = mode_to_string($self->{mode}); |
33 | return $modestr; |
34 | } |
35 | |
50394a3e |
36 | method _build_size { |
37 | my $output = $self->run_cmd(qw/cat-file -s/, $self->{sha1}); |
38 | chomp($output); |
39 | return $output; |
40 | } |
41 | |
42 | =head2 contents |
43 | |
44 | Return the contents of a given file. |
45 | |
46 | =cut |
a8a8f8f9 |
47 | |
50394a3e |
48 | method contents { |
49 | if ( $self->type ne 'blob' ) { |
50 | die "object $self->sha1 is not a file\n" |
51 | } |
52 | |
53 | my $output = $self->run_cmd(qw/cat-file -p/, $self->sha1); |
54 | return unless $output; |
55 | |
56 | return $output; |
57 | } |
a8a8f8f9 |
58 | |
59 | } # end class |