Debora/Package.pm

filter: Statementstmt 87.3% 533 / 610 Branchbran 62.1% 128 / 206 Conditioncond 52.7% 39 / 74 MC/DCmcdc 26.1% 11 / 42 Subroutinesub 88.2% 105 / 119 Podpod 100% 36 / 36 totaltotal 78.3% 852 / 1087 CC 139 SCAR 22.2
CC
139
Cov
79%
_get_packager
40.0
__ANON__
23.7
_get_dependencies
17.4
CRAP 9.2
« Debora/Util.pm ↑ Summary Debora/Package/Debian.pm »
1 package CPANPLUS::Dist::Debora::Package;
2  
3 # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
4  
5 8 ▶use 5.016;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 8 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 our $VERSION = '0.019';
10  
11 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 8 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 8 ▶use CPAN::Meta;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
15 8 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 8 ▶use File::Path qw(remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 8 ▶use File::Spec::Functions qw(catdir catfile splitdir splitpath);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 8 ▶use File::Temp qw(tempdir);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use Net::Domain qw(hostfqdn);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use Software::LicenseUtils 0.103014;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 8 ▶use CPANPLUS::Dist::Debora::License;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 8 ▶use CPANPLUS::Dist::Debora::Pod;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 8 ▶use CPANPLUS::Dist::Debora::Util qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
25 parse_version
26 module_is_distributed_with_perl
27 decode_utf8
28 can_run
29 run
30 find_most_recent_mtime
31 find_shared_objects
32 8 );
33  
34 # Map some distribution names to special package names.
35 8 my %PACKAGE_NAME_FOR = (
36 'ack' => 'ack',
37 'App-Licensecheck' => 'licensecheck',
38 'App-perlbrew' => 'perlbrew',
39 'TermReadKey' => 'perl-Term-ReadKey',
40 );
41  
42 # Version quirks.
43 0 ▶my %VERSION_FOR = ('BioPerl-Run' => sub { parse_version($_[0])->normal });
Subroutine __ANON__: not called CC=1 SCAR=1.2
44  
45 # Modules with summaries and descriptions.
46 8 my %POD_FOR = (
47 'ack' => 'ack',
48 'App-Licensecheck' => 'licensecheck',
49 'TermReadKey' => 'ReadKey.pm.PL',
50 'TimeDate' => 'Date::Parse',
51 'YAML-LibYAML' => 'YAML::XS',
52 );
53  
54 # Common modules whose license might not be guessed.
55 8 my %LICENSE_FOR = (
56 'AnyEvent' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
57 'Apache-Htpasswd' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
58 'Cache-Cache' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
59 'Canary-Stability' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
60 'CGI-FormBuilder' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
61 'CGI-FormBuilder-Source-Perl' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
62 'Crypt-CBC' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
63 'Encode-Detect' => 'MPL-1.1',
64 'Guard' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
65 'Iterator' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
66 'Iterator-Util' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
67 'Lingua-EN-Words2Nums' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
68 'Lingua-Stem-Snowball-Da' => 'GPL-2.0-only',
69 'Mozilla-CA' => 'MPL-2.0',
70 'Socket6' => 'BSD',
71 'String-ShellQuote' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
72 'Sub-Delete' => 'Artistic-1.0-Perl OR GPL-1.0-or-later',
73 'XML-Writer' => 'CC0-1.0',
74 );
75  
76 6 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77 6 my ($class, %attrs) = @_;
78  
79 6 my $attrs = $class->_buildargs(%attrs);
80  
81 6 return bless $attrs, $class;
82 }
83  
84 6 ▶sub _buildargs {
Subroutine _buildargs: called CC=8 SCAR=22.8
85 6 my ($class, %attrs) = @_;
86  
87 6 ▶ if (!exists $attrs{module}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attrs{"module"}) 0 6 6
88 0 croak 'No module';
89 }
90  
91 6 my $builddir = $attrs{builddir} = $attrs{module}->status->extract;
92 6 ▶ if (!defined $builddir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $builddir) 0 6 6
93 0 croak 'No builddir';
94 }
95  
96 6 ▶ if (!exists $attrs{installdirs}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attrs{"installdirs"}) 4 2 6
97 4 $attrs{installdirs} = 'vendor';
98 }
99  
100 6 my $installdirs = $attrs{installdirs};
101 6 ▶ if ($installdirs ne 'vendor' && $installdirs ne 'site') {
Branch: 1 branch
BranchTrueFalseTotal
if ($installdirs ne "vendor" and $installdirs ne "site") 0 6 6
Condition66%2/3
$installdirs ne "vendor" and $installdirs ne "site"
!ll&&!rl&&r
510
MC/DC0%0/2
$installdirs ne "vendor" and $installdirs ne "site"
$installdirs ne "vendor" $installdirs ne "site"
Truth table66%2/3
A and B
A= $installdirs ne "vendor"B= $installdirs ne "site"
ABresult
0X0
100
111
102 0 croak "installdirs is neither 'vendor' nor 'site': '$installdirs'";
103 }
104  
105 6 ▶ if (!exists $attrs{build_number}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $attrs{"build_number"}) 6 0 6
106 6 $attrs{build_number} = 1;
107 }
108  
109 6 my $build_number = $attrs{build_number};
110 6 ▶ if ($build_number !~ m{\A [1-9]\d* \z}xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($build_number =~ /\A [1-9]\d* \z/msux) 0 6 6
111 0 croak "build_number is not a positive integer: '$build_number'";
112 }
113  
114 6 $attrs{last_modification} = find_most_recent_mtime($builddir);
115  
116 6 return \%attrs;
117 }
118  
119 160 ▶sub _read {
Subroutine _read: called CC=2 SCAR=6.9
120 160 my ($self, $name, $default) = @_;
121  
122 160 ▶ if (!exists $self->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{$name}) 82 78 160
123 82 $self->{$name} = $default->();
124 }
125  
126 160 return $self->{$name};
127 }
128  
129 65 ▶sub module {
Subroutine module: called CC=1 SCAR=0.0
Pod documented
130 65 my $self = shift;
131  
132 65 return $self->{module};
133 }
134  
135 8 ▶sub installdirs {
Subroutine installdirs: called CC=1 SCAR=0.0
Pod documented
136 8 my $self = shift;
137  
138 8 return $self->{installdirs};
139 }
140  
141 2 ▶sub sourcefile {
Subroutine sourcefile: called CC=1 SCAR=0.0
Pod documented
142 2 my $self = shift;
143  
144 my $sourcefile
145 2 ▶ = $self->_read('sourcefile', sub { $self->module->status->fetch });
Subroutine __ANON__: called CC=1 SCAR=0.0
146  
147 2 return $sourcefile;
148 }
149  
150 1 ▶sub sourcedir {
Subroutine sourcedir: called CC=1 SCAR=0.0
Pod documented
151 1 my $self = shift;
152  
153 my $sourcedir
154 1 ▶ = $self->_read('sourcedir', sub { dirname($self->sourcefile) });
Subroutine __ANON__: called CC=1 SCAR=0.0
155  
156 1 return $sourcedir;
157 }
158  
159 19 ▶sub last_modification {
Subroutine last_modification: called CC=1 SCAR=0.0
Pod documented
160 19 my $self = shift;
161  
162 19 return $self->{last_modification};
163 }
164  
165 24 ▶sub builddir {
Subroutine builddir: called CC=1 SCAR=0.0
Pod documented
166 24 my $self = shift;
167  
168 24 return $self->{builddir};
169 }
170  
171 8 ▶sub outputdir {
Subroutine outputdir: called CC=1 SCAR=0.0
Pod documented
172 8 my $self = shift;
173  
174 8 ▶ my $outputdir = $self->_read('outputdir', sub { dirname($self->builddir) });
Subroutine __ANON__: called CC=1 SCAR=0.0
175  
176 8 return $outputdir;
177 }
178  
179 19 ▶sub stagingdir {
Subroutine stagingdir: called CC=1 SCAR=0.0
Pod documented
180 19 my $self = shift;
181  
182 my $stagingdir = $self->_read('stagingdir',
183 19 ▶ sub { tempdir('stagingXXXX', DIR => $self->outputdir) });
Subroutine __ANON__: called CC=1 SCAR=0.0
184  
185 19 return $stagingdir;
186 }
187  
188 5 ▶sub shared_objects {
Subroutine shared_objects: called CC=1 SCAR=0.0
Pod documented
189 5 my $self = shift;
190  
191 my $shared_objects
192 5 ▶ = $self->_read('shared_objects', sub { $self->_get_shared_objects });
Subroutine __ANON__: called CC=1 SCAR=0.0
193  
194 5 return $shared_objects;
195 }
196  
197 7 ▶sub is_noarch {
Subroutine is_noarch: called CC=1 SCAR=0.0
Pod documented
198 7 my $self = shift;
199  
200 7 ▶ my $is_noarch = $self->_read('is_noarch', sub { $self->_get_is_noarch });
Subroutine __ANON__: called CC=1 SCAR=0.0
201  
202 7 return $is_noarch;
203 }
204  
205 3 ▶sub module_name {
Subroutine module_name: called CC=1 SCAR=0.0
Pod documented
206 3 my $self = shift;
207  
208 my $module_name
209 3 ▶ = $self->_read('module_name', sub { $self->_get_module_name });
Subroutine __ANON__: called CC=1 SCAR=0.0
210  
211 3 return $module_name;
212 }
213  
214 50 ▶sub dist_name {
Subroutine dist_name: called CC=1 SCAR=0.0
Pod documented
215 50 my $self = shift;
216  
217 50 return $self->module->package_name;
218 }
219  
220 11 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
221 11 my $self = shift;
222  
223 my $name = $self->_read('name',
224 11 ▶ sub { $self->_normalize_name($self->dist_name) });
Subroutine __ANON__: called CC=1 SCAR=0.0
225  
226 11 return $name;
227 }
228  
229 4 ▶sub dist_version {
Subroutine dist_version: called CC=1 SCAR=0.0
Pod documented
230 4 my $self = shift;
231  
232 4 return $self->module->package_version;
233 }
234  
235 10 ▶sub version {
Subroutine version: called CC=1 SCAR=0.0
Pod documented
236 10 my $self = shift;
237  
238 my $version = $self->_read('version',
239 10 ▶ sub { $self->_normalize_version($self->dist_version) });
Subroutine __ANON__: called CC=1 SCAR=0.0
240  
241 10 return $version;
242 }
243  
244 5 ▶sub build_number {
Subroutine build_number: called CC=1 SCAR=0.0
Pod documented
245 5 my $self = shift;
246  
247 5 return $self->{build_number};
248 }
249  
250 1 ▶sub author {
Subroutine author: called CC=1 SCAR=0.0
Pod documented
251 1 my $self = shift;
252  
253 1 ▶ my $author = $self->_read('author', sub { $self->_get_author });
Subroutine __ANON__: called CC=1 SCAR=0.0
254  
255 1 return $author;
256 }
257  
258 5 ▶sub packager {
Subroutine packager: called CC=1 SCAR=0.0
Pod documented
259 5 my $self = shift;
260  
261 5 ▶ my $packager = $self->_read('packager', sub { $self->_get_packager });
Subroutine __ANON__: called CC=1 SCAR=0.0
262  
263 5 return $packager;
264 }
265  
266 3 ▶sub vendor {
Subroutine vendor: called CC=1 SCAR=0.0
Pod documented
267 3 my $self = shift;
268  
269 3 ▶ my $vendor = $self->_read('vendor', sub { $self->_get_vendor });
Subroutine __ANON__: called CC=1 SCAR=0.0
270  
271 3 return $vendor;
272 }
273  
274 3 ▶sub url {
Subroutine url: called CC=1 SCAR=0.0
Pod documented
275 3 my $self = shift;
276  
277 # A link to MetaCPAN is more useful than the homepage.
278 my $url = $self->_read('url',
279 3 ▶ sub { 'https://metacpan.org/dist/' . $self->dist_name });
Subroutine __ANON__: called CC=1 SCAR=0.0
280  
281 3 return $url;
282 }
283  
284 3 ▶sub summary {
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
285 3 my $self = shift;
286  
287 3 ▶ my $summary = $self->_read('summary', sub { $self->_get_summary });
Subroutine __ANON__: called CC=1 SCAR=0.0
288  
289 3 return $summary;
290 }
291  
292 3 ▶sub description {
Subroutine description: called CC=1 SCAR=0.0
Pod documented
293 3 my $self = shift;
294  
295 my $description
296 3 ▶ = $self->_read('description', sub { $self->_get_description });
Subroutine __ANON__: called CC=1 SCAR=0.0
297  
298 3 return $description;
299 }
300  
301 3 ▶sub dependencies {
Subroutine dependencies: called CC=1 SCAR=0.0
Pod documented
302 3 my $self = shift;
303  
304 my $dependencies
305 3 ▶ = $self->_read('dependencies', sub { $self->_get_dependencies });
Subroutine __ANON__: called CC=1 SCAR=0.0
306  
307 3 return $dependencies;
308 }
309  
310 5 ▶sub copyrights {
Subroutine copyrights: called CC=1 SCAR=0.0
Pod documented
311 5 my $self = shift;
312  
313 5 ▶ my $copyrights = $self->_read('copyrights', sub { $self->_get_copyrights });
Subroutine __ANON__: called CC=1 SCAR=0.0
314  
315 5 return $copyrights;
316 }
317  
318 5 ▶sub licenses {
Subroutine licenses: called CC=1 SCAR=0.0
Pod documented
319 5 my $self = shift;
320  
321 5 ▶ my $licenses = $self->_read('licenses', sub { $self->_get_licenses });
Subroutine __ANON__: called CC=1 SCAR=0.0
322  
323 5 return $licenses;
324 }
325  
326 3 ▶sub license {
Subroutine license: called CC=1 SCAR=0.0
Pod documented
327 3 my $self = shift;
328  
329 3 ▶ my $license = $self->_read('license', sub { $self->_get_license });
Subroutine __ANON__: called CC=1 SCAR=0.0
330  
331 3 return $license;
332 }
333  
334 7 ▶sub files {
Subroutine files: called CC=1 SCAR=0.0
Pod documented
335 7 my $self = shift;
336  
337 my $files = $self->_read('files',
338 7 ▶ sub { [@{$self->_get_docfiles}, @{$self->_get_stagingfiles}] });
Subroutine __ANON__: called CC=1 SCAR=0.0
339  
340 7 return $files;
341 }
342  
343 4 ▶sub files_by_type {
Subroutine files_by_type: called CC=1 SCAR=0.0
Pod documented
344 4 my ($self, $type) = @_;
345  
346 4 my @files = map { $_->{name} } grep { $_->{type} eq $type } @{$self->files};
347  
348 4 return \@files;
349 }
350  
351 1 ▶sub mb_opt {
Subroutine mb_opt: called CC=1 SCAR=0.0
Pod documented
352 1 my $self = shift;
353  
354 1 my $installdirs = $self->installdirs;
355  
356 1 return << "END_MB_OPT";
357 --installdirs $installdirs
358 END_MB_OPT
359 }
360  
361 1 ▶sub mm_opt {
Subroutine mm_opt: called CC=1 SCAR=0.0
Pod documented
362 1 my $self = shift;
363  
364 1 my $installdirs = $self->installdirs;
365  
366 1 return << "END_MM_OPT";
367 INSTALLDIRS=$installdirs
368 END_MM_OPT
369 }
370  
371 4 ▶sub sanitize_stagingdir {
Subroutine sanitize_stagingdir: called CC=1 SCAR=0.2
Pod documented
372 4 my $self = shift;
373  
374 4 my $fail_count = 0;
375  
376 64 ▶ my $finddepth = sub {
Subroutine __ANON__: called CC=17 SCAR=31.7
377 64 my $dir = shift;
378  
379 64 ▶ opendir my $dh, $dir
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or croak("Could not traverse '${dir}': $CPANPLUS::Dist::Debora::Package::OS_ERROR") 64 0 64
380 or croak "Could not traverse '$dir': $OS_ERROR";
381 ENTRY:
382 64 ▶ while (defined(my $entry = readdir $dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 204 64 268
383 204 ▶ next ENTRY if $entry eq q{.} || $entry eq q{..};
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." or $entry eq ".." 128 76 204
Condition100%3/3
$entry eq "." or $entry eq ".."
l!l&&r!l&&!r
646476
MC/DC100%2/2
$entry eq "." or $entry eq ".."
$entry eq "." $entry eq ".."
Truth table100%3/3
A or B
A= $entry eq "."B= $entry eq ".."
ABresult
1X1
011
000
384  
385 76 my $path = catfile($dir, $entry);
386  
387 # Skip symbolic links.
388 76 ▶ next ENTRY if -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 76 76
389  
390 # Process sub directories first.
391 76 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) 60 16 76
392 60 __SUB__->($path);
393 }
394  
395 # Sanitize the permissions.
396 76 my @stat = lstat $path;
397 76 ▶ if (!@stat) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@stat) 0 76 76
398 0 error("Could not stat '$path': $OS_ERROR");
399 0 next ENTRY;
400 }
401  
402 76 my $old_mode = $stat[2] & oct '0777';
403 76 my $new_mode = ($old_mode & oct '0755') | oct '0200';
404 76 ▶ if ($old_mode != $new_mode) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_mode != $new_mode) 0 76 76
405 0 ▶ if (!chmod $new_mode, $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (chmod $new_mode, $path) 0 0 0
406 0 error("Could not chmod '$path': $OS_ERROR");
407 0 ++$fail_count;
408 }
409 }
410  
411 # Remove empty directories and some files.
412 76 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 60 16 76
413 60 rmdir $path;
414 }
415 else {
416 16 ▶ if ( $entry eq 'perllocal.pod'
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq "perllocal.pod" or $entry eq ".packlist" or $entry =~ /[.]la \z/msux or $entry =~ /[.]bs \z/msux and -z $path) 8 8 16
Condition66%8/12
$entry eq "perllocal.pod" or $entry eq ".packlist" or $entry =~ /[.]la \z/msux or $entry =~ /[.]bs \z/msux and -z $path
l!l&&r!l&&!r
808
$entry eq "perllocal.pod" or $entry eq ".packlist" or $entry =~ /[.]la \z/msux
l!l&&r!l&&!r
808
$entry eq "perllocal.pod" or $entry eq ".packlist"
l!l&&r!l&&!r
448
$entry =~ /[.]bs \z/msux and -z $path
!ll&&!rl&&r
800
MC/DC40%2/5
$entry eq "perllocal.pod" or $entry eq ".packlist" or $entry =~ /[.]la \z/msux or $entry =~ /[.]bs \z/msux and -z $path
$entry eq "perllocal.pod" $entry eq ".packlist" $entry =~ /[.]la \z/msux $entry =~ /[.]bs \z/msux -z $path
Truth table50%3/6
A or B or C or D and E
A= $entry eq "perllocal.pod"B= $entry eq ".packlist"C= $entry =~ /[.]la \z/msuxD= $entry =~ /[.]bs \z/msuxE= -z $path
ABCDEresult
1XXXX1
01XXX1
001XX1
000111
0000X0
000100
417 || $entry eq '.packlist'
418 || $entry =~ m{[.]la \z}xms
419 || ($entry =~ m{[.]bs \z}xms && -z $path))
420 {
421 8 ▶ if (!unlink $path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (unlink $path) 0 8 8
422 0 error("Could not remove '$path': $OS_ERROR");
423 0 ++$fail_count;
424 }
425 }
426 }
427 }
428 64 closedir $dh;
429  
430 64 return;
431 4 };
432 4 $finddepth->($self->stagingdir);
433  
434 4 return $fail_count == 0;
435 }
436  
437 0 ▶sub remove_stagingdir {
Subroutine remove_stagingdir: not called CC=2 SCAR=17.9
Pod documented
438 0 my $self = shift;
439  
440 0 my $stagingdir = $self->{stagingdir};
441 0 ▶ if (defined $stagingdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stagingdir) 0 0 0
442 0 remove_tree($stagingdir);
443 0 delete $self->{stagingdir};
444 }
445  
446 0 return 1;
447 }
448  
449 0 ▶sub rpm_cmd {
Subroutine rpm_cmd: not called CC=1 SCAR=6.9
Pod documented
450 0 my $self = shift;
451  
452 0 state $rpm_cmd = can_run('rpm');
453  
454 0 return $rpm_cmd;
455 }
456  
457 9 ▶sub rpm_eval {
Subroutine rpm_eval: called CC=4 SCAR=21.2
Pod documented
458 9 my ($self, $expr) = @_;
459  
460 9 my $string = q{};
461  
462 9 my $rpm_cmd = $self->rpm_cmd;
463 9 ▶ if ($rpm_cmd) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rpm_cmd) 0 9 9
464 0 my @eval_cmd = ($rpm_cmd, '--eval', $expr);
465 0 my $output = q{};
466 0 ▶ if (run(command => \@eval_cmd, buffer => \$output)) {
Branch: 1 branch
BranchTrueFalseTotal
if (run("command", \@eval_cmd, "buffer", \$output)) 0 0 0
467 0 chomp $output;
468 0 ▶ $string = eval { decode_utf8($output) } // q{};
Condition0%0/2
eval { do { decode_utf8($output) } } // ""
l!l
00
MC/DC0%0/1
eval { do { decode_utf8($output) } } // ""
eval { do { decode_utf8($output) } }
Truth table0%0/2
A
A= eval { do { decode_utf8($output) } }
Aresult
11
00
469 }
470 }
471  
472 9 return $string;
473 }
474  
475 0 ▶sub sudo_cmd {
Subroutine sudo_cmd: not called CC=2 SCAR=17.9
Pod documented
476 0 my $self = shift;
477  
478 0 my $module = $self->module;
479 0 my $backend = $module->parent;
480 0 my $config = $backend->configure_object;
481 0 ▶ my $sudo_cmd = $config->get_program('sudo') // 'sudo';
Condition0%0/2
$config->get_program("sudo") // "sudo"
l!l
00
MC/DC0%0/1
$config->get_program("sudo") // "sudo"
$config->get_program("sudo")
Truth table0%0/2
A
A= $config->get_program("sudo")
Aresult
11
00
482  
483 0 return $sudo_cmd;
484 }
485  
486 6 ▶sub DESTROY {
Subroutine DESTROY: called CC=2 SCAR=7.0
487 6 my $self = shift;
488  
489 6 my $stagingdir = $self->{stagingdir};
490 6 ▶ if (defined $stagingdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $stagingdir) 6 0 6
491 ##no critic (ErrorHandling::RequireCheckingReturnValueOfEval)
492 6 eval { remove_tree($stagingdir) };
493 }
494  
495 6 return;
496 }
497  
498 ## no critic (Subroutines::ProhibitExcessComplexity)
499  
500 13 ▶sub _normalize_name {
Subroutine _normalize_name: called CC=3 SCAR=11.1
501 13 my ($self, $dist_name) = @_;
502  
503 13 my $name;
504 13 ▶ if (exists $PACKAGE_NAME_FOR{$dist_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $PACKAGE_NAME_FOR{$dist_name}) { } 0 13 13
505 0 $name = $PACKAGE_NAME_FOR{$dist_name};
506 }
507 else {
508 13 $name = $dist_name;
509  
510 # Prepend "perl-" unless the name starts with "perl-".
511 13 ▶ if ($name !~ m{\A perl-}xms) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name =~ /\A perl-/msux) 12 1 13
512 12 $name = 'perl-' . $name;
513 }
514 }
515  
516 13 return $name;
517 }
518  
519 18 ▶sub _normalize_version {
Subroutine _normalize_version: called CC=3 SCAR=11.1
520 18 my ($self, $dist_version) = @_;
521  
522 18 my $dist_name = $self->dist_name;
523  
524 18 ▶ my $version = $dist_version // 0;
Condition100%2/2
$dist_version // 0
l!l
171
MC/DC100%1/1
$dist_version // 0
$dist_version
Truth table100%2/2
A
A= $dist_version
Aresult
11
00
525  
526 18 ▶ if (exists $VERSION_FOR{$dist_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $VERSION_FOR{$dist_name}) 0 18 18
527 0 $version = $VERSION_FOR{$dist_name}->($version);
528 }
529  
530 18 $version =~ s{\A v}{}xms; # Strip "v".
531 18 $version =~ s/[-_]/~/g; # Handle release candidates.
532  
533 18 return $version;
534 }
535  
536 0 ▶sub _unnumify_version {
Subroutine _unnumify_version: not called CC=1 SCAR=6.9
537 0 my ($self, $dist_version) = @_;
538  
539 0 my $version
540 = $self->_normalize_version(parse_version($dist_version)->normal);
541  
542 0 return $version;
543 }
544  
545 3 ▶sub _get_meta {
Subroutine _get_meta: called CC=4 SCAR=14.0
546 3 my $self = shift;
547  
548 3 my $meta;
549  
550 3 my $builddir = $self->builddir;
551 META:
552 3 for (qw(META.json META.yml)) {
553 3 my $metafile = catfile($builddir, $_);
554 3 ▶ if (-f $metafile) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $metafile) 3 0 3
555 3 $meta = eval { CPAN::Meta->load_file($metafile) };
556 3 ▶ last META if defined $meta;
Branch: 1 branch
BranchTrueFalseTotal
if defined $meta 3 0 3
557 }
558 }
559  
560 3 return $meta;
561 }
562  
563 11 ▶sub _meta {
Subroutine _meta: called CC=1 SCAR=0.0
564 11 my $self = shift;
565  
566 11 ▶ my $meta = $self->_read('meta', sub { $self->_get_meta });
Subroutine __ANON__: called CC=1 SCAR=0.0
567  
568 11 return $meta;
569 }
570  
571 3 ▶sub _get_pod {
Subroutine _get_pod: called CC=2 SCAR=7.1
572 3 my $self = shift;
573  
574 3 my $builddir = $self->builddir;
575  
576 3 ▶ my $name = $POD_FOR{$self->dist_name} // $self->module_name;
Condition33%1/3
$POD_FOR{$self->dist_name} // $self->module_name
l!l&&r!l&&!r
030
MC/DC0%0/2
$POD_FOR{$self->dist_name} // $self->module_name
$POD_FOR{$self->dist_name} $self->module_name
Truth table33%1/3
A // B
A= $POD_FOR{$self->dist_name}B= $self->module_name
ABresult
1X1
011
000
577 3 my @dirs = map { catdir($builddir, $_) } qw(blib/lib blib/bin lib bin .);
578 3 my $pod = CPANPLUS::Dist::Debora::Pod->find($name, @dirs, $builddir);
579  
580 3 return $pod;
581 }
582  
583 11 ▶sub _pod {
Subroutine _pod: called CC=1 SCAR=0.0
584 11 my $self = shift;
585  
586 11 ▶ return $self->_read('pod', sub { $self->_get_pod });
Subroutine __ANON__: called CC=1 SCAR=0.0
587 }
588  
589 3 ▶sub _get_shared_objects {
Subroutine _get_shared_objects: called CC=2 SCAR=7.2
590 3 my $self = shift;
591  
592 3 my $stagingdir = $self->{stagingdir};
593 3 ▶ if (!defined $stagingdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stagingdir) 0 3 3
594 0 croak 'Call shared_objects after the distribution has been built';
595 }
596  
597 3 my $shared_objects = find_shared_objects($stagingdir);
598  
599 3 return $shared_objects;
600 }
601  
602 3 ▶sub _get_is_noarch {
Subroutine _get_is_noarch: called CC=5 SCAR=17.1
603 3 my $self = shift;
604  
605 # Searching for source code files isn't reliable as there are Perl
606 # distributions with C files in example directories.
607 #
608 # Instead, we look for an "auto" directory and search for shared objects
609 # after the distribution has been installed in the staging directory.
610  
611 3 my $stagingdir = $self->{stagingdir};
612 3 ▶ if (!defined $stagingdir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $stagingdir) 0 3 3
613 0 croak 'Call is_arch after the distribution has been built';
614 }
615  
616 3 my $is_noarch = @{$self->shared_objects} == 0;
617 3 ▶ if ($is_noarch) {
Branch: 1 branch
BranchTrueFalseTotal
if ($is_noarch) 3 0 3
618 3 my $installdirs = $self->installdirs;
619 3 my $archdir = $Config{"install${installdirs}arch"};
620 3 ▶ if (defined $archdir) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $archdir) 3 0 3
621 3 my $autodir = catdir($stagingdir, $archdir, 'auto');
622 3 ▶ if (-d $autodir) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $autodir) 0 3 3
623 0 $is_noarch = 0;
624 }
625 }
626 }
627  
628 3 return $is_noarch;
629 }
630  
631 3 ▶sub _get_module_name {
Subroutine _get_module_name: called CC=2 SCAR=7.0
632 3 my $self = shift;
633  
634 3 my $name = $self->module->module;
635  
636 # Is there a .pm file with the distribution's name?
637 3 my @module = split qr{-}xms, $self->dist_name;
638 3 my $filename = catfile($self->builddir, 'lib', @module) . '.pm';
639 3 ▶ if (-f $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $filename) 3 0 3
640 3 $name = join q{::}, @module;
641 }
642  
643 3 return $name;
644 }
645  
646 1 ▶sub _get_author {
Subroutine _get_author: called CC=3 SCAR=11.6
647 1 my $self = shift;
648  
649 1 my $name;
650  
651 1 my $author = $self->module->author;
652 1 ▶ if (defined $author && ref $author ne 'CPANPLUS::Module::Author::Fake') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $author and ref $author ne "CPANPLUS::Module::Author::Fake") 1 0 1
Condition33%1/3
defined $author and ref $author ne "CPANPLUS::Module::Author::Fake"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $author and ref $author ne "CPANPLUS::Module::Author::Fake"
defined $author ref $author ne "CPANPLUS::Module::Author::Fake"
Truth table33%1/3
A and B
A= defined $authorB= ref $author ne "CPANPLUS::Module::Author::Fake"
ABresult
0X0
100
111
653 1 $name = $author->author;
654 }
655  
656 1 return $name;
657 }
658  
659 3 ▶sub _get_packager {
Subroutine _get_packager: called CC=23 SCAR=36.9
660 3 my $self = shift;
661  
662 3 my $name;
663 my $email;
664  
665 3 my $EMAIL = qr{ \A
666 (?:([^<]*) \h+)? # name
667 <? ([^>]+@[^>]+) >? # email
668 }xms;
669  
670 3 ▶ if ($self->rpm_eval('%{?packager}') =~ $EMAIL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->rpm_eval("%{?packager}") =~ /$EMAIL/u) 0 3 3
671 0 $name = $1;
672 0 $email = $2;
673 }
674  
675 3 ▶ if (!$name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 3 0 3
676 NAME:
677 3 for my $key (qw(DEBFULLNAME NAME GITLAB_USER_NAME)) {
678 7 ▶ if ($ENV{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$key}) 1 6 7
679 1 $name = eval { decode_utf8($ENV{$key}) };
680 1 ▶ last NAME if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 1 0 1
681 }
682 }
683 }
684  
685 3 for my $key (qw(DEBEMAIL EMAIL GITLAB_USER_EMAIL)) {
686 9 ▶ if ($ENV{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$key}) 1 8 9
687 1 my $value = eval { decode_utf8($ENV{$key}) };
688 1 ▶ if ($value && $value =~ $EMAIL) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value and $value =~ /$EMAIL/u) 1 0 1
Condition33%1/3
$value and $value =~ /$EMAIL/u
!ll&&!rl&&r
001
MC/DC0%0/2
$value and $value =~ /$EMAIL/u
$value $value =~ /$EMAIL/u
Truth table33%1/3
A and B
A= $valueB= $value =~ /$EMAIL/u
ABresult
0X0
100
111
689 1 ▶ if (!$name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 0 1 1
690 0 $name = $1;
691 }
692 1 ▶ if (!$email) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email) 1 0 1
693 1 $email = $2;
694 }
695 }
696 }
697 }
698  
699 3 my $user;
700  
701 3 my @pw = eval { getpwuid $UID };
702 3 ▶ if (@pw) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pw) 3 0 3
703 3 $user = eval { decode_utf8($pw[0]) };
704  
705 3 ▶ if (!$name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 2 1 3
706 2 my $gecos = eval { decode_utf8($pw[6]) };
707 2 ▶ if ($gecos) {
Branch: 1 branch
BranchTrueFalseTotal
if ($gecos) 0 2 2
708 0 ($name) = split qr{,}xms, $gecos;
709 }
710 }
711 }
712  
713 3 ▶ if (!$user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 3 3
714 USER:
715 0 for my $key (qw(LOGNAME USER USERNAME)) {
716 0 ▶ if ($ENV{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{$key}) 0 0 0
717 0 $user = eval { decode_utf8($ENV{$key}) };
718 0 ▶ last USER if $user;
Branch: 1 branch
BranchTrueFalseTotal
if $user 0 0 0
719 }
720 }
721 }
722  
723 3 ▶ if (!$user) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user) 0 3 3
724 0 $user = 'nobody';
725 }
726  
727 3 ▶ if (!$name) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($name) 2 1 3
728 2 $name = $user;
729 }
730  
731 3 ▶ if (!$email) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($email) 2 1 3
732 2 my $host = hostfqdn;
733 2 ▶ if (!$host) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($host) 0 2 2
734 0 $host = 'localhost';
735 }
736 2 $host =~ s{[.]$}{}xms;
737 2 $email = $user . q{@} . $host;
738 }
739  
740 3 return "$name <$email>";
741 }
742  
743 3 ▶sub _get_vendor {
Subroutine _get_vendor: called CC=3 SCAR=11.8
744 3 my $self = shift;
745  
746 3 my $vendor = $self->rpm_eval('%{?vendor}');
747 3 ▶ if (!$vendor || $vendor =~ m{%}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $vendor or $vendor =~ /%/msux) 3 0 3
Condition33%1/3
not $vendor or $vendor =~ /%/msux
l!l&&r!l&&!r
300
MC/DC0%0/2
not $vendor or $vendor =~ /%/msux
not $vendor $vendor =~ /%/msux
Truth table33%1/3
not(A) or B
A= not $vendorB= $vendor =~ /%/msux
ABresult
1X1
011
000
748 3 $vendor = 'CPANPLUS';
749 }
750  
751 3 return $vendor;
752 }
753  
754 4 ▶sub _get_summary_from_meta {
Subroutine _get_summary_from_meta: called CC=4 SCAR=14.6
755 4 my $self = shift;
756  
757 4 my $summary;
758  
759 4 my $meta = $self->_meta;
760 4 ▶ if (defined $meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta) 4 0 4
761 4 my $text = $meta->{abstract};
762 4 ▶ if ($text && $text !~ m{unknown}xmsi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($text and not $text =~ /unknown/imsux) 4 0 4
Condition33%1/3
$text and not $text =~ /unknown/imsux
!ll&&!rl&&r
004
MC/DC0%0/2
$text and not $text =~ /unknown/imsux
$text not $text =~ /unknown/imsux
Truth table33%1/3
A and not(B)
A= $textB= not $text =~ /unknown/imsux
ABresult
0X0
100
111
763 4 $summary = $text;
764 }
765 }
766  
767 4 return $summary;
768 }
769  
770 1 ▶sub _get_summary_from_pod {
Subroutine _get_summary_from_pod: called CC=2 SCAR=7.0
771 1 my $self = shift;
772  
773 1 my $summary;
774  
775 1 my $pod = $self->_pod;
776 1 ▶ if (defined $pod) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pod) 1 0 1
777 1 $summary = $pod->summary;
778 }
779  
780 1 return $summary;
781 }
782  
783 3 ▶sub _get_summary {
Subroutine _get_summary: called CC=3 SCAR=11.6
784 3 my $self = shift;
785  
786 3 ▶ my $summary = $self->_get_summary_from_meta // $self->_get_summary_from_pod
Condition40%2/5
($self->_get_summary_from_meta // $self->_get_summary_from_pod) // "Module for the Perl programming language"
l!l
30
$self->_get_summary_from_meta // $self->_get_summary_from_pod
l!l&&r!l&&!r
300
MC/DC0%0/2
($self->_get_summary_from_meta // $self->_get_summary_from_pod) // "Module for the Perl programming language"
$self->_get_summary_from_meta $self->_get_summary_from_pod
Truth table33%1/3
A // B
A= $self->_get_summary_from_metaB= $self->_get_summary_from_pod
ABresult
1X1
011
000
787 // 'Module for the Perl programming language';
788 3 $summary =~ s{\v+}{ }xmsg; # Replace newlines.
789 3 $summary =~ s{[.]+ \z}{}xms; # Remove trailing dots.
790 3 $summary =~ s{\A (?:An? | The) \h+}{}xmsi; # Remove leading articles.
791  
792 3 return ucfirst $summary;
793 }
794  
795 3 ▶sub _get_description {
Subroutine _get_description: called CC=3 SCAR=11.8
796 3 my $self = shift;
797  
798 3 my $description = q{};
799  
800 3 my $pod = $self->_pod;
801 3 ▶ if (defined $pod) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pod) 3 0 3
802 3 $description = $pod->description;
803 }
804  
805 3 ▶ if (!$description) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($description) 0 3 3
806 0 my $module_name = $self->module_name;
807 0 $description
808 = "$module_name is a module for the Perl programming language.";
809 }
810  
811 3 return $description;
812 }
813  
814 3 ▶sub _get_requires {
Subroutine _get_requires: called CC=6 SCAR=19.7
815 3 my $self = shift;
816  
817 3 my %requires;
818  
819 3 ▶ my $prereqs = $self->module->status->prereqs // {};
Condition50%1/2
$self->module->status->prereqs // {}
l!l
30
MC/DC0%0/1
$self->module->status->prereqs // {}
$self->module->status->prereqs
Truth table50%1/2
A
A= $self->module->status->prereqs
Aresult
11
00
820  
821 3 my $meta = $self->_meta;
822 3 ▶ if (defined $meta && ref $meta->{prereqs} eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta and ref $meta->{'prereqs'} eq 'HASH') { } 3 0 3
Condition33%1/3
defined $meta and ref $meta->{"prereqs"} eq "HASH"
!ll&&!rl&&r
003
MC/DC0%0/2
defined $meta and ref $meta->{"prereqs"} eq "HASH"
defined $meta ref $meta->{"prereqs"} eq "HASH"
Truth table33%1/3
A and B
A= defined $metaB= ref $meta->{"prereqs"} eq "HASH"
ABresult
0X0
100
111
823 3 ▶ my $meta_runtime = $meta->{prereqs}->{runtime} // {};
Condition50%1/2
$meta->{"prereqs"}{"runtime"} // {}
l!l
30
MC/DC0%0/1
$meta->{"prereqs"}{"runtime"} // {}
$meta->{"prereqs"}{"runtime"}
Truth table50%1/2
A
A= $meta->{"prereqs"}{"runtime"}
Aresult
11
00
824 3 ▶ my $meta_requires = $meta_runtime->{requires} // {};
Condition50%1/2
$meta_runtime->{"requires"} // {}
l!l
30
MC/DC0%0/1
$meta_runtime->{"requires"} // {}
$meta_runtime->{"requires"}
Truth table50%1/2
A
A= $meta_runtime->{"requires"}
Aresult
11
00
825  
826 # We can only have dependencies that are in the prereqs.
827 12 %requires = map { $_ => $meta_requires->{$_} }
828 3 grep { exists $prereqs->{$_} } keys %{$meta_requires};
829 }
830 else {
831 0 %requires = %{$prereqs};
832 }
833  
834 3 return \%requires;
835 }
836  
837 3 ▶sub _get_dependencies {
Subroutine _get_dependencies: called CC=10 SCAR=28.6
838 3 my $self = shift;
839  
840 3 my %requires = %{$self->_get_requires};
841 3 my $backend = $self->module->parent;
842  
843 # Sometimes versions are numified and cannot be compared with stringified
844 # versions.
845 my %version_for = (
846 0 ▶ 'Algorithm::Diff' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
847 0 ▶ 'BioPerl' => sub { $self->_unnumify_version($_[0]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
848 0 ▶ 'Catalyst' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
849 0 ▶ 'Catalyst::Runtime' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
850 0 ▶ 'CGI::Simple' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
851 0 ▶ 'DBD::Pg' => sub { $self->_unnumify_version($_[0]) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
852 0 ▶ 'strict' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
853 0 ▶ 'Time::Local' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
854 0 ▶ 'warnings' => sub {0},
Subroutine __ANON__: not called CC=1 SCAR=6.9
855 3 );
856  
857 3 my %dependency;
858  
859 MODULE:
860 3 for my $module_name (keys %requires) {
861 12 my $module = $backend->module_tree($module_name);
862 12 ▶ next MODULE if !$module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 12 12
863  
864 # Task::Weaken is only a build dependency.
865 12 ▶ next MODULE if $module_name eq 'Task::Weaken';
Branch: 1 branch
BranchTrueFalseTotal
if $module_name eq "Task::Weaken" 0 12 12
866  
867 # Ignore dependencies on modules for VMS and Windows.
868 12 ▶ next MODULE if $module_name =~ m{\A (?:VMS | Win32)}xms;
Branch: 1 branch
BranchTrueFalseTotal
if $module_name =~ /\A (?:VMS | Win32)/msux 0 12 12
869  
870 12 my $dist_name = $module->package_name;
871 12 my $version = parse_version($requires{$module_name});
872  
873 12 ▶ my $is_core
Condition33%2/6
$module_name eq 'perl' || module_is_distributed_with_perl($module_name, $version) || $module->package_is_perl_core
l!l&&r!l&&!r
0012
$module_name eq "perl" or module_is_distributed_with_perl($module_name, $version)
l!l&&r!l&&!r
0012
MC/DC0%0/3
$module_name eq 'perl' || module_is_distributed_with_perl($module_name, $version) || $module->package_is_perl_core
$module_name eq "perl" module_is_distributed_with_perl($module_name, $version) $module->package_is_perl_core
Truth table25%1/4
A or B || C
A= $module_name eq "perl"B= module_is_distributed_with_perl($module_name, $version)C= $module->package_is_perl_core
ABCresult
1XX1
01X1
0011
0000
874 = $module_name eq 'perl'
875 || module_is_distributed_with_perl($module_name, $version)
876 || $module->package_is_perl_core;
877  
878 12 ▶ if (exists $version_for{$module_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $version_for{$module_name}) 0 12 12
879 0 $version = $version_for{$module_name}->($version);
880 }
881  
882 12 ▶ if (!exists $dependency{$module_name}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $dependency{$module_name} or $dependency{$module_name}{"version"} < $version) 12 0 12
Condition33%1/3
not exists $dependency{$module_name} or $dependency{$module_name}{"version"} < $version
l!l&&r!l&&!r
1200
MC/DC0%0/2
not exists $dependency{$module_name} or $dependency{$module_name}{"version"} < $version
not exists $dependency{$module_name} $dependency{$module_name}{"version"} < $version
Truth table33%1/3
not(A) or B
A= not exists $dependency{$module_name}B= $dependency{$module_name}{"version"} < $version
ABresult
1X1
011
000
883 || $dependency{$module_name}->{version} < $version)
884 {
885 12 $dependency{$module_name} = {
886 dist_name => $dist_name,
887 version => $version,
888 is_module => $module_name ne 'perl',
889 is_core => $is_core,
890 };
891 }
892 }
893  
894 my @dependencies = map { {
895 module_name => $_,
896 dist_name => $dependency{$_}->{dist_name},
897 package_name => $self->_normalize_name($dependency{$_}->{dist_name}),
898 version => $self->_normalize_version($dependency{$_}->{version}),
899 is_module => $dependency{$_}->{is_module},
900 is_core => $dependency{$_}->{is_core},
901 3 } } sort { uc $a cmp uc $b } keys %dependency;
902  
903 3 return \@dependencies;
904 }
905  
906 3 ▶sub _get_copyrights {
Subroutine _get_copyrights: called CC=4 SCAR=17.4
907 3 my $self = shift;
908  
909 3 my @copyrights;
910  
911 3 my $pod = $self->_pod;
912 3 ▶ if (defined $pod) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pod) 3 0 3
913 3 push @copyrights, @{$pod->copyrights};
914 }
915  
916 3 ▶ if (!@copyrights) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@copyrights) 0 3 3
917 0 my $author = $self->author;
918 0 ▶ my $holder
Branch: 1 branch
BranchTrueFalseTotal
$author ? : 0 0 0
919 = $author ? "$author and possibly others" : 'unknown authors';
920 0 my $time = $self->last_modification;
921 0 my $year = (gmtime $time)[5] + 1900;
922 0 push @copyrights, {year => $year, holder => $holder};
923 }
924  
925 3 return \@copyrights;
926 }
927  
928 4 ▶sub _get_licenses_from_meta {
Subroutine _get_licenses_from_meta: called CC=6 SCAR=18.4
929 4 my $self = shift;
930  
931 4 my @licenses;
932  
933 4 my $meta = $self->_meta;
934 4 ▶ if (defined $meta) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $meta) 4 0 4
935 4 my $keys = $meta->{license};
936 4 ▶ if (defined $keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $keys) 4 0 4
937 4 ▶ if (!ref $keys) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $keys) 0 4 4
938 0 $keys = [$keys];
939 }
940 4 my %ignore_key = map { $_ => 1 } qw(open_source unrestricted);
941 4 for my $key (grep { !exists $ignore_key{$_} } @{$keys}) {
942 my @license
943 4 = Software::LicenseUtils->guess_license_from_meta_key($key,
944 2);
945 4 ▶ if (@license) {
Branch: 1 branch
BranchTrueFalseTotal
if (@license) 4 0 4
946 4 push @licenses, @license;
947 }
948 }
949 }
950 }
951  
952 4 return \@licenses;
953 }
954  
955 4 ▶sub _get_licenses_from_pod {
Subroutine _get_licenses_from_pod: called CC=3 SCAR=11.1
956 4 my $self = shift;
957  
958 4 my @licenses;
959  
960 4 my $pod = $self->_pod;
961 4 ▶ if (defined $pod) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pod) 4 0 4
962 my @license
963 4 = Software::LicenseUtils->guess_license_from_pod($pod->text);
964 4 ▶ if (@license) {
Branch: 1 branch
BranchTrueFalseTotal
if (@license) 4 0 4
965 4 push @licenses, @license;
966 }
967 }
968  
969 4 return \@licenses;
970 }
971  
972 3 ▶sub _get_licenses {
Subroutine _get_licenses: called CC=2 SCAR=7.1
973 3 my $self = shift;
974  
975 3 my %copyright = %{$self->copyrights->[-1]};
976  
977 3 ▶ my $get_license = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
978 3 my $spdx_expression = shift;
979  
980 3 my $license = eval {
981 3 Software::LicenseUtils->new_from_spdx_expression({
982 spdx_expression => $spdx_expression,
983 %copyright
984 });
985 };
986 3 ▶ if (!$license) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($license) 0 3 3
987 0 $license = CPANPLUS::Dist::Debora::License->new({
988 package => $self,
989 %copyright
990 });
991 }
992  
993 3 return $license;
994 3 };
995  
996 my %unique_guesses
997 6 = map { $_->name => $_ } @{$self->_get_licenses_from_meta},
998 3 @{$self->_get_licenses_from_pod};
999  
1000 # Add the copyright year and author to the guessed licenses.
1001 my @licenses
1002 3 = map { $get_license->($_->spdx_expression) } values %unique_guesses;
1003 3 ▶ if (!@licenses) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@licenses) 0 3 3
1004 0 push @licenses, $get_license->($LICENSE_FOR{$self->dist_name});
1005 }
1006  
1007 my @sorted_licenses
1008 0 = sort { $a->spdx_expression cmp $b->spdx_expression } @licenses;
1009  
1010 3 return \@sorted_licenses;
1011 }
1012  
1013 3 ▶sub _get_license {
Subroutine _get_license: called CC=3 SCAR=11.4
1014 3 my $self = shift;
1015  
1016 3 my @names = map { $_->spdx_expression } @{$self->licenses};
1017 my $license = join ' AND ',
1018 3 ▶ map { @names > 1 && m{\b OR \b}xmsi ? "($_)" : $_ } @names;
Branch: 1 branch
BranchTrueFalseTotal
@names > 1 && /\b OR \b/imsux ? : 0 3 3
Condition33%1/3
@names > 1 and /\b OR \b/imsux
!ll&&!rl&&r
300
MC/DC0%0/2
@names > 1 and /\b OR \b/imsux
@names > 1 /\b OR \b/imsux
Truth table33%1/3
A and B
A= @names > 1B= /\b OR \b/imsux
ABresult
0X0
100
111
1019  
1020 3 return $license;
1021 }
1022  
1023 5 ▶sub _get_docfiles {
Subroutine _get_docfiles: called CC=1 SCAR=0.0
1024 5 my $self = shift;
1025  
1026 5 my $LICENSE = qr{ \A (?:
1027 COPYING(?:[.](?:LESSER|LIB))?
1028 | COPYRIGHT
1029 | LICEN[CS]E
1030 ) (?:[.](?:md|mkdn|pod|txt))? \z
1031 }xmsi;
1032  
1033 5 my $CHANGELOG = qr{ \A (?:
1034 Change(?:s|Log)
1035 ) (?:[.](?:md|mkdn|pod|txt))? \z
1036 }xmsi;
1037  
1038 5 my $DOC = qr{ \A (?:
1039 AUTHORS
1040 | BUGS
1041 | CONTRIBUTING
1042 | CREDITS
1043 | FAQ
1044 | NEWS
1045 | README
1046 | THANKS
1047 | TODO
1048 ) (?:[.](?:md|mkdn|pod|txt))? \z
1049 }xmsi;
1050  
1051 5 my %regex_for = (
1052 'license' => $LICENSE,
1053 'changelog' => $CHANGELOG,
1054 'doc' => $DOC,
1055 );
1056  
1057 5 my @files;
1058  
1059 5 ▶ my $fix_permissions = sub {
Subroutine __ANON__: called CC=7 SCAR=19.7
1060 5 my $dir = shift;
1061  
1062 5 chmod oct '0755', $dir;
1063  
1064 5 ▶ opendir my $dh, $dir
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or croak("Could not traverse '${dir}': $CPANPLUS::Dist::Debora::Package::OS_ERROR") 5 0 5
1065 or croak "Could not traverse '$dir': $OS_ERROR";
1066 ENTRY:
1067 5 ▶ while (defined(my $entry = readdir $dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 15 5 20
1068 15 ▶ next ENTRY if $entry eq q{.} || $entry eq q{..};
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." or $entry eq ".." 10 5 15
Condition100%3/3
$entry eq "." or $entry eq ".."
l!l&&r!l&&!r
555
MC/DC100%2/2
$entry eq "." or $entry eq ".."
$entry eq "." $entry eq ".."
Truth table100%3/3
A or B
A= $entry eq "."B= $entry eq ".."
ABresult
1X1
011
000
1069  
1070 5 my $path = catfile($dir, $entry);
1071  
1072 # Skip symbolic links.
1073 5 ▶ next ENTRY if -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 5 5
1074  
1075 5 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) { } 0 5 5
1076 0 __SUB__->($path);
1077 }
1078 else {
1079 5 chmod oct '0644', $path;
1080 }
1081 }
1082 5 closedir $dh;
1083  
1084 5 return;
1085 5 };
1086  
1087 5 ▶ my $find = sub {
Subroutine __ANON__: called CC=11 SCAR=24.0
1088 5 my $dir = shift;
1089  
1090 5 ▶ opendir my $dh, $dir
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or croak("Could not traverse '${dir}': $CPANPLUS::Dist::Debora::Package::OS_ERROR") 5 0 5
1091 or croak "Could not traverse '$dir': $OS_ERROR";
1092 ENTRY:
1093 5 ▶ while (defined(my $entry = readdir $dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 110 5 115
1094 110 ▶ next ENTRY if $entry eq q{.} || $entry eq q{..};
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." or $entry eq ".." 10 100 110
Condition100%3/3
$entry eq "." or $entry eq ".."
l!l&&r!l&&!r
55100
MC/DC100%2/2
$entry eq "." or $entry eq ".."
$entry eq "." $entry eq ".."
Truth table100%3/3
A or B
A= $entry eq "."B= $entry eq ".."
ABresult
1X1
011
000
1095  
1096 100 my $path = catfile($dir, $entry);
1097  
1098 # Skip symbolic links.
1099 100 ▶ next ENTRY if -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 100 100
1100  
1101 100 ▶ if (-d $path) {
Branch: 2 branches
BranchTrueFalseTotal
if (-d $path) { } 25 75 100
elsif (-s $path) { } 70 5 75
1102 25 ▶ if ($entry eq 'examples') {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry eq "examples") 5 20 25
1103 5 $fix_permissions->($path);
1104 5 my $file = {name => $entry, type => 'doc'};
1105 5 push @files, $file;
1106 }
1107 }
1108 elsif (-s $path) {
1109 TYPE:
1110 70 for my $type (keys %regex_for) {
1111 195 ▶ if ($entry =~ $regex_for{$type}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($entry =~ /$regex_for{$type}/u) 20 175 195
1112 20 chmod oct '0644', $path;
1113 20 my $file = {name => $entry, type => $type};
1114 20 push @files, $file;
1115 20 last TYPE;
1116 }
1117 }
1118 }
1119 }
1120 5 closedir $dh;
1121  
1122 5 return;
1123 5 };
1124 5 $find->($self->builddir);
1125  
1126 5 my @sorted_files = sort { $a->{name} cmp $b->{name} } @files;
1127  
1128 5 return \@sorted_files;
1129 }
1130  
1131 5 ▶sub _get_excludedirs {
Subroutine _get_excludedirs: called CC=5 SCAR=16.1
1132 5 my $self = shift;
1133  
1134 # A list of directories that are provided by Perl and must not be removed
1135 # by packages.
1136  
1137 5 my @vars = qw(
1138 installsitearch
1139 installsitebin
1140 installsitelib
1141 installsiteman1dir
1142 installsiteman3dir
1143 installsitescript
1144 installvendorarch
1145 installvendorbin
1146 installvendorlib
1147 installvendorman1dir
1148 installvendorman3dir
1149 installvendorscript
1150 );
1151  
1152 5 my %excludedirs = map { $_ => 1 } qw(/etc);
1153 VAR:
1154 5 for my $var (@vars) {
1155 60 my $value = $Config{$var};
1156 60 ▶ next VAR if !$value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 40 20 60
1157  
1158 20 ▶ if ($var =~ m{arch \z}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if ($var =~ /arch \z/msux) 5 15 20
1159 5 $value = catdir($value, 'auto');
1160 }
1161  
1162 20 my ($volume, $path) = File::Spec->splitpath($value, 1);
1163  
1164 20 my ($dir, @dirs) = splitdir($path);
1165 20 ▶ while (@dirs) {
Branch: 1 branch
BranchTrueFalseTotal
if (@dirs) 100 20 120
1166 100 $dir = catdir($dir, shift @dirs);
1167 100 $excludedirs{$dir} = 1;
1168 }
1169 }
1170  
1171 5 return \%excludedirs;
1172 }
1173  
1174 5 ▶sub _get_stagingfiles {
Subroutine _get_stagingfiles: called CC=1 SCAR=0.0
1175 5 my $self = shift;
1176  
1177 5 my $stagingdir = $self->stagingdir;
1178 5 my $stagingdir_length = length $stagingdir;
1179 5 my $excludedirs = $self->_get_excludedirs;
1180  
1181 5 my @files;
1182  
1183 40 ▶ my $find = sub {
Subroutine __ANON__: called CC=13 SCAR=25.8
1184 40 my $dir = shift;
1185  
1186 40 ▶ opendir my $dh, $dir
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or croak("Could not traverse '${dir}': $CPANPLUS::Dist::Debora::Package::OS_ERROR") 40 0 40
1187 or croak "Could not traverse '$dir': $OS_ERROR";
1188 ENTRY:
1189 40 ▶ while (defined(my $entry = readdir $dh)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $entry = readdir $dh)) 127 40 167
1190 127 ▶ next ENTRY if $entry eq q{.} || $entry eq q{..};
Branch: 1 branch
BranchTrueFalseTotal
if $entry eq "." or $entry eq ".." 80 47 127
Condition100%3/3
$entry eq "." or $entry eq ".."
l!l&&r!l&&!r
404047
MC/DC100%2/2
$entry eq "." or $entry eq ".."
$entry eq "." $entry eq ".."
Truth table100%3/3
A or B
A= $entry eq "."B= $entry eq ".."
ABresult
1X1
011
000
1191  
1192 47 my $path = catfile($dir, $entry);
1193  
1194 47 my $name = substr $path, $stagingdir_length;
1195 47 ▶ my $type = -l $path ? 'link' : -d $path ? 'dir' : 'file';
Branch: 2 branches
BranchTrueFalseTotal
-l $path ? : 0 47 47
-d $path ? : 35 12 47
1196 47 ▶ if ($type eq 'file') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "file") 12 35 47
1197 12 my ($volume, $dirs, $file) = splitpath($name);
1198 12 my %subdir = map { $_ => 1 } splitdir($dirs);
1199 12 ▶ if (exists $subdir{etc}) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $subdir{'etc'}) { } 0 12 12
elsif (exists $subdir{'man'}) { } 5 7 12
1200 0 $type = 'config';
1201 }
1202 elsif (exists $subdir{man}) {
1203 5 $type = 'man';
1204 }
1205 }
1206  
1207 47 ▶ if (!exists $excludedirs->{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $excludedirs->{$name}) 43 4 47
1208 43 my $file = {name => $name, type => $type};
1209 43 push @files, $file;
1210 }
1211  
1212 # Skip symbolic links.
1213 47 ▶ next ENTRY if -l $path;
Branch: 1 branch
BranchTrueFalseTotal
if -l $path 0 47 47
1214  
1215 47 ▶ if (-d $path) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $path) 35 12 47
1216 35 __SUB__->($path);
1217 }
1218 }
1219 40 closedir $dh;
1220  
1221 40 return;
1222 5 };
1223 5 $find->($stagingdir);
1224  
1225 5 my @sorted_files = sort { $a->{name} cmp $b->{name} } @files;
1226  
1227 5 return \@sorted_files;
1228 }
1229  
1230 8 1;
1231 __END__
« Debora/Util.pm ↑ Summary Debora/Package/Debian.pm »