blib/lib/Shipwright/Source/Base.pm

filter: Statementstmt 15.4% 57 / 368 Branchbran 1.7% 3 / 176 Conditioncond 0.0% 0 / 95 MC/DCmcdc 0.0% 0 / 54 Subroutinesub 55.1% 16 / 29 Podpod 100% 5 / 5 totaltotal 11.1% 81 / 727 CC 138 SCAR 88.2
CC
138
Cov
9%
_follow
10660.9
_is_skipped
90.0
_lwp_get
56.0
CRAP 6752.7
↑ Summary blib/lib/Shipwright/Script/Import.pm »
1 package Shipwright::Source::Base;
2  
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use File::Spec::Functions qw/catfile catdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Module::CoreList;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Shipwright::Source;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use Cwd qw/getcwd/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Copy::Recursive qw/rcopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use base qw/Shipwright::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 3 __PACKAGE__->mk_accessors(
16 qw/source directory scripts_directory download_directory follow
17 min_perl_version map_path skip map skip_recommends skip_all_recommends
18 skip_installed include_dual_lifed
19 keep_build_requires name log url_path version_path branches_path version
20 skip_all_test_requires skip_all_build_requires installed
21 /
22 );
23  
24 =head1 NAME
25  
26 Shipwright::Source::Base - Base class of source
27  
28 =head1 SYNOPSIS
29  
30 =head1 METHODS
31  
32 =head2 new
33  
34 =cut
35  
36 10 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
37 10 my $class = shift;
38 10 my $self = {@_};
39 10 bless $self, $class;
40 10 $self->log( Log::Log4perl->get_logger( ref $self ) );
41 10 return $self;
42 }
43  
44 =head2 run
45  
46 =cut
47  
48 0 ▶sub run {
Subroutine run: not called CC=4 SCAR=30.0
Pod documented
49 0 my $self = shift;
50 0 my %args = @_;
51 0 for ( $self->_cmd ) {
52 0 ▶ if ( ref $_ eq 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq 'CODE') { } 0 0 0
53 0 $_->();
54 }
55 else {
56 0 run_cmd($_);
57 }
58 }
59 0 ▶ $self->_copy( %{ $args{copy} } ) if $args{copy};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"copy"} 0 0 0
60 }
61  
62 # you should subclass this method.
63 0 ▶sub _cmd { }
Subroutine _cmd: not called CC=1 SCAR=0.0
64  
65 0 ▶sub _follow {
Subroutine _follow: not called CC=105 SCAR=92.7
66 0 my $self = shift;
67 0 my $path = shift;
68 0 my $cwd = getcwd;
69 0 my $require_path = catfile( $path, '__require.yml' );
70 0 my $map = {};
71 0 my $url = {};
72  
73  
74 0 ▶ unless ( $self->min_perl_version ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->min_perl_version) 0 0 0
75 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
76 0 require Config;
77 0 require version;
78 0 my $version = version->new( $Config::Config{version} );
79 0 $self->min_perl_version( $version->numify );
80 }
81  
82 0 ▶ if ( -e $self->map_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->map_path) 0 0 0
83 0 $map = load_yaml_file( $self->map_path );
84 }
85  
86 0 ▶ if ( -e $self->url_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->url_path) 0 0 0
87 0 $url = load_yaml_file( $self->url_path );
88 }
89  
90 0 my @types = qw/requires configure_requires/;
91  
92 0 my $reverse_map = { reverse %$map };
93 my $skip_recommends = $self->skip_recommends->{ $self->name }
94 || ( $reverse_map->{ $self->name }
95 0 ▶ && $self->skip_recommends->{ $reverse_map->{ $self->name } } )
Condition0%0/9
$self->skip_recommends->{$self->name} || $$reverse_map{$self->name} && $self->skip_recommends->{$$reverse_map{$self->name}} || $self->skip_all_recommends
l!l&&r!l&&!r
000
$self->skip_recommends->{$self->name} or $$reverse_map{$self->name} and $self->skip_recommends->{$$reverse_map{$self->name}}
l!l&&r!l&&!r
000
$$reverse_map{$self->name} and $self->skip_recommends->{$$reverse_map{$self->name}}
!ll&&!rl&&r
000
MC/DC0%0/4
$self->skip_recommends->{$self->name} || $$reverse_map{$self->name} && $self->skip_recommends->{$$reverse_map{$self->name}} || $self->skip_all_recommends
$self->skip_recommends->{$self->name} $$reverse_map{$self->name} $self->skip_recommends->{$$reverse_map{$self->name}} $self->skip_all_recommends
Truth table0%0/6
A or B and C || D
A= $self->skip_recommends->{$self->name}B= $$reverse_map{$self->name}C= $self->skip_recommends->{$$reverse_map{$self->name}}D= $self->skip_all_recommends
ABCDresult
1XXX1
011X1
00X11
01011
00X00
01000
96 || $self->skip_all_recommends;
97 0 ▶ push @types, 'recommends' unless $skip_recommends;
Branch: 1 branch
BranchTrueFalseTotal
unless $skip_recommends 0 0 0
98 0 ▶ push @types, 'test_requires' unless $self->skip_all_test_requires;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->skip_all_test_requires 0 0 0
99 0 ▶ push @types, 'build_requires' unless $self->skip_all_build_requires;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->skip_all_build_requires 0 0 0
100  
101 0 ▶ if ( !-e $require_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $require_path) 0 0 0
102  
103 # if not found, we'll create one according to Build.PL or Makefile.PL
104 0 my $require = {};
105 0 chdir catdir($path);
106  
107 0 my $run_failed;
108 0 ▶ if ( $path =~ /\bcpan-Bundle-(.*)/ ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($path =~ /\bcpan-Bundle-(.*)/) { } 0 0 0
elsif (-e 'Build.PL') { } 0 0 0
elsif (-e 'Makefile.PL') { } 0 0 0
109 0 $self->log->info("$path is a CPAN Bundle distribution");
110  
111 0 my $file = $1;
112 0 $file =~ s!-!/!;
113 0 $file .= '.pm';
114  
115 # so it's a bundle module
116 0 ▶ open my $fh, '<', 'MANIFEST' or confess_or_die "no manifest found: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", "MANIFEST" or confess_or_die("no manifest found: $!") 0 0 0
117 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
118 0 chomp;
119 0 ▶ if (/$file/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/$file/) 0 0 0
120 0 $file = $_;
121 0 last;
122 }
123 }
124 0 ▶ open $fh, '<', $file or confess_or_die "can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or confess_or_die("can't open ${file}: $!") 0 0 0
125 0 my $flip;
126 0 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 0 0 0
127 0 chomp;
128 0 ▶ next if /^\s*$/;
Branch: 1 branch
BranchTrueFalseTotal
if /^\s*$/ 0 0 0
129  
130 0 ▶ if (/^=head1\s+CONTENTS/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^=head1\s+CONTENTS/) { } 0 0 0
elsif (/^=(?!head1\s+CONTENTS)/) { } 0 0 0
131 0 $flip = 1;
132 0 next;
133 }
134 elsif (/^=(?!head1\s+CONTENTS)/) {
135 0 $flip = 0;
136 }
137  
138 0 ▶ next unless $flip;
Branch: 1 branch
BranchTrueFalseTotal
unless $flip 0 0 0
139 0 my $info;
140 0 ▶ if (/(.*?)-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/(.*?)-/) { } 0 0 0
141  
142 # things following '-' are comments which we don't want here
143 0 $info = $1;
144 }
145 else {
146 0 $info = $_;
147 }
148 0 my ( $module, $version ) = split /\s+/, $info;
149 0 ▶ $require->{requires}{$module} = $version || 0;
Condition0%0/2
$version || 0
l!l
00
MC/DC0%0/1
$version || 0
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
150 }
151  
152 }
153 elsif ( -e 'Build.PL' ) {
154 0 $self->log->info("$path is a Module::Build based distribution");
155  
156 0 run_cmd(
157 [
158 $^X, '-Mversion',
159 '-MModule::Build', '-MShipwright::Util::CleanINC',
160 'Build.PL'
161 ],
162 1, # don't die if this fails
163 );
164 0 ▶ run_cmd( [ $^X, 'Build.PL' ] ) if $? || !-e 'Build';
Branch: 1 branch
BranchTrueFalseTotal
if $? or not -e "Build" 0 0 0
Condition0%0/3
$? or not -e "Build"
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or not -e "Build"
$? not -e "Build"
Truth table0%0/3
A or not(B)
A= $?B= not -e "Build"
ABresult
1X1
011
000
165 0 ▶ if ( -e catfile( '_build', 'prereqs' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile('_build', 'prereqs')) { } 0 0 0
166 0 ▶ my $source = read_file( catfile( '_build', 'prereqs' ) )
Branch: 1 branch
BranchTrueFalseTotal
my $source = read_file(catfile("_build", "prereqs")) or confess_or_die("can't read _build/prereqs: $!") 0 0 0
167 or confess_or_die "can't read _build/prereqs: $!";
168 0 my $eval = '$require = ' . $source;
169 0 ▶ eval "$eval;1" or confess_or_die "eval error: $@"; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "$eval;1" or confess_or_die("eval error: $@") 0 0 0
170 }
171 else {
172 # could be something else, e.g. Module::Build::Tiny
173 0 $run_failed = 1;
174 }
175  
176 0 run_cmd(
177 [ $^X, 'Build', 'realclean', '--allow_mb_mismatch', 1 ] );
178 }
179 elsif ( -e 'Makefile.PL' ) {
180 0 ▶ my $makefile = read_file('Makefile.PL')
Branch: 1 branch
BranchTrueFalseTotal
my $makefile = read_file("Makefile.PL") or confess_or_die("can't read Makefile.PL: $!") 0 0 0
181 or confess_or_die "can't read Makefile.PL: $!";
182 0 ▶ if ( $makefile =~ /inc::Module::Install/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($makefile =~ /inc::Module::Install/) { } 0 0 0
183 0 $self->log->info(
184 "$path is a Module::Install based distribution");
185  
186 # in case people call another file, which contains
187 # keywords like requires, features, etc
188 # see Task::Plack for a real example
189 0 ▶ while ( $makefile =~ /(do\s+(['"])(.*?)\2\s*;\s*$)/m ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($makefile =~ /(do\s+(['"])(.*?)\2\s*;\s*$)/m) 0 0 0
190 0 my $line = $1;
191 0 my $content = read_file($3);
192 0 $content =~ s/^__END__$ .*//xsmg;
193 0 $makefile =~ s/$line/$content;/;
194 }
195  
196 # PREREQ_PM in Makefile is not good enough for inc::Module::Install, which
197 # will omit features(..). we'll put deps in features(...) into recommends part
198  
199 0 $makefile =~ s/^\s*requires(?!\w)/shipwright_requires/mg;
200 0 $makefile =~ s/^\s*build_requires(?!\w)/shipwright_build_requires/mg;
201 0 $makefile =~ s/^\s*configure_requires(?!\w)/shipwright_configure_requires/mg;
202 0 $makefile =~
203 s/^\s*test_requires(?!\w)/shipwright_test_requires/mg;
204 0 $makefile =~ s/^\s*recommends(?!\w)/shipwright_recommends/mg;
205 0 $makefile =~ s/^\s*features(?!\w)/shipwright_features/mg;
206 0 $makefile =~ s/^\s*feature(?!\w)/shipwright_feature/mg;
207 0 $makefile =~
208 s/^\s*requires_from(?!\w)/shipwright_requires_from/mg;
209 0 $makefile =~
210 s/^\s*test_requires_from(?!\w)/shipwright_test_requires_from/mg;
211 0 my $shipwright_makefile = <<'EOF';
212 use Data::Dumper;
213 my $shipwright_req = {};
214  
215 sub _shipwright_requires {
216 my $type = shift;
217 my %req = @_;
218 for my $name ( keys %req ) {
219 $shipwright_req->{$type}{$name} = $req{$name};
220 }
221 }
222  
223 sub shipwright_requires {
224 _shipwright_requires( 'requires', @_ == 1 ? ( @_, 0 ) : @_ );
225 goto &requires;
226 }
227  
228 sub shipwright_build_requires {
229 _shipwright_requires( 'build_requires', @_ == 1 ? ( @_, 0 ) : @_ );
230 goto &build_requires;
231 }
232  
233 sub shipwright_configure_requires {
234 _shipwright_requires( 'configure_requires', @_ == 1 ? ( @_, 0 ) : @_ );
235 goto &configure_requires;
236 }
237  
238 sub shipwright_test_requires {
239 _shipwright_requires( 'test_requires', @_ == 1 ? ( @_, 0 ) : @_ );
240 goto &test_requires;
241 }
242  
243 sub _shipwright_requires_from {
244 my $type = shift;
245 my $file = shift;
246  
247 open my $fh, '<', $file or return;
248 my $content = do { local $/; <$fh> };
249 # the following lines in this sub are mostly stolen from Module::Install::Metadata
250 my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg;
251  
252 while ( @requires ) {
253 my $module = shift @requires;
254 my $version = shift @requires;
255 _shipwright_requires( $type, $module, $version || 0 );
256 }
257 }
258  
259 sub shipwright_test_requires_from {
260 _shipwright_requires_from( 'test_requires', @_ );
261 goto &test_requires_from;
262 }
263  
264 sub shipwright_requires_from {
265 _shipwright_requires_from( 'requires', @_ );
266 goto &requires_from;
267 }
268  
269 sub shipwright_recommends {
270 _shipwright_requires( 'recommends', @_ == 1 ? ( @_, 0 ) : @_ );
271 goto &recommends;
272 }
273  
274 sub shipwright_feature {
275 my ( $name, @mods ) = @_;
276 my $type = $name && $name ne '-core' ? 'recommends' : 'requires';
277 for ( my $i = 0 ; $i < @mods ; $i++ ) {
278 if ( $mods[$i] eq '-default' ) {
279 $i++; # skip the -default value
280 }
281 elsif ( $mods[ $i + 1 ] =~ /^[\d\.]*$/ ) {
282  
283 # index $i+1 is a version
284 $shipwright_req->{$type}{ $mods[$i] } = $mods[ $i + 1 ] || 0;
285 $i++;
286 }
287 else {
288 $shipwright_req->{$type}{ $mods[$i] } = 0;
289 }
290 }
291 goto &feature;
292 }
293  
294 sub shipwright_features {
295 my @args = @_;
296 while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
297 my $type = $name && $name ne '-core' ? 'recommends' : 'requires';
298 for ( my $i = 0; $i < @$mods; $i++ ) {
299 if ( $mods->[$i] eq '-default' ) {
300 $i++;
301 next;
302 }
303  
304 if ( ref $mods->[$i] eq 'ARRAY' ) {
305 # this happends when
306 # features(
307 # 'Date loading' => [
308 # -default => 0,
309 # recommends( 'DateTime' )
310 # ],
311 # );
312 for ( my $j = 0; $j < @{$mods->[$i]}; $j++ ) {
313 if ( ref $mods->[$i][$j] eq 'ARRAY' ) {
314 $shipwright_req->{$type}{$mods->[$i][$j][0]}
315 = $mods->[$i][$j][1] || 0;
316 }
317 elsif ( $mods->[$i][$j+1] =~ /^[\d\.]*$/ ) {
318 $shipwright_req->{$type}{$mods->[$i][$j]}
319 = $mods->[$i][$j+1] || 0;
320 $j++;
321 }
322 else {
323 $shipwright_req->{$type}{$mods->[$i][$j]} = 0;
324 }
325 }
326
327 next;
328 }
329  
330 if ( $mods->[$i+1] =~ /^[\d\.]*$/ ) {
331 # index $i+1 is a version
332 $shipwright_req->{$type}{$mods->[$i]} = $mods->[$i+1] || 0;
333 $i++;
334 }
335 else {
336 $shipwright_req->{$type}{$mods->[$i]} = 0;
337 }
338 }
339 }
340
341 goto &features;
342 }
343  
344 END {
345 open my $tmp_fh, '>', 'shipwright_prereqs';
346 print $tmp_fh Data::Dumper->Dump( [$shipwright_req], [qw/require/] );
347 }
348  
349 EOF
350  
351 0 $shipwright_makefile .= $makefile;
352 0 write_file( 'shipwright_makefile.pl', $shipwright_makefile );
353  
354 0 run_cmd(
355 [
356 $^X,
357 '-Mversion',
358 '-MShipwright::Util::CleanINC',
359 'shipwright_makefile.pl'
360 ],
361 1, # don't die if this fails
362 );
363 0 ▶ run_cmd( [ $^X, 'shipwright_makefile.pl' ] )
Branch: 1 branch
BranchTrueFalseTotal
if $? or not -e "Makefile" 0 0 0
Condition0%0/3
$? or not -e "Makefile"
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or not -e "Makefile"
$? not -e "Makefile"
Truth table0%0/3
A or not(B)
A= $?B= not -e "Makefile"
ABresult
1X1
011
000
364 if $? || !-e 'Makefile';
365 0 ▶ my $prereqs = read_file( catfile('shipwright_prereqs') )
Branch: 1 branch
BranchTrueFalseTotal
my $prereqs = read_file(catfile("shipwright_prereqs")) or confess_or_die("can't read prereqs: $!") 0 0 0
366 or confess_or_die "can't read prereqs: $!";
367 0 ▶ eval "$prereqs;1;" or confess_or_die "eval error: $@"; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "$prereqs;1;" or confess_or_die("eval error: $@") 0 0 0
368  
369 0 ▶ if ( -e 'META.yml' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e "META.yml") 0 0 0
370  
371 # if there's META.yml, let's find more about it
372 0 ▶ my $meta = load_yaml_file('META.yml')
Branch: 1 branch
BranchTrueFalseTotal
my $meta = load_yaml_file("META.yml") or confess_or_die("can't read META.yml: $!") 0 0 0
373 or confess_or_die "can't read META.yml: $!";
374  
375 # Module::Install will make test_requires into build_requires
376 0 for ( keys %{ $require->{test_requires} } ) {
377 delete $meta->{build_requires}{$_}
378 0 ▶ if exists $meta->{build_requires}{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $meta->{"build_requires"}{$_} 0 0 0
379 }
380  
381 0 ▶ $require ||= {};
Condition0%0/2
$require ||= {}
l!l
00
MC/DC0%0/1
$require ||= {}
$require
Truth table0%0/2
A
A= $require
Aresult
11
00
382 $require->{requires} = {
383 0 ▶ %{ $meta->{requires} || {} },
Condition0%0/2
$meta->{'requires'} || {}
l!l
00
MC/DC0%0/1
$meta->{'requires'} || {}
$meta->{'requires'}
Truth table0%0/2
A
A= $meta->{'requires'}
Aresult
11
00
384 0 ▶ %{ $require->{requires} || {} },
Condition0%0/2
$require->{'requires'} || {}
l!l
00
MC/DC0%0/1
$require->{'requires'} || {}
$require->{'requires'}
Truth table0%0/2
A
A= $require->{'requires'}
Aresult
11
00
385 };
386 $require->{recommends} = {
387 0 ▶ %{ $meta->{recommends} || {} },
Condition0%0/2
$meta->{'recommends'} || {}
l!l
00
MC/DC0%0/1
$meta->{'recommends'} || {}
$meta->{'recommends'}
Truth table0%0/2
A
A= $meta->{'recommends'}
Aresult
11
00
388 0 ▶ %{ $require->{recommends} || {} },
Condition0%0/2
$require->{'recommends'} || {}
l!l
00
MC/DC0%0/1
$require->{'recommends'} || {}
$require->{'recommends'}
Truth table0%0/2
A
A= $require->{'recommends'}
Aresult
11
00
389 };
390 $require->{build_requires} = {
391 0 ▶ %{ $meta->{build_requires} || {} },
Condition0%0/2
$meta->{'build_requires'} || {}
l!l
00
MC/DC0%0/1
$meta->{'build_requires'} || {}
$meta->{'build_requires'}
Truth table0%0/2
A
A= $meta->{'build_requires'}
Aresult
11
00
392 0 ▶ %{ $meta->{configure_requires} || {} },
Condition0%0/2
$meta->{'configure_requires'} || {}
l!l
00
MC/DC0%0/1
$meta->{'configure_requires'} || {}
$meta->{'configure_requires'}
Truth table0%0/2
A
A= $meta->{'configure_requires'}
Aresult
11
00
393 0 ▶ %{ $require->{build_requires} || {} },
Condition0%0/2
$require->{'build_requires'} || {}
l!l
00
MC/DC0%0/1
$require->{'build_requires'} || {}
$require->{'build_requires'}
Truth table0%0/2
A
A= $require->{'build_requires'}
Aresult
11
00
394 };
395 $require->{test_requires} = {
396 0 ▶ %{ $meta->{test_rquires} || {} },
Condition0%0/2
$meta->{'test_rquires'} || {}
l!l
00
MC/DC0%0/1
$meta->{'test_rquires'} || {}
$meta->{'test_rquires'}
Truth table0%0/2
A
A= $meta->{'test_rquires'}
Aresult
11
00
397 0 ▶ %{ $require->{test_requires} || {} },
Condition0%0/2
$require->{'test_requires'} || {}
l!l
00
MC/DC0%0/1
$require->{'test_requires'} || {}
$require->{'test_requires'}
Truth table0%0/2
A
A= $require->{'test_requires'}
Aresult
11
00
398 };
399  
400 }
401  
402 0 unlink 'shipwright_makefile.pl', 'shipwright_prereqs';
403 }
404 else {
405  
406 # we extract the deps from Makefile
407 0 run_cmd(
408 [
409 $^X,
410 '-MShipwright::Util::CleanINC',
411 'Makefile.PL'
412 ],
413 1, # don't die if this fails
414 );
415 0 ▶ run_cmd( [ $^X, 'Makefile.PL' ] )
Branch: 1 branch
BranchTrueFalseTotal
if $? or not -e "Makefile" 0 0 0
Condition0%0/3
$? or not -e "Makefile"
l!l&&r!l&&!r
000
MC/DC0%0/2
$? or not -e "Makefile"
$? not -e "Makefile"
Truth table0%0/3
A or not(B)
A= $?B= not -e "Makefile"
ABresult
1X1
011
000
416 if $? || !-e 'Makefile';
417  
418 0 my @makefile = read_file('Makefile');
419 0 my ($source) = grep { /PREREQ_PM/ } @makefile;
420 0 ▶ if ( $source && $source =~ /({.*})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source and $source =~ /({.*})/) 0 0 0
Condition0%0/3
$source and $source =~ /({.*})/
!ll&&!rl&&r
000
MC/DC0%0/2
$source and $source =~ /({.*})/
$source $source =~ /({.*})/
Truth table0%0/3
A and B
A= $sourceB= $source =~ /({.*})/
ABresult
0X0
100
111
421 0 my $eval .= '$require = ' . $1;
422 0 $eval =~ s/([\w:]+)=>/'$1'=>/g;
423 0 ▶ eval "$eval;1" or confess_or_die "eval error: $@"; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "$eval;1" or confess_or_die("eval error: $@") 0 0 0
424  
425 0 for ( keys %$require ) {
426 0 $require->{requires}{$_} = delete $require->{$_};
427 }
428 }
429  
430 0 my %requires_map = (
431 PREREQ_PM => 'requires',
432 BUILD_REQUIRES => 'build_requires',
433 TEST_REQUIRES => 'test_requires',
434 CONFIGURE_REQUIRES => 'configure_requires',
435 );
436  
437 0 for my $item ( keys %requires_map ) {
438 0 my ($source) = grep { /$item/ } @makefile;
439 0 ▶ if ( $source && $source =~ /({.*})/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source and $source =~ /({.*})/) 0 0 0
Condition0%0/3
$source and $source =~ /({.*})/
!ll&&!rl&&r
000
MC/DC0%0/2
$source and $source =~ /({.*})/
$source $source =~ /({.*})/
Truth table0%0/3
A and B
A= $sourceB= $source =~ /({.*})/
ABresult
0X0
100
111
440 0 my $tmp_requires;
441 0 my $eval .= '$tmp_requires = ' . $1;
442 0 $eval =~ s/([\w:]+)=>/'$1'=>/g;
443 0 ▶ eval "$eval;1" or confess_or_die "eval error: $@"; ## no critic
Branch: 1 branch
BranchTrueFalseTotal
eval "$eval;1" or confess_or_die("eval error: $@") 0 0 0
444  
445 0 ▶ $require->{$requires_map{$item}} ||= {};
Condition0%0/2
$$require{$requires_map{$item}} ||= {}
l!l
00
MC/DC0%0/1
$$require{$requires_map{$item}} ||= {}
$$require{$requires_map{$item}}
Truth table0%0/2
A
A= $$require{$requires_map{$item}}
Aresult
11
00
446 0 for ( keys %$tmp_requires ) {
447 0 $require->{$requires_map{$item}}{$_} = delete $tmp_requires->{$_};
448 }
449 }
450 }
451  
452 }
453 run_cmd(
454 0 [ $ENV{SHIPWRIGHT_MAKE}, 'clean' ] );
455 0 unlink 'Makefile.old';
456 }
457  
458 0 ▶ if ( $run_failed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($run_failed) 0 0 0
459 # read "require" from META.yml instead
460 0 ▶ my $meta = load_yaml_file('META.yml') or confess_or_die "can't read META.yml: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $meta = load_yaml_file("META.yml") or confess_or_die("can't read META.yml: $!") 0 0 0
461 0 for my $type ( keys %$meta ) {
462 0 ▶ next unless $type =~ /requires|recommends/;
Branch: 1 branch
BranchTrueFalseTotal
unless $type =~ /requires|recommends/ 0 0 0
463 0 $require->{$type} = $meta->{$type};
464 }
465 }
466  
467 0 for my $type ( @types ) {
468 0 ▶ next unless $require->{$type};
Branch: 1 branch
BranchTrueFalseTotal
unless $require->{$type} 0 0 0
469 0 for my $module ( keys %{ $require->{$type} } ) {
470 $require->{$type}{$module}{version} =
471 0 delete $require->{$type}{$module};
472 }
473 }
474  
475 0 ▶ dump_yaml_file( $require_path, $require )
Branch: 1 branch
BranchTrueFalseTotal
dump_yaml_file($require_path, $require) or confess_or_die("can't dump __require.yml: $!") 0 0 0
476 or confess_or_die "can't dump __require.yml: $!";
477 }
478  
479 0 ▶ if ( my $require = load_yaml_file($require_path) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $require = load_yaml_file($require_path)) { } 0 0 0
480  
481 # if not have 'requires' key, all the keys in $require are supposed to be
482 # requires type
483 0 ▶ if ( !$require->{requires} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($require->{"requires"}) 0 0 0
484 0 for my $module ( keys %$require ) {
485 $require->{requires}{$module}{version} =
486 0 delete $require->{$module};
487 }
488 }
489  
490 0 for my $type ( @types ) {
491 0 for my $module ( keys %{ $require->{$type} } ) {
492  
493 #$module shouldn't be undefined, but it _indeed_ happens in reality sometimes
494 0 ▶ next unless $module;
Branch: 1 branch
BranchTrueFalseTotal
unless $module 0 0 0
495 # we don't want to require perl
496 0 ▶ if ( $module eq 'perl' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module eq "perl") 0 0 0
497 0 delete $require->{$type}{$module};
498 0 next;
499 }
500  
501 my $version =
502 ref $require->{$type}{$module}
503 ? $require->{$type}{$module}{version}
504 0 ▶ : $require->{$type}{$module};
Branch: 1 branch
BranchTrueFalseTotal
ref $require->{$type}{$module} ? : 0 0 0
505 0 ▶ $version ||= 0;
Condition0%0/2
$version ||= 0
l!l
00
MC/DC0%0/1
$version ||= 0
$version
Truth table0%0/2
A
A= $version
Aresult
11
00
506 0 $version =~ s!^\D+!!; # some may contain '>' or '>='
507 0 ▶ if ( !$self->include_dual_lifed
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->include_dual_lifed and "Module::CoreList"->first_release($module, $version) and "Module::CoreList"->first_release($module, $version) <= $self->min_perl_version and !"Module::CoreList"->removed_from($module) || "Module::CoreList"->removed_from($module) > $self->min_perl_version) 0 0 0
Condition0%0/12
not $self->include_dual_lifed and "Module::CoreList"->first_release($module, $version) and "Module::CoreList"->first_release($module, $version) <= $self->min_perl_version and !"Module::CoreList"->removed_from($module) || "Module::CoreList"->removed_from($module) > $self->min_perl_version
!ll&&!rl&&r
000
not $self->include_dual_lifed and "Module::CoreList"->first_release($module, $version) and "Module::CoreList"->first_release($module, $version) <= $self->min_perl_version
!ll&&!rl&&r
000
not $self->include_dual_lifed and "Module::CoreList"->first_release($module, $version)
!ll&&!rl&&r
000
not "Module::CoreList"->removed_from($module) or "Module::CoreList"->removed_from($module) > $self->min_perl_version
l!l&&r!l&&!r
000
MC/DC0%0/5
not $self->include_dual_lifed and "Module::CoreList"->first_release($module, $version) and "Module::CoreList"->first_release($module, $version) <= $self->min_perl_version and !"Module::CoreList"->removed_from($module) || "Module::CoreList"->removed_from($module) > $self->min_perl_version
not $self->include_dual_lifed "Module::CoreList"->first_release($module, $version) "Module::CoreList"->first_release($module, $version) <= $self->min_perl_version not "Module::CoreList"->removed_from($module) "Module::CoreList"->removed_from($module) > $self->min_perl_version
Truth table0%0/6
not(A) and B and C and not(D) or E
A= not $self->include_dual_lifedB= "Module::CoreList"->first_release($module, $version)C= "Module::CoreList"->first_release($module, $version) <= $self->min_perl_versionD= not "Module::CoreList"->removed_from($module)E= "Module::CoreList"->removed_from($module) > $self->min_perl_version
ABCDEresult
0XXXX0
10XXX0
110XX0
111000
1111X1
111011
508 && Module::CoreList->first_release( $module, $version )
509 && Module::CoreList->first_release( $module, $version ) <= $self->min_perl_version
510 && ( !Module::CoreList->removed_from($module) || Module::CoreList->removed_from($module) > $self->min_perl_version) )
511 {
512 0 $self->log->info("skipping $module because it's in core");
513 0 delete $require->{$type}{$module};
514 0 next;
515 }
516  
517 0 ▶ if ( $self->skip_installed ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip_installed) 0 0 0
518 0 ▶ if ( $module->require ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($module->require) 0 0 0
519 0 $self->log->info("found installed $module");
520 3 ▶ no strict 'refs'; ## no critic
Subroutine BEGIN: called CC=1 SCAR=0.0
521 0 require version;
522 0 my $installed_version = ${ $module . '::VERSION' };
523 0 ▶ if ( $installed_version
Branch: 1 branch
BranchTrueFalseTotal
if ($installed_version and "version"->parse($installed_version) >= "version"->parse($version)) 0 0 0
Condition0%0/3
$installed_version and "version"->parse($installed_version) >= "version"->parse($version)
!ll&&!rl&&r
000
MC/DC0%0/2
$installed_version and "version"->parse($installed_version) >= "version"->parse($version)
$installed_version "version"->parse($installed_version) >= "version"->parse($version)
Truth table0%0/3
A and B
A= $installed_versionB= "version"->parse($installed_version) >= "version"->parse($version)
ABresult
0X0
100
111
524 && version->parse($installed_version) >=
525 version->parse($version) )
526 {
527 0 $self->log->info(
528 "skipping $module because it's installed" );
529 0 delete $require->{$type}{$module};
530 0 next;
531 }
532 }
533 }
534  
535 0 my $name = $module;
536  
537 0 ▶ if ( $self->_is_skipped($module)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_skipped($module) and not $self->_is_installed($module)) { } 0 0 0
Condition0%0/3
$self->_is_skipped($module) and not $self->_is_installed($module)
!ll&&!rl&&r
000
MC/DC0%0/2
$self->_is_skipped($module) and not $self->_is_installed($module)
$self->_is_skipped($module) not $self->_is_installed($module)
Truth table0%0/3
A and not(B)
A= $self->_is_skipped($module)B= not $self->_is_installed($module)
ABresult
0X0
100
111
538 && !$self->_is_installed($module) )
539 {
540  
541 # skipped contains all modules imported before,
542 # so we need to check if they are imported ones
543 0 delete $require->{$type}{$module};
544 0 next;
545 }
546 else {
547  
548 0 opendir my $dir, $self->directory;
549 0 my @sources = readdir $dir;
550 0 close $dir;
551  
552 #reload map
553 0 ▶ if ( -e $self->map_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->map_path) 0 0 0
554 0 $map = load_yaml_file( $self->map_path );
555 }
556  
557 0 ▶ if ( $map->{$module} && $map->{$module} =~ /^cpan-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map->{$module} and $map->{$module} =~ /^cpan-/) { } 0 0 0
Condition0%0/3
$map->{$module} and $map->{$module} =~ /^cpan-/
!ll&&!rl&&r
000
MC/DC0%0/2
$map->{$module} and $map->{$module} =~ /^cpan-/
$map->{$module} $map->{$module} =~ /^cpan-/
Truth table0%0/3
A and B
A= $map->{$module}B= $map->{$module} =~ /^cpan-/
ABresult
0X0
100
111
558 0 $name = $map->{$module};
559 }
560 else {
561  
562 # assuming it's a CPAN module
563 0 $name =~ s/::/-/g;
564 0 ▶ $name = 'cpan-' . $name unless $name =~ /^cpan-/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /^cpan-/ 0 0 0
565 }
566  
567 0 ▶ unless ( grep { $name eq $_ } @sources ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$name eq $_;} @sources) 0 0 0
568 0 my $s;
569 0 my $cwd = getcwd;
570 0 chdir $self->directory;
571 0 ▶ if ( $require->{$type}{$module}{source}
Branch: 1 branch
BranchTrueFalseTotal
if ($require->{$type}{$module}{'source'} and $require->{$type}{$module}{'source'} ne 'CPAN') { } 0 0 0
Condition0%0/3
$require->{$type}{$module}{"source"} and $require->{$type}{$module}{"source"} ne "CPAN"
!ll&&!rl&&r
000
MC/DC0%0/2
$require->{$type}{$module}{"source"} and $require->{$type}{$module}{"source"} ne "CPAN"
$require->{$type}{$module}{"source"} $require->{$type}{$module}{"source"} ne "CPAN"
Truth table0%0/3
A and B
A= $require->{$type}{$module}{"source"}B= $require->{$type}{$module}{"source"} ne "CPAN"
ABresult
0X0
100
111
572 && $require->{$type}{$module}{source} ne 'CPAN' )
573 {
574 $s = Shipwright::Source->new(
575 %$self,
576 source => $require->{$type}{$module}{source},
577 0 name => $name,
578 version => undef,
579 _path => undef,
580 );
581 }
582 else {
583 0 $s = Shipwright::Source->new(
584 %$self,
585 source => "cpan:$module",
586 version => undef,
587 name => '', # cpan name is automaticaly fixed.
588 _path => undef,
589 );
590 }
591 0 ▶ unless ($s->run()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($s->run) 0 0 0
592 # if run returns false, we should skip trying to install it.
593 # this lets us skip explicit dependencies that are actually part of the perl core
594 0 delete $require->{$type}{$module};
595 0 chdir $cwd;
596 0 next;
597  
598 }
599 0 chdir $cwd;
600 }
601  
602 # reload map
603 0 ▶ if ( -e $self->map_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->map_path) 0 0 0
604 0 $map = load_yaml_file( $self->map_path );
605 }
606  
607 }
608  
609 # convert required module name to dist name like cpan-Jifty-DBI
610 0 ▶ if ( $map->{$module} && $map->{$module} =~ /^cpan-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($map->{$module} and $map->{$module} =~ /^cpan-/) { } 0 0 0
Condition0%0/3
$map->{$module} and $map->{$module} =~ /^cpan-/
!ll&&!rl&&r
000
MC/DC0%0/2
$map->{$module} and $map->{$module} =~ /^cpan-/
$map->{$module} $map->{$module} =~ /^cpan-/
Truth table0%0/3
A and B
A= $map->{$module}B= $map->{$module} =~ /^cpan-/
ABresult
0X0
100
111
611 $require->{$type}{ $map->{$module} } =
612 0 delete $require->{$type}{$module};
613 }
614 else {
615 $require->{$type}{$name} =
616 0 delete $require->{$type}{$module};
617 }
618 }
619 }
620 # don't keep recommends info if we skip them, so we won't encounter
621 # them when update later
622 0 ▶ $require->{recommends} = {} if $skip_recommends;
Branch: 1 branch
BranchTrueFalseTotal
if $skip_recommends 0 0 0
623 0 ▶ $require->{test_requires} = {} if $self->skip_all_test_requires;
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_all_test_requires 0 0 0
624 0 ▶ $require->{build_requires} = {} if $self->skip_all_build_requires;
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip_all_build_requires 0 0 0
625  
626 0 dump_yaml_file( $require_path, $require );
627 }
628 else {
629 0 confess_or_die "invalid __require.yml in $path";
630 }
631  
632 # go back to the cwd before we run _follow
633 0 chdir $cwd;
634 }
635  
636 0 ▶sub _update_map {
Subroutine _update_map: not called CC=3 SCAR=24.8
637 0 my $self = shift;
638 0 my $module = shift;
639 0 my $dist = shift;
640  
641 0 my $map = {};
642 0 ▶ if ( -e $self->map_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->map_path) 0 0 0
643 0 $map = load_yaml_file( $self->map_path );
644 }
645 0 ▶ return if $map->{$module};
Branch: 1 branch
BranchTrueFalseTotal
if $map->{$module} 0 0 0
646  
647 0 $map->{$module} = $dist;
648 0 dump_yaml_file( $self->map_path, $map );
649 }
650  
651 0 ▶sub _update_url {
Subroutine _update_url: not called CC=3 SCAR=24.8
652 0 my $self = shift;
653 0 my $name = shift;
654 0 my $url = shift;
655  
656 0 my $map = {};
657 0 ▶ if ( -e $self->url_path && !-z $self->url_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->url_path and not -z $self->url_path) 0 0 0
Condition0%0/3
-e $self->url_path and not -z $self->url_path
!ll&&!rl&&r
000
MC/DC0%0/2
-e $self->url_path and not -z $self->url_path
-e $self->url_path not -z $self->url_path
Truth table0%0/3
A and not(B)
A= -e $self->url_pathB= not -z $self->url_path
ABresult
0X0
100
111
658 0 $map = load_yaml_file( $self->url_path );
659 }
660 0 $map->{$name} = $url;
661 0 dump_yaml_file( $self->url_path, $map );
662 }
663  
664 0 ▶sub _update_version {
Subroutine _update_version: not called CC=3 SCAR=24.8
665 0 my $self = shift;
666 0 my $name = shift;
667 0 my $version = shift;
668  
669 0 my $map = {};
670 0 ▶ if ( -e $self->version_path && !-z $self->version_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->version_path and not -z $self->version_path) 0 0 0
Condition0%0/3
-e $self->version_path and not -z $self->version_path
!ll&&!rl&&r
000
MC/DC0%0/2
-e $self->version_path and not -z $self->version_path
-e $self->version_path not -z $self->version_path
Truth table0%0/3
A and not(B)
A= -e $self->version_pathB= not -z $self->version_path
ABresult
0X0
100
111
671 0 $map = load_yaml_file( $self->version_path );
672 }
673 0 $map->{$name} = $version;
674 0 dump_yaml_file( $self->version_path, $map );
675 }
676  
677 0 ▶sub _update_branches {
Subroutine _update_branches: not called CC=3 SCAR=24.8
678 0 my $self = shift;
679 0 my $name = shift;
680 0 my $branches = shift;
681  
682 0 my $map = {};
683 0 ▶ if ( -e $self->version_path && !-z $self->branches_path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->version_path and not -z $self->branches_path) 0 0 0
Condition0%0/3
-e $self->version_path and not -z $self->branches_path
!ll&&!rl&&r
000
MC/DC0%0/2
-e $self->version_path and not -z $self->branches_path
-e $self->version_path not -z $self->branches_path
Truth table0%0/3
A and not(B)
A= -e $self->version_pathB= not -z $self->branches_path
ABresult
0X0
100
111
684 0 $map = load_yaml_file( $self->branches_path );
685 }
686 0 $map->{$name} = $branches;
687 0 dump_yaml_file( $self->branches_path, $map );
688 }
689  
690 0 ▶sub _is_skipped {
Subroutine _is_skipped: not called CC=9 SCAR=45.0
691 0 my $self = shift;
692 0 my $module = shift;
693 0 my $skip;
694  
695 0 ▶ if ( $self->skip ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->skip) 0 0 0
696 0 ▶ if ( $self->skip->{$module} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->skip->{$module}) { } 0 0 0
elsif (grep {/-/;} keys %{$self->skip;}) { } 0 0 0
697 0 $skip = 1;
698 }
699 0 elsif ( grep { /-/ } keys %{ $self->skip } ) {
700  
701 # so we have a dist skip, we need to resolve the $module to the dist name
702 0 my $source = Shipwright::Source->new( source => "cpan:$module" );
703 0 $source->_run;
704 0 my $name = $source->name;
705 0 my ($name_without_prefix) = $name =~ /^cpan-(.*)/;
706 $skip = 1
707 0 ▶ if $self->skip->{$name} || $self->skip->{$name_without_prefix};
Branch: 1 branch
BranchTrueFalseTotal
if $self->skip->{$name} or $self->skip->{$name_without_prefix} 0 0 0
Condition0%0/3
$self->skip->{$name} or $self->skip->{$name_without_prefix}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->skip->{$name} or $self->skip->{$name_without_prefix}
$self->skip->{$name} $self->skip->{$name_without_prefix}
Truth table0%0/3
A or B
A= $self->skip->{$name}B= $self->skip->{$name_without_prefix}
ABresult
1X1
011
000
708 }
709  
710 0 my @spaces = grep { /::$/ } keys %{$self->skip};
711 0 for my $space ( @spaces ) {
712 # we want to skip both Foo and Foo::*
713 0 ▶ if ( "${module}::" =~ /^$space/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (("${module}::") =~ /^$space/) 0 0 0
714 0 $skip = 1;
715 0 last;
716 }
717 }
718  
719 0 ▶ if ($skip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($skip) 0 0 0
720 0 $self->log->info("skipping $module");
721 0 return 1;
722 }
723 }
724  
725 0 return;
726 }
727  
728 0 ▶sub _is_installed {
Subroutine _is_installed: not called CC=2 SCAR=17.9
729 0 my $self = shift;
730 0 my $module = shift;
731 0 my $installed;
732  
733 0 my $name = $module;
734 0 ▶ if ( $module !~ /-/ ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module =~ /-/) 0 0 0
735 0 my $source = Shipwright::Source->new( source => "cpan:$module" );
736 0 $source->_run;
737 0 $name = $source->name;
738 }
739  
740 0 return $self->installed->{$name};
741 }
742  
743 0 ▶sub _copy {
Subroutine _copy: not called CC=3 SCAR=24.8
744 0 my $self = shift;
745 0 my %file = @_;
746 0 for ( keys %file ) {
747 0 ▶ if ( $file{$_} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file{$_}) 0 0 0
748 0 ▶ my $cmd = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
749 rcopy(
750 0 ▶ $file{$_},
Condition0%0/3
$self->name || $self->just_name($self->path)
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->name || $self->just_name($self->path)
$self->name $self->just_name($self->path)
Truth table0%0/3
A || B
A= $self->nameB= $self->just_name($self->path)
ABresult
1X1
011
000
751 catfile(
752 $self->directory,
753 $self->name || $self->just_name( $self->path ), $_
754 )
755 );
756 0 };
757 0 run_cmd($cmd);
758 }
759 }
760 }
761  
762 =head2 just_name
763  
764 trim the version stuff from dist name
765  
766 =cut
767  
768 3 ▶sub just_name {
Subroutine just_name: called CC=2 SCAR=7.0
Pod documented
769 3 my $self = shift;
770 3 my $name = shift;
771  
772 3 $name =~ s/(?:tar\.bz2|zip)$/tar.gz/; # CPAN::DistnameInfo likes .tar.gz
773  
774 3 ▶ $name .= '.tar.gz' unless $name =~ /(tar\.gz|tgz)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /(tar\.gz|tgz)$/ 3 0 3
775  
776 3 require CPAN::DistnameInfo;
777 3 my $info = CPAN::DistnameInfo->new($name);
778 3 my $dist = $info->dist;
779 3 return $dist;
780 }
781  
782 =head2 just_version
783  
784 return version
785  
786 =cut
787  
788 0 ▶sub just_version {
Subroutine just_version: not called CC=3 SCAR=24.8
Pod documented
789 0 my $self = shift;
790 0 my $name = shift;
791 0 ▶ $name .= '.tar.gz' unless $name =~ /\.(tar\.gz|tgz|tar\.bz2|zip)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $name =~ /\.(tar\.gz|tgz|tar\.bz2|zip)$/ 0 0 0
792  
793 0 require CPAN::DistnameInfo;
794 0 my $info = CPAN::DistnameInfo->new($name);
795 0 my $version = $info->version;
796 0 ▶ $version =~ s/^v// if $version;
Branch: 1 branch
BranchTrueFalseTotal
if $version 0 0 0
797 0 return $version;
798 }
799  
800 =head2 is_compressed
801  
802 return true if the source is compressed file, i.e. tar.gz(tgz) and tar.bz2
803  
804 =cut
805  
806 9 ▶sub is_compressed {
Subroutine is_compressed: called CC=2 SCAR=6.9
Pod documented
807 9 my $self = shift;
808 9 ▶ return 1 if $self->source =~ m{\.(tar.(gz|bz2)|tgz|zip)$};
Branch: 1 branch
BranchTrueFalseTotal
if $self->source =~ /\.(tar.(gz|bz2)|tgz|zip)$/ 4 5 9
809 5 return;
810 }
811  
812 0 ▶sub _lwp_get {
Subroutine _lwp_get: not called CC=7 SCAR=40.3
813 0 my $self = shift;
814 0 my $source = shift;
815 0 require LWP::UserAgent;
816 0 my $ua = LWP::UserAgent->new;
817 0 $ua->env_proxy();
818 $ua->timeout( $ENV{SHIPWRIGHT_LWP_TIMEOUT} )
819 0 ▶ if $ENV{SHIPWRIGHT_LWP_TIMEOUT};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"SHIPWRIGHT_LWP_TIMEOUT"} 0 0 0
820  
821 0 ▶ if ( -e $self->source ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $self->source) 0 0 0
822 0 my $size = -s $self->source;
823 0 my $res = $ua->head($source);
824 0 ▶ if ( $res->is_success
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_success and $res->header("content-length") == $size) 0 0 0
Condition0%0/3
$res->is_success and $res->header("content-length") == $size
!ll&&!rl&&r
000
MC/DC0%0/2
$res->is_success and $res->header("content-length") == $size
$res->is_success $res->header("content-length") == $size
Truth table0%0/3
A and B
A= $res->is_successB= $res->header("content-length") == $size
ABresult
0X0
100
111
825 && $res->header('content-length') == $size )
826 {
827 0 return 1;
828 }
829 }
830  
831 0 my $response = $ua->get($source);
832  
833 0 ▶ if ( $response->is_success ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
834 0 ▶ open my $fh, '>', $self->source
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $self->source or confess_or_die(q[can't open file ] . $self->source . ": $!") 0 0 0
835 or confess_or_die "can't open file " . $self->source . ": $!";
836 0 print $fh $response->content;
837 }
838 else {
839 0 confess_or_die "failed to get $source: " . $response->status_line;
840 }
841 }
842  
843 3 1;
844  
845 __END__
↑ Summary blib/lib/Shipwright/Script/Import.pm »