4 class Gitalist::Git::Object {
5 use MooseX::Types::Moose qw/Str Int/;
6 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
7 use File::Stat::ModeString qw/mode_to_string/;
8 # project and sha1 are required initargs
9 has project => ( isa => 'Gitalist::Git::Project',
13 handles => [ 'run_cmd' ],
15 has sha1 => ( isa => NonEmptySimpleStr,
19 has $_ => ( isa => NonEmptySimpleStr,
23 for qw/type modestr size/;
25 # objects can't determine their mode or filename
26 has file => ( isa => NonEmptySimpleStr,
29 has mode => ( isa => Int,
34 method BUILD { $self->$_() for qw/type size modestr/ }
36 foreach my $key (qw/ type size /) {
37 method "_build_$key" {
38 my $v = $self->_cat_file_with_flag(substr($key, 0, 1));
44 method _build_modestr {
45 my $modestr = mode_to_string($self->mode);
49 method _cat_file_with_flag ($flag) {
50 $self->run_cmd('cat-file', '-' . $flag, $self->{sha1})
55 Return the contents of a given file.
59 # FIXME - Should be an attribute so it gets cached?
61 if ( $self->type ne 'blob' ) {
62 die "object $self->sha1 is not a file\n"
65 $self->_cat_file_with_flag('p');