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 $self->_cat_file_with_flag(substr($key, 0, 1))->chomp;
42 method _build_modestr {
43 my $modestr = mode_to_string($self->mode);
47 method _cat_file_with_flag ($flag) {
48 $self->run_cmd('cat-file', '-' . $flag, $self->{sha1})
53 Return the contents of a given file.
57 # FIXME - Should be an attribute so it gets cached?
59 if ( $self->type ne 'blob' ) {
60 die "object $self->sha1 is not a file\n"
63 $self->_cat_file_with_flag('p');