Diff/Hunk.pm

filter: Statementstmt 15.6% 10 / 64 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 18.7% 3 / 16 Podpod 54.5% 6 / 11 totaltotal 16.3% 19 / 116 CC 10 SCAR 23.2
CC
10
Cov
12%
add_line
30.0
parse_header
12.0
_process_line
12.0
CRAP 10.2
« Diff.pm ↑ Summary
1 package Git::Repository::Plugin::Diff::Hunk;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
9 0 my ( $pkg, %args ) = @_;
10 0 my $from_line_start = delete $args{from_line_start};
11 0 my $from_line_count = delete $args{from_line_count};
12 0 my $to_line_start = delete $args{to_line_start};
13 0 my $to_line_count = delete $args{to_line_count};
14 0 my $header = delete $args{_header};
15  
16 0 return bless {
17 _header => $header,
18  
19 from_line_start => $from_line_start,
20 from_line_count => $from_line_count,
21 from_lines => [],
22 _from_line_counter => $from_line_start,
23  
24 to_line_start => $to_line_start,
25 to_line_count => $to_line_count,
26 _to_line_counter => $to_line_start,
27  
28 to_lines => [],
29  
30 }, $pkg;
31 }
32  
33 # @@ -5,3 +5,5 @@
34 # @@ -0,0 +1 @@
35 # @@ -1,7 +0,0 @@
36 # @@ -1,7 +1 @@
37  
38 0 ▶sub parse_header {
Subroutine parse_header: not called CC=3 SCAR=24.8
Pod undocumented
39 0 my ( $pkg, $str ) = @_;
40  
41 0 my ( $from_file_line_numbers, $to_file_line_numbers ) =
42 $str =~ /^\@\@ \s \-(\S+) \s \+(\S+) \s \@\@/x;
43  
44 0 ▶ croak "Cant parse hunk header: $str"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from_file_line_numbers and defined $to_file_line_numbers 0 0 0
Condition0%0/3
defined $from_file_line_numbers and defined $to_file_line_numbers
!ll&&!rl&&r
000
MC/DC0%0/2
defined $from_file_line_numbers and defined $to_file_line_numbers
defined $from_file_line_numbers defined $to_file_line_numbers
Truth table0%0/3
A and B
A= defined $from_file_line_numbersB= defined $to_file_line_numbers
ABresult
0X0
100
111
45 if !defined $from_file_line_numbers || !defined $to_file_line_numbers;
46  
47 0 my ( $from_line_start, $from_line_count ) =
48 $pkg->_parse_hunk_numbers($from_file_line_numbers);
49  
50 0 my ( $to_line_start, $to_line_count ) =
51 $pkg->_parse_hunk_numbers($to_file_line_numbers);
52  
53 0 return $pkg->new(
54 _header => $str,
55  
56 from_line_start => $from_line_start,
57 from_line_count => $from_line_count,
58  
59 to_line_start => $to_line_start,
60 to_line_count => $to_line_count,
61 );
62 }
63  
64 0 ▶sub to_line_start {
Subroutine to_line_start: not called CC=1 SCAR=6.9
Pod documented
65 0 my ($self) = @_;
66 0 return $self->{to_line_start};
67 }
68  
69 0 ▶sub to_line_count {
Subroutine to_line_count: not called CC=1 SCAR=6.9
Pod documented
70 0 my ($self) = @_;
71 0 return $self->{to_line_count};
72 }
73  
74 0 ▶sub from_line_start {
Subroutine from_line_start: not called CC=1 SCAR=6.9
Pod documented
75 0 my ($self) = @_;
76 0 return $self->{from_line_start};
77 }
78  
79 0 ▶sub from_line_count {
Subroutine from_line_count: not called CC=1 SCAR=6.9
Pod documented
80 0 my ($self) = @_;
81 0 return $self->{from_line_count};
82 }
83  
84 0 ▶sub _parse_hunk_numbers {
Subroutine _parse_hunk_numbers: not called CC=2 SCAR=17.9
85 0 my ( $pkg, $numbers_str ) = @_;
86 0 my ( $line_start, $line_count ) = split ',', $numbers_str;
87 0 ▶ $line_count //= 1;
Condition0%0/2
$line_count //= 1
l!l
00
MC/DC0%0/1
$line_count //= 1
$line_count
Truth table0%0/2
A
A= $line_count
Aresult
11
00
88 0 return $line_start, $line_count;
89 }
90  
91 0 ▶sub add_line {
Subroutine add_line: not called CC=5 SCAR=34.0
Pod undocumented
92 0 my ( $self, $line ) = @_;
93  
94 0 my $diff_char = substr $line, 0, 1, "";
95  
96 0 ▶ if ( $diff_char eq ' ' ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($diff_char eq ' ') { } 0 0 0
elsif ($diff_char eq '+') { } 0 0 0
elsif ($diff_char eq '-') { } 0 0 0
elsif ($diff_char eq '\\') { } 0 0 0
97 0 $self->{_to_line_counter} += 1;
98 0 $self->{_from_line_counter} += 1;
99 0 return 1;
100 }
101 elsif ( $diff_char eq '+' ) {
102 0 $self->process_to_line($line);
103 }
104 elsif ( $diff_char eq '-' ) {
105 0 $self->process_from_line($line);
106 }
107 elsif ( $diff_char eq '\\' ) {
108 0 return 1;
109 }
110 else {
111 0 croak "Malformed diff line: '$line'";
112 }
113  
114 0 return 1;
115 }
116  
117 0 ▶sub process_from_line {
Subroutine process_from_line: not called CC=1 SCAR=6.9
Pod undocumented
118 0 my ( $self, $line ) = @_;
119 0 return $self->_process_line( "from", $line );
120 }
121  
122 0 ▶sub process_to_line {
Subroutine process_to_line: not called CC=1 SCAR=6.9
Pod undocumented
123 0 my ( $self, $line ) = @_;
124 0 return $self->_process_line( "to", $line );
125 }
126  
127 0 ▶sub _process_line {
Subroutine _process_line: not called CC=3 SCAR=24.8
128 0 my ( $self, $kind, $line ) = @_;
129  
130 0 ▶ croak "${kind} is unknown line type!"
Branch: 1 branch
BranchTrueFalseTotal
if $kind ne "to" and $kind ne "from" 0 0 0
Condition0%0/3
$kind ne "to" and $kind ne "from"
!ll&&!rl&&r
000
MC/DC0%0/2
$kind ne "to" and $kind ne "from"
$kind ne "to" $kind ne "from"
Truth table0%0/3
A and B
A= $kind ne "to"B= $kind ne "from"
ABresult
0X0
100
111
131 if $kind ne 'to' && $kind ne 'from';
132  
133 0 my $lines_key = "${kind}_lines";
134 0 my $line_counter_key = "_${kind}_line_counter";
135  
136 0 push @{ $self->{$lines_key} }, [ $self->{$line_counter_key}, $line ];
137  
138 0 $self->{$line_counter_key} += 1;
139  
140 0 return;
141 }
142  
143 0 ▶sub from_lines {
Subroutine from_lines: not called CC=1 SCAR=6.9
Pod documented
144 0 my ($self) = @_;
145 0 return @{ $self->{from_lines} };
146 }
147  
148 0 ▶sub to_lines {
Subroutine to_lines: not called CC=1 SCAR=6.9
Pod documented
149 0 my ($self) = @_;
150 0 return @{ $self->{to_lines} };
151 }
152  
153 2 1;
154  
155 __END__
« Diff.pm ↑ Summary