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',
14 _run_cmd => 'run_cmd',
15 _get_gpp_object => 'get_gpp_object',
18 has sha1 => ( isa => NonEmptySimpleStr,
22 has $_ => ( isa => NonEmptySimpleStr,
26 for qw/type modestr size/;
28 has _gpp_obj => ( isa => 'Git::PurePerl::Object',
32 handles => [ 'parents',
43 # objects can't determine their mode or filename
44 has file => ( isa => NonEmptySimpleStr,
47 has mode => ( isa => Int,
52 method BUILD { $self->$_() for qw/_gpp_obj type size modestr/ }
54 method _build__gpp_obj {
55 return $self->_get_gpp_object($self->sha1)
58 foreach my $key (qw/ type size /) {
59 method "_build_$key" {
60 my $v = $self->_cat_file_with_flag(substr($key, 0, 1));
66 method _build_modestr {
67 my $modestr = mode_to_string($self->mode);
71 method _cat_file_with_flag ($flag) {
72 $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1})
77 Return the contents of a given file.
81 # FIXME - Should be an attribute so it gets cached?
83 if ( $self->type ne 'blob' ) {
84 die "object $self->sha1 is not a file\n"
87 $self->_cat_file_with_flag('p');