| 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.54'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 3 | my $RE_PATTERN = qr/.+?(?<!\\)/; | |||||||||||||||||||||||||||||||||||||||||
| 16 | 3 | my $RE_OWNER = qr/(?:\@+"[^"]*")|(?:\H+)/; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | ▶ | sub _croak { require Carp; Carp::croak(@_); } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | ▶ | sub _usage { _croak("Usage: @_\n") } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_usage: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | my $self = bless {}, $class; | |||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | sub parse { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | ▶ | my $input = shift or _usage(q{$codeowners->parse($input)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | return $self->parse_from_array($input, @_) if ref($input) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return $self->parse_from_string($input, @_) if ref($input) eq 'SCALAR'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 5 | ▶ | return $self->parse_from_fh($input, @_) if openhandle($input); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 5 | return $self->parse_from_filepath($input, @_); | |||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | sub parse_from_filepath { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_from_filepath: called CC=3 SCAR=11.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | ▶ | my $path = shift or _usage(q{$codeowners->parse_from_filepath($filepath)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | ▶ | $self = bless({}, $self) if !ref($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | return $self->parse_from_fh(path($path)->openr_utf8, @_); | |||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | sub parse_from_fh { | ||||||||||||||||||||||||||||||||||||||||||
| 50 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_from_fh: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 10 | ▶ | my $fh = shift or _usage(q{$codeowners->parse_from_fh($fh)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 10 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 10 | ▶ | $self = bless({}, $self) if !ref($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 10 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | my $parse_unowned; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 10 | my %unowned; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 10 | my %aliases; | |||||||||||||||||||||||||||||||||||||||||
| 61 | 10 | my $current_project; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 10 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 64 | 53 | my $lineno = $. - 1; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 53 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 66 | 53 | ▶ | if ($line eq '### UNOWNED (File::Codeowners)') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | 2 | $parse_unowned++; | |||||||||||||||||||||||||||||||||||||||||
| 68 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | elsif ($line =~ /^\h*#(.*)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | my $comment = $1; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | my $project; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | ▶ | if ($comment =~ /^\h*Project:\h*(.+?)\h*$/i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | ▶ | $project = $current_project = $1 || undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || undef
MC/DC0%0/1
$1 || undef
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 15 | ▶ | $lines[$lineno] = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | comment => $comment, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | $project ? (project => $project) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | elsif ($line =~ /^\h*$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 82 | # blank line | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | ▶ | elsif ($opts{aliases} && $line =~ /^\h*\@($RE_OWNER)\h+(.+)/) { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$opts{"aliases"} and $line =~ /^\h*\@($RE_OWNER)\h+(.+)/
MC/DC100%2/2
$opts{"aliases"} and $line =~ /^\h*\@($RE_OWNER)\h+(.+)/
$opts{"aliases"}
$line =~ /^\h*\@($RE_OWNER)\h+(.+)/
Truth table100%3/3
A and B
A= $opts{"aliases"}B= $line =~ /^\h*\@($RE_OWNER)\h+(.+)/
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | my $alias = $1; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | my @owners = $2 =~ /($RE_OWNER)/g; | |||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | $aliases{$alias} = \@owners; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | $lines[$lineno] = { | |||||||||||||||||||||||||||||||||||||||||
| 89 | alias => $alias, | ||||||||||||||||||||||||||||||||||||||||||
| 90 | owners => \@owners, | ||||||||||||||||||||||||||||||||||||||||||
| 91 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||
| 93 | elsif ($line =~ /^\h*($RE_PATTERN)\h+(.+)/) { | ||||||||||||||||||||||||||||||||||||||||||
| 94 | 20 | my $pattern = $1; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 20 | my @owners = $2 =~ /($RE_OWNER)/g; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 20 | ▶ | $lines[$lineno] = { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | pattern => $pattern, | ||||||||||||||||||||||||||||||||||||||||||
| 98 | owners => \@owners, | ||||||||||||||||||||||||||||||||||||||||||
| 99 | $current_project ? (project => $current_project) : (), | ||||||||||||||||||||||||||||||||||||||||||
| 100 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | die "Parse error on line $.: $line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 9 | ▶ | if ($parse_unowned) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | ▶ | while (my $line = <$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 109 | 2 | chomp $line; | |||||||||||||||||||||||||||||||||||||||||
| 110 | 2 | ▶ | if ($line =~ /# (.+)/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 2 | my $filepath = $1; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 2 | $unowned{$filepath}++; | |||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 9 | $self->{lines} = \@lines; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 9 | $self->{unowned} = \%unowned; | |||||||||||||||||||||||||||||||||||||||||
| 119 | 9 | $self->{aliases} = \%aliases; | |||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 9 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | sub parse_from_array { | ||||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_from_array: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | my $arr = shift or _usage(q{$codeowners->parse_from_array(\@lines)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | ▶ | $self = bless({}, $self) if !ref($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | 1 | my $str = join("\n", @$arr); | |||||||||||||||||||||||||||||||||||||||||
| 132 | 1 | return $self->parse_from_string(\$str, @_); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | sub parse_from_string { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_from_string: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 3 | ▶ | my $str = shift or _usage(q{$codeowners->parse_from_string(\$string)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 3 | ▶ | $self = bless({}, $self) if !ref($self); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 3 | ▶ | my $ref = ref($str) eq 'SCALAR' ? $str : \$str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 3 | ▶ | open(my $fh, '<:encoding(UTF-8)', $ref) or die "open failed: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 3 | return $self->parse_from_fh($fh, @_); | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub write_to_filepath { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_to_filepath: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | my $path = shift or _usage(q{$codeowners->write_to_filepath($filepath)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array}]); | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub write_to_fh { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_to_fh: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | my $charset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | for my $line (@{$self->write_to_array($charset)}) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | print $fh "$line\n"; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | sub write_to_string { | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_to_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | my $charset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 0 | my $str = join("\n", @{$self->write_to_array($charset)}) . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | return \$str; | |||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||||
| 177 | sub write_to_array { | ||||||||||||||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write_to_array: called CC=10 SCAR=23.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 2 | my $charset = shift; | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 2 | my @format; | |||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 184 | 8 | ▶ | if (my $comment = $line->{comment}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 4 | push @format, "#$comment"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||
| 187 | elsif (my $pattern = $line->{pattern}) { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 3 | my $owners = join(' ', @{$line->{owners}}); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 3 | push @format, "$pattern $owners"; | |||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||
| 191 | elsif (my $alias = $line->{alias}) { | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | my $owners = join(' ', @{$line->{owners}}); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 1 | push @format, "\@$alias $owners"; | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | push @format, ''; | |||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 2 | my @unowned = sort keys %{$self->_unowned}; | |||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | if (@unowned) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | push @format, '' if $format[-1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | push @format, '### UNOWNED (File::Codeowners)'; | |||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | for my $unowned (@unowned) { | |||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | push @format, "# $unowned"; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | if (defined $charset) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $_ = encode($charset, $_) for @format; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 2 | return \@format; | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | sub match { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
match: called CC=10 SCAR=23.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 6 | ▶ | my $filepath = shift or _usage(q{$codeowners->match($filepath)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | my $expand = $opts{expand} ? do { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | my $aliases = $self->aliases; | |||||||||||||||||||||||||||||||||||||||||
| 223 | sub { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 2 | ▶ | my $owner = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 2 | my $alias = $aliases->{$owner}; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 2 | ▶ | return @$alias if $alias; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 1 | return $owner; | |||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 6 | ▶ | } : sub { shift }; # noop | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | 6 | ▶ | my $lines = $self->{match_lines} ||= [reverse grep { ($_ || {})->{pattern} } @{$self->_lines}]; | ||||||||||||||||||||||||||||||||||||||||
|
Condition75%3/4
$self->{"match_lines"} ||= [reverse(grep({+($_ || {})->{"pattern"};} @{$self->_lines;}))]
$_ || {}
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"}
Truth table50%1/2
A
A= $_
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 6 | for my $line (@$lines) { | |||||||||||||||||||||||||||||||||||||||||
| 234 | 15 | ▶ | my $matcher = $line->{matcher} ||= build_gitignore_matcher([$line->{pattern}]); | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$line->{"matcher"} ||= build_gitignore_matcher([$line->{"pattern"}])
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"}])
| |||||||||||||||||||||||||||||||||||||||||||
| 235 | return { # deep copy | ||||||||||||||||||||||||||||||||||||||||||
| 236 | pattern => $line->{pattern}, | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | ▶ | owners => [map { $expand->($_) } @{$line->{owners} || []}], | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 15 | ▶ | $line->{project} ? (project => $line->{project}) : (), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 239 | } if $matcher->($filepath); | ||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | return undef; ## no critic (Subroutines::ProhibitExplicitReturn) | |||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||||||||||||
| 246 | sub owners { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
owners: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 5 | my $pattern = shift; | |||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 5 | ▶ | return $self->{owners} if !$pattern && $self->{owners}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $pattern and $self->{"owners"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | my %owners; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 254 | 44 | ▶ | next if $pattern && $line->{pattern} && $pattern ne $line->{pattern}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$pattern and $line->{"pattern"} and $pattern ne $line->{"pattern"}
$pattern and $line->{"pattern"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 255 | 39 | ▶ | $owners{$_}++ for (@{$line->{owners} || []}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 4 | my $owners = [sort keys %owners]; | |||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | $self->{owners} = $owners if !$pattern; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | return $owners; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | sub patterns { | ||||||||||||||||||||||||||||||||||||||||||
| 266 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
patterns: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | my $owner = shift; | |||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | ▶ | return $self->{patterns} if !$owner && $self->{patterns}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $owner and $self->{"patterns"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | my %patterns; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 273 | 32 | ▶ | next if $owner && !grep { $_ eq $owner } @{$line->{owners} || []}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$owner and not grep({$_ eq $owner;} @{$line->{"owners"} or [];})
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 [];})
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 20 | my $pattern = $line->{pattern}; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 20 | ▶ | $patterns{$pattern}++ if $pattern; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | my $patterns = [sort keys %patterns]; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 3 | ▶ | $self->{patterns} = $patterns if !$owner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | return $patterns; | |||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | sub aliases { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 3 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
aliases: called CC=4 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 3 | ▶ | return $self->{aliases} if $self->{aliases}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my %aliases; | |||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | next if !defined $line->{alias}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 293 | 0 | $aliases{$line->{alias}} = [@{$line->{owners}}]; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | |||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return $self->{aliases} = \%aliases; | |||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | sub projects { | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
projects: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | ▶ | return $self->{projects} if $self->{projects}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 2 | my %projects; | |||||||||||||||||||||||||||||||||||||||||
| 306 | 2 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 307 | 28 | my $project = $line->{project}; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 28 | ▶ | $projects{$project}++ if $project; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | 2 | my $projects = [sort keys %projects]; | |||||||||||||||||||||||||||||||||||||||||
| 312 | 2 | $self->{projects} = $projects; | |||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | 2 | return $projects; | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | sub update_owners { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_owners: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my $pattern = shift; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 2 | my $owners = shift; | |||||||||||||||||||||||||||||||||||||||||
| 322 | 2 | ▶ | $pattern && $owners or _usage(q{$codeowners->update_owners($pattern => \@owners)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$pattern and $owners
MC/DC0%0/2
$pattern and $owners
$pattern
$owners
Truth table33%1/3
A and B
A= $patternB= $owners
| |||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | ▶ | $owners = [$owners] if ref($owners) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 2 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 331 | 4 | ▶ | next if !$line->{pattern}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 2 | ▶ | next if $pattern ne $line->{pattern}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 333 | 1 | $line->{owners} = [@$owners]; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 1 | ++$count; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | sub update_owners_by_project { | ||||||||||||||||||||||||||||||||||||||||||
| 342 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
update_owners_by_project: called CC=8 SCAR=21.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 343 | 1 | my $project = shift; | |||||||||||||||||||||||||||||||||||||||||
| 344 | 1 | my $owners = shift; | |||||||||||||||||||||||||||||||||||||||||
| 345 | 1 | ▶ | $project && $owners or _usage(q{$codeowners->update_owners_by_project($project => \@owners)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$project and $owners
MC/DC0%0/2
$project and $owners
$project
$owners
Truth table33%1/3
A and B
A= $projectB= $owners
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | ▶ | $owners = [$owners] if ref($owners) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||
| 349 | 1 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 354 | 14 | ▶ | next if !$line->{project} || !$line->{owners}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$line->{"project"} and $line->{"owners"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | ▶ | next if $project ne $line->{project}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | $line->{owners} = [@$owners]; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 1 | ++$count; | |||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | sub rename_owner { | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_owner: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $old_owner = shift; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | my $new_owner = shift; | |||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | $old_owner && $new_owner or _usage(q{$codeowners->rename_owner($owner => $new_owner)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$old_owner and $new_owner
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
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | ▶ | next if !exists $line->{owners}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | for (my $i = 0; $i < @{$line->{owners}}; ++$i) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | next if $line->{owners}[$i] ne $old_owner; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | $line->{owners}[$i] = $new_owner; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | ++$count; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||
| 387 | sub rename_project { | ||||||||||||||||||||||||||||||||||||||||||
| 388 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
rename_project: called CC=7 SCAR=19.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | my $old_project = shift; | |||||||||||||||||||||||||||||||||||||||||
| 390 | 1 | my $new_project = shift; | |||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | ▶ | $old_project && $new_project or _usage(q{$codeowners->rename_project($project => $new_project)}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$old_project and $new_project
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
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | 1 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | 1 | for my $line (@{$self->_lines}) { | |||||||||||||||||||||||||||||||||||||||||
| 398 | 14 | ▶ | next if !exists $line->{project} || $old_project ne $line->{project}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not exists $line->{"project"} or $old_project ne $line->{"project"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | 2 | $line->{project} = $new_project; | |||||||||||||||||||||||||||||||||||||||||
| 400 | 2 | ▶ | $line->{comment} = " Project: $new_project" if exists $line->{comment}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 2 | ++$count; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | sub append { | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 1 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 1 | ▶ | push @{$self->_lines}, (@_ ? {@_} : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | sub prepend { | ||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepend: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | $self->_clear; | |||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | ▶ | unshift @{$self->_lines}, (@_ ? {@_} : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | sub unowned { | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unowned: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 4 | ▶ | [sort keys %{$self->{unowned} || {}}]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | sub add_unowned { | ||||||||||||||||||||||||||||||||||||||||||
| 429 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_unowned: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 1 | $self->_unowned->{$_}++ for @_; | |||||||||||||||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | sub remove_unowned { | ||||||||||||||||||||||||||||||||||||||||||
| 435 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove_unowned: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 436 | 1 | delete $self->_unowned->{$_} for @_; | |||||||||||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | sub is_unowned { | ||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_unowned: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | my $filepath = shift; | |||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | $self->_unowned->{$filepath}; | |||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | sub clear_unowned { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear_unowned: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | 1 | $self->{unowned} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||||||||||||||||
| 453 | 27 | ▶ | sub _lines { shift->{lines} ||= [] } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lines: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->{"lines"} ||= []
MC/DC0%0/1
+(shift())->{"lines"} ||= []
+(shift())->{"lines"}
Truth table50%1/2
A
A= +(shift())->{"lines"}
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 5 | ▶ | sub _unowned { shift->{unowned} ||= {} } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_unowned: called CC=2 SCAR=7.6
Condition50%1/2
+(shift())->{"unowned"} ||= {}
MC/DC0%0/1
+(shift())->{"unowned"} ||= {}
+(shift())->{"unowned"}
Truth table50%1/2
A
A= +(shift())->{"unowned"}
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | sub _clear { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 6 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_clear: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 6 | delete $self->{match_lines}; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 6 | delete $self->{owners}; | |||||||||||||||||||||||||||||||||||||||||
| 460 | 6 | delete $self->{patterns}; | |||||||||||||||||||||||||||||||||||||||||
| 461 | 6 | delete $self->{aliases}; | |||||||||||||||||||||||||||||||||||||||||
| 462 | 6 | delete $self->{projects}; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||
| 468 | __END__ | ||||||||||||||||||||||||||||||||||||||||||