File Coverage

blib/lib/Git/Repository/Log.pm
Criterion Covered Total %
statement 37 37 100.0
branch 6 6 100.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 52 52 100.0


line stmt bran cond sub pod time code
1             package Git::Repository::Log;
2             $Git::Repository::Log::VERSION = '1.314';
3 3     3   15364 use strict;
  3         4  
  3         76  
4 3     3   9 use warnings;
  3         3  
  3         72  
5 3     3   55 use 5.006;
  3         9  
6              
7             # a few simple accessors
8             for my $attr (
9             qw(
10             commit diff_from tree
11             author author_name author_email
12             committer committer_name committer_email
13             author_localtime author_tz author_gmtime
14             committer_localtime committer_tz committer_gmtime
15             raw_message message subject body
16             gpgsig
17             extra
18             )
19             )
20             {
21 3     3   12 no strict 'refs';
  3         2  
  3         251  
22 207     207   17735 *$attr = sub { return $_[0]{$attr} };
23             }
24             for my $attr (qw( parent mergetag )) {
25 3     3   11 no strict 'refs';
  3         4  
  3         1285  
26 73 100   73   10668 *$attr = sub { return @{ $_[0]{$attr} || [] } };
  73         547  
27             }
28              
29             sub new {
30 43     43 1 1485 my ( $class, @args ) = @_;
31 43         147 my $self = bless { parent => [] }, $class;
32              
33             # pick up key/values from the list
34 43         151 while ( my ( $key, $value ) = splice @args, 0, 2 ) {
35 344 100       682 if ( $key =~ /^(?:parent|mergetag)$/ ) {
36 77         61 push @{ $self->{$key} }, $value;
  77         265  
37             }
38             else {
39 267         847 $self->{$key} = $value;
40             }
41             }
42              
43             # special case
44 43         295 ($self->{commit}, $self->{diff_from}) = $self->{commit} =~ /^(\S+)(?: \(from (\S+)\))?/;
45              
46             # compute other keys
47 43         89 $self->{raw_message} = $self->{message};
48 43         205 $self->{message} =~ s/^ //gm;
49 43         107 @{$self}{qw( subject body )}
50 43         124 = ( split( /\n/m, $self->{message}, 2 ), '', '' );
51 43         94 $self->{body} =~ s/\A\s//gm;
52              
53             # author and committer details
54 43         76 for my $who (qw( author committer )) {
55 86         356 $self->{$who} =~ /^(.*) <(.*)> (.*) (([-+])(..)(..))$/;
56 86         283 my @keys = ( "${who}_name", "${who}_email", "${who}_gmtime",
57             "${who}_tz" );
58 86         105 @{$self}{@keys} = ( $1, $2, $3, $4 );
  86         506  
59 86 100       633 $self->{"${who}_localtime"} = $self->{"${who}_gmtime"}
60             + ( $5 eq '-' ? -1 : 1 ) * ( $6 * 3600 + $7 * 60 );
61             }
62              
63 43         259 return $self;
64             }
65              
66             1;
67              
68             __END__