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',
41 # This feels wrong, but current templates assume
42 # these attributes are present on every object.
43 foreach my $key (qw/tree_sha1 comment content/) {
44 has $key => ( isa => Str,
49 method "_build_$key" {
50 confess("Object can't " . $key) unless $self->_gpp_obj->can($key);
51 return $self->_gpp_obj->$key;
55 # objects can't determine their mode or filename
56 has file => ( isa => NonEmptySimpleStr,
59 has mode => ( isa => Int,
64 method BUILD { $self->$_() for qw/_gpp_obj type size modestr/ }
66 method _build__gpp_obj {
67 return $self->_get_gpp_object($self->sha1)
70 foreach my $key (qw/ type size /) {
71 method "_build_$key" {
72 my $v = $self->_cat_file_with_flag(substr($key, 0, 1));
78 method _build_modestr {
79 my $modestr = mode_to_string($self->mode);
83 method _cat_file_with_flag ($flag) {
84 $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1})