Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / Git / PurePerl / NewObject / Commit.pm
1 package Git::PurePerl::NewObject::Commit;
2 use Moose;
3 use MooseX::StrictConstructor;
4 use Moose::Util::TypeConstraints;
5 use DateTime;
6 use namespace::autoclean;
7
8 extends 'Git::PurePerl::NewObject';
9
10 has 'kind' =>
11     ( is => 'ro', isa => 'ObjectKind', required => 1, default => 'commit' );
12 has 'tree'   => ( is => 'rw', isa => 'Str',                  required => 1 );
13 has 'parent' => ( is => 'rw', isa => 'Str',                  required => 0 );
14 has 'author' => ( is => 'rw', isa => 'Git::PurePerl::Actor', required => 1 );
15 has 'authored_time' => ( is => 'rw', isa => 'DateTime', required => 1 );
16 has 'committer' =>
17     ( is => 'rw', isa => 'Git::PurePerl::Actor', required => 1 );
18 has 'committed_time' => ( is => 'rw', isa => 'DateTime', required => 1 );
19 has 'comment'        => ( is => 'rw', isa => 'Str',      required => 1 );
20
21 sub _build_content {
22     my $self = shift;
23     my $content;
24
25     $content .= 'tree ' . $self->tree . "\n";
26     $content .= 'parent ' . $self->parent . "\n" if $self->parent;
27     $content
28         .= "author "
29         . $self->author->name . ' <'
30         . $self->author->email . "> "
31         . $self->authored_time->epoch . " "
32         . DateTime::TimeZone->offset_as_string( $self->authored_time->offset )
33         . "\n";
34     $content
35         .= "committer "
36         . $self->committer->name . ' <'
37         . $self->author->email . "> "
38         . $self->committed_time->epoch . " "
39         . DateTime::TimeZone->offset_as_string(
40         $self->committed_time->offset )
41         . "\n";
42     $content .= "\n";
43     my $comment = $self->comment;
44     chomp $comment;
45     $content .= "$comment\n";
46
47     $self->content($content);
48 }
49
50 __PACKAGE__->meta->make_immutable;
51