Cogit/Object/Commit.pm

filter: Statementstmt 95.3% 82 / 86 Branchbran 80.0% 8 / 10 Conditioncond 80.0% 8 / 10 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 5 totaltotal 87.1% 115 / 132 CC 12 SCAR 16.8
CC
12
Cov
92%
BUILD
11.0
_build_content
2.0
parents
2.0
CRAP 5.4
« Cogit.pm ↑ Summary Cogit/Protocol/Git.pm »
1 package Cogit::Object::Commit;
2 4 $Cogit::Object::Commit::VERSION = '0.001001';
3 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use MooX::Types::MooseLike::Base qw( ArrayRef Str InstanceOf );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use Encode qw/decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Cogit::Actor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 extends 'Cogit::Object';
11  
12 4 has '+git' => ( required => 1 );
13 4 ▶has '+kind' => ( default => sub { 'commit' } );
Subroutine __ANON__: called CC=1 SCAR=0.0
14  
15 4 has tree_sha1 => (
16 is => 'rw',
17 isa => Str,
18 init_arg => 'tree',
19 );
20  
21 4 has _parent => (
22 init_arg => 'parent',
23 is => 'rw',
24 isa => Str,
25 );
26  
27 has parent_sha1s => (
28 is => 'rw',
29 isa => ArrayRef[Str],
30 52 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
31 4 );
32  
33 4 has author => (
34 is => 'rw',
35 isa => InstanceOf['Cogit::Actor'],
36 );
37  
38 4 has authored_time => (
39 is => 'rw',
40 isa => InstanceOf['DateTime'],
41 );
42  
43 4 has committer => (
44 is => 'rw',
45 isa => InstanceOf['Cogit::Actor'],
46 );
47  
48 4 has committed_time => (
49 is => 'rw',
50 isa => InstanceOf['DateTime'],
51 );
52  
53 4 has comment => (
54 is => 'rw',
55 isa => Str,
56 );
57  
58 4 has encoding => (
59 is => 'rw',
60 isa => Str,
61 );
62  
63 4 my %method_map = (
64 tree => 'tree_sha1',
65 parent => '_push_parent_sha1',
66 author => 'authored_time',
67 committer => 'committed_time'
68 );
69  
70 52 ▶sub BUILD {
Subroutine BUILD: called CC=11 SCAR=24.0
Pod undocumented
71 52 my $self = shift;
72 52 ▶ return unless $self->has_content;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_content 4 48 52
73 48 my @lines = split "\n", $self->content;
74 48 my %header;
75 48 ▶ while ( my $line = shift @lines ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $line = shift @lines) 168 48 216
76 168 ▶ last unless $line;
Branch: 1 branch
BranchTrueFalseTotal
unless $line 0 168 168
77 168 my ( $key, $value ) = split ' ', $line, 2;
78 168 push @{$header{$key}}, $value;
79 }
80 $header{encoding}
81 48 ▶ ||= [ $self->git->config->get(key => "i18n.commitEncoding") || "utf-8" ];
Condition75%3/4
$header{"encoding"} ||= [$self->git->config->get("key", "i18n.commitEncoding") || "utf-8"]
l!l
147
$self->git->config->get('key', 'i18n.commitEncoding') || 'utf-8'
l!l
047
MC/DC100%1/1
$header{"encoding"} ||= [$self->git->config->get("key", "i18n.commitEncoding") || "utf-8"]
$header{"encoding"}
MC/DC0%0/1
$self->git->config->get('key', 'i18n.commitEncoding') || 'utf-8'
$self->git->config->get('key', 'i18n.commitEncoding')
Truth table100%2/2
A
A= $header{"encoding"}
Aresult
11
00
Truth table50%1/2
A
A= $self->git->config->get('key', 'i18n.commitEncoding')
Aresult
11
00
82 48 my $encoding = $header{encoding}->[-1];
83 48 for my $key (keys %header) {
84 215 for my $value (@{$header{$key}}) {
85 215 $value = decode($encoding, $value);
86 215 ▶ if ( $key eq 'committer' or $key eq 'author' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key eq 'committer' or $key eq 'author') { } 96 119 215
Condition100%3/3
$key eq "committer" or $key eq "author"
l!l&&r!l&&!r
4848119
MC/DC100%2/2
$key eq "committer" or $key eq "author"
$key eq "committer" $key eq "author"
Truth table100%3/3
A or B
A= $key eq "committer"B= $key eq "author"
ABresult
1X1
011
000
87 96 my @data = split ' ', $value;
88 96 my ( $email, $epoch, $tz ) = splice( @data, -3 );
89 96 $email = substr( $email, 1, -1 );
90 96 my $name = join ' ', @data;
91 96 my $actor
92 = Cogit::Actor->new( name => $name, email => $email );
93 96 $self->$key($actor);
94 96 $key = $method_map{$key};
95 96 my $dt
96 = DateTime->from_epoch( epoch => $epoch, time_zone => $tz );
97 96 $self->$key($dt);
98 } else {
99 119 ▶ $key = $method_map{$key} || $key;
Condition66%2/3
$method_map{$key} || $key
l!l&&r!l&&!r
71480
MC/DC0%0/2
$method_map{$key} || $key
$method_map{$key} $key
Truth table66%2/3
A || B
A= $method_map{$key}B= $key
ABresult
1X1
011
000
100 119 $self->$key($value);
101 }
102 }
103 }
104 48 $self->comment( decode($encoding, join "\n", @lines) );
105 }
106  
107 4 ▶sub _build_content {
Subroutine _build_content: called CC=2 SCAR=6.9
108 4 my $self = shift;
109  
110 4 my $content;
111  
112 4 $content .= 'tree ' . $self->tree_sha1 . "\n";
113 4 ▶ $content .= 'parent ' . $self->parent . "\n" if $self->parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->parent 0 4 4
114 4 $content
115 .= "author "
116 . $self->author->name . ' <'
117 . $self->author->email . "> "
118 . $self->authored_time->epoch . " "
119 . DateTime::TimeZone->offset_as_string( $self->authored_time->offset )
120 . "\n";
121 4 $content
122 .= "committer "
123 . $self->committer->name . ' <'
124 . $self->author->email . "> "
125 . $self->committed_time->epoch . " "
126 . DateTime::TimeZone->offset_as_string(
127 $self->committed_time->offset )
128 . "\n";
129 4 $content .= "\n";
130 4 my $comment = $self->comment;
131 4 chomp $comment;
132 4 $content .= "$comment\n";
133  
134 4 return $content;
135 }
136  
137 14 ▶sub tree {
Subroutine tree: called CC=1 SCAR=0.0
Pod undocumented
138 14 my $self = shift;
139 14 return $self->git->get_object( $self->tree_sha1 );
140 }
141  
142  
143 23 ▶sub _push_parent_sha1 {
Subroutine _push_parent_sha1: called CC=1 SCAR=0.0
144 23 my ($self, $sha1) = @_;
145  
146 23 push(@{$self->parent_sha1s}, $sha1);
147 }
148  
149 23 ▶sub parent_sha1 {
Subroutine parent_sha1: called CC=1 SCAR=0.0
Pod undocumented
150 23 return shift->parent_sha1s->[0];
151 }
152  
153 14 ▶sub parent {
Subroutine parent: called CC=1 SCAR=0.0
Pod undocumented
154 14 my $self = shift;
155 14 return $self->git->get_object( $self->parent_sha1 );
156 }
157  
158 0 ▶sub parents {
Subroutine parents: not called CC=1 SCAR=6.9
Pod undocumented
159 0 my $self = shift;
160  
161 0 return map { $self->git->get_object( $_ ) } @{$self->parent_sha1s};
162 }
163  
164 4 1;
165  
166 __END__
« Cogit.pm ↑ Summary Cogit/Protocol/Git.pm »