4 class Gitalist::Git::Object {
5 use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/;
6 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
10 S_IFINVALID => 0030000,
11 S_IFGITLINK => 0160000,
20 # repository and sha1 are required initargs
21 has repository => ( isa => 'Gitalist::Git::Repository',
26 _run_cmd => 'run_cmd',
27 _run_cmd_fh => 'run_cmd_fh',
28 _run_cmd_list => 'run_cmd_list',
29 _get_gpp_object => 'get_gpp_object',
32 has sha1 => ( isa => NonEmptySimpleStr,
36 has type => ( isa => NonEmptySimpleStr,
40 has $_ => ( isa => NonEmptySimpleStr,
46 has _gpp_obj => ( isa => 'Git::PurePerl::Object',
50 handles => [ 'content',
54 # objects can't determine their mode or filename
55 has file => ( isa => NonEmptySimpleStr,
58 has mode => ( isa => Int,
63 method BUILD { $self->$_() for qw/_gpp_obj size modestr/ }
68 method _build__gpp_obj {
69 return $self->_get_gpp_object($self->sha1)
72 method "_build_size" {
73 my $v = $self->_cat_file_with_flag('s');
78 method _cat_file_with_flag ($flag) {
79 $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1})
82 method _build_modestr {
83 # XXX The POSIX constants make win32 sad :(
84 return _mode_str($self->mode);
88 # submodule/subrepository, a commit object reference
90 return (($_[0] & S_IFMT) == S_IFGITLINK)
93 # convert file mode in octal to symbolic file mode string
97 if (S_ISGITLINK($mode)) {
99 } elsif (S_ISDIR($mode & S_IFMT)) {
101 } elsif (S_ISLNK($mode)) {
103 } elsif (S_ISREG($mode)) {
104 # git cares only about the executable bit
105 if ($mode & S_IXUSR) {
121 Gitalist::Git::Object - Model of a git object.
125 my $object = Repository->get_object($sha1);
129 Abstract base class for git objects.
140 See L<Gitalist> for authors.
144 See L<Gitalist> for the license.