Massive tree action speedup
[catagits/Gitalist.git] / lib / Gitalist / Git / Object.pm
CommitLineData
a8a8f8f9 1use MooseX::Declare;
84f31a44 2use Moose::Autobox;
a8a8f8f9 3
1aae440e 4class Gitalist::Git::Object with Gitalist::Git::Serializable is dirty {
5 use MooseX::Storage::Meta::Attribute::Trait::DoNotSerialize;
6
b36b7e0b 7 use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/;
84f31a44 8 use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
eb8ee28a 9 use Gitalist::Utils qw/mode_string/;
f9a3c4ab 10 use overload '""' => '_to_string', fallback => 1;
1501cb4e 11
82bc0f05 12 # repository and sha1 are required initargs
13 has repository => ( isa => 'Gitalist::Git::Repository',
50394a3e 14 required => 1,
15 is => 'ro',
84f31a44 16 weak_ref => 1,
77edf882 17 handles => {
18 _run_cmd => 'run_cmd',
aa7f1f92 19 _run_cmd_fh => 'run_cmd_fh',
1501cb4e 20 _run_cmd_list => 'run_cmd_list',
77edf882 21 _get_gpp_object => 'get_gpp_object',
22 },
50394a3e 23 );
84f31a44 24 has sha1 => ( isa => NonEmptySimpleStr,
1501cb4e 25 required => 1,
26 is => 'ro' );
54368e9d 27
98390bf6 28 has type => ( isa => NonEmptySimpleStr,
29 is => 'ro',
30 required => 1 );
31
84f31a44 32 has $_ => ( isa => NonEmptySimpleStr,
1501cb4e 33 required => 1,
34 is => 'ro',
35 lazy_build => 1 )
98390bf6 36 for qw/modestr size/;
54368e9d 37
1aae440e 38 has _gpp_obj => ( isa => 'Git::PurePerl::Object',
39 required => 1,
40 is => 'ro',
77edf882 41 lazy_build => 1,
1aae440e 42 handles => [ 'content' ],
43 traits => ['DoNotSerialize']
77edf882 44 );
45
54368e9d 46 # objects can't determine their mode or filename
84f31a44 47 has file => ( isa => NonEmptySimpleStr,
54368e9d 48 required => 0,
49 is => 'ro' );
50 has mode => ( isa => Int,
1501cb4e 51 required => 1,
52 default => 0,
53 is => 'ro' );
54368e9d 54
98390bf6 55 method BUILD { $self->$_() for qw/_gpp_obj size modestr/ }
77edf882 56
1501cb4e 57## Private methods
acd0be23 58 method _to_string {
59 return $self->sha1;
60 };
1501cb4e 61
62## Builders
98390bf6 63 method _build__gpp_obj {
77edf882 64 return $self->_get_gpp_object($self->sha1)
65 }
a8a8f8f9 66
98390bf6 67 method "_build_size" {
68 my $v = $self->_cat_file_with_flag('s');
69 chomp($v);
70 return $v;
50394a3e 71 }
54368e9d 72
b421837d 73 method _cat_file_with_flag ($flag) {
74 $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1})
75 }
76
a8a8f8f9 77 method _build_modestr {
eb8ee28a 78 return mode_string($self->mode);
50394a3e 79 }
80
a8a8f8f9 81} # end class
775e96e0 82
c19af0d0 83__END__
84
85=head1 NAME
86
87Gitalist::Git::Object - Model of a git object.
88
89=head1 SYNOPSIS
90
44a9ed75 91 my $object = Repository->get_object($sha1);
c19af0d0 92
93=head1 DESCRIPTION
94
95Abstract base class for git objects.
96
97
98=head1 ATTRIBUTES
99
100
101=head1 METHODS
775e96e0 102
103
104=head1 AUTHORS
105
106See L<Gitalist> for authors.
107
108=head1 LICENSE
109
110See L<Gitalist> for the license.
111
112=cut