X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FGit%2FObject.pm;h=b47ab93a1d612703151871bf5a546913449f7953;hb=ba65bc524eae2d8b065076fed85e7e3d248128b2;hp=0c3d82f538ea1db845d9fd93c24baeb1ffa345e0;hpb=8d953eae3007db34c656febc732bacbd46f5ef7f;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/Git/Object.pm b/lib/Gitalist/Git/Object.pm index 0c3d82f..b47ab93 100644 --- a/lib/Gitalist/Git/Object.pm +++ b/lib/Gitalist/Git/Object.pm @@ -1,26 +1,47 @@ use MooseX::Declare; +use Moose::Autobox; class Gitalist::Git::Object { use MooseX::Types::Moose qw/Str Int/; + use MooseX::Types::Common::String qw/NonEmptySimpleStr/; use File::Stat::ModeString qw/mode_to_string/; # project and sha1 are required initargs has project => ( isa => 'Gitalist::Git::Project', required => 1, is => 'ro', - handles => [ 'run_cmd' ], + weak_ref => 1, + handles => { + _run_cmd => 'run_cmd', + _get_gpp_object => 'get_gpp_object', + }, ); - has sha1 => ( isa => Str, + has sha1 => ( isa => NonEmptySimpleStr, required => 1, is => 'ro' ); - has $_ => ( isa => Str, + has $_ => ( isa => NonEmptySimpleStr, required => 1, is => 'ro', lazy_build => 1 ) for qw/type modestr size/; + has _gpp_obj => ( isa => 'Git::PurePerl::Object', + required => 1, + is => 'ro', + lazy_build => 1, + handles => [ 'parents', + 'parent_sha1', + 'comment', + 'author', + 'authored_time', + 'committer', + 'committed_time', + 'tree_sha1', + ], + ); + # objects can't determine their mode or filename - has file => ( isa => Str, + has file => ( isa => NonEmptySimpleStr, required => 0, is => 'ro' ); has mode => ( isa => Int, @@ -28,14 +49,18 @@ class Gitalist::Git::Object { default => 0, is => 'ro' ); - method BUILD { - $self->$_() for qw/type modestr size/; # Ensure to build early. + method BUILD { $self->$_() for qw/_gpp_obj type size modestr/ } + + method _build__gpp_obj { + return $self->_get_gpp_object($self->sha1) } - method _build_type { - my $output = $self->run_cmd(qw/cat-file -t/, $self->sha1); - chomp($output); - return $output; + foreach my $key (qw/ type size /) { + method "_build_$key" { + my $v = $self->_cat_file_with_flag(substr($key, 0, 1)); + chomp($v); + return $v; + } } method _build_modestr { @@ -43,10 +68,8 @@ class Gitalist::Git::Object { return $modestr; } - method _build_size { - my $output = $self->run_cmd(qw/cat-file -s/, $self->sha1); - chomp($output); - return $output; + method _cat_file_with_flag ($flag) { + $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1}) } =head2 contents @@ -55,15 +78,13 @@ Return the contents of a given file. =cut + # FIXME - Should be an attribute so it gets cached? method contents { if ( $self->type ne 'blob' ) { die "object $self->sha1 is not a file\n" } - my $output = $self->run_cmd(qw/cat-file -p/, $self->sha1); - return unless $output; - - return $output; + $self->_cat_file_with_flag('p'); } } # end class