lib/CPAN/Maker.pm

filter: Statementstmt 13.2% 93 / 702 Branchbran 0.3% 1 / 298 Conditioncond 0.0% 0 / 144 MC/DCmcdc 0.0% 0 / 87 Subroutinesub 39.4% 28 / 71 Podpod 8.3% 2 / 24 totaltotal 9.3% 124 / 1326 CC 220 SCAR 62.5
CC
220
Cov
8%
write_makefile
2256.0
stage_distribution
756.0
cmd_create_cpanfile
380.0
CRAP 517.5
↑ Summary lib/CPAN/Maker/Role/FileUtils.pm »
1 package CPAN::Maker;
2  
3 # a CPAN distribution creation utility
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use CPAN::Maker::Constants qw( :all );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use CPAN::Maker::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use CLI::Simple::Constants qw(:booleans :chars);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use CLI::Simple::Utils qw(choose slurp);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Cwd qw(getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use English qw( -no_match_vars );
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use ExtUtils::MM;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Basename qw(basename fileparse);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use File::Process qw( process_file filter );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use File::Temp qw( tempfile tempdir );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use File::Copy qw(cp);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use File::Path qw(make_path);
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use IPC::Open3;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Symbol qw(gensym);
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use File::ShareDir qw(dist_dir dist_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 1 ▶use JSON qw( encode_json decode_json );
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use List::Util qw( pairs uniq none);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Log::Log4perl::Level;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use Scalar::Util qw( reftype );
Subroutine BEGIN: called CC=1 SCAR=0.0
30 1 ▶use YAML::Tiny qw(Load Dump LoadFile);
Subroutine BEGIN: called CC=1 SCAR=0.0
31 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 1 ▶use parent qw(CLI::Simple);
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 1 ▶use Role::Tiny::With;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37 1 with 'CPAN::Maker::Role::ModuleUtils';
38 1 with 'CPAN::Maker::Role::FileUtils';
39 1 with 'CPAN::Maker::Role::Provides';
40  
41 1 our $VERSION = '2.0.12';
42 1 our $GIT_SHA = '61a54cafa632f61811b2f1fd2d968664e3ae14bf';
43 1 our $GIT_DIRTY = '61a54cafa632f61811b2f1fd2d968664e3ae14bf';
44  
45 1 __PACKAGE__->use_log4perl( level => 'info', color => $FALSE );
46  
47 1 ▶caller or exit __PACKAGE__->main();
Branch: 1 branch
BranchTrueFalseTotal
caller or exit __PACKAGE__->main 1 0 1
48  
49 ########################################################################
50 0 ▶sub init {
Subroutine init: not called CC=6 SCAR=37.4
Pod documented
51 ########################################################################
52 0 my ($self) = @_;
53  
54 0 ▶ if ( $self->get_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_version) 0 0 0
55 0 $self->command('version');
56 0 return;
57 }
58  
59 0 my $log_level = $self->get_log_level;
60  
61 0 $self->_set_log_level($log_level);
62  
63 0 my $project_root = $self->get_project_root;
64  
65 0 ▶ $self->set_project_root( $project_root // $ENV{PROJECT_HOME} // getcwd );
Condition0%0/6
($project_root // $ENV{"PROJECT_HOME"}) // getcwd()
l!l&&r!l&&!r
000
$project_root // $ENV{"PROJECT_HOME"}
l!l&&r!l&&!r
000
MC/DC0%0/3
($project_root // $ENV{"PROJECT_HOME"}) // getcwd()
$project_root $ENV{"PROJECT_HOME"} getcwd()
Truth table0%0/4
A // B // C
A= $project_rootB= $ENV{"PROJECT_HOME"}C= getcwd()
ABCresult
1XX1
01X1
0011
0000
66  
67 # set the min perl version for deteriming core modules
68 0 $self->_min_perl_version;
69  
70 # invoked by bash script to generate Makefile.PL - no buildspec
71 0 ▶ if ( !$self->get_buildspec && $self->get_module ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->get_buildspec and $self->get_module) 0 0 0
Condition0%0/3
not $self->get_buildspec and $self->get_module
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->get_buildspec and $self->get_module
not $self->get_buildspec $self->get_module
Truth table0%0/3
not(A) and B
A= not $self->get_buildspecB= $self->get_module
ABresult
0X0
100
111
72 0 $self->command('write-makefile');
73 }
74  
75 0 return;
76 }
77  
78 ########################################################################
79 0 ▶sub _set_log_level {
Subroutine _set_log_level: not called CC=1 SCAR=6.9
80 ########################################################################
81 0 my ( $self, $log_level ) = @_;
82  
83 0 my @numeric_levels = (
84 $ERROR => 1,
85 $WARN => 2,
86 $INFO => 3,
87 $DEBUG => 4,
88 $TRACE => 5,
89 );
90  
91 0 my @text_levels = (
92 error => 1,
93 warn => 2,
94 info => 3,
95 debug => 4,
96 trace => 5,
97 );
98  
99 0 ▶ my $numeric_level = choose {
Subroutine __ANON__: not called CC=3 SCAR=24.8
100  
101 0 ▶ if ( $log_level =~ /^(?:[12345])$/xsm ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($log_level =~ /^(?:[12345])$/msx) { } 0 0 0
elsif (($log_level) = grep({$log_level eq $_;} @text_levels)) { } 0 0 0
102 0 $log_level = { reverse @numeric_levels }->{$log_level};
103 0 return $self->get_log_level;
104 }
105 0 elsif ( ($log_level) = grep { $log_level eq $_ } @text_levels ) {
106 0 return {@text_levels}->{$log_level};
107 }
108 else {
109 0 return {@text_levels}->{info};
110 }
111 0 };
112  
113 0 $self->get_logger->level( { reverse @numeric_levels }->{$numeric_level} );
114  
115 0 $self->set_log_level($numeric_level);
116  
117 0 return $numeric_level;
118 }
119  
120 ########################################################################
121 0 ▶sub cmd_version {
Subroutine cmd_version: not called CC=1 SCAR=6.9
Pod undocumented
122 ########################################################################
123 0 my ($self) = @_;
124  
125 0 print $PROGRAM_NAME . ' v' . $VERSION . $NL;
126  
127 0 return $SUCCESS;
128 }
129  
130 ########################################################################
131 0 ▶sub cmd_create_cpanfile {
Subroutine cmd_create_cpanfile: not called CC=19 SCAR=59.4
Pod undocumented
132 ########################################################################
133 0 my ($self) = @_;
134  
135 0 my @file_list = $self->get_args;
136 0 ▶ my $dep_type = $self->get_dependency_type // 'requires';
Condition0%0/2
$self->get_dependency_type // "requires"
l!l
00
MC/DC0%0/1
$self->get_dependency_type // "requires"
$self->get_dependency_type
Truth table0%0/2
A
A= $self->get_dependency_type
Aresult
11
00
137  
138 0 my @dep_types = qw(requires suggests recommends);
139  
140 die sprintf "ERROR: --dependency-type must be one of %s\n", join q{, }, @dep_types
141 0 ▶ if none { $dep_type eq $_ } @dep_types;
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if &none(sub { $dep_type eq $_; } , @dep_types) 0 0 0
142  
143 0 ▶ die "ERROR: usage cpan-maker create-cpanfile file1 file2 ...\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @file_list 0 0 0
144 if !@file_list;
145  
146 0 my @requires;
147  
148 0 foreach (@file_list) {
149 0 push @requires, split /\n/xsm, slurp($_);
150 }
151  
152 0 my @filtered_requires;
153  
154 0 foreach (@requires) {
155 0 ▶ next if /^[#]/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if /^[#]/msx 0 0 0
156 0 s/^[+]//xsm;
157 0 push @filtered_requires, $_;
158 }
159  
160 0 @requires = uniq sort @filtered_requires;
161  
162 0 ▶ my $fh = choose {
Subroutine __ANON__: not called CC=4 SCAR=30.0
163 0 my $outfile = $self->get_outfile;
164  
165 0 ▶ return \*STDOUT
Branch: 1 branch
BranchTrueFalseTotal
if $outfile eq "-" 0 0 0
166 if $outfile eq q{-};
167  
168 0 ▶ $outfile //= 'cpanfile';
Condition0%0/2
$outfile //= "cpanfile"
l!l
00
MC/DC0%0/1
$outfile //= "cpanfile"
$outfile
Truth table0%0/2
A
A= $outfile
Aresult
11
00
169  
170 0 $self->set_outfile($outfile);
171  
172 0 ▶ open my $fh, '>', $outfile
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $outfile or die "ERROR: could not open cpanfile for writing: $CPAN::Maker::OS_ERROR\n" 0 0 0
173 or die "ERROR: could not open cpanfile for writing: $OS_ERROR\n";
174  
175 0 return $fh;
176 0 };
177  
178 0 foreach (@requires) {
179 0 my (@module) = split /\s+/xsm, $_;
180  
181 0 my $req = {
182 module => shift @module,
183 version => shift @module,
184 };
185  
186 0 ▶ if (@module) {
Branch: 1 branch
BranchTrueFalseTotal
if (@module) 0 0 0
187 0 foreach my $e (@module) {
188 0 ▶ die "ERROR: invalid entry only dist, url or mirror permitted after version\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $e =~ /^(?:dist=|url=|mirror=)/msx 0 0 0
189 if $e !~ /^(?:dist=|url=|mirror=)/xsm;
190  
191 0 my (@args) = split /=/, $e;
192 0 $req->{ $args[0] } = $args[1];
193 }
194 }
195  
196 0 ▶ if ( keys %{$req} == 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %{$req;} == 2) { } 0 0 0
197 0 ▶ print {$fh} sprintf qq{%s "%s", "%s";\n}, $dep_type, $req->{module} // q{}, $req->{version} // q{};
Condition0%0/4
$req->{"module"} // ""
l!l
00
$req->{"version"} // ""
l!l
00
MC/DC0%0/1
$req->{"module"} // ""
$req->{"module"}
MC/DC0%0/1
$req->{"version"} // ""
$req->{"version"}
Truth table0%0/2
A
A= $req->{"module"}
Aresult
11
00
Truth table0%0/2
A
A= $req->{"version"}
Aresult
11
00
198 }
199 else {
200 0 my @extra;
201 0 foreach ( keys %{$req} ) {
202 0 ▶ next if /^(?:module|version)/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if /^(?:module|version)/msx 0 0 0
203 0 push @extra, sprintf ' %s => "%s"', $_, $req->{$_};
204 }
205  
206 0 ▶ print {$fh} sprintf qq{requires "%s", "%s";\n}, $req->{module} // q{}, $req->{version} // q{};
Condition0%0/4
$req->{"module"} // ""
l!l
00
$req->{"version"} // ""
l!l
00
MC/DC0%0/1
$req->{"module"} // ""
$req->{"module"}
MC/DC0%0/1
$req->{"version"} // ""
$req->{"version"}
Truth table0%0/2
A
A= $req->{"module"}
Aresult
11
00
Truth table0%0/2
A
A= $req->{"version"}
Aresult
11
00
207  
208 0 print {$fh} sprintf ",\n%s", join ",\n", @extra;
209 0 print {$fh} ";\n";
210 }
211 }
212  
213 0 ▶ if ( $self->get_outfile ne '-' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_outfile ne "-") 0 0 0
214 0 close $fh;
215 }
216  
217 0 return $SUCCESS;
218 }
219  
220 ########################################################################
221 0 ▶sub cmd_validate {
Subroutine cmd_validate: not called CC=6 SCAR=37.4
Pod undocumented
222 ########################################################################
223 0 my ($self) = @_;
224  
225 0 my $is_validator_available = eval { require JSON::Validator; 1; }; ## scandeps: recommends
226  
227 0 ▶ die "ERROR: JSON::Validator must be installed to validate your 'buildspec.yml' file.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $is_validator_available 0 0 0
228 if !$is_validator_available;
229  
230 0 my ($file) = $self->get_args;
231 0 ▶ $file //= $self->get_buildspec // 'buildspec.yml';
Condition0%0/5
$file //= $self->get_buildspec // "buildspec.yml"
l!l&&r!l&&!r
000
$self->get_buildspec // "buildspec.yml"
l!l
00
MC/DC0%0/2
$file //= $self->get_buildspec // "buildspec.yml"
$file $self->get_buildspec
Truth table0%0/3
A //= B
A= $fileB= $self->get_buildspec
ABresult
1X1
011
000
232  
233 0 ▶ croak "ERROR: $file not found\n" if !-e $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file 0 0 0
234  
235 0 my $buildspec = $self->read_buildspec($file);
236  
237 0 ▶ if ( $self->validate_buildspec($buildspec) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->validate_buildspec($buildspec)) { } 0 0 0
238 0 $self->get_logger->info("$file is valid");
239 0 return $SUCCESS;
240 }
241 else {
242 0 $self->get_logger->error("$file is invalid");
243 0 return $FAILURE;
244 }
245 }
246  
247 ########################################################################
248 0 ▶sub cmd_build {
Subroutine cmd_build: not called CC=19 SCAR=59.4
Pod undocumented
249 ########################################################################
250 0 my ($self) = @_;
251  
252 0 ▶ die "ERROR: no buildspec.yml specified.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_buildspec 0 0 0
253 if !$self->get_buildspec;
254  
255 0 $self->parse_buildspec;
256  
257 0 ▶ if ( $self->get_dryrun ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_dryrun) 0 0 0
258 0 print {*STDOUT} Dumper(
259 { requires => $self->get_requires,
260 recommends => $self->get_recommends,
261 suggests => $self->get_suggests,
262 test_requires => $self->get_test_requires,
263 build_requires => $self->get_build_requires,
264 }
265 );
266 0 return $SUCCESS;
267 }
268  
269 0 my $builddir = tempdir( 'cpan-maker-XXXXXX', TMPDIR => $TRUE, CLEANUP => !$self->get_no_cleanup );
270  
271 0 $self->get_logger->debug("builddir: $builddir");
272  
273 0 my $cwd = getcwd;
274 0 ▶ my $project_root = $self->get_project_root // $cwd;
Condition0%0/3
$self->get_project_root // $cwd
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_project_root // $cwd
$self->get_project_root $cwd
Truth table0%0/3
A // B
A= $self->get_project_rootB= $cwd
ABresult
1X1
011
000
275  
276 0 ▶ chdir $project_root
Branch: 1 branch
BranchTrueFalseTotal
chdir $project_root or die "ERROR: could not chdir to ${project_root}: $CPAN::Maker::OS_ERROR\n" 0 0 0
277 or die "ERROR: could not chdir to $project_root: $OS_ERROR\n";
278  
279 0 my $provides_file = $self->stage_distribution( builddir => $builddir );
280  
281 0 $self->set_work_dir($builddir);
282  
283 {
284 0 my $makefile_pl = "$builddir/Makefile.PL";
285  
286 0 $self->get_logger->info("writing $makefile_pl");
287  
288 0 $self->write_makefile(
289 dest => $makefile_pl,
290 provides_file => $provides_file,
291 );
292 }
293  
294 0 ▶ chdir $builddir
Branch: 1 branch
BranchTrueFalseTotal
chdir $builddir or die "ERROR: could not chdir to ${builddir}: $CPAN::Maker::OS_ERROR\n" 0 0 0
295 or die "ERROR: could not chdir to $builddir: $OS_ERROR\n";
296  
297 0 ▶ if ( $provides_file && -e $provides_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($provides_file and -e $provides_file) 0 0 0
Condition0%0/3
$provides_file and -e $provides_file
!ll&&!rl&&r
000
MC/DC0%0/2
$provides_file and -e $provides_file
$provides_file -e $provides_file
Truth table0%0/3
A and B
A= $provides_fileB= -e $provides_file
ABresult
0X0
100
111
298 0 ▶ cp( $provides_file, "$builddir/provides" )
Branch: 1 branch
BranchTrueFalseTotal
cp($provides_file, "$builddir/provides") or die "ERROR: could not copy provides to builddir: $CPAN::Maker::OS_ERROR\n" 0 0 0
299 or die "ERROR: could not copy provides to builddir: $OS_ERROR\n";
300 }
301  
302 0 ▶ my $destdir = $self->get_destdir // $cwd;
Condition0%0/3
$self->get_destdir // $cwd
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_destdir // $cwd
$self->get_destdir $cwd
Truth table0%0/3
A // B
A= $self->get_destdirB= $cwd
ABresult
1X1
011
000
303  
304 # write MANIFEST.SKIP to prevent MYMETA files, Makefile, and
305 # intermediate build artifacts from being included in the distribution
306 {
307 0 ▶ open my $fh, '>', 'MANIFEST.SKIP'
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "MANIFEST.SKIP" or die "ERROR: could not write MANIFEST.SKIP: $CPAN::Maker::OS_ERROR\n" 0 0 0
308 or die "ERROR: could not write MANIFEST.SKIP: $OS_ERROR\n";
309 0 print {$fh} "Makefile\$\nMYMETA.json\nMYMETA.yml\nprovides\n";
310 0 close $fh;
311 }
312  
313 0 ▶ my @steps = ( [ $^X, 'Makefile.PL' ], [ 'make', 'manifest' ], sub { $self->_sort_manifest }, [ 'make', 'dist' ], );
Subroutine __ANON__: not called CC=1 SCAR=6.9
314  
315 0 ▶ push @steps, [ 'make', 'test' ]
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_skip_tests 0 0 0
316 if !$self->get_skip_tests;
317  
318 0 for my $step (@steps) {
319 0 my ( $rc, $label );
320  
321 0 ▶ if ( ref $step eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $step eq 'CODE') { } 0 0 0
322 0 $rc = $step->();
323 0 $label = 'sort-manifest';
324 }
325 else {
326 0 $rc = $self->_run_cmd( @{$step} );
327 0 $label = join $SPACE, @{$step};
328 }
329  
330 0 ▶ if ( $rc != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($rc != 0) 0 0 0
331 0 chdir $cwd;
332 0 die sprintf "ERROR: '%s' failed with exit code %d\n", $label, $rc;
333 }
334 }
335  
336 0 my @tarballs = glob '*.tar.gz';
337  
338 0 ▶ die "ERROR: no tarball produced by make dist\n"
Branch: 1 branch
BranchTrueFalseTotal
unless @tarballs 0 0 0
339 if !@tarballs;
340  
341 0 my $tarball = ( sort @tarballs )[-1];
342  
343 0 ▶ cp( $tarball, $destdir )
Branch: 1 branch
BranchTrueFalseTotal
cp($tarball, $destdir) or die "ERROR: could not copy $tarball to ${destdir}: $CPAN::Maker::OS_ERROR\n" 0 0 0
344 or die "ERROR: could not copy $tarball to $destdir: $OS_ERROR\n";
345  
346 0 $self->get_logger->info("distribution written to $destdir/$tarball");
347  
348 0 ▶ if ( $self->get_preserve_makefile ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_preserve_makefile) 0 0 0
349 0 ▶ cp( 'Makefile.PL', $destdir )
Branch: 1 branch
BranchTrueFalseTotal
cp("Makefile.PL", $destdir) or die "ERROR: could not copy Makefile.PL to ${destdir}: $CPAN::Maker::OS_ERROR\n" 0 0 0
350 or die "ERROR: could not copy Makefile.PL to $destdir: $OS_ERROR\n";
351 }
352  
353 0 chdir $cwd;
354  
355 0 return $SUCCESS;
356 }
357  
358 ########################################################################
359 0 ▶sub _sort_manifest {
Subroutine _sort_manifest: not called CC=5 SCAR=34.0
360 ########################################################################
361 0 my ($self) = @_;
362  
363 0 my $file = 'MANIFEST';
364  
365 0 ▶ open my $fh, '<', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die sprintf("ERROR: cannot read %s: %s\n", $file, $CPAN::Maker::OS_ERROR) 0 0 0
366 or die sprintf "ERROR: cannot read %s: %s\n", $file, $OS_ERROR;
367 0 chomp( my @lines = <$fh> );
368 0 close $fh;
369  
370 # ExtUtils::Manifest sorts with { lc $a cmp lc $b } and no tiebreaker, so
371 # entries differing only in case (botocore's JWT...Exception vs
372 # jwt...Exception) compare equal and fall back to directory-walk order,
373 # which varies between builds. Add a case-sensitive tiebreaker for a
374 # total, reproducible order.
375 0 ▶ my @sorted = sort { lc $a cmp lc $b or $a cmp $b } @lines;
Condition0%0/3
lc $a cmp lc $b || $a cmp $b
l!l&&r!l&&!r
000
MC/DC0%0/2
lc $a cmp lc $b || $a cmp $b
lc $a cmp lc $b $a cmp $b
Truth table0%0/3
A || B
A= lc $a cmp lc $bB= $a cmp $b
ABresult
1X1
011
000
376  
377 0 ▶ open my $out, '>', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $file or die sprintf("ERROR: cannot write %s: %s\n", $file, $CPAN::Maker::OS_ERROR) 0 0 0
378 or die sprintf "ERROR: cannot write %s: %s\n", $file, $OS_ERROR;
379 0 print {$out} map {"$_\n"} @sorted;
380  
381 0 ▶ close $out
Branch: 1 branch
BranchTrueFalseTotal
close $out or die sprintf("ERROR: cannot close %s: %s\n", $file, $CPAN::Maker::OS_ERROR) 0 0 0
382 or die sprintf "ERROR: cannot close %s: %s\n", $file, $OS_ERROR;
383  
384 0 return 0;
385 }
386  
387 ########################################################################
388 0 ▶sub cmd_makefile {
Subroutine cmd_makefile: not called CC=5 SCAR=34.0
Pod undocumented
389 ########################################################################
390 0 my ($self) = @_;
391  
392 0 ▶ croak 'no module specified'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_module 0 0 0
393 if !$self->get_module;
394  
395 0 ▶ croak 'no requires file specified'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_requires 0 0 0
396 if !$self->get_requires;
397  
398 # TBD, update error to 'not found...use --scan path to create a requires file'
399 0 ▶ croak sprintf q{requires file '%s' not found}, $self->get_requires
Branch: 1 branch
BranchTrueFalseTotal
unless -f $self->get_requires 0 0 0
400 if !-f $self->get_requires;
401  
402 # TBD, use outfile if provided
403 0 ▶ return $self->write_makefile( dest => \*STDOUT ) ? $SUCCESS : $FAILURE;
Branch: 1 branch
BranchTrueFalseTotal
$self->write_makefile('dest', \*STDOUT) ? : 0 0 0
404 }
405  
406 ########################################################################
407 0 ▶sub get_exe_file_list {
Subroutine get_exe_file_list: not called CC=3 SCAR=24.8
Pod undocumented
408 ########################################################################
409 0 my ( $self, $file ) = @_;
410  
411 0 my $lines;
412  
413 0 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 0 0 0
414 ($lines) = process_file(
415 $file,
416 chomp => $TRUE,
417 skip_blank_lines => $TRUE,
418 0 ▶ process => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
419 0 my $f = pop @_;
420 0 $f =~ s/^.*\/(.*)$/bin\/$1/xsm;
421 0 return $f;
422 }
423 0 );
424 }
425  
426 0 ▶ return $lines ? @{$lines} : ();
Branch: 1 branch
BranchTrueFalseTotal
$lines ? : 0 0 0
427 }
428  
429 ########################################################################
430 0 ▶sub fetch_perl_version {
Subroutine fetch_perl_version: not called CC=2 SCAR=17.9
Pod undocumented
431 ########################################################################
432 0 my ( $self, $requires ) = @_;
433  
434 0 my $version;
435  
436 return
437 0 ▶ if !-e $requires;
Branch: 1 branch
BranchTrueFalseTotal
unless -e $requires 0 0 0
438  
439 process_file(
440 $requires,
441 chomp => $TRUE,
442 0 ▶ process => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
443 0 my $module = pop @_;
444  
445 0 ▶ if ( $module !~ /^perl\s+/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module =~ /^perl\s+/msx) 0 0 0
446 0 return ();
447 }
448  
449 0 ( undef, $version ) = split /\s+/xsm, $module;
450 0 return;
451 }
452 0 );
453  
454 0 return $version;
455 }
456  
457 ########################################################################
458 0 ▶sub read_resources {
Subroutine read_resources: not called CC=1 SCAR=6.9
Pod undocumented
459 ########################################################################
460 0 my ( $self, $file ) = @_;
461  
462 0 return get_json_file($file);
463 }
464  
465 ########################################################################
466 0 ▶sub write_resources {
Subroutine write_resources: not called CC=4 SCAR=30.0
Pod undocumented
467 ########################################################################
468 0 my ( $self, $resources ) = @_;
469  
470 0 my $resources_file;
471  
472 0 ▶ if ($resources) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resources) 0 0 0
473 0 $resources_file = 'resources';
474  
475 0 ▶ open my $fh, '>', $resources_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $resources_file or croak("could not open resources for writing\n") 0 0 0
476 or croak "could not open resources for writing\n";
477  
478 0 print {$fh} JSON->new->pretty->encode($resources);
479  
480 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or croak("could not close file $resources_file\n") 0 0 0
481 or croak "could not close file $resources_file\n";
482 }
483  
484 0 return;
485 }
486  
487 ########################################################################
488 0 ▶sub write_pl_files {
Subroutine write_pl_files: not called CC=2 SCAR=17.9
Pod undocumented
489 ########################################################################
490 0 my ( $self, $pl_files ) = @_;
491  
492 return
493 0 ▶ if !$pl_files;
Branch: 1 branch
BranchTrueFalseTotal
unless $pl_files 0 0 0
494  
495 0 my ( $fh, $filename ) = tempfile( 'make-cpan-dist-XXXXX', TMPDIR => $TRUE );
496  
497 0 print {$fh} join $SPACE, %{$pl_files};
498  
499 0 close $fh;
500  
501 0 $self->set_pl_files($filename);
502  
503 0 return;
504 }
505  
506 ########################################################################
507 0 ▶sub write_makefile {
Subroutine write_makefile: not called CC=47 SCAR=77.2
Pod undocumented
508 ########################################################################
509 0 my ( $self, %params ) = @_;
510  
511 0 ▶ my $dest = $params{dest} // \*STDOUT;
Condition0%0/2
$params{"dest"} // \*STDOUT
l!l
00
MC/DC0%0/1
$params{"dest"} // \*STDOUT
$params{"dest"}
Truth table0%0/2
A
A= $params{"dest"}
Aresult
11
00
512  
513 0 my $core = $self->get_core_modules;
514 0 my $MODULE_ABSTRACT = $self->get_abstract;
515 0 my $AUTHOR = $self->get_author;
516 0 my $project_root = $self->get_project_root;
517 0 ▶ my $LICENSE = $self->get_license // 'perl';
Condition0%0/2
$self->get_license // "perl"
l!l
00
MC/DC0%0/1
$self->get_license // "perl"
$self->get_license
Truth table0%0/2
A
A= $self->get_license
Aresult
11
00
518  
519 0 ▶ my ( $author, $email ) = choose {
Subroutine __ANON__: not called CC=3 SCAR=24.8
520  
521 0 ▶ if ( $AUTHOR && $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($AUTHOR and $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/msx) 0 0 0
Condition0%0/3
$AUTHOR and $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$AUTHOR and $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/msx
$AUTHOR $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/msx
Truth table0%0/3
A and B
A= $AUTHORB= $AUTHOR =~ /^([^<]+)\s+<([^>]+)>\s*$/msx
ABresult
0X0
100
111
522 0 return ( $1, $2 );
523 }
524  
525 # TBD: look in ENV, ~/.gitconfig ?
526 0 return ( 'Anonymouse', 'anonymouse@example.org' );
527 0 };
528  
529 0 $AUTHOR = sprintf '%s <%s>', $author, $email;
530  
531 0 my $PM_MODULE = $self->get_module;
532  
533 0 ▶ my %buildspec = (
Condition0%0/3
$MODULE_ABSTRACT // $PM_MODULE
l!l&&r!l&&!r
000
MC/DC0%0/2
$MODULE_ABSTRACT // $PM_MODULE
$MODULE_ABSTRACT $PM_MODULE
Truth table0%0/3
A // B
A= $MODULE_ABSTRACTB= $PM_MODULE
ABresult
1X1
011
000
534 version => $VERSION,
535 project => {
536 description => $MODULE_ABSTRACT // $PM_MODULE,
537 author => {
538 name => $author,
539 mailto => $email,
540 },
541 },
542 'pm-module' => $PM_MODULE,
543 );
544  
545 0 ▶ my $VERSION_FROM = $self->get_version_from // $self->get_module;
Condition0%0/3
$self->get_version_from // $self->get_module
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_version_from // $self->get_module
$self->get_version_from $self->get_module
Truth table0%0/3
A // B
A= $self->get_version_fromB= $self->get_module
ABresult
1X1
011
000
546  
547 0 ▶ if ( $VERSION_FROM !~ /\//xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($VERSION_FROM =~ m[/]msx) 0 0 0
548 0 $VERSION_FROM = 'lib/' . $self->make_path_from_module($VERSION_FROM);
549 }
550  
551 0 $buildspec{'version-from'} = $VERSION_FROM;
552  
553 0 local $Data::Dumper::Terse = $TRUE;
554 0 local $Data::Dumper::Sortkeys = $TRUE;
555 0 local $Data::Dumper::Indent = 2;
556 0 local $Data::Dumper::Pad = $SPACE x $INDENT;
557  
558 # dependencies = key name taken as file name if not provided
559 0 foreach my $d (qw(requires test_requires build_requires recommends suggests)) {
560 0 ▶ $self->set( $d, $self->get($d) || $d );
Condition0%0/3
$self->get($d) || $d
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get($d) || $d
$self->get($d) $d
Truth table0%0/3
A || B
A= $self->get($d)B= $d
ABresult
1X1
011
000
561 }
562  
563 $buildspec{dependencies} = {
564 0 'build-requires' => $self->get_build_requires,
565 'recommends' => $self->get_recommends,
566 'requires' => $self->get_requires,
567 'suggests' => $self->get_suggests,
568 'test-requires' => $self->get_test_requires,
569 };
570  
571 0 foreach (qw(requires test-requires build-requires recommends suggests)) {
572 0 my $dependency_file = $buildspec{dependencies}->{$_};
573 0 $dependency_file =~ s/$project_root\/?//xsm;
574 0 ▶ next if -s $dependency_file;
Branch: 1 branch
BranchTrueFalseTotal
if -s $dependency_file 0 0 0
575  
576 0 delete $buildspec{dependencies}->{$_};
577 }
578  
579 0 ▶ my $MIN_PERL_VERSION = $self->get_min_perl_version // $DEFAULT_PERL_VERSION;
Condition0%0/3
$self->get_min_perl_version // $CPAN::Maker::DEFAULT_PERL_VERSION
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_min_perl_version // $CPAN::Maker::DEFAULT_PERL_VERSION
$self->get_min_perl_version $CPAN::Maker::DEFAULT_PERL_VERSION
Truth table0%0/3
A // B
A= $self->get_min_perl_versionB= $CPAN::Maker::DEFAULT_PERL_VERSION
ABresult
1X1
011
000
580  
581 0 my $require_versions = $self->get_require_versions;
582  
583 0 my $PRE_REQ = Dumper $self->fetch_requires(
584 requires => $self->get_requires,
585 include_core_modules => $core,
586 include_version => $require_versions,
587 min_perl_version => $MIN_PERL_VERSION,
588 );
589  
590 0 $PRE_REQ = trim($PRE_REQ);
591 0 $PRE_REQ =~ s/[@](\d+)/== $1/xsmg;
592  
593 0 my $TEST_REQ = {};
594  
595 0 ▶ if ( $self->get_test_requires && -s $self->get_test_requires ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_test_requires and -s $self->get_test_requires) { } 0 0 0
Condition0%0/3
$self->get_test_requires and -s $self->get_test_requires
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_test_requires and -s $self->get_test_requires
$self->get_test_requires -s $self->get_test_requires
Truth table0%0/3
A and B
A= $self->get_test_requiresB= -s $self->get_test_requires
ABresult
0X0
100
111
596 0 $TEST_REQ = Dumper $self->fetch_requires(
597 requires => $self->get_test_requires,
598 include_core_modules => $core,
599 include_version => $require_versions,
600 min_perl_version => $MIN_PERL_VERSION,
601 );
602 }
603 else {
604 0 $TEST_REQ = '{}';
605 }
606  
607 0 $TEST_REQ = trim($TEST_REQ);
608 0 $TEST_REQ =~ s/[@](\d+)/== $1/xsmg;
609  
610 0 my $build_req = {};
611 0 my $build_requires = $self->get_build_requires;
612  
613 0 ▶ if ( $build_requires && -s $build_requires ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($build_requires and -s $build_requires) 0 0 0
Condition0%0/3
$build_requires and -s $build_requires
!ll&&!rl&&r
000
MC/DC0%0/2
$build_requires and -s $build_requires
$build_requires -s $build_requires
Truth table0%0/3
A and B
A= $build_requiresB= -s $build_requires
ABresult
0X0
100
111
614 0 $build_req = $self->fetch_requires(
615 requires => $build_requires,
616 include_core_modules => $TRUE,
617 include_version => $require_versions,
618 min_perl_version => $MIN_PERL_VERSION,
619 );
620 }
621  
622 0 my %build_req_defaults = (
623 'ExtUtils::MakeMaker' => '6.64',
624 'File::ShareDir::Install' => $NO_VERSION,
625 );
626  
627 0 foreach my $m ( keys %build_req_defaults ) {
628 0 ▶ $build_req->{$m} ||= $build_req_defaults{$m};
Condition0%0/3
$build_req->{$m} ||= $build_req_defaults{$m}
l!l&&r!l&&!r
000
MC/DC0%0/2
$build_req->{$m} ||= $build_req_defaults{$m}
$build_req->{$m} $build_req_defaults{$m}
Truth table0%0/3
A ||= B
A= $build_req->{$m}B= $build_req_defaults{$m}
ABresult
1X1
011
000
629 }
630  
631 0 $build_req = Dumper $build_req;
632 0 $build_req = trim($build_req);
633 0 $build_req =~ s/[@](\d+)/== $1/xsmg;
634  
635 0 my @exe_file_list;
636 $buildspec{path} = {
637 0 ▶ 'pm-module' => $self->get_module_path,
Branch: 1 branch
BranchTrueFalseTotal
$self->get_recurse ? : 0 0 0
638 recurse => $self->get_recurse ? 'yes' : 'no',
639 };
640  
641 0 ▶ my $exe_files = $self->get_exe_files || $self->get_exec_path;
Condition0%0/3
$self->get_exe_files || $self->get_exec_path
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_exe_files || $self->get_exec_path
$self->get_exe_files $self->get_exec_path
Truth table0%0/3
A || B
A= $self->get_exe_filesB= $self->get_exec_path
ABresult
1X1
011
000
642  
643 0 ▶ if ( $exe_files && -f $exe_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exe_files and -f $exe_files) 0 0 0
Condition0%0/3
$exe_files and -f $exe_files
!ll&&!rl&&r
000
MC/DC0%0/2
$exe_files and -f $exe_files
$exe_files -f $exe_files
Truth table0%0/3
A and B
A= $exe_filesB= -f $exe_files
ABresult
0X0
100
111
644 0 @exe_file_list = $self->get_exe_file_list($exe_files);
645 0 $self->set_exec_path($exe_files);
646 }
647  
648 0 foreach my $p ( pairs qw(exe-files exec-path scripts scripts-path tests tests-path) ) {
649 0 my ( $spec_option, $path ) = @{$p};
650  
651 next
652 0 ▶ if !$self->get($path);
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get($path) 0 0 0
653  
654 0 my $real_path = $self->get($path);
655  
656 0 my $project_file = sprintf '%s/%s', $project_root, $real_path;
657  
658 0 ▶ if ( -e $project_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $project_file) { } 0 0 0
659 0 $buildspec{path}->{$spec_option} = $real_path;
660 }
661 else {
662 0 $buildspec{$spec_option} = $self->fetch_relative_filelist( $project_root, $real_path );
663  
664 # remove temporary files?
665 0 ▶ if ( $real_path =~ /make\-cpan\-dist\-[[:alpha:]]{5}/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($real_path =~ /make\-cpan\-dist\-[[:alpha:]]{5}/msx) 0 0 0
666 0 unlink $real_path;
667 }
668 }
669 }
670  
671 0 ▶ if ( my $path = $self->get_extra_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $self->get_extra_path) 0 0 0
672 0 $buildspec{'extra-files'} = $path;
673 }
674  
675 0 my $EXE_FILES = Dumper \@exe_file_list;
676  
677 # was: blindly putting all exe_files into MAN3PODS
678 # fix: MAN1PODS only for scripts that actually contain POD
679  
680 0 my %man1pods;
681  
682 0 foreach (@exe_file_list) {
683 0 my ( $name, $path, $ext ) = fileparse( $_, qr/[.][^.]+\z/xsm );
684  
685 # only include scripts that actually contain POD
686 0 ▶ my $content = eval { slurp($_) } // q{};
Condition0%0/2
eval { // ""
l!l
00
MC/DC0%0/1
eval { do { slurp($_) } } // ""
eval { do { slurp($_) } }
Truth table0%0/2
A
A= eval { do { slurp($_) } }
Aresult
11
00
687 0 ▶ next if $content !~ /^=(head\d|pod|over|item|begin|encoding)/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /^=(head\d|pod|over|item|begin|encoding)/msx 0 0 0
688  
689 0 $man1pods{$_} = sprintf 'blib/man1/%s.1', $name;
690 }
691  
692 0 my $MAN1PODS = Dumper \%man1pods;
693  
694 0 my %provides;
695  
696 0 ▶ my $provides_file = $params{provides_file} // 'provides';
Condition0%0/2
$params{"provides_file"} // "provides"
l!l
00
MC/DC0%0/1
$params{"provides_file"} // "provides"
$params{"provides_file"}
Truth table0%0/2
A
A= $params{"provides_file"}
Aresult
11
00
697  
698 0 ▶ if ( -e $provides_file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $provides_file) 0 0 0
699 0 %provides = $self->get_provides(
700 file => $provides_file,
701 work_dir => $self->get_work_dir,
702 );
703 $buildspec{provides} = [
704 0 map { sprintf '%s %s', $_, $provides{$_}->{version} }
705 sort keys %provides
706 ];
707 }
708  
709 0 ▶ my $resources_path = $self->get_resources // 'resources';
Condition0%0/2
$self->get_resources // "resources"
l!l
00
MC/DC0%0/1
$self->get_resources // "resources"
$self->get_resources
Truth table0%0/2
A
A= $self->get_resources
Aresult
11
00
710 0 my $resources;
711  
712 0 ▶ if ( -e $resources_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $resources_path) 0 0 0
713 0 $resources = $self->read_resources($resources_path);
714 0 $buildspec{resources} = $resources;
715 }
716  
717 0 my $recommends = {};
718  
719 0 ▶ if ( $self->get_recommends && -s $self->get_recommends ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_recommends and -s $self->get_recommends) 0 0 0
Condition0%0/3
$self->get_recommends and -s $self->get_recommends
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_recommends and -s $self->get_recommends
$self->get_recommends -s $self->get_recommends
Truth table0%0/3
A and B
A= $self->get_recommendsB= -s $self->get_recommends
ABresult
0X0
100
111
720 0 $recommends = $self->fetch_requires(
721 requires => $self->get_recommends,
722 include_core_modules => $core,
723 include_version => $require_versions,
724 min_perl_version => $MIN_PERL_VERSION,
725 );
726 }
727  
728 0 my $suggests = {};
729  
730 0 ▶ if ( $self->get_suggests && -s $self->get_suggests ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_suggests and -s $self->get_suggests) 0 0 0
Condition0%0/3
$self->get_suggests and -s $self->get_suggests
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_suggests and -s $self->get_suggests
$self->get_suggests -s $self->get_suggests
Truth table0%0/3
A and B
A= $self->get_suggestsB= -s $self->get_suggests
ABresult
0X0
100
111
731 0 $suggests = $self->fetch_requires(
732 requires => $self->get_suggests,
733 include_core_modules => $core,
734 include_version => $require_versions,
735 min_perl_version => $MIN_PERL_VERSION,
736 );
737 }
738  
739 0 my %prereqs_runtime;
740 0 ▶ $prereqs_runtime{recommends} = $recommends if keys %{$recommends};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$recommends;} 0 0 0
741 0 ▶ $prereqs_runtime{suggests} = $suggests if keys %{$suggests};
Branch: 1 branch
BranchTrueFalseTotal
if keys %{$suggests;} 0 0 0
742  
743 0 my $META_MERGE = 'META_MERGE ' . $FAT_ARROW;
744  
745 {
746 0 local $Data::Dumper::Pair = $FAT_ARROW;
747 0 ▶ $META_MERGE .= Dumper(
Branch: 2 branches
BranchTrueFalseTotal
%prereqs_runtime ? : 0 0 0
$resources ? : 0 0 0
748 { 'meta-spec' => { version => 2 },
749 'provides' => \%provides,
750 ( %prereqs_runtime ? ( 'prereqs' => { 'runtime' => \%prereqs_runtime } ) : () ),
751 $resources ? ( 'resources' => $resources ) : ()
752 }
753 );
754 }
755  
756 0 my $timestamp = scalar localtime;
757  
758 0 $buildspec{'min-perl-version'} = $MIN_PERL_VERSION;
759  
760 # From: https://metacpan.org/pod/ExtUtils::MakeMaker
761 #
762 # MakeMaker can run programs to generate files for you at build
763 # time. By default any file named *.PL (except Makefile.PL and
764 # Build.PL) in the top level directory will be assumed to be a Perl
765 # program and run passing its own basename in as an argument. This
766 # basename is actually a build target, and there is an intention, but
767 # not a requirement, that the *.PL file make the file passed to to as
768 # an argument. For example...
769 #
770 # perl foo.PL foo
771 #
772 0 my %pl_list;
773  
774 0 my $pl_files = $self->get_pl_files;
775  
776 0 ▶ if ( $pl_files && -s $pl_files ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pl_files and -s $pl_files) 0 0 0
Condition0%0/3
$pl_files and -s $pl_files
!ll&&!rl&&r
000
MC/DC0%0/2
$pl_files and -s $pl_files
$pl_files -s $pl_files
Truth table0%0/3
A and B
A= $pl_filesB= -s $pl_files
ABresult
0X0
100
111
777 0 my @file_list = split /\n/xsm, slurp($pl_files);
778  
779 0 foreach my $pl_file (@file_list) {
780 0 my ( $file, $target ) = split /\s+/xsm, $pl_file;
781 0 $pl_list{$file} = $target;
782 }
783  
784 0 $buildspec{'pl-files'} = \%pl_list;
785 }
786  
787 0 my $PL_FILES = Dumper( \%pl_list );
788  
789 0 $buildspec{postamble} = $self->get_postamble;
790  
791 0 my $MAKEFILE = <<"END_OF_TEXT";
792 use strict;
793 use warnings;
794  
795 use ExtUtils::MakeMaker;
796 use File::ShareDir::Install;
797  
798 \$File::ShareDir::Install::INCLUDE_DOTFILES = 1;
799  
800 if ( -d 'share' ) {
801 install_share 'share';
802 }
803  
804 WriteMakefile(
805 NAME => '$PM_MODULE',
806 MIN_PERL_VERSION => '$MIN_PERL_VERSION',
807 AUTHOR => '$AUTHOR',
808 VERSION_FROM => '$VERSION_FROM',
809 ABSTRACT => '$MODULE_ABSTRACT',
810 LICENSE => '$LICENSE',
811 PL_FILES => $PL_FILES,
812 EXE_FILES => $EXE_FILES,
813 MAN1PODS => $MAN1PODS,
814 PREREQ_PM => $PRE_REQ,
815 BUILD_REQUIRES => $build_req,
816 CONFIGURE_REQUIRES => {
817 'ExtUtils::MakeMaker' => '6.64',
818 'File::ShareDir::Install' => $NO_VERSION,
819 },
820 TEST_REQUIRES => $TEST_REQ,
821 $META_MERGE
822 );
823 END_OF_TEXT
824  
825 0 $MAKEFILE .= <<'END_OF_MAKEFILE';
826 package MY;
827  
828 use File::ShareDir::Install;
829 use English qw(-no_match_vars);
830  
831 sub postamble {
832 my $self = shift;
833  
834 my @ret = File::ShareDir::Install::postamble($self);
835  
836 my $postamble = join "\n", @ret;
837  
838 if ( -e 'postamble' ) {
839  
840 local $RS = undef;
841  
842 open my $fh, '<', 'postamble'
843 or die "could not open postamble\n";
844  
845 $postamble .= <$fh>;
846  
847 close $fh;
848 }
849  
850 return $postamble;
851 }
852  
853 1;
854 END_OF_MAKEFILE
855  
856 # TBD: use openhandle and refactor this block
857 0 ▶ if ( ref $dest ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $dest) { } 0 0 0
858 0 print {$dest} $MAKEFILE;
859 }
860 else {
861 0 ▶ open my $fh, '>', $dest
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $dest or die "ERROR: could not open $dest for writing: $CPAN::Maker::OS_ERROR\n" 0 0 0
862 or die "ERROR: could not open $dest for writing: $OS_ERROR\n";
863  
864 0 print {$fh} $MAKEFILE;
865  
866 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or die "ERROR: could not close ${dest}: $CPAN::Maker::OS_ERROR\n" 0 0 0
867 or die "ERROR: could not close $dest: $OS_ERROR\n";
868 }
869  
870 0 ▶ $self->get_logger->debug( sub { return $MAKEFILE } );
Subroutine __ANON__: not called CC=1 SCAR=6.9
871  
872 0 $self->write_buildspec_file( \%buildspec );
873  
874 0 return $TRUE;
875 }
876  
877 ########################################################################
878 0 ▶sub write_buildspec_file {
Subroutine write_buildspec_file: not called CC=5 SCAR=34.0
Pod undocumented
879 ########################################################################
880 0 my ( $self, $buildspec ) = @_;
881  
882 0 my $buildspec_file = $self->get_create_buildspec;
883 0 my $overwrite = $self->get_overwrite;
884  
885 return
886 0 ▶ if !$buildspec_file;
Branch: 1 branch
BranchTrueFalseTotal
unless $buildspec_file 0 0 0
887  
888 0 ▶ die "$buildspec_file exists\n"
Branch: 1 branch
BranchTrueFalseTotal
if -e $buildspec_file and not $overwrite 0 0 0
Condition0%0/3
-e $buildspec_file and not $overwrite
!ll&&!rl&&r
000
MC/DC0%0/2
-e $buildspec_file and not $overwrite
-e $buildspec_file not $overwrite
Truth table0%0/3
A and not(B)
A= -e $buildspec_fileB= not $overwrite
ABresult
0X0
100
111
889 if -e $buildspec_file && !$overwrite;
890  
891 0 ▶ open my $fh, '>', $buildspec_file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $buildspec_file or die "could not open $buildspec_file for writing\n" 0 0 0
892 or die "could not open $buildspec_file for writing\n";
893  
894 0 print {$fh} Dump($buildspec);
895  
896 0 close $fh;
897  
898 0 return;
899 }
900  
901 ########################################################################
902 0 ▶sub parse_dependencies {
Subroutine parse_dependencies: not called CC=14 SCAR=53.5
Pod undocumented
903 ########################################################################
904 0 my ( $self, $dependencies ) = @_;
905  
906 0 ▶ if ($dependencies) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies) 0 0 0
907 croak 'malformed buildspec.yml file - dependencies section with no keys?'
908 0 ▶ if !keys %{$dependencies};
Branch: 1 branch
BranchTrueFalseTotal
unless keys %{$dependencies;} 0 0 0
909  
910 0 ▶ $dependencies->{'core-modules'} //= 'no';
Condition0%0/2
$dependencies->{"core-modules"} //= "no"
l!l
00
MC/DC0%0/1
$dependencies->{"core-modules"} //= "no"
$dependencies->{"core-modules"}
Truth table0%0/2
A
A= $dependencies->{"core-modules"}
Aresult
11
00
911 0 ▶ $dependencies->{'required-modules'} //= 'yes';
Condition0%0/2
$dependencies->{"required-modules"} //= "yes"
l!l
00
MC/DC0%0/1
$dependencies->{"required-modules"} //= "yes"
$dependencies->{"required-modules"}
Truth table0%0/2
A
A= $dependencies->{"required-modules"}
Aresult
11
00
912  
913 0 ▶ if ( $dependencies->{path} ) { # deprecated
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"path"}) 0 0 0
914 0 $self->set_requires( $dependencies->{path} );
915 0 warn "path is deprecated: use requires\n";
916 }
917  
918 0 ▶ if ( $dependencies->{requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"requires"}) 0 0 0
919 0 $self->set_requires( $dependencies->{requires} );
920 }
921  
922 0 ▶ if ( $dependencies->{'test-requires'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"test-requires"}) 0 0 0
923 0 $self->set_test_requires( $dependencies->{'test-requires'} );
924 }
925  
926 0 ▶ if ( $dependencies->{'build-requires'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"build-requires"}) 0 0 0
927 0 $self->set_build_requires( $dependencies->{'build-requires'} );
928 }
929  
930 0 ▶ if ( $dependencies->{recommends} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"recommends"}) 0 0 0
931 0 $self->set_recommends( $dependencies->{recommends} );
932 }
933  
934 0 ▶ if ( $dependencies->{suggests} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"suggests"}) 0 0 0
935 0 $self->set_suggests( $dependencies->{suggests} );
936 }
937  
938 0 ▶ if ( $dependencies->{'core-modules'} eq 'yes' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dependencies->{"core-modules"} eq "yes") 0 0 0
939 0 $self->set_core_modules($TRUE);
940 }
941  
942 # NOTE: required-modules and resolver have no corresponding
943 # CLI::Simple accessor (not in option_specs, no extra_options
944 # declared) -- there is currently nowhere valid to apply these
945 # buildspec.yml values. Preserved here as parsed/validated but
946 # intentionally not applied; flagging rather than guessing at
947 # attribute names that don't exist.
948 0 my $required_modules_requested = $dependencies->{'required-modules'} eq 'no';
949 0 my $resolver = $dependencies->{resolver};
950  
951 0 ▶ if ( $self->get_requires && $resolver ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_requires and $resolver) 0 0 0
Condition0%0/3
$self->get_requires and $resolver
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_requires and $resolver
$self->get_requires $resolver
Truth table0%0/3
A and B
A= $self->get_requiresB= $resolver
ABresult
0X0
100
111
952 0 croak "use either path or resolver for dependencies, but not both\n";
953 }
954 }
955  
956 0 return;
957 }
958  
959 ########################################################################
960 0 ▶sub parse_include_version {
Subroutine parse_include_version: not called CC=3 SCAR=24.8
Pod undocumented
961 ########################################################################
962 0 my ( $self, $version ) = @_;
963  
964 return
965 0 ▶ if !defined $version;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $version 0 0 0
966  
967 0 ▶ if ( $version =~ /(no|0|off)/ixsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /(no|0|off)/imsx) 0 0 0
968 0 $self->set_require_versions($FALSE);
969 }
970  
971 0 return;
972 }
973  
974 ########################################################################
975 0 ▶sub parse_project {
Subroutine parse_project: not called CC=6 SCAR=37.4
Pod undocumented
976 ########################################################################
977 0 my ( $self, $project ) = @_;
978  
979 return
980 0 ▶ if !$project;
Branch: 1 branch
BranchTrueFalseTotal
unless $project 0 0 0
981  
982 0 ▶ if ( $project->{author} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($project->{"author"}) 0 0 0
983 0 ▶ my $name = $project->{author}->{name} // 'anonymouse';
Condition0%0/2
$project->{"author"}{"name"} // "anonymouse"
l!l
00
MC/DC0%0/1
$project->{"author"}{"name"} // "anonymouse"
$project->{"author"}{"name"}
Truth table0%0/2
A
A= $project->{"author"}{"name"}
Aresult
11
00
984 0 my $author = $name;
985  
986 0 ▶ if ( my $mailto = $project->{author}->{mailto} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $mailto = $project->{"author"}{"mailto"}) 0 0 0
987 0 $author .= ' <' . $mailto . '>';
988 }
989  
990 0 $self->set_author($author);
991 }
992  
993 0 ▶ if ( my $description = $project->{description} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $description = $project->{"description"}) 0 0 0
994 0 $self->set_abstract($description);
995 }
996  
997 # NOTE: 'git' has no corresponding CLI::Simple accessor (not in
998 # option_specs, no extra_options declared) -- there is currently
999 # nowhere valid to apply this buildspec.yml value. Left unapplied
1000 # rather than guessing at an attribute name that doesn't exist.
1001  
1002 0 return;
1003 }
1004  
1005 ########################################################################
1006 0 ▶sub parse_pm_module {
Subroutine parse_pm_module: not called CC=2 SCAR=17.9
Pod undocumented
1007 ########################################################################
1008 0 my ( $self, $pm_module ) = @_;
1009  
1010 return
1011 0 ▶ if !$pm_module;
Branch: 1 branch
BranchTrueFalseTotal
unless $pm_module 0 0 0
1012  
1013 0 $self->set_module($pm_module);
1014  
1015 0 return;
1016 }
1017  
1018 ########################################################################
1019 0 ▶sub read_buildspec {
Subroutine read_buildspec: not called CC=7 SCAR=40.3
Pod undocumented
1020 ########################################################################
1021 0 my ( $self, $file ) = @_;
1022  
1023 0 ▶ croak 'file not found or empty ' . $file . $NL
Branch: 1 branch
BranchTrueFalseTotal
unless -s $file 0 0 0
1024 if !-s $file;
1025  
1026 0 local $RS = undef;
1027 0 ▶ open my $fh, '<', $file or croak "could not open $file: $OS_ERROR\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or croak("could not open ${file}: $CPAN::Maker::OS_ERROR\n") 0 0 0
1028 0 my $text = <$fh>;
1029 0 close $fh;
1030  
1031 0 my $normalized = (
1032 $text =~ s/^(\s*)(\w+)(\s*:)/
1033 0 my ($pre, $key, $post) = ($1, $2, $3);
1034 0 $key =~ s|_|-|g;
1035 0 "$pre$key$post"/xsmgre
1036 );
1037  
1038 0 ▶ if ( $normalized ne $text ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($normalized ne $text) 0 0 0
1039 0 my $current = $file . '.current';
1040 0 ▶ open my $out, '>', $current or croak "could not write $current: $OS_ERROR\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">", $current or croak("could not write ${current}: $CPAN::Maker::OS_ERROR\n") 0 0 0
1041 0 print {$out} $normalized;
1042 0 close $out;
1043 0 $self->get_logger->warn("deprecated underscore keys found - normalized buildspec written to $current");
1044 }
1045  
1046 0 my $buildspec = eval { Load($normalized) };
1047  
1048 0 ▶ croak 'could not read ' . $file . $NL . $EVAL_ERROR . $NL
Branch: 1 branch
BranchTrueFalseTotal
if $CPAN::Maker::EVAL_ERROR or not $buildspec 0 0 0
Condition0%0/3
$CPAN::Maker::EVAL_ERROR or not $buildspec
l!l&&r!l&&!r
000
MC/DC0%0/2
$CPAN::Maker::EVAL_ERROR or not $buildspec
$CPAN::Maker::EVAL_ERROR not $buildspec
Truth table0%0/3
A or not(B)
A= $CPAN::Maker::EVAL_ERRORB= not $buildspec
ABresult
1X1
011
000
1049 if $EVAL_ERROR || !$buildspec;
1050  
1051 0 return $buildspec;
1052 }
1053  
1054 # this method converts a buildspec into options to be passed to shell script
1055 # which eventually calls this script to create the Makefile.PL
1056 ########################################################################
1057 0 ▶sub parse_buildspec {
Subroutine parse_buildspec: not called CC=14 SCAR=53.5
Pod undocumented
1058 ########################################################################
1059 0 my ($self) = @_;
1060  
1061 0 my $file = $self->get_buildspec;
1062  
1063 0 my $project_root = $self->get_project_root;
1064  
1065 0 my $buildspec = $self->read_buildspec($file);
1066  
1067 0 ▶ croak 'invalid buildspec.yml'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->validate_buildspec($buildspec) 0 0 0
1068 if !$self->validate_buildspec($buildspec);
1069  
1070 0 ▶ if ( $buildspec->{license} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"license"}) 0 0 0
1071 0 $self->set_license( $buildspec->{license} );
1072 }
1073  
1074 0 ▶ if ( $buildspec->{'min-perl-version'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"min-perl-version"}) 0 0 0
1075 0 $self->set_min_perl_version( $buildspec->{'min-perl-version'} );
1076 }
1077  
1078 0 ▶ if ( $buildspec->{'version-from'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"version-from"}) 0 0 0
1079 0 $self->set_version_from( $buildspec->{'version-from'} );
1080 }
1081  
1082 0 ▶ if ( $buildspec->{'exe-files'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"exe-files"}) 0 0 0
1083 0 $self->set_exe_files( $self->create_temp_filelist( $project_root, $buildspec->{'exe-files'} ) );
1084 }
1085  
1086 0 ▶ if ( $buildspec->{tests} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"tests"}) 0 0 0
1087 0 $self->set_tests_path( $self->create_temp_filelist( $project_root, $buildspec->{tests} ) );
1088 }
1089  
1090 0 ▶ if ( $buildspec->{scripts} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"scripts"}) 0 0 0
1091 0 $self->set_scripts_path( $self->create_temp_filelist( $project_root, $buildspec->{scripts} ) );
1092 }
1093  
1094 0 $self->write_resources( $buildspec->{resources} );
1095  
1096 0 $self->parse_project( $buildspec->{project} );
1097  
1098 0 $self->parse_pm_module( $buildspec->{'pm-module'} );
1099  
1100 0 $self->parse_include_version( $buildspec->{'include-version'} );
1101  
1102 0 $self->parse_dependencies( $buildspec->{dependencies} );
1103  
1104 0 $self->parse_path( $project_root, $buildspec->{path} );
1105  
1106 $self->write_extra_files(
1107 extra_files => $buildspec->{'extra-files'},
1108 extra => $buildspec->{extra},
1109 0 project_root => $project_root,
1110 );
1111  
1112 0 ▶ if ( $buildspec->{provides} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"provides"}) 0 0 0
1113 $self->write_provides(
1114 provides => $buildspec->{provides},
1115 0 file => 'provides',
1116 );
1117 }
1118  
1119 0 $self->write_pl_files( $buildspec->{'pl-files'} );
1120  
1121 0 ▶ if ( my $links = $buildspec->{'man-links'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $links = $buildspec->{"man-links"}) 0 0 0
1122 0 my $man_links_content = $self->_generate_man_links($links);
1123  
1124 0 my ( $fh, $filename ) = tempfile( 'make-cpan-dist-XXXXX', TMPDIR => $TRUE );
1125  
1126 # preserve existing postamble if one was specified
1127 0 ▶ if ( my $postamble = $self->get_postamble ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $postamble = $self->get_postamble) 0 0 0
1128 0 ▶ if ( -e $postamble ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $postamble) 0 0 0
1129 0 local $RS = undef;
1130 0 ▶ open my $existing, '<', $postamble
Branch: 1 branch
BranchTrueFalseTotal
open my $existing, "<", $postamble or die "could not read postamble ${postamble}: $CPAN::Maker::OS_ERROR\n" 0 0 0
1131 or die "could not read postamble $postamble: $OS_ERROR\n";
1132 0 print {$fh} <$existing>;
1133 0 close $existing;
1134 }
1135 }
1136  
1137 0 print {$fh} $man_links_content;
1138 0 close $fh;
1139  
1140 0 $self->set_postamble($filename);
1141 }
1142  
1143 0 ▶ if ( $buildspec->{destdir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($buildspec->{"destdir"}) 0 0 0
1144 0 $self->set_destdir( $buildspec->{destdir} );
1145 }
1146  
1147 # NOTE: top-level buildspec 'extra' has no corresponding
1148 # CLI::Simple accessor (not in option_specs, no extra_options
1149 # declared) -- it is still applied where it's actually used, as the
1150 # extra-files output path in write_extra_files above.
1151  
1152 0 return;
1153 }
1154  
1155 ########################################################################
1156 0 ▶sub _generate_man_links {
Subroutine _generate_man_links: not called CC=6 SCAR=37.4
1157 ########################################################################
1158 0 my ( $self, $links ) = @_;
1159  
1160 0 my $content = q{};
1161  
1162 0 for my $entry ( @{$links} ) {
1163 0 for my $p ( pairs %{$entry} ) {
1164 0 my ( $alias, $module ) = @{$p};
1165  
1166 # derive the .pm path from the module name and check for POD
1167 0 ( my $pm_path = "lib/$module.pm" ) =~ s|::|/|gxsm;
1168  
1169 0 ▶ if ( -e $pm_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $pm_path) { } 0 0 0
1170 0 ▶ my $pm_content = eval { slurp($pm_path) } // q{};
Condition0%0/2
eval { // ""
l!l
00
MC/DC0%0/1
eval { do { slurp($pm_path) } } // ""
eval { do { slurp($pm_path) } }
Truth table0%0/2
A
A= eval { do { slurp($pm_path) } }
Aresult
11
00
1171  
1172 0 ▶ if ( $pm_content !~ /^=(head\d|pod|over|item|begin|encoding)/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pm_content =~ /^=(head\d|pod|over|item|begin|encoding)/msx) 0 0 0
1173 0 next;
1174 }
1175 }
1176 else {
1177 0 next;
1178 }
1179  
1180 0 $content .= <<"POSTAMBLE";
1181 install ::
1182 \t-\$(NOECHO) ln -sf \$(INSTALLMAN3DIR)/$module.3pm \$(DESTINSTALLMAN3DIR)/$alias.3pm; \
1183 \t\$(NOECHO) echo \$(INSTALLMAN3DIR)/$alias.3pm >> \$(DESTINSTALLSITEARCH)/auto/\$(FULLEXT)/.packlist
1184 POSTAMBLE
1185 }
1186 }
1187  
1188 0 return $content;
1189 }
1190  
1191 ########################################################################
1192 0 ▶sub fetch_requires {
Subroutine fetch_requires: not called CC=3 SCAR=24.8
Pod undocumented
1193 ########################################################################
1194 0 my ( $self, %args ) = @_;
1195  
1196 my ( $requires, $core_modules, $min_perl_version, $include_version )
1197 0 = @args{qw(requires include_core_modules min_perl_version include_version)};
1198  
1199 0 my $logger = $self->get_logger;
1200  
1201 0 $logger->trace( sprintf 'processing %s file', $requires );
1202 0 ▶ $logger->trace( sprintf "\t include_version: [%s]", $include_version ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$include_version ? : 0 0 0
1203 0 $logger->trace( sprintf "\tmin_perl_version: [%s]", $min_perl_version );
1204 0 ▶ $logger->trace( sprintf "\t core_modules: [%s]", $core_modules ? 'yes' : 'no' );
Branch: 1 branch
BranchTrueFalseTotal
$core_modules ? : 0 0 0
1205  
1206 0 my %modules;
1207  
1208 process_file(
1209 $requires,
1210 chomp => $TRUE,
1211 skip_blank_lines => $TRUE,
1212 skip_comments => $TRUE,
1213 0 ▶ filter => sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
1214 0 my ( $fh, $all_lines, $args, $line ) = @_;
1215 0 $line = filter( $fh, $all_lines, $args, $line );
1216  
1217 0 ▶ return () if $line && $line =~ /^perl\s+/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if $line and $line =~ /^perl\s+/msx 0 0 0
Condition0%0/3
$line and $line =~ /^perl\s+/msx
!ll&&!rl&&r
000
MC/DC0%0/2
$line and $line =~ /^perl\s+/msx
$line $line =~ /^perl\s+/msx
Truth table0%0/3
A and B
A= $lineB= $line =~ /^perl\s+/msx
ABresult
0X0
100
111
1218 0 ▶ return $line if !defined $line;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
1219 0 ▶ return $line if $core_modules;
Branch: 1 branch
BranchTrueFalseTotal
if $core_modules 0 0 0
1220 0 ▶ return $line if $line =~ /^[+]/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /^[+]/msx 0 0 0
1221 0 ▶ return is_core( $line, $min_perl_version ) ? undef : $line;
Branch: 1 branch
BranchTrueFalseTotal
is_core($line, $min_perl_version) ? : 0 0 0
1222 },
1223 0 ▶ process => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1224 0 my $line = pop @_;
1225  
1226 0 $line =~ s/^[+]//xsm;
1227  
1228 0 my ( $module, $version ) = split /\s+/xsm, $line;
1229  
1230 0 $logger->trace( sprintf "\tprocessing line (%s): %s", basename($requires), $line );
1231  
1232 0 ▶ $logger->trace( sprintf "\t\t[%s:%s]", $module, $version // $EMPTY );
Condition0%0/3
$version // $CPAN::Maker::EMPTY
l!l&&r!l&&!r
000
MC/DC0%0/2
$version // $CPAN::Maker::EMPTY
$version $CPAN::Maker::EMPTY
Truth table0%0/3
A // B
A= $versionB= $CPAN::Maker::EMPTY
ABresult
1X1
011
000
1233  
1234 0 ▶ if ( !$include_version ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $include_version) { } 0 0 0
1235 0 $version = '0';
1236 }
1237 else {
1238 0 ▶ $version ||= '0';
Condition0%0/2
$version ||= 0
l!l
00
MC/DC0%0/1
$version ||= 0
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
1239 }
1240  
1241 0 $modules{$module} = $version;
1242  
1243 0 return $line;
1244 }
1245 0 );
1246  
1247 0 return \%modules;
1248 }
1249  
1250 ########################################################################
1251 0 ▶sub get_modules {
Subroutine get_modules: not called CC=1 SCAR=6.9
Pod undocumented
1252 ########################################################################
1253 0 my ( $self, $module_list ) = @_;
1254  
1255 0 my ($modules) = process_file( $module_list, chomp => $TRUE );
1256  
1257 0 return $modules;
1258 }
1259  
1260 ########################################################################
1261 0 ▶sub validate_buildspec {
Subroutine validate_buildspec: not called CC=6 SCAR=37.4
Pod undocumented
1262 ########################################################################
1263 0 my ( $self, $buildspec ) = @_;
1264  
1265 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_validate 0 0 0
1266 if !$self->get_validate;
1267  
1268 0 my $schema_file = eval { dist_file( 'CPAN-Maker', 'buildspec-schema.json' ) };
1269  
1270 0 ▶ if ( !$schema_file || !-e $schema_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($schema_file and -e $schema_file) 0 0 0
Condition0%0/3
$schema_file and -e $schema_file
!ll&&!rl&&r
000
MC/DC0%0/2
$schema_file and -e $schema_file
$schema_file -e $schema_file
Truth table0%0/3
A and B
A= $schema_fileB= -e $schema_file
ABresult
0X0
100
111
1271 0 $self->get_logger->warn('buildspec-schema.json not found - skipping validation');
1272 0 return $TRUE;
1273 }
1274  
1275 0 my @errors = JSON::Validator->new->schema($schema_file)->validate($buildspec);
1276  
1277 0 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 0 0 0
1278 0 $self->get_logger->error('buildspec.yml validation failed:');
1279 0 $self->get_logger->error( ' - ' . $_ ) for @errors;
1280 0 return $FALSE;
1281 }
1282  
1283 0 return $TRUE;
1284 }
1285  
1286 ########################################################################
1287 0 ▶sub _min_perl_version {
Subroutine _min_perl_version: not called CC=1 SCAR=6.9
1288 ########################################################################
1289 0 my ($self) = @_;
1290  
1291 0 ▶ my $min_perl_version = choose {
Subroutine __ANON__: not called CC=3 SCAR=24.8
1292 0 ▶ return $self->get_min_perl_version
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_min_perl_version 0 0 0
1293 if $self->get_min_perl_version;
1294  
1295 0 ▶ return $self->fetch_perl_version( $self->get_requires )
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_requires 0 0 0
1296 if $self->get_requires;
1297  
1298 0 return $DEFAULT_PERL_VERSION;
1299 0 };
1300  
1301 0 $min_perl_version = version->parse($min_perl_version)->stringify;
1302  
1303 0 $self->set_min_perl_version($min_perl_version);
1304  
1305 0 return;
1306 }
1307  
1308 ########################################################################
1309 # _run_cmd: run an external command, logging its output.
1310 #
1311 # STDERR is deliberately merged into STDOUT (via '>&STDOUT') so we read
1312 # a SINGLE pipe with a SINGLE loop below. This is not cosmetic -- it
1313 # avoids a classic IPC::Open3 deadlock.
1314 #
1315 # The deadlock we are avoiding: open3 connects the child's STDOUT and
1316 # STDERR to two separate pipes, each with a fixed (~64K) kernel buffer.
1317 # If the parent drains one pipe to EOF *before* reading the other (e.g.
1318 # `while (<$out>) {...} while (<$err>) {...}`), a child that emits more
1319 # than a buffer's worth on the *second* stream blocks in write(), the
1320 # parent won't read that stream until the first hits EOF, and the first
1321 # never EOFs because the child can't exit -- both sides wait forever.
1322 #
1323 # This stayed hidden for small services (output < one buffer) and only
1324 # surfaced on large APIs like CloudFront, whose `make manifest`/`make
1325 # dist` emit enough output to fill a pipe. Merging the streams removes
1326 # the second pipe entirely, so there is nothing to block on.
1327 #
1328 # Do NOT "fix" this by making the handles hot/autoflush -- that changes
1329 # WHEN bytes are written, not the pipe capacity or who drains it, and if
1330 # anything makes the deadlock more reliable. The only real fixes are to
1331 # drain both streams concurrently or to merge them (done here). If the
1332 # STDERR/STDOUT split is ever needed back, switch to IPC::Run3, which
1333 # spools each stream to a temp file and sidesteps the deadlock that way.
1334 ########################################################################
1335  
1336 ########################################################################
1337 0 ▶sub _run_cmd {
Subroutine _run_cmd: not called CC=2 SCAR=17.9
1338 ########################################################################
1339 0 my ( $self, @cmd ) = @_;
1340  
1341 0 $self->get_logger->info( join $SPACE, @cmd );
1342  
1343 0 my $pid = open3( my $in, my $out, '>&STDOUT', @cmd ); # child STDERR dup'd onto STDOUT
1344 0 close $in;
1345  
1346 0 ▶ while ( my $line = <$out> ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $out)) 0 0 0
1347 0 chomp $line;
1348 0 $self->get_logger->info($line);
1349 }
1350  
1351 0 waitpid $pid, 0;
1352  
1353 0 return $CHILD_ERROR >> 8;
1354 }
1355  
1356 ########################################################################
1357 0 ▶sub stage_distribution {
Subroutine stage_distribution: not called CC=27 SCAR=66.3
Pod undocumented
1358 ########################################################################
1359 0 my ( $self, %params ) = @_;
1360  
1361 0 my ($builddir) = @params{qw(builddir)};
1362  
1363 0 my $buildspec = $self->read_buildspec( $self->get_buildspec );
1364 0 my $project_root = $self->get_project_root;
1365  
1366 # --- lib/ ---
1367 0 ▶ my $pm_path = $self->get_module_path // $buildspec->{path}{'pm-module'} // 'lib';
Condition0%0/5
($self->get_module_path // $buildspec->{"path"}{"pm-module"}) // "lib"
l!l
00
$self->get_module_path // $buildspec->{"path"}{"pm-module"}
l!l&&r!l&&!r
000
MC/DC0%0/2
($self->get_module_path // $buildspec->{"path"}{"pm-module"}) // "lib"
$self->get_module_path $buildspec->{"path"}{"pm-module"}
Truth table0%0/3
A // B
A= $self->get_module_pathB= $buildspec->{"path"}{"pm-module"}
ABresult
1X1
011
000
1368  
1369 0 ▶ if ( $pm_path !~ /^\//xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($pm_path =~ m[^/]msx) 0 0 0
1370 0 $pm_path = "$project_root/$pm_path";
1371 }
1372  
1373 0 ▶ if ( -d $pm_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $pm_path) 0 0 0
1374 find(
1375 { follow => $TRUE,
1376 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1377 0 ▶ return if -d $_;
Branch: 1 branch
BranchTrueFalseTotal
if -d $_ 0 0 0
1378 0 ▶ return if !/[.](?:pm|pod)$/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless /[.](?:pm|pod)$/msx 0 0 0
1379  
1380 0 my $rel = $File::Find::name;
1381 0 $rel =~ s{^\Q$pm_path\E/?}{}xsm;
1382  
1383 0 my $dest = "$builddir/lib/$rel";
1384  
1385 0 make_path( File::Basename::dirname($dest) );
1386  
1387 0 ▶ cp( $File::Find::name, $dest )
Branch: 1 branch
BranchTrueFalseTotal
cp($File::Find::name, $dest) or die "ERROR: could not copy $File::Find::name to ${dest}: $CPAN::Maker::OS_ERROR\n" 0 0 0
1388 or die "ERROR: could not copy $File::Find::name to $dest: $OS_ERROR\n";
1389  
1390 0 return;
1391 },
1392 },
1393 0 $pm_path,
1394 );
1395  
1396 0 my ( $fh, $provides_file ) = tempfile( 'cpan-maker-provides-XXXXXX', TMPDIR => $TRUE );
1397  
1398 0 close $fh;
1399  
1400 0 $self->create_provides(
1401 path => "$builddir/lib",
1402 file => $provides_file,
1403 );
1404  
1405 0 $params{provides_file_ref} = \$provides_file;
1406 }
1407  
1408 # --- bin/ (exe-files) ---
1409 0 ▶ my $exe_path = $self->get_exec_path // $buildspec->{path}{'exe-files'};
Condition0%0/3
$self->get_exec_path // $buildspec->{"path"}{"exe-files"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_exec_path // $buildspec->{"path"}{"exe-files"}
$self->get_exec_path $buildspec->{"path"}{"exe-files"}
Truth table0%0/3
A // B
A= $self->get_exec_pathB= $buildspec->{"path"}{"exe-files"}
ABresult
1X1
011
000
1410  
1411 0 ▶ if ($exe_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($exe_path) 0 0 0
1412 0 ▶ if ( $exe_path !~ /^\//xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($exe_path =~ m[^/]msx) 0 0 0
1413 0 $exe_path = "$project_root/$exe_path";
1414 }
1415  
1416 0 ▶ if ( -d $exe_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $exe_path) 0 0 0
1417 0 make_path("$builddir/bin");
1418  
1419 0 my ( $list_fh, $list_file ) = tempfile( 'cpan-maker-exe-XXXXXX', TMPDIR => $TRUE );
1420  
1421 find(
1422 { follow => $TRUE,
1423 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1424 0 ▶ return if -d $_ || !-x $_;
Branch: 1 branch
BranchTrueFalseTotal
if -d $_ or not -x $_ 0 0 0
Condition0%0/3
-d $_ or not -x $_
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $_ or not -x $_
-d $_ not -x $_
Truth table0%0/3
A or not(B)
A= -d $_B= not -x $_
ABresult
1X1
011
000
1425 0 my $dest = "$builddir/bin/" . File::Basename::basename($File::Find::name);
1426 0 ▶ cp( $File::Find::name, $dest )
Branch: 1 branch
BranchTrueFalseTotal
cp($File::Find::name, $dest) or die "ERROR: could not copy $File::Find::name: $CPAN::Maker::OS_ERROR\n" 0 0 0
1427 or die "ERROR: could not copy $File::Find::name: $OS_ERROR\n";
1428 0 print {$list_fh} "$dest\n";
1429 },
1430 },
1431 0 $exe_path,
1432 );
1433  
1434 0 close $list_fh;
1435 0 $self->set_exec_path($list_file);
1436 }
1437 }
1438  
1439 # --- t/ ---
1440 0 ▶ my $tests_path = $self->get_tests_path // $buildspec->{path}{tests};
Condition0%0/3
$self->get_tests_path // $buildspec->{"path"}{"tests"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_tests_path // $buildspec->{"path"}{"tests"}
$self->get_tests_path $buildspec->{"path"}{"tests"}
Truth table0%0/3
A // B
A= $self->get_tests_pathB= $buildspec->{"path"}{"tests"}
ABresult
1X1
011
000
1441  
1442 0 ▶ if ($tests_path) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tests_path) 0 0 0
1443 0 ▶ $tests_path = "$project_root/$tests_path"
Branch: 1 branch
BranchTrueFalseTotal
unless $tests_path =~ m[^/]msx 0 0 0
1444 if $tests_path !~ /^\//xsm;
1445  
1446 0 ▶ if ( -d $tests_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $tests_path) 0 0 0
1447 0 make_path("$builddir/t");
1448 find(
1449 { follow => $TRUE,
1450 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
1451 0 ▶ return if -d $_ || !/\.t$/xsm;
Branch: 1 branch
BranchTrueFalseTotal
if -d $_ or not /\.t$/msx 0 0 0
Condition0%0/3
-d $_ or not /\.t$/msx
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $_ or not /\.t$/msx
-d $_ not /\.t$/msx
Truth table0%0/3
A or not(B)
A= -d $_B= not /\.t$/msx
ABresult
1X1
011
000
1452 0 ▶ cp( $File::Find::name, "$builddir/t/" . File::Basename::basename($File::Find::name) )
Branch: 1 branch
BranchTrueFalseTotal
cp($File::Find::name, "$builddir/t/" . File::Basename::basename($File::Find::name)) or die "ERROR: could not copy $File::Find::name: $CPAN::Maker::OS_ERROR\n" 0 0 0
1453 or die "ERROR: could not copy $File::Find::name: $OS_ERROR\n";
1454 },
1455 },
1456 0 $tests_path,
1457 );
1458 }
1459 }
1460  
1461 # --- extra-files ---
1462 0 my $extra_files = $buildspec->{'extra-files'};
1463  
1464 0 ▶ if ($extra_files) {
Branch: 1 branch
BranchTrueFalseTotal
if ($extra_files) 0 0 0
1465 0 my @file_list;
1466 0 $self->get_logger->debug( Dumper( [ extra_files => $extra_files ] ) );
1467  
1468 0 for my $e ( @{$extra_files} ) {
1469 0 $self->get_logger->debug( Dumper( [ e => $e ] ) );
1470  
1471 0 ▶ if ( !ref $e ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not ref $e) { } 0 0 0
elsif (ref $e eq 'HASH') { } 0 0 0
1472 0 push @file_list,
1473 $self->fetch_file_list(
1474 file_list => [$e],
1475 destination => $EMPTY,
1476 project_root => $project_root,
1477 );
1478 }
1479 elsif ( ref $e eq 'HASH' ) {
1480 0 my ($destdir) = keys %{$e};
1481 0 my $file_list = $e->{$destdir};
1482  
1483 0 $self->get_logger->debug(
1484 Dumper(
1485 [ destdir => $destdir,
1486 file_list => $file_list,
1487 project_root => $project_root
1488 ]
1489 )
1490 );
1491  
1492 0 push @file_list,
1493 $self->fetch_file_list(
1494 file_list => $file_list,
1495 destination => $destdir,
1496 project_root => $project_root,
1497 );
1498 }
1499 }
1500  
1501 0 ▶ $builddir ||= getcwd;
Condition0%0/3
$builddir ||= getcwd()
l!l&&r!l&&!r
000
MC/DC0%0/2
$builddir ||= getcwd()
$builddir getcwd()
Truth table0%0/3
A ||= B
A= $builddirB= getcwd()
ABresult
1X1
011
000
1502  
1503 0 $self->get_logger->debug( Dumper( [ file_list => \@file_list, builddir => $builddir ] ) );
1504  
1505 0 for my $entry (@file_list) {
1506  
1507 0 my ( $src, $dest ) = split /\s+/xsm, $entry, 2;
1508 0 $self->get_logger->debug( Dumper( [ src => $src, dest => $dest ] ) );
1509  
1510 0 ▶ $src = "$project_root/$src" if $src !~ /^\//xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $src =~ m[^/]msx 0 0 0
1511 0 ▶ $dest = $dest ? "$builddir/$dest" : "$builddir/" . File::Basename::basename($src);
Branch: 1 branch
BranchTrueFalseTotal
$dest ? : 0 0 0
1512  
1513 0 $self->get_logger->debug( Dumper( [ src => $src, dest => $dest ] ) );
1514  
1515 0 make_path( File::Basename::dirname($dest) );
1516  
1517 0 ▶ cp( $src, $dest )
Branch: 1 branch
BranchTrueFalseTotal
cp($src, $dest) or die "ERROR: could not copy $src to ${dest}: $CPAN::Maker::OS_ERROR\n" 0 0 0
1518 or die "ERROR: could not copy $src to $dest: $OS_ERROR\n";
1519 }
1520 }
1521  
1522 # --- postamble ---
1523 0 ▶ my $postamble = $self->get_postamble // $buildspec->{postamble};
Condition0%0/3
$self->get_postamble // $buildspec->{"postamble"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->get_postamble // $buildspec->{"postamble"}
$self->get_postamble $buildspec->{"postamble"}
Truth table0%0/3
A // B
A= $self->get_postambleB= $buildspec->{"postamble"}
ABresult
1X1
011
000
1524  
1525 0 ▶ if ( $postamble && -e $postamble ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postamble and -e $postamble) 0 0 0
Condition0%0/3
$postamble and -e $postamble
!ll&&!rl&&r
000
MC/DC0%0/2
$postamble and -e $postamble
$postamble -e $postamble
Truth table0%0/3
A and B
A= $postambleB= -e $postamble
ABresult
0X0
100
111
1526 0 ▶ cp( $postamble, "$builddir/postamble" )
Branch: 1 branch
BranchTrueFalseTotal
cp($postamble, "$builddir/postamble") or die "ERROR: could not copy postamble: $CPAN::Maker::OS_ERROR\n" 0 0 0
1527 or die "ERROR: could not copy postamble: $OS_ERROR\n";
1528 }
1529  
1530 0 ▶ my $provides_file = $params{provides_file_ref} ? ${ $params{provides_file_ref} } : $EMPTY;
Branch: 1 branch
BranchTrueFalseTotal
$params{'provides_file_ref'} ? : 0 0 0
1531  
1532 0 return $provides_file;
1533 }
1534  
1535 ########################################################################
1536 0 ▶sub main {
Subroutine main: not called CC=2 SCAR=17.9
Pod documented
1537 ########################################################################
1538  
1539 0 my @option_specs = qw(
1540 abstract|A=s
1541 author|a=s
1542 build-requires|B=s
1543 buildspec|b=s
1544 cleanup!
1545 core-modules!
1546 color!
1547 create-buildspec=s
1548 debug|D
1549 dependency-type=s
1550 dryrun
1551 exe-files|e=s
1552 exec-path=s
1553 extra-path=s
1554 help|h
1555 license=s
1556 log-level|l=s
1557 min-perl-version|M=s
1558 module-path=s
1559 module|m=s
1560 overwrite
1561 outfile|o=s
1562 pager|P!
1563 pl-files=s
1564 postamble=s
1565 project-root|p=s
1566 recommends=s
1567 recurse
1568 require-versions|R!
1569 requires|r=s
1570 resources=s
1571 destdir=s
1572 no-cleanup
1573 preserve-makefile
1574 scripts-path=s
1575 skip-tests
1576 suggests=s
1577 test-requires|t=s
1578 tests-path=s
1579 validate!
1580 verbose|V
1581 version-from=s
1582 version|v
1583 work-dir|w=s
1584 );
1585  
1586 0 my $is_json_validator_available = eval { require JSON::Validator; 1 }; ## scandeps: recommends
1587  
1588 0 ▶ my $default_options = {
Condition0%0/3
$is_json_validator_available // $CPAN::Maker::FALSE
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_json_validator_available // $CPAN::Maker::FALSE
$is_json_validator_available $CPAN::Maker::FALSE
Truth table0%0/3
A // B
A= $is_json_validator_availableB= $CPAN::Maker::FALSE
ABresult
1X1
011
000
1589 cleanup => $TRUE,
1590 pager => $TRUE,
1591 require_versions => $TRUE,
1592 validate => $is_json_validator_available // $FALSE,
1593 };
1594  
1595 0 my %commands = (
1596 'build' => \&cmd_build,
1597 'create-cpanfile' => \&cmd_create_cpanfile,
1598 'default' => \&cmd_build,
1599 'validate' => \&cmd_validate,
1600 'version' => \&cmd_version,
1601 'write-makefile' => \&cmd_makefile,
1602 );
1603  
1604 0 my $cli = CPAN::Maker->new(
1605 commands => \%commands,
1606 option_specs => \@option_specs,
1607 default_options => $default_options,
1608 );
1609  
1610 0 return $cli->run();
1611 }
1612  
1613 1 1;
1614  
1615 __END__
1616  
1617 =pod
1618  
1619 =encoding UTF-8
1620  
1621 =head1 NAME
1622  
1623 CPAN::Maker - create a CPAN distribution
1624  
1625 =head1 SYNOPSIS
1626  
1627 cpan-maker -b buildspec.yml
1628 cpan-maker build -b buildspec.yml
1629 cpan-maker create-cpanfile file1 file2 ...
1630  
1631 =head2 Options
1632  
1633 -a, --author author in 'name <email>' format (default: anonymouse <anonymouse@example.org)
1634 -A, --abstract description of the module
1635 -B, --build-requires build dependencies
1636 -b, --buildspec buildspec YAML file
1637 --cleanup, --no-cleanup remove temp dir after build (default: cleanup)
1638 --create-buildspec name of a buildspec file to create
1639 -d, --debug debug mode
1640 --destdir destination directory for the tarball (default: cwd)
1641 --dryrun dump parsed buildspec args and exit
1642 --exe-files path to the executables list
1643 --extra-path path to the extra files list
1644 -h, --help help
1645 --license License under which the software can be used (default: perl)
1646 -l, --log-level ERROR, WARN, INFO, DEBUG, TRACE
1647 -m, --module module name
1648 -M, --min-perl-version minimum perl version to consider core (default: 5.010)
1649 --no-cleanup preserve temp dir after build
1650 --no-require-versions omit version numbers from dependencies
1651 -o, --outfile output file for create-cpanfile (default: cpanfile, - for STDOUT)
1652 -P, --pager, --no-pager use a pager for help (default: use pager)
1653 --pl-files path to the PL_FILES list (see perldoc ExtUtils::MakeMaker)
1654 --postamble name of the file containing the postamble instructions
1655 --preserve-makefile copy Makefile.PL to destdir after build
1656 -p, --project-root default: current working directory
1657 --recommends path to the file containing the recommended modules and versions
1658 --recurse recurse directories when searching for files
1659 -R, --require-versions add version numbers to dependencies
1660 -r, --requires path to the file containing the required modules and versions (required for write-makefile)
1661 --scripts-path path to the scripts listing
1662 --skip-tests skip C<make test> during build
1663 --suggests path to the file containing the suggested modules and versions
1664 --tests-path path to the tests listing
1665 -V, --verbose verbose output
1666 -v, --version version
1667 --version-from module that provides the version
1668  
1669 =head2 Commands
1670  
1671 =over 4
1672  
1673 =item * build
1674  
1675 Parse a C<buildspec.yml> file and build the CPAN distribution tarball.
1676 This is the default command and is invoked automatically when
1677 C<-b buildspec.yml> is passed without an explicit command.
1678  
1679 cpan-maker build -b buildspec.yml
1680 cpan-maker -b buildspec.yml
1681  
1682 =item * validate
1683  
1684 Validate a C<buildspec.yml> file against the JSON Schema. Reports all
1685 errors before exiting. Returns a non-zero exit status if validation
1686 fails, making it suitable for use in CI pipelines.
1687  
1688 cpan-maker validate
1689 cpan-maker validate path/to/buildspec.yml
1690 cpan-maker -b path/to/buildspec.yml validate
1691  
1692 I<Note: If your file uses underscore-style keys (C<pm_module>,
1693 C<extra_files>, etc.) they are automatically normalized to their
1694 canonical hyphenated forms and a corrected copy is written to
1695 F<buildspec.yml.current>.>
1696  
1697 =item * write-makefile
1698  
1699 Generate a C<Makefile.PL> to STDOUT from options passed on the command
1700 line. Useful for inspecting the generated C<Makefile.PL> without
1701 running a full build.
1702  
1703 cpan-maker write-makefile -m Foo::Bar -r requires -a 'A. U. Thor <au@example.com>'
1704  
1705 =item * create-cpanfile
1706  
1707 Generate a F<cpanfile> from one or more dependency list files. Each file
1708 contains one dependency per line in the format:
1709  
1710 Module::Name version [dist=name] [url=URL] [mirror=URL]
1711  
1712 Lines beginning with C<#> are treated as comments and ignored. A leading
1713 C<+> on a module name (as used in C<CPAN::Maker::Bootstrapper> dependency
1714 files to pin a version) is stripped before processing. Duplicate entries
1715 are removed and the output is sorted alphabetically.
1716  
1717 By default the result is written to F<cpanfile> in the current directory.
1718 Use C<-o -> to write to STDOUT instead.
1719  
1720 cpan-maker create-cpanfile requires test-requires
1721 cpan-maker create-cpanfile -o - requires > cpanfile
1722 cpan-maker create-cpanfile -o my-cpanfile requires test-requires
1723  
1724 The optional C<dist=>, C<url=>, and C<mirror=> qualifiers map to the
1725 corresponding C<cpanfile> source directives, allowing you to pin
1726 dependencies to a specific distribution, URL, or mirror.
1727  
1728 =item * version
1729  
1730 Print the installed version of C<CPAN::Maker> and exit.
1731  
1732 cpan-maker version
1733  
1734 =back
1735  
1736 =head1 DESCRIPTION
1737  
1738 C<CPAN::Maker> is a utility for creating CPAN distribution tarballs
1739 from a declarative YAML build specification. It handles dependency
1740 resolution, C<Makefile.PL> generation, file staging, and packaging
1741 entirely in Perl — no external bash scripts are required.
1742  
1743 The build pipeline, invoked via C<cpan-maker -b buildspec.yml>:
1744  
1745 =over 5
1746  
1747 =item * parses and validates the build specification
1748  
1749 =item * stages distribution files (lib, bin, t, extra-files, postamble)
1750 into a temporary build directory
1751  
1752 =item * generates a C<Makefile.PL> in the build directory
1753  
1754 =item * runs C<perl Makefile.PL>, C<make manifest>, C<make dist>, and
1755 optionally C<make test>
1756  
1757 =item * copies the resulting tarball to the destination directory
1758  
1759 =back
1760  
1761 I<Note: Prior to version 2.0.0, the build was delegated to an external
1762 bash script (C<make-cpan-dist>). That script is no longer invoked and
1763 is retained only as a compatibility shim. All build logic now runs
1764 within C<cpan-maker> itself.>
1765  
1766 =head1 OPTION DETAILS
1767  
1768 =over 5
1769  
1770 =item -A, --abstract
1771  
1772 A short description of the module purpose.
1773  
1774 =item -a, --author
1775  
1776 Author name and email address.
1777  
1778 Example: -a 'Rob Lauer <rlauer6@comcast.net>'
1779  
1780 =item -B, --build-requires
1781  
1782 Path to a file listing build-time dependencies.
1783  
1784 =item -b, --buildspec
1785  
1786 Path to the build specification file in YAML format.
1787 See L</BUILD SPECIFICATION FORMAT>.
1788  
1789 =item --cleanup, --no-cleanup
1790  
1791 Remove the temporary build directory after the build completes. The
1792 default is to remove it. Use C<--no-cleanup> to preserve the directory
1793 for inspection.
1794  
1795 =item -C, --create-buildspec
1796  
1797 Write a buildspec file derived from the current options to the named
1798 file.
1799  
1800 =item -d, --debug
1801  
1802 Enable debug logging.
1803  
1804 =item --destdir
1805  
1806 Directory where the finished tarball (and C<Makefile.PL> if
1807 C<--preserve-makefile> is set) will be written. Defaults to the
1808 current working directory.
1809  
1810 =item --dryrun
1811  
1812 Parse the buildspec and dump the resulting argument hash without
1813 running the build.
1814  
1815 =item -h, --help
1816  
1817 Print the option summary.
1818  
1819 =item -l, --log-level
1820  
1821 Log level. Valid values: C<error>, C<warn>, C<info>, C<debug>,
1822 C<trace>. Default: C<error>.
1823  
1824 =item -m, --module
1825  
1826 Name of the primary Perl module to package.
1827  
1828 =item -M, --min-perl-version
1829  
1830 Minimum Perl version used when determining which modules are core.
1831 Default: C<5.010>.
1832  
1833 =item --no-cleanup
1834  
1835 Preserve the temporary build directory after the build. Equivalent to
1836 C<--no-cleanup>; the directory path is logged at C<debug> level.
1837  
1838 =item -o, --outfile
1839  
1840 Output file path for the C<create-cpanfile> command. Defaults to
1841 F<cpanfile> in the current directory. Pass C<-> to write to STDOUT.
1842  
1843 =item -P, --pager, --no-pager
1844  
1845 Route help output through a pager. Default: use pager.
1846  
1847 =item --pl-files
1848  
1849 Path to a file listing C<PL_FILES> targets.
1850 See L<ExtUtils::MakeMaker> for the format.
1851  
1852 =item --postamble
1853  
1854 Path to a file containing C<Makefile> postamble instructions to append
1855 to the generated C<Makefile.PL>.
1856  
1857 =item --preserve-makefile
1858  
1859 Copy the generated C<Makefile.PL> to C<--destdir> after the build.
1860 Useful for inspecting the result.
1861  
1862 =item -p, --project-root
1863  
1864 Root of the project tree. Paths in the buildspec are resolved relative
1865 to this directory. Defaults to the current working directory.
1866  
1867 =item --recommends
1868  
1869 Path to a file listing recommended (but not strictly required)
1870 dependencies. Optional - a distribution with no recommended
1871 dependencies simply omits this option. See
1872 L</BUILD SPECIFICATION FORMAT>.
1873  
1874 =item --recurse
1875  
1876 Recurse into subdirectories of the C<pm-module> path when collecting
1877 modules. Default: yes.
1878  
1879 =item -R, --require-versions, --no-require-versions
1880  
1881 Include version numbers in the generated C<PREREQ_PM> section.
1882 Default: include versions.
1883  
1884 =item -r, --requires
1885  
1886 Path to a file listing required (runtime) dependencies. Unlike
1887 C<--recommends> and C<--suggests>, this one is not optional: most CPAN
1888 installers (C<cpanm> in particular) only install C<requires>
1889 dependencies by default - C<--with-recommends> and C<--with-suggests>
1890 both default to off - so a distribution with no C<requires> entries at
1891 all has, for practical purposes, no guaranteed dependencies. The
1892 C<write-makefile> command enforces this and will refuse to proceed
1893 without a C<--requires> file that actually exists. See
1894 L</BUILD SPECIFICATION FORMAT>.
1895  
1896 =item --skip-tests
1897  
1898 Skip C<make test> during the build.
1899  
1900 =item --suggests
1901  
1902 Path to a file listing suggested (optional) dependencies - modules
1903 that meaningfully enhance the distribution but aren't needed for it to
1904 function. Optional - a distribution with no suggested dependencies
1905 simply omits this option. See L</BUILD SPECIFICATION FORMAT>.
1906  
1907 =item --version-from
1908  
1909 Module name from which the distribution version is extracted.
1910 Defaults to the primary module.
1911  
1912 =back
1913  
1914 =head1 ENVIRONMENT VARIABLES
1915  
1916 No environment variables are used by C<cpan-maker>. Options previously
1917 controlled by C<PRESERVE_MAKEFILE>, C<SKIP_TESTS>, and C<DEBUG>
1918 environment variables (which applied to the now-removed bash script)
1919 are now available as C<--preserve-makefile>, C<--skip-tests>, and
1920 C<--debug> command-line options.
1921  
1922 =head1 BUILD SPECIFICATION FORMAT
1923  
1924 The preferred way to use C<cpan-maker> is with a F<buildspec.yml>
1925 file:
1926  
1927 cpan-maker -b buildspec.yml
1928  
1929 =head2 Minimal example
1930  
1931 project:
1932 description: My awesome module
1933 author:
1934 name: A. U. Thor
1935 mailto: au@example.com
1936  
1937 pm-module: Foo::Bar
1938  
1939 dependencies:
1940 requires: requires
1941 test-requires: test-requires
1942  
1943 =head2 Full key reference
1944  
1945 =over 5
1946  
1947 =item project
1948  
1949 =over 15
1950  
1951 =item description
1952  
1953 Short description of the module. Used as C<ABSTRACT> in
1954 C<Makefile.PL>.
1955  
1956 =item author
1957  
1958 =over 10
1959  
1960 =item name
1961  
1962 Author's full name.
1963  
1964 =item mailto
1965  
1966 Author's email address.
1967  
1968 =back
1969  
1970 =item git
1971  
1972 URI of the project's git repository.
1973  
1974 =back
1975  
1976 =item pm-module
1977  
1978 The fully-qualified name of the primary module to package
1979 (e.g. C<Foo::Bar>).
1980  
1981 =item license
1982  
1983 License under which the software can be use.
1984  
1985 default: perl
1986  
1987 =item version-from
1988  
1989 Module from which the version number is read. Defaults to C<pm-module>.
1990  
1991 =item min-perl-version
1992  
1993 Minimum Perl version to assume when deciding which modules are core.
1994 Default: C<5.010>.
1995  
1996 =item man-links
1997  
1998 List of C<name: Module::Name> pairs. For each entry a man page symlink
1999 is created so that C<man name> resolves to the module's man page.
2000  
2001 man-links:
2002 - foo-bar: Foo::Bar
2003  
2004 =item include-version
2005  
2006 Whether to include version numbers in dependency declarations.
2007 Set to C<no> to omit. Default: C<yes>.
2008  
2009 =item dependencies
2010  
2011 =over 15
2012  
2013 =item requires
2014  
2015 Path to a file listing runtime dependencies. Defaults to a file named
2016 F<requires> in the project root.
2017  
2018 =item test-requires
2019  
2020 Path to a file listing test dependencies.
2021  
2022 =item build-requires
2023  
2024 Path to a file listing build-time dependencies.
2025  
2026 =item recommends
2027  
2028 Path to a file listing optional recommended dependencies. These appear
2029 under C<prereqs.runtime.recommends> in generated META files and are
2030 installed by C<cpanm --with-recommends>.
2031  
2032 =item suggests
2033  
2034 Path to a file listing optional suggested dependencies - a weaker
2035 signal than C<recommends>. These appear under
2036 C<prereqs.runtime.suggests> in generated META files and are installed
2037 by C<cpanm --with-suggests>.
2038  
2039 =item resolver (optional)
2040  
2041 Name of a program that produces a dependency list when passed a module
2042 name. Use the special value C<scandeps> to invoke F<scandeps.pl>.
2043  
2044 =item required-modules
2045  
2046 Whether the resolver should follow C<require> statements. Default: C<yes>.
2047  
2048 =back
2049  
2050 =item path (optional)
2051  
2052 =over 15
2053  
2054 =item pm-module
2055  
2056 Directory containing the module files. Default: F<lib>.
2057  
2058 =item recurse (optional)
2059  
2060 Whether to recurse into subdirectories. Default: C<yes>.
2061  
2062 =item tests (optional)
2063  
2064 Directory containing test files (C<*.t>).
2065  
2066 =item exe-files
2067  
2068 Directory containing executable Perl scripts. Only files with
2069 executable permissions are included.
2070  
2071 Examples:
2072 src/main/perl/bin
2073 bin/
2074  
2075 =item scripts
2076  
2077 Directory containing non-Perl executable scripts (e.g. bash).
2078 Only files with executable permissions are included.
2079  
2080 =back
2081  
2082 =item provides (optional)
2083  
2084 Explicit list of modules provided by this distribution. By default all
2085 C<.pm> files found under the C<pm-module> path are listed.
2086  
2087 =item resources (optional)
2088  
2089 Values added to the C<resources> section of C<META_MERGE> in the
2090 generated C<Makefile.PL>. See L<CPAN::Meta::Spec> for the format.
2091  
2092 =item extra-files (optional)
2093  
2094 List of files to be included in the package.
2095  
2096 Examples:
2097  
2098 extra-files:
2099 - ChangeLog
2100 - README
2101 - examples:
2102 - src/examples <= include all files in this directory
2103  
2104 extra-files:
2105 - ChangeLog
2106 - README
2107 - examples:
2108 - src/examples/foo.pl
2109 - src/examples/boo.pl
2110  
2111 I<CAUTION: specifying a directory will include ALL of the files in
2112 that directory. It is better practice to list the specific files you
2113 want to include, or provide a manifest of files via the C<extra> key:>
2114  
2115 extra: manifest
2116  
2117 If you include a C<share> destination in your C<extra-files>
2118 specification, those files will be installed as part of the
2119 distribution under the share directory. The installed location can be
2120 found at runtime with:
2121  
2122 perl -MFile::ShareDir=dist_dir -e 'print dist_dir(q{My-Project});'
2123  
2124 The specification...
2125  
2126 extra-files:
2127 - share: <= indicates ../auto/share/dist/My-Project
2128 - resources/foo.cfg
2129  
2130 ...would package F<resources/foo.cfg> from your project into the
2131 distribution's share directory root. While this specification...
2132  
2133 extra-files:
2134 - share/resources: <= indicates ../auto/share/dist/My-Project/resources
2135 - resources/foo.cfg
2136  
2137 ...would package F<foo.cfg> into the F<resources> subdirectory of the
2138 distribution's share directory.
2139  
2140 I<All other files in the C<extra-files> section will be added to the
2141 root of the tarball but will not be installed.>
2142  
2143 =item extra (optional)
2144  
2145 Path to a manifest file listing additional files to include, one per
2146 line.
2147  
2148 =back
2149  
2150 =head2 Key Naming
2151  
2152 Keys may be written with hyphens (C<pm-module>) or underscores
2153 (C<pm_module>). The hyphenated form is canonical. If underscore keys
2154 are detected they are normalised before parsing and a corrected copy of
2155 the buildspec is written to F<buildspec.yml.current>. The original file
2156 is never modified.
2157  
2158 =head1 DEPENDENCIES
2159  
2160 Runtime and test dependencies are read from plain-text files, one
2161 module per line with an optional version number:
2162  
2163 Amazon::Credentials 1.15
2164 HTTP::Tiny
2165  
2166 By default the files are named F<requires> and F<test-requires>. The
2167 paths can be overridden in the C<dependencies> section of the
2168 buildspec.
2169  
2170 If the dependency file is named F<cpanfile> it is parsed in cpanfile
2171 format.
2172  
2173 =head1 VERSION
2174  
2175 This documentation refers to version 2.0.12
2176  
2177 =head1 AUTHOR
2178  
2179 Rob Lauer - <rlauer@treasurersbriefcase.com>
2180  
2181 =cut
↑ Summary lib/CPAN/Maker/Role/FileUtils.pm »