Commit | Line | Data |
a8a8f8f9 |
1 | use MooseX::Declare; |
84f31a44 |
2 | use Moose::Autobox; |
a8a8f8f9 |
3 | |
4 | class Gitalist::Git::Object { |
b36b7e0b |
5 | use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/; |
84f31a44 |
6 | use MooseX::Types::Common::String qw/NonEmptySimpleStr/; |
a8a8f8f9 |
7 | use File::Stat::ModeString qw/mode_to_string/; |
1501cb4e |
8 | |
54368e9d |
9 | # project and sha1 are required initargs |
50394a3e |
10 | has project => ( isa => 'Gitalist::Git::Project', |
11 | required => 1, |
12 | is => 'ro', |
84f31a44 |
13 | weak_ref => 1, |
77edf882 |
14 | handles => { |
15 | _run_cmd => 'run_cmd', |
aa7f1f92 |
16 | _run_cmd_fh => 'run_cmd_fh', |
1501cb4e |
17 | _run_cmd_list => 'run_cmd_list', |
77edf882 |
18 | _get_gpp_object => 'get_gpp_object', |
19 | }, |
50394a3e |
20 | ); |
84f31a44 |
21 | has sha1 => ( isa => NonEmptySimpleStr, |
1501cb4e |
22 | required => 1, |
23 | is => 'ro' ); |
54368e9d |
24 | |
98390bf6 |
25 | has type => ( isa => NonEmptySimpleStr, |
26 | is => 'ro', |
27 | required => 1 ); |
28 | |
84f31a44 |
29 | has $_ => ( isa => NonEmptySimpleStr, |
1501cb4e |
30 | required => 1, |
31 | is => 'ro', |
32 | lazy_build => 1 ) |
98390bf6 |
33 | for qw/modestr size/; |
54368e9d |
34 | |
77edf882 |
35 | has _gpp_obj => ( isa => 'Git::PurePerl::Object', |
36 | required => 1, |
37 | is => 'ro', |
38 | lazy_build => 1, |
f3083570 |
39 | handles => [ 'content', |
40 | ], |
77edf882 |
41 | ); |
42 | |
54368e9d |
43 | # objects can't determine their mode or filename |
84f31a44 |
44 | has file => ( isa => NonEmptySimpleStr, |
54368e9d |
45 | required => 0, |
46 | is => 'ro' ); |
47 | has mode => ( isa => Int, |
1501cb4e |
48 | required => 1, |
49 | default => 0, |
50 | is => 'ro' ); |
54368e9d |
51 | |
98390bf6 |
52 | method BUILD { $self->$_() for qw/_gpp_obj size modestr/ } |
77edf882 |
53 | |
1501cb4e |
54 | ## Private methods |
1501cb4e |
55 | |
56 | ## Builders |
98390bf6 |
57 | method _build__gpp_obj { |
77edf882 |
58 | return $self->_get_gpp_object($self->sha1) |
59 | } |
a8a8f8f9 |
60 | |
98390bf6 |
61 | method "_build_size" { |
62 | my $v = $self->_cat_file_with_flag('s'); |
63 | chomp($v); |
64 | return $v; |
50394a3e |
65 | } |
54368e9d |
66 | |
a8a8f8f9 |
67 | method _build_modestr { |
8d953eae |
68 | my $modestr = mode_to_string($self->mode); |
a8a8f8f9 |
69 | return $modestr; |
70 | } |
71 | |
84f31a44 |
72 | method _cat_file_with_flag ($flag) { |
77edf882 |
73 | $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1}) |
50394a3e |
74 | } |
75 | |
a8a8f8f9 |
76 | } # end class |
775e96e0 |
77 | |
78 | |
79 | |
80 | =head1 AUTHORS |
81 | |
82 | See L<Gitalist> for authors. |
83 | |
84 | =head1 LICENSE |
85 | |
86 | See L<Gitalist> for the license. |
87 | |
88 | =cut |