Make the version number sane and clean up copyright/license statements everywhere
[catagits/Gitalist.git] / lib / Gitalist / Git / Object.pm
1 use MooseX::Declare;
2 use Moose::Autobox;
3
4 class Gitalist::Git::Object {
5     use MooseX::Types::Moose qw/Str Int Bool Maybe ArrayRef/;
6     use MooseX::Types::Common::String qw/NonEmptySimpleStr/;
7     use File::Stat::ModeString qw/mode_to_string/;
8
9     # project and sha1 are required initargs
10     has project => ( isa => 'Gitalist::Git::Project',
11                      required => 1,
12                      is => 'ro',
13                      weak_ref => 1,
14                      handles => {
15                          _run_cmd => 'run_cmd',
16                          _run_cmd_fh => 'run_cmd_fh',
17                          _run_cmd_list => 'run_cmd_list',
18                          _get_gpp_object => 'get_gpp_object',
19                      },
20                  );
21     has sha1 => ( isa => NonEmptySimpleStr,
22                   required => 1,
23                   is => 'ro' );
24
25     has type => ( isa => NonEmptySimpleStr,
26                   is => 'ro',
27                   required => 1 );
28
29     has $_ => ( isa => NonEmptySimpleStr,
30                 required => 1,
31                 is => 'ro',
32                 lazy_build => 1 )
33         for qw/modestr size/;
34
35     has _gpp_obj => ( isa => 'Git::PurePerl::Object',
36                       required => 1,
37                       is => 'ro',
38                       lazy_build => 1,
39                       handles => [ 'content',
40                                ],
41                   );
42
43     # objects can't determine their mode or filename
44     has file => ( isa => NonEmptySimpleStr,
45                   required => 0,
46                   is => 'ro' );
47     has mode => ( isa => Int,
48                   required => 1,
49                   default => 0,
50                   is => 'ro' );
51
52     method BUILD { $self->$_() for qw/_gpp_obj size modestr/ }
53
54 ## Private methods
55
56 ## Builders
57     method _build__gpp_obj {
58         return $self->_get_gpp_object($self->sha1)
59     }
60
61     method "_build_size" {
62         my $v = $self->_cat_file_with_flag('s');
63         chomp($v);
64         return $v;
65     }
66
67     method _build_modestr {
68         my $modestr = mode_to_string($self->mode);
69         return $modestr;
70     }
71
72     method _cat_file_with_flag ($flag) {
73         $self->_run_cmd('cat-file', '-' . $flag, $self->{sha1})
74     }
75
76 } # end class
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