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