Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Git / PurePerl / NewObject.pm
CommitLineData
3fea05b9 1package Git::PurePerl::NewObject;
2use Moose;
3use MooseX::StrictConstructor;
4use Moose::Util::TypeConstraints;
5use namespace::autoclean;
6
7enum 'ObjectKind' => qw(commit tree blob tag);
8
9has 'kind' => ( is => 'ro', isa => 'ObjectKind', required => 1 );
10has 'size' => ( is => 'ro', isa => 'Int', required => 0, lazy_build => 1 );
11has 'content' => ( is => 'rw', isa => 'Str', required => 0, lazy_build => 1 );
12has 'sha1' => ( is => 'ro', isa => 'Str', required => 0, lazy_build => 1 );
13
14sub _build_sha1 {
15 my $self = shift;
16 my $sha1 = Digest::SHA1->new;
17 $sha1->add( $self->raw );
18 my $sha1_hex = $sha1->hexdigest;
19 return $sha1_hex;
20}
21
22sub _build_size {
23 my $self = shift;
24 return length $self->content;
25}
26
27sub raw {
28 my $self = shift;
29 return $self->kind . ' ' . $self->size . "\0" . $self->content;
30}
31
32__PACKAGE__->meta->make_immutable;
33