1 package Git::PurePerl::Object::Commit;
3 use MooseX::StrictConstructor;
4 use Moose::Util::TypeConstraints;
6 use namespace::autoclean;
8 extends 'Git::PurePerl::Object';
11 ( is => 'ro', isa => 'ObjectKind', required => 1, default => 'commit' );
12 has 'tree_sha1' => ( is => 'rw', isa => 'Str', required => 0 );
13 has 'parent_sha1s' => ( is => 'rw', isa => 'ArrayRef[Str]', required => 0, default => sub { [] });
14 has 'author' => ( is => 'rw', isa => 'Git::PurePerl::Actor', required => 0 );
15 has 'authored_time' => ( is => 'rw', isa => 'DateTime', required => 0 );
17 ( is => 'rw', isa => 'Git::PurePerl::Actor', required => 0 );
18 has 'committed_time' => ( is => 'rw', isa => 'DateTime', required => 0 );
19 has 'comment' => ( is => 'rw', isa => 'Str', required => 0 );
20 has 'encoding' => ( is => 'rw', isa => 'Str', required => 0 );
23 'tree' => 'tree_sha1',
24 'parent' => '_push_parent_sha1',
25 'author' => 'authored_time',
26 'committer' => 'committed_time'
31 return unless $self->content;
32 my @lines = split "\n", $self->content;
34 while ( my $line = shift @lines ) {
36 my ( $key, $value ) = split ' ', $line, 2;
37 push @{$header{$key}}, $value;
40 ||= [ $self->git->config->get(key => "i18n.commitEncoding") || "utf-8" ];
41 my $encoding = $header{encoding}->[-1];
42 for my $key (keys %header) {
43 for my $value (@{$header{$key}}) {
44 $value = decode($encoding, $value);
45 if ( $key eq 'committer' or $key eq 'author' ) {
46 my @data = split ' ', $value;
47 my ( $email, $epoch, $tz ) = splice( @data, -3 );
48 $email = substr( $email, 1, -1 );
49 my $name = join ' ', @data;
51 = Git::PurePerl::Actor->new( name => $name, email => $email );
53 $key = $method_map{$key};
55 = DateTime->from_epoch( epoch => $epoch, time_zone => $tz );
58 $key = $method_map{$key} || $key;
63 $self->comment( decode($encoding, join "\n", @lines) );
69 return $self->git->get_object( $self->tree_sha1 );
73 sub _push_parent_sha1 {
74 my ($self, $sha1) = @_;
76 push(@{$self->parent_sha1s}, $sha1);
80 return shift->parent_sha1s->[0];
85 return $self->git->get_object( $self->parent_sha1 );
91 return map { $self->git->get_object( $_ ) } @{$self->parent_sha1s};
94 __PACKAGE__->meta->make_immutable;