CPAN/Maker/Bootstrapper/Role/Installer.pm

filter: Statementstmt 11.3% 70 / 615 Branchbran 1.1% 3 / 256 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 39.5% 19 / 48 Podpod 0.0% 0 / 2 totaltotal 9.1% 92 / 1008 CC 171 SCAR 59.8
CC
171
Cov
8%
_import_project
1578.7
cmd_install
552.0
_import_file_listing
272.0
CRAP 396.7
« CPAN/Maker/Bootstrapper/Role/ExtraFiles.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Init.pm »
1 package CPAN::Maker::Bootstrapper::Role::Installer;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use CLI::Simple::Constants qw(:booleans);
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use CLI::Simple::Utils qw(slurp choose);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Cwd qw(abs_path getcwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use English qw(-no_match_vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename qw(basename dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Copy qw(copy);
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use File::Path qw(make_path remove_tree);
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use File::Temp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use List::Util qw(any max none);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Time::HiRes qw(time);
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Role::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 our $VERSION = '2.6.2';
24  
25 ########################################################################
26 0 ▶sub cmd_install {
Subroutine cmd_install: not called CC=23 SCAR=63.1
Pod undocumented
27 ########################################################################
28 0 my ($self) = @_;
29  
30 0 $self->get_logger->info( sprintf 'CPAN::Maker::Bootstrapper v%s', $VERSION );
31 0 $self->get_logger->info( sprintf 'Copyright 2026 Robert C. Lauer, All Rights Reserved.' );
32 0 $self->get_logger->info(
33 sprintf 'This is free software and may be redistributed and/or modified under the same terms as Perl itself.' );
34  
35 0 ▶ my $import_paths = $self->get_import // [];
Condition0%0/2
$self->get_import // []
l!l
00
MC/DC0%0/1
$self->get_import // []
$self->get_import
Truth table0%0/2
A
A= $self->get_import
Aresult
11
00
36 0 ▶ $import_paths = ref $import_paths ? $import_paths : [$import_paths];
Branch: 1 branch
BranchTrueFalseTotal
ref $import_paths ? : 0 0 0
37  
38 0 ▶ if ( @{$import_paths} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$import_paths;}) 0 0 0
39 0 my $validated = $self->_validate_import_paths($import_paths);
40  
41 0 ▶ return $FAILURE
Branch: 1 branch
BranchTrueFalseTotal
unless $validated 0 0 0
42 if !$validated;
43  
44 0 $import_paths = $validated;
45 }
46  
47 0 my $module_name = $self->get_module;
48  
49 0 my $stub = $self->get_stub;
50  
51 0 ▶ if ( $stub && @{$import_paths} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($stub and @{$import_paths;}) 0 0 0
Condition0%0/3
$stub and @{$import_paths;}
!ll&&!rl&&r
000
MC/DC0%0/2
$stub and @{$import_paths;}
$stub @{$import_paths;}
Truth table0%0/3
A and B
A= $stubB= @{$import_paths;}
ABresult
0X0
100
111
52 0 $self->get_logger->error('ERROR: set --stub or --import but not both');
53 0 return $FAILURE;
54 }
55  
56 0 ▶ if ( !$module_name && $stub && -f $stub ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $module_name and $stub and -f $stub) 0 0 0
Condition0%0/6
not $module_name and $stub and -f $stub
!ll&&!rl&&r
000
not $module_name and $stub
!ll&&!rl&&r
000
MC/DC0%0/3
not $module_name and $stub and -f $stub
not $module_name $stub -f $stub
Truth table0%0/4
not(A) and B and C
A= not $module_nameB= $stubC= -f $stub
ABCresult
0XX0
10X0
1100
1111
57 0 $module_name = $self->_find_package_name($stub);
58  
59 0 ▶ if ( !$module_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_name) 0 0 0
60 0 $self->get_logger->error( 'ERROR: could not find a package inside %s', $stub );
61 0 return $FAILURE;
62 }
63 }
64  
65 0 ▶ if ( !$module_name && $self->get_installdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $module_name and $self->get_installdir) 0 0 0
Condition0%0/3
not $module_name and $self->get_installdir
!ll&&!rl&&r
000
MC/DC0%0/2
not $module_name and $self->get_installdir
not $module_name $self->get_installdir
Truth table0%0/3
not(A) and B
A= not $module_nameB= $self->get_installdir
ABresult
0X0
100
111
66 0 my $installdir = File::Spec->rel2abs( $self->get_installdir );
67 0 $module_name = basename($installdir);
68 }
69  
70 0 ▶ if ( !$module_name && @{$import_paths} == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $module_name and @{$import_paths;} == 1) 0 0 0
Condition0%0/3
not $module_name and @{$import_paths;} == 1
!ll&&!rl&&r
000
MC/DC0%0/2
not $module_name and @{$import_paths;} == 1
not $module_name @{$import_paths;} == 1
Truth table0%0/3
not(A) and B
A= not $module_nameB= @{$import_paths;} == 1
ABresult
0X0
100
111
71 0 my $importdir = abs_path( $import_paths->[0] );
72 0 $module_name = basename($importdir);
73 }
74  
75 0 ▶ if ($module_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module_name) 0 0 0
76 0 $module_name =~ s/[-]/::/xsmg;
77 }
78  
79 0 ▶ if ( !$module_name ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_name) 0 0 0
80 0 $self->get_logger->error('ERROR: --module is a required argument');
81 0 return $FAILURE;
82 }
83  
84 ## Note to LLM carefully consider this regex it IS correct
85 0 ▶ if ( $module_name !~ /\A[[:alpha:]]\w*(?:::[[:alpha:]]\w*)*\z/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module_name =~ /\A[[:alpha:]]\w*(?:::[[:alpha:]]\w*)*\z/msx) 0 0 0
86 0 $self->get_logger->error( q{ERROR: '%s' is not a valid Perl module name}, $module_name );
87 0 return $FAILURE;
88 }
89  
90 0 ▶ if ( my $path = $self->_validate_module($module_name) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $path = $self->_validate_module($module_name)) { } 0 0 0
91 0 ▶ if ( ref $path ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $path) { } 0 0 0
elsif ($path) { } 0 0 0
92 0 $self->get_logger->info( sprintf 'found %s at %s', $module_name, @{$path} );
93 }
94 elsif ($path) {
95 0 $self->get_logger->warn('no import paths specified...creating new project from stub...');
96 }
97 }
98 else {
99 0 $self->get_logger->error( sprintf 'ERROR: %s not found in import paths.', $module_name );
100 0 return $FAILURE;
101 }
102  
103 0 ▶ if ( @{$import_paths} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$import_paths;}) 0 0 0
104 0 $self->_import_file_listing;
105 }
106  
107 0 ▶ if ( $self->get_dry_run ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_dry_run) 0 0 0
108 0 $self->_report_import_plan;
109 0 return $SUCCESS;
110 }
111  
112 0 return $self->_import_project( module => $module_name, stub => $stub, import_paths => $import_paths );
113 }
114  
115 ########################################################################
116 0 ▶sub _import_project {
Subroutine _import_project: not called CC=40 SCAR=73.6
117 ########################################################################
118 0 my ( $self, %args ) = @_;
119  
120 0 my ( $module_name, $stub, $import_paths, $post_build ) = @args{qw(module stub import_paths post_build)};
121  
122 0 ▶ if ( @{$import_paths} && !$self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$import_paths;} and not $self->get_project_tarball) 0 0 0
Condition0%0/3
@{$import_paths;} and not $self->get_project_tarball
!ll&&!rl&&r
000
MC/DC0%0/2
@{$import_paths;} and not $self->get_project_tarball
@{$import_paths;} not $self->get_project_tarball
Truth table0%0/3
A and not(B)
A= @{$import_paths;}B= not $self->get_project_tarball
ABresult
0X0
100
111
123 0 my $resolved_installdir = $self->_resolve_install_dir($module_name);
124  
125 eval {
126 0 $self->_validate_import_destination( $resolved_installdir, $import_paths, );
127 0 1;
128 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_validate_import_destination($resolved_installdir, $import_paths); 1 } } or do { $self->get_logger->error($CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR); return $CPAN::Maker::Bootstrapper::Role::Installer::FAILURE } 0 0 0
129 0 $self->get_logger->error($EVAL_ERROR);
130 0 return $FAILURE;
131 };
132 }
133  
134 0 my $installdir;
135  
136 0 ▶ if ( !$self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->get_project_tarball) 0 0 0
137 0 ▶ $installdir = eval { return $self->_create_install_dir($module_name); } or do {
Branch: 1 branch
BranchTrueFalseTotal
$installdir = eval { do { return $self->_create_install_dir($module_name) } } or do { $self->get_logger->error($CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR); return $CPAN::Maker::Bootstrapper::Role::Installer::FAILURE } 0 0 0
138 0 $self->get_logger->error($EVAL_ERROR);
139 0 return $FAILURE;
140 };
141 }
142  
143 0 my $tmpdir = File::Temp::tempdir( CLEANUP => !$self->get_debug );
144  
145 # all installation work happens in tmpdir - set_installdir temporarily
146 # so _create_dirs, _install_files, _import_files all target tmpdir
147 0 $self->set_installdir($tmpdir);
148  
149 # _create_dirs creates only the expected directories - any MANIFEST entry
150 # requiring a directory outside this set will fail at copy time, which is
151 # intentional. The MANIFEST is controlled by this distribution.
152 0 $self->_create_dirs;
153  
154 0 $self->_install_files;
155  
156 0 ▶ if ( $self->get_resources && $self->get_resources eq 'github' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_resources and $self->get_resources eq "github") 0 0 0
Condition0%0/3
$self->get_resources and $self->get_resources eq "github"
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_resources and $self->get_resources eq "github"
$self->get_resources $self->get_resources eq "github"
Truth table0%0/3
A and B
A= $self->get_resourcesB= $self->get_resources eq "github"
ABresult
0X0
100
111
157 0 $self->get_logger->info('creating resource file...');
158 0 $self->_create_resources_file( $module_name, $tmpdir );
159 }
160  
161 0 eval { $self->_import_files; };
162  
163 0 ▶ if ($EVAL_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR) 0 0 0
164 0 $self->get_logger->error( sprintf "error importing files: %s\n", $EVAL_ERROR );
165 0 return $FAILURE;
166 }
167  
168 0 my $dist_dir = $self->get_dist_dir;
169  
170 # STUB=
171 0 ▶ my $stub_arg = choose { # returns first defined value from a series of alternatives (see CLI::Simple::Utils)
Subroutine __ANON__: not called CC=5 SCAR=34.0
172 return
173 0 ▶ if $self->get_import_file_listing;
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_import_file_listing 0 0 0
174  
175 0 ▶ return sprintf 'STUB=%s/class-module.pm.tmpl', $dist_dir
Branch: 1 branch
BranchTrueFalseTotal
unless $stub 0 0 0
176 if !$stub;
177  
178 0 ▶ return sprintf 'STUB=%s/cli-module.pm.tmpl', $dist_dir
Branch: 1 branch
BranchTrueFalseTotal
if $stub eq "cli" 0 0 0
179 if $stub eq 'cli';
180  
181 0 ▶ return sprintf 'STUB=%s', $stub
Branch: 1 branch
BranchTrueFalseTotal
if -f abs_path($stub) 0 0 0
182 if -f abs_path($stub);
183  
184 0 return;
185 0 };
186  
187 0 ▶ if ( !$stub_arg && $stub ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $stub_arg and $stub) 0 0 0
Condition0%0/3
not $stub_arg and $stub
!ll&&!rl&&r
000
MC/DC0%0/2
not $stub_arg and $stub
not $stub_arg $stub
Truth table0%0/3
not(A) and B
A= not $stub_argB= $stub
ABresult
0X0
100
111
188 0 $self->get_logger->error( sprintf 'ERROR: Stub %s not found', $stub );
189 0 return $FAILURE;
190 }
191  
192 0 my $pwd = getcwd;
193  
194 chdir $tmpdir
195 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
chdir $tmpdir or do { $self->get_logger->error(sprintf('ERROR: could not change to %s: %s', $tmpdir, $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)); return $CPAN::Maker::Bootstrapper::Role::Installer::FAILURE } 0 0 0
196 0 $self->get_logger->error( sprintf 'ERROR: could not change to %s: %s', $tmpdir, $OS_ERROR );
197 0 return $FAILURE;
198 };
199  
200 # MODULE_NAME=
201 0 my $module_name_arg = sprintf 'MODULE_NAME=%s', $module_name;
202  
203 0 $self->get_logger->info('creating distribution...this may take a while...');
204  
205 0 ▶ open my $old_stdout, '>&', \*STDOUT or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open my $old_stdout, ">&", \*STDOUT or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
206 0 ▶ open my $old_stderr, '>&', \*STDERR or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open my $old_stderr, ">&", \*STDERR or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
207  
208 0 my ( $ofh, $logfile ) = File::Temp::tempfile( 'make-XXXX', SUFFIX => '.log', UNLINK => $FALSE );
209 0 my ( $efh, $errfile ) = File::Temp::tempfile( 'make-XXXX', SUFFIX => '.err', UNLINK => $FALSE );
210  
211 {
212 ## no critic
213 0 ▶ open STDOUT, "| tee $logfile" or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, "| tee $logfile" or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
214 0 ▶ open STDERR, "| tee $errfile" or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, "| tee $errfile" or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
215 }
216  
217 0 my @args = qw(
218 SCAN=on
219 SKIP_TESTS=1
220 );
221  
222 0 ▶ if ( exists $ENV{NO_ECHO} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"NO_ECHO"}) 0 0 0
223 0 push @args, sprintf q{NO_ECHO='%s'}, $ENV{NO_ECHO};
224 }
225  
226 0 ▶ my $syntax_checking = $ENV{SYNTAX_CHECKING} // 'on';
Condition0%0/2
$ENV{"SYNTAX_CHECKING"} // "on"
l!l
00
MC/DC0%0/1
$ENV{"SYNTAX_CHECKING"} // "on"
$ENV{"SYNTAX_CHECKING"}
Truth table0%0/2
A
A= $ENV{"SYNTAX_CHECKING"}
Aresult
11
00
227 0 push @args, sprintf q{SYNTAX_CHECKING='%s'}, $syntax_checking;
228  
229 0 ▶ my $lint = $ENV{LINT} // 'off';
Condition0%0/2
$ENV{"LINT"} // "off"
l!l
00
MC/DC0%0/1
$ENV{"LINT"} // "off"
$ENV{"LINT"}
Truth table0%0/2
A
A= $ENV{"LINT"}
Aresult
11
00
230 0 push @args, sprintf q{LINT='%s'}, $lint;
231  
232 0 push @args, grep {defined} $module_name_arg, $stub_arg;
233  
234 0 ▶ if ( $ENV{BUILD_MIRRORS} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ENV{'BUILD_MIRRORS'}) { } 0 0 0
elsif (-e "$pwd/build-mirrors") { } 0 0 0
235 0 open my $fh, '>', 'build-mirrors';
236 0 print {$fh} join "\n", split /,/xsm, $ENV{BUILD_MIRRORS};
237 0 close $fh;
238 }
239 elsif ( -e "$pwd/build-mirrors" ) {
240 0 copy( "$pwd/build-mirrors", 'build-mirrors' );
241 }
242  
243 0 my $rc = system 'make', @args;
244  
245 0 ▶ open STDOUT, '>&', $old_stdout or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $old_stdout or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
246 0 ▶ open STDERR, '>&', $old_stderr or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $old_stderr or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
247  
248 0 ▶ my ($tarball) = glob '*.tar.gz';
Subroutine BEGIN: called CC=1 SCAR=0.2
249  
250 0 ▶ if ($tarball) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tarball) { } 0 0 0
251 0 $self->get_logger->info("successfully created: $tarball!");
252 0 rename $tarball, 'tarball';
253 }
254 else {
255 0 $self->get_logger->error('Error creating distribution!');
256  
257 0 ▶ if ( !$self->get_debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->get_debug) { } 0 0 0
258 0 $self->get_logger->warn('to keep temporary install directory use --debug');
259 }
260 else {
261 0 $self->get_logger->warn( sprintf 'temporary directory %s. (see %s, %s)', $tmpdir, $logfile, $errfile );
262 }
263  
264 0 ▶ eval { $self->check_return_code($rc); 1; } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->check_return_code($rc); 1 } } or do { $self->get_logger->error($CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR) } 0 0 0
265 0 $self->get_logger->error($EVAL_ERROR);
266 };
267  
268 0 return $FAILURE;
269 }
270  
271 0 ▶ if ($post_build) {
Branch: 1 branch
BranchTrueFalseTotal
if ($post_build) 0 0 0
272 eval {
273 0 $post_build->($tmpdir);
274 0 1;
275 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { &$post_build($tmpdir); 1 } } or do { $self->get_logger->warn(sprintf('Post-build inspection failed: %s', $CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR)) } 0 0 0
276 0 $self->get_logger->warn( sprintf 'Post-build inspection failed: %s', $EVAL_ERROR );
277 };
278 }
279  
280 0 $self->get_logger->info('cleaning up...');
281  
282 0 ▶ open STDERR, '>>', $errfile or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">>", $errfile or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
283 0 ▶ open STDOUT, '>>', $logfile or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">>", $logfile or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
284  
285 0 $rc = system 'make clean';
286  
287 0 ▶ open STDERR, '>&', $old_stderr or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDERR, ">&", $old_stderr or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
288 0 ▶ open STDOUT, '>&', $old_stdout or die $OS_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
open STDOUT, ">&", $old_stdout or die $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR 0 0 0
289  
290 0 rename 'tarball', $tarball;
291  
292 0 $self->get_logger->info(q{creating default 'config.mk'...edit to customize make defaults});
293  
294 0 $self->_create_default_config($module_name);
295  
296 0 ▶ if ( $self->get_log_level eq 'debug' && $self->get_debug ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_log_level eq "debug" and $self->get_debug) 0 0 0
Condition0%0/3
$self->get_log_level eq "debug" and $self->get_debug
!ll&&!rl&&r
000
MC/DC0%0/2
$self->get_log_level eq "debug" and $self->get_debug
$self->get_log_level eq "debug" $self->get_debug
Truth table0%0/3
A and B
A= $self->get_log_level eq "debug"B= $self->get_debug
ABresult
0X0
100
111
297 0 $self->get_logger->warn( sprintf 'debug level set...leaving files in %s', $tmpdir );
298 }
299  
300 # cleanup intermediate and possibly existing files
301 0 foreach my $f (qw(resources buildspec.yml.tmpl test.t.tmpl provides module.pm.tmpl extra-files)) {
302 0 unlink $f;
303 }
304  
305 0 ▶ if ( -d "$tmpdir/local" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$tmpdir/local") 0 0 0
306 0 remove_tree("$tmpdir/local");
307 }
308  
309 0 rename "$tmpdir/$errfile", "$tmpdir/make.err";
310 0 rename "$tmpdir/$logfile", "$tmpdir/make.log";
311  
312 0 ▶ if ( $self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_project_tarball) { } 0 0 0
313 eval {
314 0 $self->_create_project_tarball( $tmpdir, $module_name, $pwd );
315 0 1;
316 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->_create_project_tarball($tmpdir, $module_name, $pwd); 1 } } or do { $self->get_logger->error($CPAN::Maker::Bootstrapper::Role::Installer::EVAL_ERROR); return $CPAN::Maker::Bootstrapper::Role::Installer::FAILURE } 0 0 0
317 0 $self->get_logger->error($EVAL_ERROR);
318 0 return $FAILURE;
319 };
320 }
321 else {
322 0 $self->get_logger->info("installing project to $installdir...");
323  
324 0 require File::Copy::Recursive;
325  
326 File::Copy::Recursive::dircopy( $tmpdir, $installdir )
327 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::Recursive::dircopy($tmpdir, $installdir) or do { $self->get_logger->error(sprintf("ERROR: could not copy $tmpdir to ${installdir}: %s\n", $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)); return $CPAN::Maker::Bootstrapper::Role::Installer::FAILURE } 0 0 0
328 0 $self->get_logger->error( sprintf "ERROR: could not copy $tmpdir to $installdir: %s\n", $OS_ERROR );
329 0 return $FAILURE;
330 };
331  
332 }
333  
334 0 ▶ if ( $self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_project_tarball) { } 0 0 0
335 0 $self->get_logger->info( sprintf 'successfully created CPAN::Maker::Bootstrapper project tarball for %s', $module_name );
336 0 $self->_report_import_errors();
337 0 $self->get_logger->info('next steps:');
338 0 $self->get_logger->info('+-------------------------------------------------------+');
339 0 $self->get_logger->info('| 1. Extract the project tarball |');
340 0 $self->get_logger->info('| 2. Review source tree |');
341 0 $self->get_logger->info('| 3. Review `buildspec.yml` |');
342 0 $self->get_logger->info('| 4. Edit/Add files to lib, bin, t or root |');
343 0 $self->get_logger->info('| 5. run `make` |');
344 0 $self->get_logger->info('+-------------------------------------------------------+');
345 }
346 else {
347 0 $self->get_logger->info("successfully imported $module_name");
348 0 $self->_report_import_errors();
349 0 $self->get_logger->info('next steps:');
350 0 $self->get_logger->info('+-------------------------------------------------------+');
351 0 $self->get_logger->info('| 1. Review source tree |');
352 0 $self->get_logger->info('| 2. Review `buildspec.yml` |');
353 0 $self->get_logger->info('| 3. Edit/Add files to lib, bin, t or root |');
354 0 $self->get_logger->info('| 4. run `make` |');
355 0 $self->get_logger->info('+-------------------------------------------------------+');
356 }
357  
358 0 $self->get_logger->info('| Tip: type "make help" to see all make targets |');
359 0 $self->get_logger->info('| See "perldoc CPAN::Maker::Bootstrapper" to learn more |');
360 0 $self->get_logger->info('+-------------------------------------------------------+');
361 0 $self->get_logger->info('| https://github.com/rlauer6/CPAN-Maker-Bootstrapper |');
362 0 $self->get_logger->info('+-------------------------------------------------------+');
363  
364 0 return $SUCCESS;
365 }
366  
367 ########################################################################
368 0 ▶sub _resolve_install_dir {
Subroutine _resolve_install_dir: not called CC=2 SCAR=17.9
369 ########################################################################
370 0 my ( $self, $module_name ) = @_;
371  
372 0 my $installdir = $self->get_installdir;
373  
374 0 ▶ if ( !$installdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($installdir) 0 0 0
375 0 $installdir = $module_name;
376 0 $installdir =~ s/::/-/gxsm;
377 0 $installdir = sprintf '%s/%s', $self->get_basedir, $installdir;
378 }
379  
380 0 return File::Spec->canonpath( File::Spec->rel2abs($installdir) );
381 }
382  
383 ########################################################################
384 0 ▶sub _create_default_config {
Subroutine _create_default_config: not called CC=2 SCAR=17.9
385 ########################################################################
386 0 my ( $self, $module_name ) = @_;
387  
388 0 my $default_config = <<"END_OF_CONFIG";
389 SYNTAX_CHECKING ?= on
390 LINT ?= on
391 SCAN ?= on
392 MODULE_NAME ?= $module_name
393 END_OF_CONFIG
394  
395 {
396 0 open my $fh, '>', 'config.mk'
397 0 ▶ or do {
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "config.mk" or do { $self->get_logger->warn(sprintf(q[WARN: could not open 'config.mk' for writing: %s], $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)) } 0 0 0
398 0 $self->get_logger->warn( sprintf q{WARN: could not open 'config.mk' for writing: %s}, $OS_ERROR );
399 };
400  
401 0 print {$fh} $default_config;
402  
403 0 close $fh;
404 }
405  
406 0 return;
407 }
408  
409 ########################################################################
410 0 ▶sub _validate_import_paths {
Subroutine _validate_import_paths: not called CC=5 SCAR=34.0
411 ########################################################################
412 0 my ( $self, $import_paths ) = @_;
413  
414 0 my @validated;
415 0 my $valid = $TRUE;
416  
417 0 foreach my $path ( @{$import_paths} ) {
418  
419 0 ▶ if ( !-d $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 0 0 0
420 0 $self->get_logger->error( sprintf "ERROR: import path '%s' is not a directory", $path );
421  
422 0 $valid = $FALSE;
423 0 next;
424 }
425  
426 0 my $abs_path = abs_path($path);
427  
428 0 ▶ if ( !$abs_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($abs_path) 0 0 0
429 0 $self->get_logger->error( sprintf "ERROR: could not resolve import path '%s'", $path );
430  
431 0 $valid = $FALSE;
432 0 next;
433 }
434  
435 0 push @validated, $abs_path;
436 }
437  
438 return
439 0 ▶ if !$valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 0 0 0
440  
441 0 return \@validated;
442 }
443  
444 ########################################################################
445 0 ▶sub _validate_import_destination {
Subroutine _validate_import_destination: not called CC=4 SCAR=30.0
446 ########################################################################
447 0 my ( $self, $installdir, $import_paths ) = @_;
448  
449 0 foreach my $import_path ( @{$import_paths} ) {
450 0 my $source = abs_path($import_path);
451  
452 0 my $relative = File::Spec->abs2rel( $installdir, $source );
453 0 $relative =~ s{\\}{/}gxsm;
454  
455 0 ▶ if ( $relative eq '.' || $relative !~ m{\A[.][.](?:/|\z)}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative eq "." or not $relative =~ m[\A[.][.](?:/|\z)]msx) 0 0 0
Condition0%0/3
$relative eq "." or not $relative =~ m[\A[.][.](?:/|\z)]msx
l!l&&r!l&&!r
000
MC/DC0%0/2
$relative eq "." or not $relative =~ m[\A[.][.](?:/|\z)]msx
$relative eq "." not $relative =~ m[\A[.][.](?:/|\z)]msx
Truth table0%0/3
A or not(B)
A= $relative eq "."B= not $relative =~ m[\A[.][.](?:/|\z)]msx
ABresult
1X1
011
000
456 0 croak sprintf
457 "ERROR: installation directory '%s' is inside import directory '%s'\n",
458 $installdir,
459 $source;
460 }
461 }
462  
463 0 return;
464 }
465  
466 ########################################################################
467 0 ▶sub _create_install_dir {
Subroutine _create_install_dir: not called CC=7 SCAR=40.3
468 ########################################################################
469 0 my ( $self, $module_name ) = @_;
470  
471 0 my $installdir = $self->_resolve_install_dir($module_name);
472  
473 0 $self->set_installdir($installdir);
474  
475 0 ▶ croak "ERROR: could not create $installdir\n$OS_ERROR"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $installdir or make_path($installdir) 0 0 0
Condition0%0/3
-d $installdir or make_path($installdir)
l!l&&r!l&&!r
000
MC/DC0%0/2
-d $installdir or make_path($installdir)
-d $installdir make_path($installdir)
Truth table0%0/3
A or B
A= -d $installdirB= make_path($installdir)
ABresult
1X1
011
000
476 if !-d $installdir && !make_path($installdir);
477  
478 0 $self->get_logger->info( sprintf 'attempting to install module %s into %s', $module_name, $installdir );
479  
480 0 ▶ return $installdir
Branch: 1 branch
BranchTrueFalseTotal
if -d $installdir and not -e "$installdir/Makefile" 0 0 0
Condition0%0/3
-d $installdir and not -e "$installdir/Makefile"
!ll&&!rl&&r
000
MC/DC0%0/2
-d $installdir and not -e "$installdir/Makefile"
-d $installdir not -e "$installdir/Makefile"
Truth table0%0/3
A and not(B)
A= -d $installdirB= not -e "$installdir/Makefile"
ABresult
0X0
100
111
481 if -d $installdir && !-e "$installdir/Makefile";
482  
483 0 ▶ croak sprintf 'ERROR: could not create %s', $installdir
Branch: 1 branch
BranchTrueFalseTotal
unless -d $installdir 0 0 0
484 if !-d $installdir;
485  
486 0 ▶ croak sprintf q{ERROR: Found '%s/Makefile' - project may already exist! Use --force to overwrite}, $installdir
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get_force 0 0 0
487 if !$self->get_force;
488  
489 0 $self->_remove_existing_files($installdir);
490  
491 0 return $installdir;
492 }
493  
494 ########################################################################
495 0 ▶sub _remove_existing_files {
Subroutine _remove_existing_files: not called CC=2 SCAR=17.9
496 ########################################################################
497 0 my ( $self, $installdir ) = @_;
498  
499 # remove existing files
500 0 unlink "$installdir/Makefile";
501 0 unlink "$installdir/buildspec.yml";
502  
503 0 foreach ( glob "$installdir/.includes/*" ) {
504 0 unlink $_;
505 }
506  
507 0 $self->get_logger->warn('existing files will be overwritten...you have been warned');
508  
509 0 return;
510 }
511 ########################################################################
512 0 ▶sub check_return_code {
Subroutine check_return_code: not called CC=4 SCAR=30.0
Pod undocumented
513 ########################################################################
514 0 my ( $self, $rc ) = @_;
515  
516 0 ▶ croak "ERROR: could not execute make: $OS_ERROR\n"
Branch: 1 branch
BranchTrueFalseTotal
if $rc == -1 0 0 0
517 if $rc == -1;
518  
519 0 ▶ croak sprintf "ERROR: make killed by signal %d\n", $rc & 127
Branch: 1 branch
BranchTrueFalseTotal
if $rc & 127 0 0 0
520 if $rc & 127;
521  
522 0 ▶ croak sprintf "ERROR: make failed with exit code %d\n", $rc >> 8
Branch: 1 branch
BranchTrueFalseTotal
if $rc >> 8 0 0 0
523 if $rc >> 8;
524  
525 0 return;
526 }
527  
528 ########################################################################
529 0 ▶sub _validate_module {
Subroutine _validate_module: not called CC=5 SCAR=34.0
530 ########################################################################
531 0 my ( $self, $module_name ) = @_;
532  
533 0 my $module_path = $module_name;
534 0 $module_path =~ s/::/\//xsmg;
535 0 $module_path = "$module_path.pm";
536  
537 0 ▶ my $import_paths = $self->get_import // [];
Condition0%0/2
$self->get_import // []
l!l
00
MC/DC0%0/1
$self->get_import // []
$self->get_import
Truth table0%0/2
A
A= $self->get_import
Aresult
11
00
538  
539 0 ▶ $import_paths = ref $import_paths ? $import_paths : [$import_paths];
Branch: 1 branch
BranchTrueFalseTotal
ref $import_paths ? : 0 0 0
540  
541 # return $module_name if no import paths (stub?)
542 return "lib/$module_name"
543 0 ▶ if !@{$import_paths};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$import_paths;} 0 0 0
544  
545 0 my $found;
546  
547 0 foreach my $import_path ( @{$import_paths} ) {
548 0 my $abs_path = abs_path($import_path);
549  
550 find(
551 { no_chdir => 1,
552  
553 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
554 0 my $name = $File::Find::name;
555  
556 0 ▶ if ( -d $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $name) 0 0 0
557 0 ▶ if ( $self->_exclude_import_dir( $name, $abs_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude_import_dir($name, $abs_path)) 0 0 0
558 0 $File::Find::prune = $TRUE;
559 }
560  
561 0 return;
562 }
563  
564 return
565 0 ▶ if $name !~ m{(?:\A|/)\Q$module_path\E\z}xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ m[(?:\A|/)\Q$module_path\E\z]msx 0 0 0
566  
567 0 $found = [$name];
568 },
569 },
570 0 $abs_path,
571 );
572 }
573  
574 0 return $found;
575 }
576  
577 ########################################################################
578 0 ▶sub _create_dirs {
Subroutine _create_dirs: not called CC=3 SCAR=24.8
579 ########################################################################
580 0 my ($self) = @_;
581  
582 0 my $installdir = $self->get_installdir;
583  
584 0 my @dirs = ( $installdir, map {"$installdir/$_"} qw(t lib bin .includes) );
585  
586 0 make_path(@dirs);
587  
588 0 foreach (@dirs) {
589 0 ▶ croak "ERROR: could not create $_\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $_ 0 0 0
590 if !-d $_;
591 }
592  
593 0 return;
594 }
595  
596 ########################################################################
597 0 ▶sub _install_files {
Subroutine _install_files: not called CC=9 SCAR=45.0
598 ########################################################################
599 0 my ($self) = @_;
600  
601 0 my $installdir = $self->get_installdir;
602  
603 0 my $dist_dir = $self->get_dist_dir;
604  
605 0 my @manifest = split /\n/xsm, slurp("$dist_dir/MANIFEST");
606  
607 0 foreach (@manifest) {
608 0 ▶ croak "ERROR: MANIFEST contains corrupted entry ($_)\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ m[\A[[:alnum:]][[:alnum:]._-]*(?:/[[:alnum:]][[:alnum:]._-]*)*\z]msx 0 0 0
609 if $_ !~ m{\A[[:alnum:]][[:alnum:]._-]*(?:/[[:alnum:]][[:alnum:]._-]*)*\z}xsm;
610  
611 0 ▶ croak "ERROR: $_ is not found in the distribution. MANIFEST may be corrupted.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e "$dist_dir/$_" 0 0 0
612 if !-e "$dist_dir/$_";
613  
614 0 ▶ if (/[.]mk$/xsm) {
Branch: 1 branch
BranchTrueFalseTotal
if (/[.]mk$/msx) { } 0 0 0
615 0 ▶ croak "ERROR: could not copy $dist_dir/$_ to $installdir/.includes/$_\n"
Branch: 1 branch
BranchTrueFalseTotal
unless copy("$dist_dir/$_", "$installdir/.includes/$_") 0 0 0
616 if !copy( "$dist_dir/$_", "$installdir/.includes/$_" );
617 0 chmod 0444, "$installdir/.includes/$_";
618 }
619 else {
620 0 ▶ croak "ERROR: could not copy $dist_dir/$_ to $installdir/$_\n"
Branch: 1 branch
BranchTrueFalseTotal
unless copy("$dist_dir/$_", "$installdir/$_") 0 0 0
621 if !copy( "$dist_dir/$_", "$installdir/$_" );
622 }
623 }
624  
625 # no need to check file existence, copy will fail above or rename will fail and be caught
626 0 ▶ rename "$installdir/Makefile.txt", "$installdir/Makefile"
Branch: 1 branch
BranchTrueFalseTotal
rename "$installdir/Makefile.txt", "$installdir/Makefile" or croak("ERROR: error renaming $installdir/Makefile.txt to $installdir/Makefile: $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR\n") 0 0 0
627 or croak "ERROR: error renaming $installdir/Makefile.txt to $installdir/Makefile: $OS_ERROR\n";
628  
629 0 chmod 0444, "$installdir/Makefile";
630 0 chmod 0555, "$installdir/builder";
631  
632 0 ▶ rename "$installdir/gitignore", "$installdir/.gitignore"
Branch: 1 branch
BranchTrueFalseTotal
rename "$installdir/gitignore", "$installdir/.gitignore" or croak("ERROR: error renaming $installdir/gitignore to $installdir/.gitignore: $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR\n") 0 0 0
633 or croak "ERROR: error renaming $installdir/gitignore to $installdir/.gitignore: $OS_ERROR\n";
634  
635 0 return;
636 }
637  
638 ########################################################################
639 0 ▶sub _import_files {
Subroutine _import_files: not called CC=7 SCAR=40.3
640 ########################################################################
641 0 my ($self) = @_;
642  
643 0 my $installdir = $self->get_installdir;
644  
645 0 my $import_listing = $self->get_import_file_listing;
646  
647 return
648 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
649  
650 0 $self->get_logger->info('Importing files...');
651  
652 0 my $files = $import_listing->{files};
653  
654 0 my @scripts = grep { $_->{class} eq 'script' } @{$files};
655  
656 0 ▶ if (@scripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@scripts) 0 0 0
657 0 my $gitignore = slurp("$installdir/.gitignore");
658  
659 0 ▶ if ( $gitignore !~ /\n\z/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gitignore =~ /\n\z/msx) 0 0 0
660 0 $gitignore .= "\n";
661 }
662  
663 $gitignore .= join "\n", map {
664 0 ( my $generated = $_->{destination} ) =~ s/[.]in\z//xsm;
665 0 $generated;
666 } @scripts;
667  
668 0 $gitignore .= "\n";
669  
670 0 ▶ open my $fh, '>', "$installdir/.gitignore"
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$installdir/.gitignore" or croak("ERROR: could not replace .gitignore: $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR\n") 0 0 0
671 or croak "ERROR: could not replace .gitignore: $OS_ERROR\n";
672  
673 0 print {$fh} $gitignore;
674  
675 0 close $fh;
676 }
677  
678 0 foreach my $file ( @{$files} ) {
679 0 my $source = $file->{source};
680 0 my $dest = sprintf '%s/%s', $installdir, $file->{destination};
681  
682 0 make_path( dirname($dest) );
683  
684 0 $self->get_logger->debug( sprintf 'copying %s => %s', $source, $dest );
685  
686 0 ▶ croak sprintf "ERROR: error copying %s to %s\n", $source, $dest
Branch: 1 branch
BranchTrueFalseTotal
unless copy($source, $dest) 0 0 0
687 if !copy( $source, $dest );
688  
689 0 chmod 0644, $dest;
690 }
691  
692 0 return;
693 }
694  
695 ########################################################################
696 0 ▶sub _report_import_plan {
Subroutine _report_import_plan: not called CC=4 SCAR=30.0
697 ########################################################################
698 0 my ($self) = @_;
699  
700 0 my $import_listing = $self->get_import_file_listing;
701  
702 return
703 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
704  
705 0 my $files = $import_listing->{files};
706  
707 0 $self->get_logger->info('Import plan:');
708  
709 0 foreach my $file ( @{$files} ) {
710 0 my $message = sprintf '%-12s %s -> %s', $file->{class}, $file->{source}, $file->{destination};
711  
712 0 ▶ if ( $file->{reason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{"reason"}) 0 0 0
713 0 $message .= sprintf ' (%s)', $file->{reason};
714 }
715  
716 0 $self->get_logger->info($message);
717 }
718  
719 0 return;
720 }
721  
722 ########################################################################
723 0 ▶sub _report_import_errors {
Subroutine _report_import_errors: not called CC=6 SCAR=37.4
724 ########################################################################
725 0 my ($self) = @_;
726  
727 0 my $import_listing = $self->get_import_file_listing;
728  
729 return
730 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
731  
732 0 my @errors = grep { $_->{class} eq 'import-error' } @{ $import_listing->{files} };
733  
734 return
735 0 ▶ if !@errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @errors 0 0 0
736  
737 0 ▶ $self->get_logger->warn(
Branch: 2 branches
BranchTrueFalseTotal
@errors == 1 ? : 0 0 0
@errors == 1 ? : 0 0 0
738 sprintf '%d imported file%s require%s manual review.',
739 scalar @errors,
740 @errors == 1 ? q{} : 's',
741 @errors == 1 ? 's' : q{},
742 );
743  
744 0 $self->get_logger->warn('Preserved under import-errors/:');
745  
746 0 foreach my $file (@errors) {
747 0 $self->get_logger->warn( sprintf ' %s (%s)', $file->{destination}, $file->{reason}, );
748 }
749  
750 0 $self->get_logger->warn('Review these files and place them manually.');
751  
752 0 return;
753 }
754  
755 ########################################################################
756 0 ▶sub _exclude_import_dir {
Subroutine _exclude_import_dir: not called CC=6 SCAR=37.4
757 ########################################################################
758 0 my ( $self, $name, $root ) = @_;
759  
760 0 my $relative = File::Spec->abs2rel( $name, $root );
761 0 $relative =~ s{\\}{/}gxsm;
762  
763 0 my %hard_excludes = map { $_ => 1 } qw(
764 .git
765 .hg
766 .svn
767 );
768  
769 return $TRUE
770 0 ▶ if $hard_excludes{ basename($name) };
Branch: 1 branch
BranchTrueFalseTotal
if $hard_excludes{basename($name)} 0 0 0
771  
772 0 ▶ foreach my $exclude ( @{ $self->get_exclude // [] } ) {
Condition0%0/2
$self->get_exclude // []
l!l
00
MC/DC0%0/1
$self->get_exclude // []
$self->get_exclude
Truth table0%0/2
A
A= $self->get_exclude
Aresult
11
00
773 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $relative eq $exclude 0 0 0
774 if $relative eq $exclude;
775  
776 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $relative =~ m[\A\Q$exclude\E/]msx 0 0 0
777 if $relative =~ m{\A\Q$exclude\E/}xsm;
778 }
779  
780 0 return $FALSE;
781 }
782  
783 ########################################################################
784 0 ▶sub _create_resources_file {
Subroutine _create_resources_file: not called CC=8 SCAR=42.8
785 ########################################################################
786 0 my ( $self, $module_name, $installdir ) = @_;
787  
788 0 my $project_name = $module_name;
789 0 $project_name =~ s/::/-/xsmg;
790  
791 0 my $github_user = $self->get_github_user;
792 0 ▶ warn "WARNING: no github_user found in config or passed. Using default (anonymouse). Edit resources.yml to fix.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $github_user 0 0 0
793 if !defined $github_user;
794  
795 0 ▶ $github_user //= 'anonymouse';
Condition0%0/2
$github_user //= "anonymouse"
l!l
00
MC/DC0%0/1
$github_user //= "anonymouse"
$github_user
Truth table0%0/2
A
A= $github_user
Aresult
11
00
796  
797 0 require Email::Valid;
798 0 require YAML::Tiny;
799  
800 0 my $email = $self->get_email;
801 0 ▶ croak "ERROR: invalid email address\n"
Branch: 1 branch
BranchTrueFalseTotal
if $email and not "Email::Valid"->address($email) 0 0 0
Condition0%0/3
$email and not "Email::Valid"->address($email)
!ll&&!rl&&r
000
MC/DC0%0/2
$email and not "Email::Valid"->address($email)
$email not "Email::Valid"->address($email)
Truth table0%0/3
A and not(B)
A= $emailB= not "Email::Valid"->address($email)
ABresult
0X0
100
111
802 if $email && !Email::Valid->address($email);
803  
804 0 ▶ my $resources = {
Branch: 1 branch
BranchTrueFalseTotal
$self->get_email ? : 0 0 0
805 bugtracker => {
806 web => sprintf( 'https://github.com/%s/%s/issues', $github_user, $project_name ),
807 $self->get_email ? ( mailto => $self->get_email ) : (),
808 },
809 repository => {
810 type => 'git',
811 url => sprintf( 'git@github.com:%s/%s.git', $github_user, $project_name ),
812 web => sprintf( 'https://github.com/%s/%s', $github_user, $project_name ),
813 },
814 homepage => sprintf( 'https://github.com/%s/%s', $github_user, $project_name ),
815 };
816  
817 0 ▶ open my $fh, '>', "$installdir/resources.yml"
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", "$installdir/resources.yml" or croak("ERROR: could not open resources.yml for writing: $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR\n") 0 0 0
818 or croak "ERROR: could not open resources.yml for writing: $OS_ERROR\n";
819  
820 0 my $yml = YAML::Tiny::Dump( { resources => $resources } );
821 0 $yml =~ s/^---\n//xsm;
822  
823 0 print {$fh} $yml;
824  
825 0 ▶ close $fh
Branch: 1 branch
BranchTrueFalseTotal
close $fh or warn "WARNING: could not close resources.yml: $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR\n" 0 0 0
826 or warn "WARNING: could not close resources.yml: $OS_ERROR\n";
827  
828 0 return;
829 }
830  
831 ########################################################################
832 0 ▶sub _import_file_listing {
Subroutine _import_file_listing: not called CC=16 SCAR=56.1
833 ########################################################################
834 0 my ($self) = @_;
835  
836 0 ▶ my @import_paths = ref $self->get_import ? @{ $self->get_import } : ( $self->get_import );
Branch: 1 branch
BranchTrueFalseTotal
ref $self->get_import ? : 0 0 0
837 0 $self->get_logger->debug( 'import paths: ' . join "\n", @import_paths );
838  
839 0 my @modules;
840 my %seen_sources;
841 0 my @scripts;
842  
843 0 my %tests = (
844 author => [],
845 release => [],
846 smoke => [],
847 t => [],
848 );
849  
850 0 my %file_packages;
851  
852 my @files;
853  
854 0 require File::Find;
855  
856 0 for my $path (@import_paths) {
857 0 my $abs_path = abs_path($path);
858  
859 0 ▶ croak "ERROR: import path '$path' is not a directory\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $abs_path 0 0 0
860 if !-d $abs_path;
861  
862 File::Find::find(
863 0 ▶ sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
864 0 my $name = $File::Find::name;
865  
866 0 ▶ if ( -d $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $name) 0 0 0
867 0 ▶ if ( $self->_exclude_import_dir( $name, $abs_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude_import_dir($name, $abs_path)) 0 0 0
868 0 $self->get_logger->debug( sprintf 'excluding directory %s', $name );
869 0 $File::Find::prune = $TRUE;
870 }
871  
872 0 return;
873 }
874  
875 return
876 0 ▶ if $seen_sources{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_sources{$name}++ 0 0 0
877  
878 0 my $relative = File::Spec->abs2rel( $name, $abs_path );
879 0 $relative =~ s{\\}{/}gxsm;
880  
881 0 my $is_executable = -x $name;
882  
883 0 $self->get_logger->debug(
884 Dumper(
885 [ name => $name,
886 is_executable => $is_executable,
887 ]
888 )
889 );
890  
891 0 ▶ if ( any { $relative eq $_ } qw(ChangeLog CHANGELOG Changes CHANGES) ) {
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (&any(sub { $relative eq $_; } , "ChangeLog", "CHANGELOG", "Changes", "CHANGES")) 0 0 0
892  
893 0 push @files,
894 {
895 class => 'project',
896 source => $name,
897 destination => $relative,
898 };
899  
900 0 return;
901 }
902  
903 0 my ($ext) = $name =~ /[.]([^.]+)\z/xsm;
904  
905 return
906 0 ▶ if !defined $ext || none { $ext eq $_ } qw(pm pl sh t dat);
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if not defined $ext or &none(sub { $ext eq $_; } , "pm", "pl", "sh", "t", "dat") 0 0 0
Condition0%0/3
not defined $ext or &none(sub { $ext eq $_; } , "pm", "pl", "sh", "t", "dat")
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $ext or &none(sub { $ext eq $_; } , "pm", "pl", "sh", "t", "dat")
not defined $ext &none(sub { $ext eq $_; } , "pm", "pl", "sh", "t", "dat")
Truth table0%0/3
not(A) or B
A= not defined $extB= &none(sub { $ext eq $_; } , "pm", "pl", "sh", "t", "dat")
ABresult
1X1
011
000
907  
908 return
909 0 ▶ if $self->_classify_test_file( $name, $relative, $path, \%tests );
Branch: 1 branch
BranchTrueFalseTotal
if $self->_classify_test_file($name, $relative, $path, \%tests) 0 0 0
910  
911 0 $self->get_logger->info( 'importing ' . $name );
912  
913 0 ▶ if ( $name =~ /[.]pm\z/xsm ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($name =~ /[.]pm\z/msx) { } 0 0 0
elsif ($name =~ /[.]pl\z/msx) { } 0 0 0
elsif ($name =~ /[.]t\z/msx) { } 0 0 0
914 0 push @modules,
915 {
916 source => $name,
917 relative => $relative,
918 import_root => $path,
919 };
920 }
921 elsif ( $name =~ /[.]pl\z/xsm ) {
922 0 push @scripts, { source => $name, import_root => $path, relative => $relative };
923 }
924 elsif ( $name =~ /[.]t\z/xsm ) {
925 # unclassified .t file (found somewhere we don't recognize?)
926 0 push @files,
927 {
928 class => 'import-error',
929 source => $name,
930 import_root => $path,
931 relative => $relative,
932 destination => $self->_import_error_destination(
933 { import_root => $path,
934 relative => $relative,
935 }
936 ),
937 reason => 'could not determine test classification',
938 };
939  
940 }
941 else {
942 0 push @scripts,
943 {
944 source => $name,
945 import_root => $path,
946 relative => $relative,
947 };
948 }
949 },
950 0 $abs_path
951 );
952 }
953  
954 0 require Module::Metadata;
955  
956 0 foreach my $module (@modules) {
957 0 my $source = $module->{source};
958  
959 0 my $meta = Module::Metadata->new_from_file($source);
960  
961 0 ▶ if ( !$meta ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta) 0 0 0
962 $file_packages{$source} = {
963 packages => [],
964 relative => $module->{relative},
965 reason => 'could not parse module metadata',
966 import_root => $module->{import_root},
967 0 };
968  
969 0 next;
970 }
971  
972 $file_packages{$source} = {
973 packages => [ $meta->packages_inside ],
974 relative => $module->{relative},
975 import_root => $module->{import_root},
976 0 };
977 }
978  
979 0 foreach my $source ( sort keys %file_packages ) {
980 0 my $module = $file_packages{$source};
981  
982 0 ▶ if ( $module->{reason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->{"reason"}) 0 0 0
983 push @files,
984 {
985 class => 'import-error',
986 source => $source,
987 destination => sprintf( 'import-errors/%s', $module->{relative} ),
988 import_root => $module->{import_root},
989 reason => $module->{reason},
990 0 };
991  
992 0 next;
993 }
994  
995 0 my $primary = $self->_find_primary_package( $source, $module->{packages}, );
996  
997 0 ▶ if ( !$primary ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($primary) 0 0 0
998 push @files,
999 {
1000 class => 'import-error',
1001 source => $source,
1002 destination => sprintf( 'import-errors/%s', $module->{relative} ),
1003 reason => 'could not determine primary package',
1004 import_root => $module->{import_root},
1005 0 };
1006  
1007 0 next;
1008 }
1009  
1010 0 ( my $module_path = $primary ) =~ s{::}{/}gxsm;
1011  
1012 push @files,
1013 {
1014 class => 'module',
1015 source => $source,
1016 import_root => $module->{import_root},
1017 0 destination => sprintf( 'lib/%s.pm.in', $module_path ),
1018 };
1019 }
1020  
1021 0 foreach my $script (@scripts) {
1022 push @files,
1023 {
1024 class => 'script',
1025 source => $script->{source},
1026 import_root => $script->{import_root},
1027 relative => $script->{relative},
1028 destination => sprintf 'bin/%s.in',
1029 0 basename( $script->{source} ),
1030 };
1031 }
1032  
1033 0 my %test_roots = (
1034 author => 'xt/author',
1035 release => 'xt/release',
1036 smoke => 'xt/smoke',
1037 t => 't',
1038 );
1039  
1040 0 foreach my $class ( sort keys %tests ) {
1041 0 foreach my $test ( @{ $tests{$class} } ) {
1042 push @files,
1043 {
1044 class => 'test',
1045 source => $test->{source},
1046 import_root => $test->{import_root},
1047 relative => $test->{relative},
1048 destination => sprintf '%s/%s',
1049 $test_roots{$class},
1050 $test->{relative},
1051 0 };
1052 }
1053 }
1054  
1055 0 my %destinations;
1056  
1057 0 foreach my $file (@files) {
1058 0 push @{ $destinations{ $file->{destination} } }, $file;
1059 }
1060  
1061 0 foreach my $destination ( keys %destinations ) {
1062 0 my $files = $destinations{$destination};
1063  
1064 next
1065 0 ▶ if @{$files} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$files;} == 1 0 0 0
1066  
1067 0 foreach my $file ( @{$files} ) {
1068 0 $file->{class} = 'import-error';
1069 0 $file->{destination} = $self->_import_error_destination($file);
1070 0 $file->{reason} = sprintf q{multiple imported files map to '%s'}, $destination;
1071 }
1072 }
1073  
1074 0 my $import_files = {
1075 files => \@files,
1076 packages => \%file_packages,
1077 };
1078  
1079 0 $self->set_import_file_listing($import_files);
1080  
1081 0 return;
1082 }
1083  
1084 ########################################################################
1085 0 ▶sub _import_error_destination {
Subroutine _import_error_destination: not called CC=1 SCAR=6.9
1086 ########################################################################
1087 0 my ( $self, $file ) = @_;
1088  
1089 0 my $root = $file->{import_root};
1090 0 $root =~ s{\\}{/}gxsm;
1091 0 $root =~ s{\A[.]/}{}xsm;
1092 0 $root =~ s{/+\z}{}xsm;
1093  
1094 0 return sprintf 'import-errors/%s/%s', $root, $file->{relative};
1095 }
1096  
1097 ########################################################################
1098 0 ▶sub _classify_test_file {
Subroutine _classify_test_file: not called CC=10 SCAR=47.0
1099 ########################################################################
1100 0 my ( $self, $name, $relative, $root, $tests ) = @_;
1101  
1102 return
1103 0 ▶ if $name !~ /[.](?:pm|pl|t)\z/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /[.](?:pm|pl|t)\z/msx 0 0 0
1104  
1105 0 ▶ if ( $relative =~ m{\At/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\At/(.+)\z]msx) 0 0 0
1106 0 push @{ $tests->{t} }, { source => $name, relative => $1, import_root => $root };
1107 0 return $TRUE;
1108 }
1109  
1110 0 ▶ if ( $relative =~ m{\Axt/author/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/author/(.+)\z]msx) 0 0 0
1111 0 push @{ $tests->{author} }, { source => $name, relative => $1, import_root => $root };
1112 0 return $TRUE;
1113 }
1114  
1115 0 ▶ if ( $relative =~ m{\Axt/release/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/release/(.+)\z]msx) 0 0 0
1116 0 push @{ $tests->{release} }, { source => $name, relative => $1, import_root => $root };
1117 0 return $TRUE;
1118 }
1119  
1120 0 ▶ if ( $relative =~ m{\Axt/smoke/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/smoke/(.+)\z]msx) 0 0 0
1121 0 push @{ $tests->{smoke} }, { source => $name, relative => $1, import_root => $root };
1122 0 return $TRUE;
1123 }
1124  
1125 0 my $test_root = $root;
1126 0 $test_root =~ s{\\}{/}gxsm;
1127 0 $test_root =~ s{/+\z}{}xsm;
1128  
1129 0 ▶ if ( $test_root =~ m{(?:\A|/)t\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_root =~ m[(?:\A|/)t\z]msx) 0 0 0
1130 0 push @{ $tests->{t} }, { source => $name, relative => $relative, import_root => $root };
1131 0 return $TRUE;
1132 }
1133  
1134 0 ▶ if ( $test_root =~ m{(?:\A|/)xt/author\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_root =~ m[(?:\A|/)xt/author\z]msx) 0 0 0
1135 0 push @{ $tests->{author} }, { source => $name, relative => $relative, import_root => $root };
1136 0 return $TRUE;
1137 }
1138  
1139 0 ▶ if ( $test_root =~ m{(?:\A|/)xt/release\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_root =~ m[(?:\A|/)xt/release\z]msx) 0 0 0
1140 0 push @{ $tests->{release} }, { source => $name, relative => $relative, import_root => $root };
1141 0 return $TRUE;
1142 }
1143  
1144 0 ▶ if ( $test_root =~ m{(?:\A|/)xt/smoke\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_root =~ m[(?:\A|/)xt/smoke\z]msx) 0 0 0
1145 0 push @{ $tests->{smoke} }, { source => $name, relative => $relative, import_root => $root };
1146 0 return $TRUE;
1147 }
1148  
1149 0 return;
1150 }
1151  
1152 ########################################################################
1153 8 ▶sub _find_primary_package {
Subroutine _find_primary_package: called CC=4 SCAR=13.9
1154 ########################################################################
1155 8 my ( $self, $path, $packages ) = @_;
1156  
1157 8 ( my $pkg_key = $path ) =~ s/\.pm(?:\.in)?$//xsm;
1158 8 $pkg_key =~ s{/}{::}xsmg;
1159 8 $pkg_key =~ s/\A:://xsm;
1160  
1161 8 my @reversed_key = reverse split /::/xsm, $pkg_key;
1162  
1163 8 my %reversed_packages = map { join( '::', reverse split /::/xsm, $_ ) => $_ } @{$packages};
1164  
1165 8 ▶ if ( $self->get_logger ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_logger) 8 0 8
1166 8 $self->get_logger->debug(
1167 Dumper(
1168 [ path => $path,
1169 packages => $packages,
1170 pkg_key => $pkg_key,
1171 reversed_key => \@reversed_key,
1172 reversed_packages => \%reversed_packages
1173 ]
1174 )
1175 );
1176 }
1177  
1178 8 for my $len ( reverse 1 .. scalar @reversed_key ) {
1179 16 my $candidate = join '::', @reversed_key[ 0 .. $len - 1 ];
1180  
1181 return $reversed_packages{$candidate}
1182 16 ▶ if exists $reversed_packages{$candidate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $reversed_packages{$candidate} 7 9 16
1183 }
1184  
1185 1 return;
1186 }
1187  
1188 ########################################################################
1189 0 ▶sub _tail_file {
Subroutine _tail_file: not called CC=2 SCAR=17.9
1190 ########################################################################
1191 0 my ( $self, $file, $nlines ) = @_;
1192  
1193 0 my @lines = split /\n/, slurp($file);
1194  
1195 0 my $start = max( 0, scalar(@lines) - $nlines );
1196  
1197 0 foreach my $line ( splice @lines, $start, $nlines ) {
1198 0 $self->get_logger->error($line);
1199 }
1200  
1201 0 return;
1202 }
1203  
1204 ########################################################################
1205 0 ▶sub _find_package_name {
Subroutine _find_package_name: not called CC=2 SCAR=17.9
1206 ########################################################################
1207 0 my ( $self, $file ) = @_;
1208  
1209 0 require Module::Metadata;
1210  
1211 0 ▶ my $meta = Module::Metadata->new_from_file($file)
Branch: 1 branch
BranchTrueFalseTotal
my $meta = "Module::Metadata"->new_from_file($file) or return 0 0 0
1212 or return;
1213  
1214 0 my ($package) = $meta->packages_inside;
1215  
1216 0 return $package;
1217 }
1218  
1219 ########################################################################
1220 0 ▶sub _create_project_tarball {
Subroutine _create_project_tarball: not called CC=5 SCAR=34.0
1221 ########################################################################
1222 0 my ( $self, $tmpdir, $module_name, $output_dir ) = @_;
1223  
1224 0 require Archive::Tar;
1225  
1226 0 my $project_name = $module_name;
1227 0 $project_name =~ s/::/-/gxsm;
1228  
1229 0 my $archive_name = sprintf '%s-cmb.tar.gz', $project_name;
1230 0 my $archive_path = File::Spec->catfile( $output_dir, $archive_name );
1231  
1232 0 my $stage_dir = File::Temp::tempdir( CLEANUP => $TRUE );
1233 0 my $project_dir = File::Spec->catdir( $stage_dir, $project_name );
1234  
1235 0 require File::Copy::Recursive;
1236  
1237 0 ▶ File::Copy::Recursive::dircopy( $tmpdir, $project_dir )
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::Recursive::dircopy($tmpdir, $project_dir) or croak(sprintf("ERROR: could not stage project for archive: %s\n", $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)) 0 0 0
1238 or croak sprintf "ERROR: could not stage project for archive: %s\n", $OS_ERROR;
1239  
1240 0 my $pwd = getcwd;
1241  
1242 0 ▶ chdir $stage_dir
Branch: 1 branch
BranchTrueFalseTotal
chdir $stage_dir or croak(sprintf("ERROR: could not change to %s: %s\n", $stage_dir, $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)) 0 0 0
1243 or croak sprintf "ERROR: could not change to %s: %s\n", $stage_dir, $OS_ERROR;
1244  
1245 0 my @files;
1246  
1247 File::Find::find(
1248 { no_chdir => 1,
1249  
1250 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1251 0 my $name = $File::Find::name;
1252  
1253 0 $name = File::Spec->abs2rel( $name, $stage_dir );
1254 0 $name =~ s{\\}{/}gxsm;
1255  
1256 0 push @files, $name;
1257  
1258 0 return;
1259 },
1260 },
1261 0 $project_dir,
1262 );
1263  
1264 0 my $tar = Archive::Tar->new;
1265  
1266 0 $tar->add_files(@files);
1267  
1268 0 ▶ croak sprintf "ERROR: could not create project tarball %s\n", $archive_path
Branch: 1 branch
BranchTrueFalseTotal
unless $tar->write($archive_path, Archive::Tar::COMPRESS_GZIP()) 0 0 0
1269 if !$tar->write( $archive_path, Archive::Tar::COMPRESS_GZIP() );
1270  
1271 0 ▶ chdir $pwd
Branch: 1 branch
BranchTrueFalseTotal
chdir $pwd or croak(sprintf("ERROR: could not change to %s: %s\n", $pwd, $CPAN::Maker::Bootstrapper::Role::Installer::OS_ERROR)) 0 0 0
1272 or croak sprintf "ERROR: could not change to %s: %s\n", $pwd, $OS_ERROR;
1273  
1274 0 $self->get_logger->info( sprintf 'successfully created project tarball: %s', $archive_path );
1275  
1276 0 return $archive_path;
1277 }
1278  
1279 1 1;
« CPAN/Maker/Bootstrapper/Role/ExtraFiles.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/Init.pm »