File/Codeowners.pm

filter: Statementstmt 83.1% 207 / 249 Branchbran 67.9% 91 / 134 Conditioncond 65.2% 30 / 46 MC/DCmcdc 39.2% 11 / 28 Subroutinesub 78.9% 30 / 38 Podpod 100% 25 / 25 totaltotal 75.7% 394 / 520 SCAR 54.4
CC
100
Cov
76%
rename_owner
56.0
parse_from_fh
15.0
write_to_fh
12.0
CRAP 230.5
↑ Summary Test/File/Codeowners.pm »
1 package File::Codeowners;
2 # ABSTRACT: Read and write CODEOWNERS files
3  
4 3 ▶use v5.10.1; # defined-or
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Encode qw(encode);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Path::Tiny 0.089;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Text::Gitignore qw(build_gitignore_matcher);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 our $VERSION = '0.53'; # VERSION
14  
15 0 ▶sub _croak { require Carp; Carp::croak(@_); }
Subroutine _croak: not called CC=1 SCAR=6.9
16 0 ▶sub _usage { _croak("Usage: @_\n") }
Subroutine _usage: not called CC=1 SCAR=6.9
17  
18  
19 sub new {
20 0 ▶ my $class = shift;
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
21 0 my $self = bless {}, $class;
22 }
23  
24  
25 sub parse {
26 4 ▶ my $self = shift;
Subroutine parse: called CC=6 SCAR=18.7
Pod documented
27 4 ▶ my $input = shift or _usage(q{$codeowners->parse($input)});
Branch: 1 branch
BranchTrueFalseTotal
my $input = shift() or _usage("\$codeowners->parse(\$input)") 0 4 4
28  
29 4 ▶ return $self->parse_from_array($input, @_) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
30 4 ▶ return $self->parse_from_array($input) if ref($input) eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $input eq "ARRAY" 0 4 4
31 4 ▶ return $self->parse_from_string($input) if ref($input) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
if ref $input eq "SCALAR" 1 3 4
32 3 ▶ return $self->parse_from_fh($input) if openhandle($input);
Branch: 1 branch
BranchTrueFalseTotal
if &openhandle($input) 0 3 3
33 3 return $self->parse_from_filepath($input);
34 }
35  
36  
37 sub parse_from_filepath {
38 4 ▶ my $self = shift;
Subroutine parse_from_filepath: called CC=3 SCAR=11.4
Pod documented
39 4 ▶ my $path = shift or _usage(q{$codeowners->parse_from_filepath($filepath)});
Branch: 1 branch
BranchTrueFalseTotal
my $path = shift() or _usage("\$codeowners->parse_from_filepath(\$filepath)") 0 4 4
40  
41 4 ▶ $self = bless({}, $self) if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 4 0 4
42  
43 4 return $self->parse_from_fh(path($path)->openr_utf8);
44 }
45  
46  
47 sub parse_from_fh {
48 8 ▶ my $self = shift;
Subroutine parse_from_fh: called CC=15 SCAR=27.1
Pod documented
49 8 ▶ my $fh = shift or _usage(q{$codeowners->parse_from_fh($fh)});
Branch: 1 branch
BranchTrueFalseTotal
my $fh = shift() or _usage("\$codeowners->parse_from_fh(\$fh)") 0 8 8
50  
51 8 ▶ $self = bless({}, $self) if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 7 8
52  
53 8 my @lines;
54  
55 my $parse_unowned;
56 8 my %unowned;
57 8 my $current_project;
58  
59 8 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 45 5 50
60 45 my $lineno = $. - 1;
61 45 chomp $line;
62 45 ▶ if ($line eq '### UNOWNED (File::Codeowners)') {
Branch: 4 branches
BranchTrueFalseTotal
if ($line eq '### UNOWNED (File::Codeowners)') { } 2 43 45
elsif ($line =~ /^\h*#(.*)/) { } 11 32 43
elsif ($line =~ /^\h*$/) { } 14 18 32
elsif ($line =~ /^\h*(.+?)(?<!\\)\h+(.+)/) { } 17 1 18
63 2 $parse_unowned++;
64 2 last;
65 }
66 elsif ($line =~ /^\h*#(.*)/) {
67 11 my $comment = $1;
68 11 my $project;
69 11 ▶ if ($comment =~ /^\h*Project:\h*(.+?)\h*$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($comment =~ /^\h*Project:\h*(.+?)\h*$/i) 2 9 11
70 2 ▶ $project = $current_project = $1 || undef;
Condition50%1/2
$1 || undef
l!l
20
MC/DC0%0/1
$1 || undef
$1
Truth table50%1/2
A
A= $1
Aresult
11
00
71 }
72 11 ▶ $lines[$lineno] = {
Branch: 1 branch
BranchTrueFalseTotal
$project ? : 2 9 11
73 comment => $comment,
74 $project ? (project => $project) : (),
75 };
76 }
77 elsif ($line =~ /^\h*$/) {
78 # blank line
79 }
80 elsif ($line =~ /^\h*(.+?)(?<!\\)\h+(.+)/) {
81 17 my $pattern = $1;
82 17 my @owners = $2 =~ /( (?:\@+"[^"]*") | (?:\H+) )/gx;
83 17 ▶ $lines[$lineno] = {
Branch: 1 branch
BranchTrueFalseTotal
$current_project ? : 2 15 17
84 pattern => $pattern,
85 owners => \@owners,
86 $current_project ? (project => $current_project) : (),
87 };
88 }
89 else {
90 1 die "Parse error on line $.: $line\n";
91 }
92 }
93  
94 7 ▶ if ($parse_unowned) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parse_unowned) 2 5 7
95 2 ▶ while (my $line = <$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $fh)) 2 2 4
96 2 chomp $line;
97 2 ▶ if ($line =~ /# (.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /# (.+)/) 2 0 2
98 2 my $filepath = $1;
99 2 $unowned{$filepath}++;
100 }
101 }
102 }
103  
104 7 $self->{lines} = \@lines;
105 7 $self->{unowned} = \%unowned;
106  
107 7 return $self;
108 }
109  
110  
111 sub parse_from_array {
112 1 ▶ my $self = shift;
Subroutine parse_from_array: called CC=4 SCAR=14.5
Pod documented
113 1 ▶ my $arr = shift or _usage(q{$codeowners->parse_from_array(\@lines)});
Branch: 1 branch
BranchTrueFalseTotal
my $arr = shift() or _usage("\$codeowners->parse_from_array(\\\@lines)") 0 1 1
114  
115 1 ▶ $self = bless({}, $self) if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 1 0 1
116  
117 1 ▶ $arr = [$arr, @_] if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 1 1
118 1 my $str = join("\n", @$arr);
119 1 return $self->parse_from_string(\$str);
120 }
121  
122  
123 sub parse_from_string {
124 3 ▶ my $self = shift;
Subroutine parse_from_string: called CC=5 SCAR=16.4
Pod documented
125 3 ▶ my $str = shift or _usage(q{$codeowners->parse_from_string(\$string)});
Branch: 1 branch
BranchTrueFalseTotal
my $str = shift() or _usage("\$codeowners->parse_from_string(\\\$string)") 0 3 3
126  
127 3 ▶ $self = bless({}, $self) if !ref($self);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 2 1 3
128  
129 3 ▶ my $ref = ref($str) eq 'SCALAR' ? $str : \$str;
Branch: 1 branch
BranchTrueFalseTotal
ref $str eq 'SCALAR' ? : 3 0 3
130 3 ▶ open(my $fh, '<:encoding(UTF-8)', $ref) or die "open failed: $!";
Subroutine BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<:encoding(UTF-8)", $ref or die "open failed: $!" 0 3 3
131  
132 3 return $self->parse_from_fh($fh);
133 }
134  
135  
136 sub write_to_filepath {
137 0 ▶ my $self = shift;
Subroutine write_to_filepath: not called CC=2 SCAR=17.9
Pod documented
138 0 ▶ my $path = shift or _usage(q{$codeowners->write_to_filepath($filepath)});
Branch: 1 branch
BranchTrueFalseTotal
my $path = shift() or _usage("\$codeowners->write_to_filepath(\$filepath)") 0 0 0
139  
140 0 path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array}]);
141 }
142  
143  
144 sub write_to_fh {
145 0 ▶ my $self = shift;
Subroutine write_to_fh: not called CC=3 SCAR=24.8
Pod documented
146 0 ▶ my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)});
Branch: 1 branch
BranchTrueFalseTotal
my $fh = shift() or _usage("\$codeowners->write_to_fh(\$fh)") 0 0 0
147 0 my $charset = shift;
148  
149 0 for my $line (@{$self->write_to_array($charset)}) {
150 0 print $fh "$line\n";
151 }
152 }
153  
154  
155 sub write_to_string {
156 0 ▶ my $self = shift;
Subroutine write_to_string: not called CC=1 SCAR=6.9
Pod documented
157 0 my $charset = shift;
158  
159 0 my $str = join("\n", @{$self->write_to_array($charset)}) . "\n";
160 0 return \$str;
161 }
162  
163  
164 sub write_to_array {
165 1 ▶ my $self = shift;
Subroutine write_to_array: called CC=9 SCAR=22.6
Pod documented
166 1 my $charset = shift;
167  
168 1 my @format;
169  
170 1 for my $line (@{$self->_lines}) {
171 4 ▶ if (my $comment = $line->{comment}) {
Branch: 2 branches
BranchTrueFalseTotal
if (my $comment = $line->{'comment'}) { } 2 2 4
elsif (my $pattern = $line->{'pattern'}) { } 2 0 2
172 2 push @format, "#$comment";
173 }
174 elsif (my $pattern = $line->{pattern}) {
175 2 my $owners = join(' ', @{$line->{owners}});
176 2 push @format, "$pattern $owners";
177 }
178 else {
179 0 push @format, '';
180 }
181 }
182  
183 1 my @unowned = sort keys %{$self->_unowned};
184 1 ▶ if (@unowned) {
Branch: 1 branch
BranchTrueFalseTotal
if (@unowned) 1 0 1
185 1 ▶ push @format, '' if $format[-1];
Branch: 1 branch
BranchTrueFalseTotal
if $format[-1] 1 0 1
186 1 push @format, '### UNOWNED (File::Codeowners)';
187 1 for my $unowned (@unowned) {
188 1 push @format, "# $unowned";
189 }
190 }
191  
192 1 ▶ if (defined $charset) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $charset) 0 1 1
193 0 $_ = encode($charset, $_) for @format;
194 }
195 1 return \@format;
196 }
197  
198  
199 sub match {
200 4 ▶ my $self = shift;
Subroutine match: called CC=9 SCAR=22.7
Pod documented
201 4 ▶ my $filepath = shift or _usage(q{$codeowners->match($filepath)});
Branch: 1 branch
BranchTrueFalseTotal
my $filepath = shift() or _usage("\$codeowners->match(\$filepath)") 0 4 4
202  
203 4 ▶ my $lines = $self->{match_lines} ||= [reverse grep { ($_ || {})->{pattern} } @{$self->_lines}];
Condition75%3/4
$self->{"match_lines"} ||= [reverse(grep({+($_ || {})->{"pattern"};} @{$self->_lines;}))]
l!l
31
$_ || {}
l!l
140
MC/DC100%1/1
$self->{"match_lines"} ||= [reverse(grep({+($_ || {})->{"pattern"};} @{$self->_lines;}))]
$self->{"match_lines"}
MC/DC0%0/1
$_ || {}
$_
Truth table100%2/2
A
A= $self->{"match_lines"}
Aresult
11
00
Truth table50%1/2
A
A= $_
Aresult
11
00
204  
205 4 for my $line (@$lines) {
206 13 ▶ my $matcher = $line->{matcher} ||= build_gitignore_matcher([$line->{pattern}]);
Condition66%2/3
$line->{"matcher"} ||= build_gitignore_matcher([$line->{"pattern"}])
l!l&&r!l&&!r
760
MC/DC0%0/2
$line->{"matcher"} ||= build_gitignore_matcher([$line->{"pattern"}])
$line->{"matcher"} build_gitignore_matcher([$line->{"pattern"}])
Truth table66%2/3
A ||= B
A= $line->{"matcher"}B= build_gitignore_matcher([$line->{"pattern"}])
ABresult
1X1
011
000
207 return { # deep copy
208 pattern => $line->{pattern},
209 4 ▶ owners => [@{$line->{owners} || []}],
Branch: 2 branches
BranchTrueFalseTotal
$line->{"owners"} or [] 0 4 4
$line->{'project'} ? : 2 2 4
210 13 ▶ $line->{project} ? (project => $line->{project}) : (),
Branch: 1 branch
BranchTrueFalseTotal
if &$matcher($filepath) 4 9 13
211 } if $matcher->($filepath);
212 }
213  
214 0 return undef; ## no critic (Subroutines::ProhibitExplicitReturn)
215 }
216  
217  
218 sub owners {
219 5 ▶ my $self = shift;
Subroutine owners: called CC=10 SCAR=23.0
Pod documented
220 5 my $pattern = shift;
221  
222 5 ▶ return $self->{owners} if !$pattern && $self->{owners};
Branch: 1 branch
BranchTrueFalseTotal
if not $pattern and $self->{"owners"} 1 4 5
Condition100%3/3
not $pattern and $self->{"owners"}
!ll&&!rl&&r
131
MC/DC100%2/2
not $pattern and $self->{"owners"}
not $pattern $self->{"owners"}
Truth table100%3/3
not(A) and B
A= not $patternB= $self->{"owners"}
ABresult
0X0
100
111
223  
224 4 my %owners;
225 4 for my $line (@{$self->_lines}) {
226 44 ▶ next if $pattern && $line->{pattern} && $pattern ne $line->{pattern};
Branch: 1 branch
BranchTrueFalseTotal
if $pattern and $line->{"pattern"} and $pattern ne $line->{"pattern"} 5 39 44
Condition100%6/6
$pattern and $line->{"pattern"} and $pattern ne $line->{"pattern"}
!ll&&!rl&&r
3815
$pattern and $line->{"pattern"}
!ll&&!rl&&r
3086
MC/DC100%3/3
$pattern and $line->{"pattern"} and $pattern ne $line->{"pattern"}
$pattern $line->{"pattern"} $pattern ne $line->{"pattern"}
Truth table100%4/4
A and B and C
A= $patternB= $line->{"pattern"}C= $pattern ne $line->{"pattern"}
ABCresult
0XX0
10X0
1100
1111
227 39 ▶ $owners{$_}++ for (@{$line->{owners} || []});
Branch: 1 branch
BranchTrueFalseTotal
$line->{"owners"} or [] 25 14 39
228 }
229  
230 4 my $owners = [sort keys %owners];
231 4 ▶ $self->{owners} = $owners if !$pattern;
Branch: 1 branch
BranchTrueFalseTotal
unless $pattern 3 1 4
232  
233 4 return $owners;
234 }
235  
236  
237 sub patterns {
238 2 ▶ my $self = shift;
Subroutine patterns: called CC=9 SCAR=22.0
Pod documented
239 2 my $owner = shift;
240  
241 2 ▶ return $self->{patterns} if !$owner && $self->{patterns};
Branch: 1 branch
BranchTrueFalseTotal
if not $owner and $self->{"patterns"} 0 2 2
Condition66%2/3
not $owner and $self->{"patterns"}
!ll&&!rl&&r
110
MC/DC0%0/2
not $owner and $self->{"patterns"}
not $owner $self->{"patterns"}
Truth table66%2/3
not(A) and B
A= not $ownerB= $self->{"patterns"}
ABresult
0X0
100
111
242  
243 2 my %patterns;
244 2 for my $line (@{$self->_lines}) {
245 28 ▶ next if $owner && !grep { $_ eq $owner } @{$line->{owners} || []};
Branch: 2 branches
BranchTrueFalseTotal
if $owner and not grep({$_ eq $owner;} @{$line->{"owners"} or [];}) 12 16 28
$line->{"owners"} or [] 8 6 14
Condition100%3/3
$owner and not grep({$_ eq $owner;} @{$line->{"owners"} or [];})
!ll&&!rl&&r
14212
MC/DC100%2/2
$owner and not grep({$_ eq $owner;} @{$line->{"owners"} or [];})
$owner not grep({$_ eq $owner;} @{$line->{"owners"} or [];})
Truth table100%3/3
A and not(B)
A= $ownerB= not grep({$_ eq $owner;} @{$line->{"owners"} or [];})
ABresult
0X0
100
111
246 16 my $pattern = $line->{pattern};
247 16 ▶ $patterns{$pattern}++ if $pattern;
Branch: 1 branch
BranchTrueFalseTotal
if $pattern 8 8 16
248 }
249  
250 2 my $patterns = [sort keys %patterns];
251 2 ▶ $self->{patterns} = $patterns if !$owner;
Branch: 1 branch
BranchTrueFalseTotal
unless $owner 1 1 2
252  
253 2 return $patterns;
254 }
255  
256  
257 sub projects {
258 2 ▶ my $self = shift;
Subroutine projects: called CC=4 SCAR=13.9
Pod documented
259  
260 2 ▶ return $self->{projects} if $self->{projects};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"projects"} 0 2 2
261  
262 2 my %projects;
263 2 for my $line (@{$self->_lines}) {
264 28 my $project = $line->{project};
265 28 ▶ $projects{$project}++ if $project;
Branch: 1 branch
BranchTrueFalseTotal
if $project 4 24 28
266 }
267  
268 2 my $projects = [sort keys %projects];
269 2 $self->{projects} = $projects;
270  
271 2 return $projects;
272 }
273  
274  
275 sub update_owners {
276 2 ▶ my $self = shift;
Subroutine update_owners: called CC=7 SCAR=19.7
Pod documented
277 2 my $pattern = shift;
278 2 my $owners = shift;
279 2 ▶ $pattern && $owners or _usage(q{$codeowners->update_owners($pattern => \@owners)});
Branch: 1 branch
BranchTrueFalseTotal
$pattern and $owners or _usage("\$codeowners->update_owners(\$pattern => \\\@owners)") 0 2 2
Condition33%1/3
$pattern and $owners
!ll&&!rl&&r
002
MC/DC0%0/2
$pattern and $owners
$pattern $owners
Truth table33%1/3
A and B
A= $patternB= $owners
ABresult
0X0
100
111
280  
281 2 ▶ $owners = [$owners] if ref($owners) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $owners ne "ARRAY" 0 2 2
282  
283 2 $self->_clear;
284  
285 2 my $count = 0;
286  
287 2 for my $line (@{$self->_lines}) {
288 4 ▶ next if !$line->{pattern};
Branch: 1 branch
BranchTrueFalseTotal
unless $line->{"pattern"} 2 2 4
289 2 ▶ next if $pattern ne $line->{pattern};
Branch: 1 branch
BranchTrueFalseTotal
if $pattern ne $line->{"pattern"} 1 1 2
290 1 $line->{owners} = [@$owners];
291 1 ++$count;
292 }
293  
294 2 return $count;
295 }
296  
297  
298 sub update_owners_by_project {
299 1 ▶ my $self = shift;
Subroutine update_owners_by_project: called CC=8 SCAR=21.2
Pod documented
300 1 my $project = shift;
301 1 my $owners = shift;
302 1 ▶ $project && $owners or _usage(q{$codeowners->update_owners_by_project($project => \@owners)});
Branch: 1 branch
BranchTrueFalseTotal
$project and $owners or _usage("\$codeowners->update_owners_by_project(\$project => \\\@owners)") 0 1 1
Condition33%1/3
$project and $owners
!ll&&!rl&&r
001
MC/DC0%0/2
$project and $owners
$project $owners
Truth table33%1/3
A and B
A= $projectB= $owners
ABresult
0X0
100
111
303  
304 1 ▶ $owners = [$owners] if ref($owners) ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $owners ne "ARRAY" 1 0 1
305  
306 1 $self->_clear;
307  
308 1 my $count = 0;
309  
310 1 for my $line (@{$self->_lines}) {
311 14 ▶ next if !$line->{project} || !$line->{owners};
Branch: 1 branch
BranchTrueFalseTotal
unless $line->{"project"} and $line->{"owners"} 13 1 14
Condition100%3/3
$line->{"project"} and $line->{"owners"}
!ll&&!rl&&r
1211
MC/DC100%2/2
$line->{"project"} and $line->{"owners"}
$line->{"project"} $line->{"owners"}
Truth table100%3/3
A and B
A= $line->{"project"}B= $line->{"owners"}
ABresult
0X0
100
111
312 1 ▶ next if $project ne $line->{project};
Branch: 1 branch
BranchTrueFalseTotal
if $project ne $line->{"project"} 0 1 1
313 1 $line->{owners} = [@$owners];
314 1 ++$count;
315 }
316  
317 1 return $count;
318 }
319  
320  
321 sub rename_owner {
322 0 ▶ my $self = shift;
Subroutine rename_owner: not called CC=7 SCAR=40.3
Pod documented
323 0 my $old_owner = shift;
324 0 my $new_owner = shift;
325 0 ▶ $old_owner && $new_owner or _usage(q{$codeowners->rename_owner($owner => $new_owner)});
Branch: 1 branch
BranchTrueFalseTotal
$old_owner and $new_owner or _usage("\$codeowners->rename_owner(\$owner => \$new_owner)") 0 0 0
Condition0%0/3
$old_owner and $new_owner
!ll&&!rl&&r
000
MC/DC0%0/2
$old_owner and $new_owner
$old_owner $new_owner
Truth table0%0/3
A and B
A= $old_ownerB= $new_owner
ABresult
0X0
100
111
326  
327 0 $self->_clear;
328  
329 0 my $count = 0;
330  
331 0 for my $line (@{$self->_lines}) {
332 0 ▶ next if !exists $line->{owners};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $line->{"owners"} 0 0 0
333 0 ▶ for (my $i = 0; $i < @{$line->{owners}}; ++$i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @{$line->{"owners"};}) 0 0 0
334 0 ▶ next if $line->{owners}[$i] ne $old_owner;
Branch: 1 branch
BranchTrueFalseTotal
if $line->{"owners"}[$i] ne $old_owner 0 0 0
335 0 $line->{owners}[$i] = $new_owner;
336 0 ++$count;
337 }
338 }
339  
340 0 return $count;
341 }
342  
343  
344 sub rename_project {
345 1 ▶ my $self = shift;
Subroutine rename_project: called CC=7 SCAR=19.7
Pod documented
346 1 my $old_project = shift;
347 1 my $new_project = shift;
348 1 ▶ $old_project && $new_project or _usage(q{$codeowners->rename_project($project => $new_project)});
Branch: 1 branch
BranchTrueFalseTotal
$old_project and $new_project or _usage("\$codeowners->rename_project(\$project => \$new_project)") 0 1 1
Condition33%1/3
$old_project and $new_project
!ll&&!rl&&r
001
MC/DC0%0/2
$old_project and $new_project
$old_project $new_project
Truth table33%1/3
A and B
A= $old_projectB= $new_project
ABresult
0X0
100
111
349  
350 1 $self->_clear;
351  
352 1 my $count = 0;
353  
354 1 for my $line (@{$self->_lines}) {
355 14 ▶ next if !exists $line->{project} || $old_project ne $line->{project};
Branch: 1 branch
BranchTrueFalseTotal
if not exists $line->{"project"} or $old_project ne $line->{"project"} 12 2 14
Condition66%2/3
not exists $line->{"project"} or $old_project ne $line->{"project"}
l!l&&r!l&&!r
1202
MC/DC50%1/2
not exists $line->{"project"} or $old_project ne $line->{"project"}
not exists $line->{"project"} $old_project ne $line->{"project"}
Truth table66%2/3
not(A) or B
A= not exists $line->{"project"}B= $old_project ne $line->{"project"}
ABresult
1X1
011
000
356 2 $line->{project} = $new_project;
357 2 ▶ $line->{comment} = " Project: $new_project" if exists $line->{comment};
Branch: 1 branch
BranchTrueFalseTotal
if exists $line->{"comment"} 1 1 2
358 2 ++$count;
359 }
360  
361 1 return $count;
362 }
363  
364  
365 sub append {
366 1 ▶ my $self = shift;
Subroutine append: called CC=2 SCAR=7.0
Pod documented
367 1 $self->_clear;
368 1 ▶ push @{$self->_lines}, (@_ ? {@_} : undef);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
369 }
370  
371  
372 sub prepend {
373 1 ▶ my $self = shift;
Subroutine prepend: called CC=2 SCAR=7.0
Pod documented
374 1 $self->_clear;
375 1 ▶ unshift @{$self->_lines}, (@_ ? {@_} : undef);
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
376 }
377  
378  
379 sub unowned {
380 4 ▶ my $self = shift;
Subroutine unowned: called CC=2 SCAR=7.1
Pod documented
381 4 ▶ [sort keys %{$self->{unowned} || {}}];
Branch: 1 branch
BranchTrueFalseTotal
$self->{"unowned"} or {} 0 4 4
382 }
383  
384  
385 sub add_unowned {
386 1 ▶ my $self = shift;
Subroutine add_unowned: called CC=2 SCAR=6.9
Pod documented
387 1 $self->_unowned->{$_}++ for @_;
388 }
389  
390  
391 sub remove_unowned {
392 1 ▶ my $self = shift;
Subroutine remove_unowned: called CC=2 SCAR=6.9
Pod documented
393 1 delete $self->_unowned->{$_} for @_;
394 }
395  
396  
397  
398 sub is_unowned {
399 0 ▶ my $self = shift;
Subroutine is_unowned: not called CC=1 SCAR=6.9
Pod documented
400 0 my $filepath = shift;
401 0 $self->_unowned->{$filepath};
402 }
403  
404  
405 sub clear_unowned {
406 1 ▶ my $self = shift;
Subroutine clear_unowned: called CC=1 SCAR=0.0
Pod documented
407 1 $self->{unowned} = {};
408 }
409  
410 24 ▶sub _lines { shift->{lines} ||= [] }
Subroutine _lines: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->{"lines"} ||= []
l!l
240
MC/DC0%0/1
+(shift())->{"lines"} ||= []
+(shift())->{"lines"}
Truth table50%1/2
A
A= +(shift())->{"lines"}
Aresult
11
00
411 4 ▶sub _unowned { shift->{unowned} ||= {} }
Subroutine _unowned: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->{"unowned"} ||= {}
l!l
40
MC/DC0%0/1
+(shift())->{"unowned"} ||= {}
+(shift())->{"unowned"}
Truth table50%1/2
A
A= +(shift())->{"unowned"}
Aresult
11
00
412  
413 sub _clear {
414 6 ▶ my $self = shift;
Subroutine _clear: called CC=1 SCAR=0.0
415 6 delete $self->{match_lines};
416 6 delete $self->{owners};
417 6 delete $self->{patterns};
418 6 delete $self->{projects};
419 }
420  
421 3 1;
422  
423 __END__
↑ Summary Test/File/Codeowners.pm »