CPAN/Maker/Bootstrapper/Role/Installer.pm

filter: Statementstmt 11.4% 70 / 610 Branchbran 1.1% 3 / 252 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 33 Subroutinesub 39.5% 19 / 48 Podpod 0.0% 0 / 2 totaltotal 9.2% 92 / 999 CC 169 SCAR 58.8
CC
169
Cov
8%
_import_project
1424.5
cmd_install
552.0
_import_file_listing
272.0
CRAP 358.6
« CPAN/Maker/Bootstrapper/Role/ExtraFiles.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/LLM/ChangeLog.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.5.0';
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=38 SCAR=72.6
117 ########################################################################
118 0 my ( $self, %args ) = @_;
119  
120 0 my ( $module_name, $stub, $import_paths ) = @args{qw(module stub import_paths)};
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 $self->get_logger->info('cleaning up...');
272  
273 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
274 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
275  
276 0 $rc = system 'make clean';
277  
278 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
279 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
280  
281 0 rename 'tarball', $tarball;
282  
283 0 $self->get_logger->info(q{creating default 'config.mk'...edit to customize make defaults});
284  
285 0 $self->_create_default_config($module_name);
286  
287 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
288 0 $self->get_logger->warn( sprintf 'debug level set...leaving files in %s', $tmpdir );
289 }
290  
291 # cleanup intermediate and possibly existing files
292 0 foreach my $f (qw(resources buildspec.yml.tmpl test.t.tmpl provides module.pm.tmpl extra-files)) {
293 0 unlink $f;
294 }
295  
296 0 ▶ if ( -d "$tmpdir/local" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d "$tmpdir/local") 0 0 0
297 0 remove_tree("$tmpdir/local");
298 }
299  
300 0 rename "$tmpdir/$errfile", "$tmpdir/make.err";
301 0 rename "$tmpdir/$logfile", "$tmpdir/make.log";
302  
303 0 ▶ if ( $self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_project_tarball) { } 0 0 0
304 eval {
305 0 $self->_create_project_tarball( $tmpdir, $module_name, $pwd );
306 0 1;
307 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
308 0 $self->get_logger->error($EVAL_ERROR);
309 0 return $FAILURE;
310 };
311 }
312 else {
313 0 $self->get_logger->info("installing project to $installdir...");
314  
315 0 require File::Copy::Recursive;
316  
317 File::Copy::Recursive::dircopy( $tmpdir, $installdir )
318 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
319 0 $self->get_logger->error( sprintf "ERROR: could not copy $tmpdir to $installdir: %s\n", $OS_ERROR );
320 0 return $FAILURE;
321 };
322  
323 }
324  
325 0 ▶ if ( $self->get_project_tarball ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_project_tarball) { } 0 0 0
326 0 $self->get_logger->info( sprintf 'successfully created CPAN::Maker::Bootstrapper project tarball for %s', $module_name );
327 0 $self->_report_import_errors();
328 0 $self->get_logger->info('next steps:');
329 0 $self->get_logger->info('+-------------------------------------------------------+');
330 0 $self->get_logger->info('| 1. Extract the project tarball |');
331 0 $self->get_logger->info('| 2. Review source tree |');
332 0 $self->get_logger->info('| 3. Review `buildspec.yml` |');
333 0 $self->get_logger->info('| 4. Edit/Add files to lib, bin, t or root |');
334 0 $self->get_logger->info('| 5. run `make` |');
335 0 $self->get_logger->info('+-------------------------------------------------------+');
336 }
337 else {
338 0 $self->get_logger->info("successfully imported $module_name");
339 0 $self->_report_import_errors();
340 0 $self->get_logger->info('next steps:');
341 0 $self->get_logger->info('+-------------------------------------------------------+');
342 0 $self->get_logger->info('| 1. Review source tree |');
343 0 $self->get_logger->info('| 2. Review `buildspec.yml` |');
344 0 $self->get_logger->info('| 3. Edit/Add files to lib, bin, t or root |');
345 0 $self->get_logger->info('| 4. run `make` |');
346 0 $self->get_logger->info('+-------------------------------------------------------+');
347 }
348  
349 0 $self->get_logger->info('| Tip: type "make help" to see all make targets |');
350 0 $self->get_logger->info('| See "perldoc CPAN::Maker::Bootstrapper" to learn more |');
351 0 $self->get_logger->info('+-------------------------------------------------------+');
352 0 $self->get_logger->info('| https://github.com/rlauer6/CPAN-Maker-Bootstrapper |');
353 0 $self->get_logger->info('+-------------------------------------------------------+');
354  
355 0 return $SUCCESS;
356 }
357  
358 ########################################################################
359 0 ▶sub _resolve_install_dir {
Subroutine _resolve_install_dir: not called CC=2 SCAR=17.9
360 ########################################################################
361 0 my ( $self, $module_name ) = @_;
362  
363 0 my $installdir = $self->get_installdir;
364  
365 0 ▶ if ( !$installdir ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($installdir) 0 0 0
366 0 $installdir = $module_name;
367 0 $installdir =~ s/::/-/gxsm;
368 0 $installdir = sprintf '%s/%s', $self->get_basedir, $installdir;
369 }
370  
371 0 return File::Spec->canonpath( File::Spec->rel2abs($installdir) );
372 }
373  
374 ########################################################################
375 0 ▶sub _create_default_config {
Subroutine _create_default_config: not called CC=2 SCAR=17.9
376 ########################################################################
377 0 my ( $self, $module_name ) = @_;
378  
379 0 my $default_config = <<"END_OF_CONFIG";
380 SYNTAX_CHECKING ?= on
381 LINT ?= on
382 SCAN ?= on
383 MODULE_NAME ?= $module_name
384 END_OF_CONFIG
385  
386 {
387 0 open my $fh, '>', 'config.mk'
388 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
389 0 $self->get_logger->warn( sprintf q{WARN: could not open 'config.mk' for writing: %s}, $OS_ERROR );
390 };
391  
392 0 print {$fh} $default_config;
393  
394 0 close $fh;
395 }
396  
397 0 return;
398 }
399  
400 ########################################################################
401 0 ▶sub _validate_import_paths {
Subroutine _validate_import_paths: not called CC=5 SCAR=34.0
402 ########################################################################
403 0 my ( $self, $import_paths ) = @_;
404  
405 0 my @validated;
406 0 my $valid = $TRUE;
407  
408 0 foreach my $path ( @{$import_paths} ) {
409  
410 0 ▶ if ( !-d $path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $path) 0 0 0
411 0 $self->get_logger->error( sprintf "ERROR: import path '%s' is not a directory", $path );
412  
413 0 $valid = $FALSE;
414 0 next;
415 }
416  
417 0 my $abs_path = abs_path($path);
418  
419 0 ▶ if ( !$abs_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($abs_path) 0 0 0
420 0 $self->get_logger->error( sprintf "ERROR: could not resolve import path '%s'", $path );
421  
422 0 $valid = $FALSE;
423 0 next;
424 }
425  
426 0 push @validated, $abs_path;
427 }
428  
429 return
430 0 ▶ if !$valid;
Branch: 1 branch
BranchTrueFalseTotal
unless $valid 0 0 0
431  
432 0 return \@validated;
433 }
434  
435 ########################################################################
436 0 ▶sub _validate_import_destination {
Subroutine _validate_import_destination: not called CC=4 SCAR=30.0
437 ########################################################################
438 0 my ( $self, $installdir, $import_paths ) = @_;
439  
440 0 foreach my $import_path ( @{$import_paths} ) {
441 0 my $source = abs_path($import_path);
442  
443 0 my $relative = File::Spec->abs2rel( $installdir, $source );
444 0 $relative =~ s{\\}{/}gxsm;
445  
446 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
447 0 croak sprintf
448 "ERROR: installation directory '%s' is inside import directory '%s'\n",
449 $installdir,
450 $source;
451 }
452 }
453  
454 0 return;
455 }
456  
457 ########################################################################
458 0 ▶sub _create_install_dir {
Subroutine _create_install_dir: not called CC=7 SCAR=40.3
459 ########################################################################
460 0 my ( $self, $module_name ) = @_;
461  
462 0 my $installdir = $self->_resolve_install_dir($module_name);
463  
464 0 $self->set_installdir($installdir);
465  
466 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
467 if !-d $installdir && !make_path($installdir);
468  
469 0 $self->get_logger->info( sprintf 'attempting to install module %s into %s', $module_name, $installdir );
470  
471 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
472 if -d $installdir && !-e "$installdir/Makefile";
473  
474 0 ▶ croak sprintf 'ERROR: could not create %s', $installdir
Branch: 1 branch
BranchTrueFalseTotal
unless -d $installdir 0 0 0
475 if !-d $installdir;
476  
477 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
478 if !$self->get_force;
479  
480 0 $self->_remove_existing_files($installdir);
481  
482 0 return $installdir;
483 }
484  
485 ########################################################################
486 0 ▶sub _remove_existing_files {
Subroutine _remove_existing_files: not called CC=2 SCAR=17.9
487 ########################################################################
488 0 my ( $self, $installdir ) = @_;
489  
490 # remove existing files
491 0 unlink "$installdir/Makefile";
492 0 unlink "$installdir/buildspec.yml";
493  
494 0 foreach ( glob "$installdir/.includes/*" ) {
495 0 unlink $_;
496 }
497  
498 0 $self->get_logger->warn('existing files will be overwritten...you have been warned');
499  
500 0 return;
501 }
502 ########################################################################
503 0 ▶sub check_return_code {
Subroutine check_return_code: not called CC=4 SCAR=30.0
Pod undocumented
504 ########################################################################
505 0 my ( $self, $rc ) = @_;
506  
507 0 ▶ croak "ERROR: could not execute make: $OS_ERROR\n"
Branch: 1 branch
BranchTrueFalseTotal
if $rc == -1 0 0 0
508 if $rc == -1;
509  
510 0 ▶ croak sprintf "ERROR: make killed by signal %d\n", $rc & 127
Branch: 1 branch
BranchTrueFalseTotal
if $rc & 127 0 0 0
511 if $rc & 127;
512  
513 0 ▶ croak sprintf "ERROR: make failed with exit code %d\n", $rc >> 8
Branch: 1 branch
BranchTrueFalseTotal
if $rc >> 8 0 0 0
514 if $rc >> 8;
515  
516 0 return;
517 }
518  
519 ########################################################################
520 0 ▶sub _validate_module {
Subroutine _validate_module: not called CC=5 SCAR=34.0
521 ########################################################################
522 0 my ( $self, $module_name ) = @_;
523  
524 0 my $module_path = $module_name;
525 0 $module_path =~ s/::/\//xsmg;
526 0 $module_path = "$module_path.pm";
527  
528 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
529  
530 0 ▶ $import_paths = ref $import_paths ? $import_paths : [$import_paths];
Branch: 1 branch
BranchTrueFalseTotal
ref $import_paths ? : 0 0 0
531  
532 # return $module_name if no import paths (stub?)
533 return "lib/$module_name"
534 0 ▶ if !@{$import_paths};
Branch: 1 branch
BranchTrueFalseTotal
unless @{$import_paths;} 0 0 0
535  
536 0 my $found;
537  
538 0 foreach my $import_path ( @{$import_paths} ) {
539 0 my $abs_path = abs_path($import_path);
540  
541 find(
542 { no_chdir => 1,
543  
544 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
545 0 my $name = $File::Find::name;
546  
547 0 ▶ if ( -d $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $name) 0 0 0
548 0 ▶ if ( $self->_exclude_import_dir( $name, $abs_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude_import_dir($name, $abs_path)) 0 0 0
549 0 $File::Find::prune = $TRUE;
550 }
551  
552 0 return;
553 }
554  
555 return
556 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
557  
558 0 $found = [$name];
559 },
560 },
561 0 $abs_path,
562 );
563 }
564  
565 0 return $found;
566 }
567  
568 ########################################################################
569 0 ▶sub _create_dirs {
Subroutine _create_dirs: not called CC=3 SCAR=24.8
570 ########################################################################
571 0 my ($self) = @_;
572  
573 0 my $installdir = $self->get_installdir;
574  
575 0 my @dirs = ( $installdir, map {"$installdir/$_"} qw(t lib bin .includes) );
576  
577 0 make_path(@dirs);
578  
579 0 foreach (@dirs) {
580 0 ▶ croak "ERROR: could not create $_\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $_ 0 0 0
581 if !-d $_;
582 }
583  
584 0 return;
585 }
586  
587 ########################################################################
588 0 ▶sub _install_files {
Subroutine _install_files: not called CC=9 SCAR=45.0
589 ########################################################################
590 0 my ($self) = @_;
591  
592 0 my $installdir = $self->get_installdir;
593  
594 0 my $dist_dir = $self->get_dist_dir;
595  
596 0 my @manifest = split /\n/xsm, slurp("$dist_dir/MANIFEST");
597  
598 0 foreach (@manifest) {
599 0 ▶ croak "ERROR: MANIFEST contains corrupted entry ($_)\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $_ =~ m[\A[[:alnum:]][[:alnum:]._-]*(?:/[[:alnum:]][[:alnum:]._-]*)*\z]msx 0 0 0
600 if $_ !~ m{\A[[:alnum:]][[:alnum:]._-]*(?:/[[:alnum:]][[:alnum:]._-]*)*\z}xsm;
601  
602 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
603 if !-e "$dist_dir/$_";
604  
605 0 ▶ if (/[.]mk$/xsm) {
Branch: 1 branch
BranchTrueFalseTotal
if (/[.]mk$/msx) { } 0 0 0
606 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
607 if !copy( "$dist_dir/$_", "$installdir/.includes/$_" );
608 0 chmod 0444, "$installdir/.includes/$_";
609 }
610 else {
611 0 ▶ croak "ERROR: could not copy $dist_dir/$_ to $installdir/$_\n"
Branch: 1 branch
BranchTrueFalseTotal
unless copy("$dist_dir/$_", "$installdir/$_") 0 0 0
612 if !copy( "$dist_dir/$_", "$installdir/$_" );
613 }
614 }
615  
616 # no need to check file existence, copy will fail above or rename will fail and be caught
617 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
618 or croak "ERROR: error renaming $installdir/Makefile.txt to $installdir/Makefile: $OS_ERROR\n";
619  
620 0 chmod 0444, "$installdir/Makefile";
621 0 chmod 0555, "$installdir/builder";
622  
623 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
624 or croak "ERROR: error renaming $installdir/gitignore to $installdir/.gitignore: $OS_ERROR\n";
625  
626 0 return;
627 }
628  
629 ########################################################################
630 0 ▶sub _import_files {
Subroutine _import_files: not called CC=7 SCAR=40.3
631 ########################################################################
632 0 my ($self) = @_;
633  
634 0 my $installdir = $self->get_installdir;
635  
636 0 my $import_listing = $self->get_import_file_listing;
637  
638 return
639 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
640  
641 0 $self->get_logger->info('Importing files...');
642  
643 0 my $files = $import_listing->{files};
644  
645 0 my @scripts = grep { $_->{class} eq 'script' } @{$files};
646  
647 0 ▶ if (@scripts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@scripts) 0 0 0
648 0 my $gitignore = slurp("$installdir/.gitignore");
649  
650 0 ▶ if ( $gitignore !~ /\n\z/xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($gitignore =~ /\n\z/msx) 0 0 0
651 0 $gitignore .= "\n";
652 }
653  
654 $gitignore .= join "\n", map {
655 0 ( my $generated = $_->{destination} ) =~ s/[.]in\z//xsm;
656 0 $generated;
657 } @scripts;
658  
659 0 $gitignore .= "\n";
660  
661 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
662 or croak "ERROR: could not replace .gitignore: $OS_ERROR\n";
663  
664 0 print {$fh} $gitignore;
665  
666 0 close $fh;
667 }
668  
669 0 foreach my $file ( @{$files} ) {
670 0 my $source = $file->{source};
671 0 my $dest = sprintf '%s/%s', $installdir, $file->{destination};
672  
673 0 make_path( dirname($dest) );
674  
675 0 $self->get_logger->debug( sprintf 'copying %s => %s', $source, $dest );
676  
677 0 ▶ croak sprintf "ERROR: error copying %s to %s\n", $source, $dest
Branch: 1 branch
BranchTrueFalseTotal
unless copy($source, $dest) 0 0 0
678 if !copy( $source, $dest );
679  
680 0 chmod 0644, $dest;
681 }
682  
683 0 return;
684 }
685  
686 ########################################################################
687 0 ▶sub _report_import_plan {
Subroutine _report_import_plan: not called CC=4 SCAR=30.0
688 ########################################################################
689 0 my ($self) = @_;
690  
691 0 my $import_listing = $self->get_import_file_listing;
692  
693 return
694 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
695  
696 0 my $files = $import_listing->{files};
697  
698 0 $self->get_logger->info('Import plan:');
699  
700 0 foreach my $file ( @{$files} ) {
701 0 my $message = sprintf '%-12s %s -> %s', $file->{class}, $file->{source}, $file->{destination};
702  
703 0 ▶ if ( $file->{reason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file->{"reason"}) 0 0 0
704 0 $message .= sprintf ' (%s)', $file->{reason};
705 }
706  
707 0 $self->get_logger->info($message);
708 }
709  
710 0 return;
711 }
712  
713 ########################################################################
714 0 ▶sub _report_import_errors {
Subroutine _report_import_errors: not called CC=6 SCAR=37.4
715 ########################################################################
716 0 my ($self) = @_;
717  
718 0 my $import_listing = $self->get_import_file_listing;
719  
720 return
721 0 ▶ if !$import_listing;
Branch: 1 branch
BranchTrueFalseTotal
unless $import_listing 0 0 0
722  
723 0 my @errors = grep { $_->{class} eq 'import-error' } @{ $import_listing->{files} };
724  
725 return
726 0 ▶ if !@errors;
Branch: 1 branch
BranchTrueFalseTotal
unless @errors 0 0 0
727  
728 0 ▶ $self->get_logger->warn(
Branch: 2 branches
BranchTrueFalseTotal
@errors == 1 ? : 0 0 0
@errors == 1 ? : 0 0 0
729 sprintf '%d imported file%s require%s manual review.',
730 scalar @errors,
731 @errors == 1 ? q{} : 's',
732 @errors == 1 ? 's' : q{},
733 );
734  
735 0 $self->get_logger->warn('Preserved under import-errors/:');
736  
737 0 foreach my $file (@errors) {
738 0 $self->get_logger->warn( sprintf ' %s (%s)', $file->{destination}, $file->{reason}, );
739 }
740  
741 0 $self->get_logger->warn('Review these files and place them manually.');
742  
743 0 return;
744 }
745  
746 ########################################################################
747 0 ▶sub _exclude_import_dir {
Subroutine _exclude_import_dir: not called CC=6 SCAR=37.4
748 ########################################################################
749 0 my ( $self, $name, $root ) = @_;
750  
751 0 my $relative = File::Spec->abs2rel( $name, $root );
752 0 $relative =~ s{\\}{/}gxsm;
753  
754 0 my %hard_excludes = map { $_ => 1 } qw(
755 .git
756 .hg
757 .svn
758 );
759  
760 return $TRUE
761 0 ▶ if $hard_excludes{ basename($name) };
Branch: 1 branch
BranchTrueFalseTotal
if $hard_excludes{basename($name)} 0 0 0
762  
763 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
764 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $relative eq $exclude 0 0 0
765 if $relative eq $exclude;
766  
767 0 ▶ return $TRUE
Branch: 1 branch
BranchTrueFalseTotal
if $relative =~ m[\A\Q$exclude\E/]msx 0 0 0
768 if $relative =~ m{\A\Q$exclude\E/}xsm;
769 }
770  
771 0 return $FALSE;
772 }
773  
774 ########################################################################
775 0 ▶sub _create_resources_file {
Subroutine _create_resources_file: not called CC=8 SCAR=42.8
776 ########################################################################
777 0 my ( $self, $module_name, $installdir ) = @_;
778  
779 0 my $project_name = $module_name;
780 0 $project_name =~ s/::/-/xsmg;
781  
782 0 my $github_user = $self->get_github_user;
783 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
784 if !defined $github_user;
785  
786 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
787  
788 0 require Email::Valid;
789 0 require YAML::Tiny;
790  
791 0 my $email = $self->get_email;
792 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
793 if $email && !Email::Valid->address($email);
794  
795 0 ▶ my $resources = {
Branch: 1 branch
BranchTrueFalseTotal
$self->get_email ? : 0 0 0
796 bugtracker => {
797 web => sprintf( 'https://github.com/%s/%s/issues', $github_user, $project_name ),
798 $self->get_email ? ( mailto => $self->get_email ) : (),
799 },
800 repository => {
801 type => 'git',
802 url => sprintf( 'git@github.com:%s/%s.git', $github_user, $project_name ),
803 web => sprintf( 'https://github.com/%s/%s', $github_user, $project_name ),
804 },
805 homepage => sprintf( 'https://github.com/%s/%s', $github_user, $project_name ),
806 };
807  
808 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
809 or croak "ERROR: could not open resources.yml for writing: $OS_ERROR\n";
810  
811 0 my $yml = YAML::Tiny::Dump( { resources => $resources } );
812 0 $yml =~ s/^---\n//xsm;
813  
814 0 print {$fh} $yml;
815  
816 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
817 or warn "WARNING: could not close resources.yml: $OS_ERROR\n";
818  
819 0 return;
820 }
821  
822 ########################################################################
823 0 ▶sub _import_file_listing {
Subroutine _import_file_listing: not called CC=16 SCAR=56.1
824 ########################################################################
825 0 my ($self) = @_;
826  
827 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
828 0 $self->get_logger->debug( 'import paths: ' . join "\n", @import_paths );
829  
830 0 my @modules;
831 my %seen_sources;
832 0 my @scripts;
833  
834 0 my %tests = (
835 author => [],
836 release => [],
837 smoke => [],
838 t => [],
839 );
840  
841 0 my %file_packages;
842  
843 my @files;
844  
845 0 require File::Find;
846  
847 0 for my $path (@import_paths) {
848 0 my $abs_path = abs_path($path);
849  
850 0 ▶ croak "ERROR: import path '$path' is not a directory\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -d $abs_path 0 0 0
851 if !-d $abs_path;
852  
853 File::Find::find(
854 0 ▶ sub {
Subroutine __ANON__: not called CC=11 SCAR=48.8
855 0 my $name = $File::Find::name;
856  
857 0 ▶ if ( -d $name ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $name) 0 0 0
858 0 ▶ if ( $self->_exclude_import_dir( $name, $abs_path ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_exclude_import_dir($name, $abs_path)) 0 0 0
859 0 $self->get_logger->debug( sprintf 'excluding directory %s', $name );
860 0 $File::Find::prune = $TRUE;
861 }
862  
863 0 return;
864 }
865  
866 return
867 0 ▶ if $seen_sources{$name}++;
Branch: 1 branch
BranchTrueFalseTotal
if $seen_sources{$name}++ 0 0 0
868  
869 0 my $relative = File::Spec->abs2rel( $name, $abs_path );
870 0 $relative =~ s{\\}{/}gxsm;
871  
872 0 my $is_executable = -x $name;
873  
874 0 $self->get_logger->debug(
875 Dumper(
876 [ name => $name,
877 is_executable => $is_executable,
878 ]
879 )
880 );
881  
882 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
883  
884 0 push @files,
885 {
886 class => 'project',
887 source => $name,
888 destination => $relative,
889 };
890  
891 0 return;
892 }
893  
894 0 my ($ext) = $name =~ /[.]([^.]+)\z/xsm;
895  
896 return
897 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
898  
899 return
900 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
901  
902 0 $self->get_logger->info( 'importing ' . $name );
903  
904 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
905 0 push @modules,
906 {
907 source => $name,
908 relative => $relative,
909 import_root => $path,
910 };
911 }
912 elsif ( $name =~ /[.]pl\z/xsm ) {
913 0 push @scripts, { source => $name, import_root => $path, relative => $relative };
914 }
915 elsif ( $name =~ /[.]t\z/xsm ) {
916 # unclassified .t file (found somewhere we don't recognize?)
917 0 push @files,
918 {
919 class => 'import-error',
920 source => $name,
921 import_root => $path,
922 relative => $relative,
923 destination => $self->_import_error_destination(
924 { import_root => $path,
925 relative => $relative,
926 }
927 ),
928 reason => 'could not determine test classification',
929 };
930  
931 }
932 else {
933 0 push @scripts,
934 {
935 source => $name,
936 import_root => $path,
937 relative => $relative,
938 };
939 }
940 },
941 0 $abs_path
942 );
943 }
944  
945 0 require Module::Metadata;
946  
947 0 foreach my $module (@modules) {
948 0 my $source = $module->{source};
949  
950 0 my $meta = Module::Metadata->new_from_file($source);
951  
952 0 ▶ if ( !$meta ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($meta) 0 0 0
953 $file_packages{$source} = {
954 packages => [],
955 relative => $module->{relative},
956 reason => 'could not parse module metadata',
957 import_root => $module->{import_root},
958 0 };
959  
960 0 next;
961 }
962  
963 $file_packages{$source} = {
964 packages => [ $meta->packages_inside ],
965 relative => $module->{relative},
966 import_root => $module->{import_root},
967 0 };
968 }
969  
970 0 foreach my $source ( sort keys %file_packages ) {
971 0 my $module = $file_packages{$source};
972  
973 0 ▶ if ( $module->{reason} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->{"reason"}) 0 0 0
974 push @files,
975 {
976 class => 'import-error',
977 source => $source,
978 destination => sprintf( 'import-errors/%s', $module->{relative} ),
979 import_root => $module->{import_root},
980 reason => $module->{reason},
981 0 };
982  
983 0 next;
984 }
985  
986 0 my $primary = $self->_find_primary_package( $source, $module->{packages}, );
987  
988 0 ▶ if ( !$primary ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($primary) 0 0 0
989 push @files,
990 {
991 class => 'import-error',
992 source => $source,
993 destination => sprintf( 'import-errors/%s', $module->{relative} ),
994 reason => 'could not determine primary package',
995 import_root => $module->{import_root},
996 0 };
997  
998 0 next;
999 }
1000  
1001 0 ( my $module_path = $primary ) =~ s{::}{/}gxsm;
1002  
1003 push @files,
1004 {
1005 class => 'module',
1006 source => $source,
1007 import_root => $module->{import_root},
1008 0 destination => sprintf( 'lib/%s.pm.in', $module_path ),
1009 };
1010 }
1011  
1012 0 foreach my $script (@scripts) {
1013 push @files,
1014 {
1015 class => 'script',
1016 source => $script->{source},
1017 import_root => $script->{import_root},
1018 relative => $script->{relative},
1019 destination => sprintf 'bin/%s.in',
1020 0 basename( $script->{source} ),
1021 };
1022 }
1023  
1024 0 my %test_roots = (
1025 author => 'xt/author',
1026 release => 'xt/release',
1027 smoke => 'xt/smoke',
1028 t => 't',
1029 );
1030  
1031 0 foreach my $class ( sort keys %tests ) {
1032 0 foreach my $test ( @{ $tests{$class} } ) {
1033 push @files,
1034 {
1035 class => 'test',
1036 source => $test->{source},
1037 import_root => $test->{import_root},
1038 relative => $test->{relative},
1039 destination => sprintf '%s/%s',
1040 $test_roots{$class},
1041 $test->{relative},
1042 0 };
1043 }
1044 }
1045  
1046 0 my %destinations;
1047  
1048 0 foreach my $file (@files) {
1049 0 push @{ $destinations{ $file->{destination} } }, $file;
1050 }
1051  
1052 0 foreach my $destination ( keys %destinations ) {
1053 0 my $files = $destinations{$destination};
1054  
1055 next
1056 0 ▶ if @{$files} == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @{$files;} == 1 0 0 0
1057  
1058 0 foreach my $file ( @{$files} ) {
1059 0 $file->{class} = 'import-error';
1060 0 $file->{destination} = $self->_import_error_destination($file);
1061 0 $file->{reason} = sprintf q{multiple imported files map to '%s'}, $destination;
1062 }
1063 }
1064  
1065 0 my $import_files = {
1066 files => \@files,
1067 packages => \%file_packages,
1068 };
1069  
1070 0 $self->set_import_file_listing($import_files);
1071  
1072 0 return;
1073 }
1074  
1075 ########################################################################
1076 0 ▶sub _import_error_destination {
Subroutine _import_error_destination: not called CC=1 SCAR=6.9
1077 ########################################################################
1078 0 my ( $self, $file ) = @_;
1079  
1080 0 my $root = $file->{import_root};
1081 0 $root =~ s{\\}{/}gxsm;
1082 0 $root =~ s{\A[.]/}{}xsm;
1083 0 $root =~ s{/+\z}{}xsm;
1084  
1085 0 return sprintf 'import-errors/%s/%s', $root, $file->{relative};
1086 }
1087  
1088 ########################################################################
1089 0 ▶sub _classify_test_file {
Subroutine _classify_test_file: not called CC=10 SCAR=47.0
1090 ########################################################################
1091 0 my ( $self, $name, $relative, $root, $tests ) = @_;
1092  
1093 return
1094 0 ▶ if $name !~ /[.](?:pm|pl|t)\z/xsm;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /[.](?:pm|pl|t)\z/msx 0 0 0
1095  
1096 0 ▶ if ( $relative =~ m{\At/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\At/(.+)\z]msx) 0 0 0
1097 0 push @{ $tests->{t} }, { source => $name, relative => $1, import_root => $root };
1098 0 return $TRUE;
1099 }
1100  
1101 0 ▶ if ( $relative =~ m{\Axt/author/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/author/(.+)\z]msx) 0 0 0
1102 0 push @{ $tests->{author} }, { source => $name, relative => $1, import_root => $root };
1103 0 return $TRUE;
1104 }
1105  
1106 0 ▶ if ( $relative =~ m{\Axt/release/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/release/(.+)\z]msx) 0 0 0
1107 0 push @{ $tests->{release} }, { source => $name, relative => $1, import_root => $root };
1108 0 return $TRUE;
1109 }
1110  
1111 0 ▶ if ( $relative =~ m{\Axt/smoke/(.+)\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($relative =~ m[\Axt/smoke/(.+)\z]msx) 0 0 0
1112 0 push @{ $tests->{smoke} }, { source => $name, relative => $1, import_root => $root };
1113 0 return $TRUE;
1114 }
1115  
1116 0 my $test_root = $root;
1117 0 $test_root =~ s{\\}{/}gxsm;
1118 0 $test_root =~ s{/+\z}{}xsm;
1119  
1120 0 ▶ if ( $test_root =~ m{(?:\A|/)t\z}xsm ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($test_root =~ m[(?:\A|/)t\z]msx) 0 0 0
1121 0 push @{ $tests->{t} }, { source => $name, relative => $relative, import_root => $root };
1122 0 return $TRUE;
1123 }
1124  
1125 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
1126 0 push @{ $tests->{author} }, { source => $name, relative => $relative, import_root => $root };
1127 0 return $TRUE;
1128 }
1129  
1130 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
1131 0 push @{ $tests->{release} }, { source => $name, relative => $relative, import_root => $root };
1132 0 return $TRUE;
1133 }
1134  
1135 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
1136 0 push @{ $tests->{smoke} }, { source => $name, relative => $relative, import_root => $root };
1137 0 return $TRUE;
1138 }
1139  
1140 0 return;
1141 }
1142  
1143 ########################################################################
1144 8 ▶sub _find_primary_package {
Subroutine _find_primary_package: called CC=4 SCAR=13.9
1145 ########################################################################
1146 8 my ( $self, $path, $packages ) = @_;
1147  
1148 8 ( my $pkg_key = $path ) =~ s/\.pm(?:\.in)?$//xsm;
1149 8 $pkg_key =~ s{/}{::}xsmg;
1150 8 $pkg_key =~ s/\A:://xsm;
1151  
1152 8 my @reversed_key = reverse split /::/xsm, $pkg_key;
1153  
1154 8 my %reversed_packages = map { join( '::', reverse split /::/xsm, $_ ) => $_ } @{$packages};
1155  
1156 8 ▶ if ( $self->get_logger ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->get_logger) 8 0 8
1157 8 $self->get_logger->debug(
1158 Dumper(
1159 [ path => $path,
1160 packages => $packages,
1161 pkg_key => $pkg_key,
1162 reversed_key => \@reversed_key,
1163 reversed_packages => \%reversed_packages
1164 ]
1165 )
1166 );
1167 }
1168  
1169 8 for my $len ( reverse 1 .. scalar @reversed_key ) {
1170 16 my $candidate = join '::', @reversed_key[ 0 .. $len - 1 ];
1171  
1172 return $reversed_packages{$candidate}
1173 16 ▶ if exists $reversed_packages{$candidate};
Branch: 1 branch
BranchTrueFalseTotal
if exists $reversed_packages{$candidate} 7 9 16
1174 }
1175  
1176 1 return;
1177 }
1178  
1179 ########################################################################
1180 0 ▶sub _tail_file {
Subroutine _tail_file: not called CC=2 SCAR=17.9
1181 ########################################################################
1182 0 my ( $self, $file, $nlines ) = @_;
1183  
1184 0 my @lines = split /\n/, slurp($file);
1185  
1186 0 my $start = max( 0, scalar(@lines) - $nlines );
1187  
1188 0 foreach my $line ( splice @lines, $start, $nlines ) {
1189 0 $self->get_logger->error($line);
1190 }
1191  
1192 0 return;
1193 }
1194  
1195 ########################################################################
1196 0 ▶sub _find_package_name {
Subroutine _find_package_name: not called CC=2 SCAR=17.9
1197 ########################################################################
1198 0 my ( $self, $file ) = @_;
1199  
1200 0 require Module::Metadata;
1201  
1202 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
1203 or return;
1204  
1205 0 my ($package) = $meta->packages_inside;
1206  
1207 0 return $package;
1208 }
1209  
1210 ########################################################################
1211 0 ▶sub _create_project_tarball {
Subroutine _create_project_tarball: not called CC=5 SCAR=34.0
1212 ########################################################################
1213 0 my ( $self, $tmpdir, $module_name, $output_dir ) = @_;
1214  
1215 0 require Archive::Tar;
1216  
1217 0 my $project_name = $module_name;
1218 0 $project_name =~ s/::/-/gxsm;
1219  
1220 0 my $archive_name = sprintf '%s-cmb.tar.gz', $project_name;
1221 0 my $archive_path = File::Spec->catfile( $output_dir, $archive_name );
1222  
1223 0 my $stage_dir = File::Temp::tempdir( CLEANUP => $TRUE );
1224 0 my $project_dir = File::Spec->catdir( $stage_dir, $project_name );
1225  
1226 0 require File::Copy::Recursive;
1227  
1228 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
1229 or croak sprintf "ERROR: could not stage project for archive: %s\n", $OS_ERROR;
1230  
1231 0 my $pwd = getcwd;
1232  
1233 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
1234 or croak sprintf "ERROR: could not change to %s: %s\n", $stage_dir, $OS_ERROR;
1235  
1236 0 my @files;
1237  
1238 File::Find::find(
1239 { no_chdir => 1,
1240  
1241 0 ▶ wanted => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1242 0 my $name = $File::Find::name;
1243  
1244 0 $name = File::Spec->abs2rel( $name, $stage_dir );
1245 0 $name =~ s{\\}{/}gxsm;
1246  
1247 0 push @files, $name;
1248  
1249 0 return;
1250 },
1251 },
1252 0 $project_dir,
1253 );
1254  
1255 0 my $tar = Archive::Tar->new;
1256  
1257 0 $tar->add_files(@files);
1258  
1259 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
1260 if !$tar->write( $archive_path, Archive::Tar::COMPRESS_GZIP() );
1261  
1262 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
1263 or croak sprintf "ERROR: could not change to %s: %s\n", $pwd, $OS_ERROR;
1264  
1265 0 $self->get_logger->info( sprintf 'successfully created project tarball: %s', $archive_path );
1266  
1267 0 return $archive_path;
1268 }
1269  
1270 1 1;
« CPAN/Maker/Bootstrapper/Role/ExtraFiles.pm ↑ Summary CPAN/Maker/Bootstrapper/Role/LLM/ChangeLog.pm »