blib/lib/Shipwright/Source/Compressed.pm

filter: Statementstmt 38.8% 28 / 72 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 69.2% 9 / 13 Podpod 100% 2 / 2 totaltotal 30.7% 39 / 127 CC 16 SCAR 32.8
CC
16
Cov
26%
__ANON__
56.0
run
42.0
path
20.0
CRAP 26.6
« blib/lib/Shipwright/Source/Directory.pm ↑ Summary blib/lib/Shipwright/Script/Maintain.pm »
1 package Shipwright::Source::Compressed;
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  
7 3 ▶use base qw/Shipwright::Source::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Archive::Extract;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Copy::Recursive qw/rmove/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use Cwd qw/getcwd/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head2 run
15  
16 =cut
17  
18 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
19 0 my $self = shift;
20  
21 0 ▶ $self->name( $self->just_name( $self->path ) ) unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 0 0 0
22 0 ▶ $self->version( $self->just_version( $self->path ) ) unless $self->version;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->version 0 0 0
23 0 $self->log->info( 'running source ' . $self->name . ': ' . $self->source );
24  
25 0 $self->_update_version( $self->name, $self->version );
26  
27 $self->_update_url( $self->name, 'file:' . $self->source )
28 0 ▶ unless $self->{_no_update_url};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_no_update_url"} 0 0 0
29  
30 0 my $newer = $self->_cmd; # if we really get something new
31  
32 0 my $ret = $self->SUPER::run(@_);
33  
34 # follow only if --follow and we really added new stuff.
35 0 ▶ $self->_follow( catdir( $self->directory, $self->name ) )
Branch: 1 branch
BranchTrueFalseTotal
if $self->follow and $newer 0 0 0
Condition0%0/3
$self->follow and $newer
!ll&&!rl&&r
000
MC/DC0%0/2
$self->follow and $newer
$self->follow $newer
Truth table0%0/3
A and B
A= $self->followB= $newer
ABresult
0X0
100
111
36 if $self->follow && $newer;
37 0 return catdir( $self->directory, $self->name );
38 }
39  
40 =head2 path
41  
42 the decompressed source path
43  
44 =cut
45  
46 0 ▶sub path {
Subroutine path: not called CC=4 SCAR=30.0
Pod documented
47 0 my $self = shift;
48  
49 # we memoize path info so we don't need to extract on each call.
50 0 ▶ return $self->{_path} if $self->{_path};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_path"} 0 0 0
51  
52 0 my $source = $self->source;
53 0 my $ae = Archive::Extract->new( archive => $source );
54 # this's to check if $source is valid, aka. it only contains one directory.
55 0 my $tmp_dir = tempdir( 'shipwright_tmp_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
56 0 $ae->extract( to => $tmp_dir );
57 0 my $files = $ae->files;
58  
59 # 1st file in Crypt-DH-0.07.tar.gz is "./"
60 0 ▶ shift @$files if $files->[0] =~ /^\.[\/\\]$/;
Branch: 1 branch
BranchTrueFalseTotal
if $files->[0] =~ m(^\.[/\\]$) 0 0 0
61 0 my $base_dir = $files->[0];
62 # some compressed file has name like ./PerlImagick-6.67/
63 0 $base_dir =~ s!^\.[/\\]!!;
64  
65 # sunnavy found that the 1st file is not the directory name when extracting
66 # HTML-Strip-1.06.tar.gz, which is weird but valid compressed file.
67 0 $base_dir =~ s![/\\].*!!;
68  
69 0 ▶ if ( @$files != grep { /^(?:\.[\/\\])?\Q$base_dir\E/ } @$files ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$files != grep({m(^(?:\.[/\\])?\Q$base_dir\E);} @$files)) 0 0 0
70 0 confess_or_die 'only support compressed file which contains only one directory: '
71 . $base_dir;
72 }
73  
74 0 $self->{_path} = $base_dir;
75  
76 0 return $base_dir;
77 }
78  
79 0 ▶sub _cmd {
Subroutine _cmd: not called CC=2 SCAR=17.9
80 0 my $self = shift;
81 0 my $arg;
82  
83 0 my ( $from, $to );
84 0 $from = catdir( $self->directory, $self->path );
85 0 $to = catdir( $self->directory, $self->name );
86  
87 # if it already exists, assuming we have processed it already, don't do it
88 # again
89 0 ▶ return if -e $to;
Branch: 1 branch
BranchTrueFalseTotal
if -e $to 0 0 0
90  
91 0 my $ae = Archive::Extract->new( archive => $self->source );
92  
93 0 ▶ return sub {
Subroutine __ANON__: not called CC=7 SCAR=40.3
94 0 $ae->extract( to => $self->directory );
95  
96 0 ▶ if ( -e catfile( $from, 'dist.ini' )
Branch: 1 branch
BranchTrueFalseTotal
if (-e catfile($from, "dist.ini") and not -e catfile($from, "configure") and not -e catfile($from, "Makefile.PL") and not -e catfile($from, "Build.PL")) 0 0 0
Condition0%0/9
-e catfile($from, "dist.ini") and not -e catfile($from, "configure") and not -e catfile($from, "Makefile.PL") and not -e catfile($from, "Build.PL")
!ll&&!rl&&r
000
-e catfile($from, "dist.ini") and not -e catfile($from, "configure") and not -e catfile($from, "Makefile.PL")
!ll&&!rl&&r
000
-e catfile($from, "dist.ini") and not -e catfile($from, "configure")
!ll&&!rl&&r
000
MC/DC0%0/4
-e catfile($from, "dist.ini") and not -e catfile($from, "configure") and not -e catfile($from, "Makefile.PL") and not -e catfile($from, "Build.PL")
-e catfile($from, "dist.ini") not -e catfile($from, "configure") not -e catfile($from, "Makefile.PL") not -e catfile($from, "Build.PL")
Truth table0%0/5
A and not(B) and not(C) and not(D)
A= -e catfile($from, "dist.ini")B= not -e catfile($from, "configure")C= not -e catfile($from, "Makefile.PL")D= not -e catfile($from, "Build.PL")
ABCDresult
0XXX0
10XX0
110X0
11100
11111
97 && !-e catfile( $from, 'configure' )
98 && !-e catfile( $from, 'Makefile.PL' )
99 && !-e catfile( $from, 'Build.PL' ) )
100 {
101 # assume it's a Dist::Zilla dist
102 0 ▶ if ( $from eq $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from eq $to) 0 0 0
103 0 rmove( $from, $from . '-tmp' );
104 }
105  
106 0 my $old = getcwd();
107 0 chdir $from . '-tmp';
108 0 run_cmd( [ $ENV{SHIPWRIGHT_DZIL}, 'build', '--in', $to ] );
109 0 chdir $old;
110 }
111  
112 0 ▶ if ( $from ne $to ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($from ne $to) 0 0 0
113 0 rmove( $from, $to );
114 }
115 0 };
116 }
117  
118 3 1;
119  
120 __END__
« blib/lib/Shipwright/Source/Directory.pm ↑ Summary blib/lib/Shipwright/Script/Maintain.pm »