blib/lib/Shipwright/Source/CPAN.pm

filter: Statementstmt 48.7% 59 / 121 Branchbran 15.7% 6 / 38 Conditioncond 6.6% 1 / 15 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 85.7% 12 / 14 Podpod 100% 2 / 2 totaltotal 40.0% 80 / 200 CC 25 SCAR 43.1
CC
25
Cov
38%
_run
182.0
run
56.0
new
7.8
CRAP 74.3
« blib/lib/Shipwright/Source/Shipyard.pm ↑ Summary blib/lib/Shipwright/Script/Ktf.pm »
1 package Shipwright::Source::CPAN;
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 Shipwright::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use File::Spec::Functions qw/catfile catdir rootdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Shipwright::Source::Compressed;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use CPAN;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use CPAN::DistnameInfo;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 3 ▶use base qw/Shipwright::Source::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 my $cpan_dir = tempdir( 'shipwright_cpan_XXXXXX', CLEANUP => 1, TMPDIR => 1 );
17 3 unshift @INC, $cpan_dir;
18  
19 =head1 NAME
20  
21 Shipwright::Source::CPAN - CPAN source
22  
23 =head1 DESCRIPTION
24  
25 =head2 new
26  
27 =cut
28  
29 3 ▶sub new {
Subroutine new: called CC=7 SCAR=20.5
Pod documented
30 3 my $class = shift;
31 3 my $self = $class->SUPER::new(@_);
32  
33 3 require Module::Info;
34 3 ▶ if ( Module::Info->new_from_module('CPAN::Config') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Module::Info"->new_from_module("CPAN::Config")) 0 3 3
35  
36 # keep original CPAN::Config info
37 0 require CPAN::Config;
38 }
39  
40 3 unshift @INC, catdir( $ENV{'HOME'}, '.cpan' );
41 3 ▶ if ( Module::Info->new_from_module('CPAN::MyConfig') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Module::Info"->new_from_module("CPAN::MyConfig")) 3 0 3
42  
43 # keep user's CPAN::MyConfig too
44 3 require CPAN::MyConfig;
45 }
46 3 shift @INC;
47  
48  
49 3 mkdir catdir( $cpan_dir, 'CPAN' );
50 3 my $config_file = catfile( $cpan_dir, 'CPAN', 'MyConfig.pm' );
51  
52 3 ▶ unless ( -f $config_file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $config_file) 2 1 3
53  
54 # hack $CPAN::Config, mostly to make cpan stuff temporary
55 2 $CPAN::Config->{cpan_home} = catdir($cpan_dir);
56 2 $CPAN::Config->{build_dir} = catdir( $cpan_dir, 'build' );
57 2 $CPAN::Config->{histfile} = catfile( $cpan_dir, 'histfile' );
58  
59 # be careful, if you use minicpan, then the source won't be copied to
60 # $CPAN::Config->{keep_source_where}
61 $CPAN::Config->{keep_source_where} =
62 2 catdir( $self->download_directory, 'cpan' );
63 2 $CPAN::Config->{prefs_dir} = catdir( $cpan_dir, 'prefs' );
64 2 $CPAN::Config->{prerequisites_policy} = 'follow';
65 2 ▶ unless ( $CPAN::Config->{urllist} && @{ $CPAN::Config->{urllist} } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($CPAN::Config->{"urllist"} and @{$CPAN::Config->{"urllist"};}) 0 2 2
Condition33%1/3
$CPAN::Config->{"urllist"} and @{$CPAN::Config->{"urllist"};}
!ll&&!rl&&r
002
MC/DC0%0/2
$CPAN::Config->{"urllist"} and @{$CPAN::Config->{"urllist"};}
$CPAN::Config->{"urllist"} @{$CPAN::Config->{"urllist"};}
Truth table33%1/3
A and B
A= $CPAN::Config->{"urllist"}B= @{$CPAN::Config->{"urllist"};}
ABresult
0X0
100
111
66 0 $CPAN::Config->{urllist} = [ 'http://search.cpan.org/CPAN' ];
67 }
68  
69 2 ▶ if ( $ENV{SHIPWRIGHT_CPAN_MIRROR} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ENV{"SHIPWRIGHT_CPAN_MIRROR"}) 0 2 2
70 0 unshift @{$CPAN::Config->{urllist}}, $ENV{SHIPWRIGHT_CPAN_MIRROR};
71 }
72  
73 2 write_file( $config_file,
74 Data::Dumper->Dump( [$CPAN::Config], ['$CPAN::Config'] ) );
75  
76 }
77 3 require CPAN::MyConfig;
78 3 return $self;
79 }
80  
81 =head2 run
82  
83 =cut
84  
85 0 ▶sub run {
Subroutine run: not called CC=7 SCAR=40.3
Pod documented
86 0 my $self = shift;
87 0 $self->log->info( "preparing to run source: " . $self->source );
88  
89 0 my $result = $self->_run;
90 0 ▶ if ( $result && $result == 1) {
Branch: 2 branches
BranchTrueFalseTotal
if ($result and $result == 1) { } 0 0 0
elsif (not $result and $self->source =~ /\S/) { } 0 0 0
Condition0%0/3
$result and $result == 1
!ll&&!rl&&r
000
MC/DC0%0/2
$result and $result == 1
$result $result == 1
Truth table0%0/3
A and B
A= $resultB= $result == 1
ABresult
0X0
100
111
91 0 my $compressed =
92 Shipwright::Source::Compressed->new( %$self, _no_update_url => 1 );
93 0 $compressed->run(@_);
94 }
95 ▶ elsif ( !$result && $self->source =~ /\S/ ) {
Condition0%0/3
not $result and $self->source =~ /\S/
!ll&&!rl&&r
000
MC/DC0%0/2
not $result and $self->source =~ /\S/
not $result $self->source =~ /\S/
Truth table0%0/3
not(A) and B
A= not $resultB= $self->source =~ /\S/
ABresult
0X0
100
111
96 0 ▶ if ( Module::CoreList->is_core( $self->source )) {
Branch: 1 branch
BranchTrueFalseTotal
if ("Module::CoreList"->is_core($self->source)) 0 0 0
97 0 $self->log->info("skipping dual lifed " . $self->source . " because can't find it on cpan any more");
98 0 return;
99 }
100 0 my $error = q{invalid source: can't find '} . $self->source . q{'};
101 0 ▶ if ( $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version) 0 0 0
102 0 $error .= ' version ' . $self->version;
103 }
104 0 $error .= ' in your CPAN mirror(s)' . " [@{$CPAN::Config->{urllist}}].";
105 0 chdir rootdir(); #< chdir to root dir in case CPAN has chdir'd
106 #into one of the temp dirs, preventing its
107 #deletion
108 0 confess_or_die $error;
109 } else {
110 0 $self->log->warn("removing source ".$self->source);
111 0 return;
112 }
113 }
114  
115 0 ▶sub _run {
Subroutine _run: not called CC=13 SCAR=52.0
116 0 my $self = shift;
117 0 ▶ return if $self->source eq 'perl'; # don't expand perl itself;
Branch: 1 branch
BranchTrueFalseTotal
if $self->source eq "perl" 0 0 0
118  
119 0 my ( $source, $distribution );
120  
121 0 select_fh('cpan');
122  
123 0 ▶ if ( $self->source =~ /\.tar\.gz$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->source =~ /\.tar\.gz$/) { } 0 0 0
124  
125 # it's a disribution
126 0 $distribution = CPAN::Shell->expand( 'Distribution', $self->source );
127  
128 0 ▶ unless ($distribution) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($distribution) 0 0 0
129 0 $self->log->warn( "can't find "
130 . $self->source
131 . ' on CPAN, assuming you will manually fix it. good luck!' );
132 0 return;
133 }
134  
135 # distribution source isn't good for shipwright, convert it to a
136 # module name it contains
137 0 $self->source( ( $distribution->containsmods )[0] );
138  
139 0 $source = $distribution->{ID};
140 }
141 else {
142  
143 # it's a module
144 0 ▶ my $type = $self->source =~ /^Bundle/ ? 'Bundle' : 'Module';
Branch: 1 branch
BranchTrueFalseTotal
$self->source =~ /^Bundle/ ? : 0 0 0
145 0 my $module = CPAN::Shell->expand( $type, $self->source );
146  
147 0 ▶ unless ($module) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($module) 0 0 0
148 0 $self->log->warn( "can't find "
149 . $self->source
150 . ' on CPAN, assuming you will manually fix it. good luck!' );
151 0 return;
152 }
153  
154 0 $source = $module->cpan_file;
155  
156 0 $distribution = $module->distribution;
157  
158 0 my $info = CPAN::DistnameInfo->new( $module->cpan_file );
159  
160 0 ▶ if ( $self->version ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->version) 0 0 0
161 0 my $latest_version = $info->version;
162 0 my $version = $self->version;
163 0 ▶ if ( $latest_version =~ /^v/ && $version !~ /^v/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($latest_version =~ /^v/ and not $version =~ /^v/) 0 0 0
Condition0%0/3
$latest_version =~ /^v/ and not $version =~ /^v/
!ll&&!rl&&r
000
MC/DC0%0/2
$latest_version =~ /^v/ and not $version =~ /^v/
$latest_version =~ /^v/ not $version =~ /^v/
Truth table0%0/3
A and not(B)
A= $latest_version =~ /^v/B= not $version =~ /^v/
ABresult
0X0
100
111
164 0 $version = 'v' . $version;
165 }
166 0 $distribution->{ID} =~ s/$latest_version/$version/;
167 0 $source =~ s/$latest_version/$version/;
168 }
169 }
170  
171 0 my $name = CPAN::DistnameInfo->new( $distribution->{ID} )->dist;
172  
173 0 ▶ if (!$name ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $name) { } 0 0 0
elsif ($name eq 'perl') { } 0 0 0
174 0 $self->log->warn("skipping " . $self->source . " because it's not on CPAN");
175 0 return -1;
176 }
177 elsif ( $name eq 'perl' ) {
178 0 $self->log->warn(
179 'skipping ' . $self->source . " because it's in core" );
180 0 return -1;
181 }
182  
183 0 select_fh('stdout');
184  
185 0 $self->name( 'cpan-' . $name );
186 0 $self->_update_map( $self->source, 'cpan-' . $name );
187  
188 my ($file) = catfile( $CPAN::Config->{keep_source_where},
189 0 "authors", "id", split /\//, $distribution->id );
190  
191 0 ▶ if ( -e $file && -s $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-e $file and -s $file) { } 0 0 0
Condition0%0/3
-e $file and -s $file
!ll&&!rl&&r
000
MC/DC0%0/2
-e $file and -s $file
-e $file -s $file
Truth table0%0/3
A and B
A= -e $fileB= -s $file
ABresult
0X0
100
111
192 0 $self->source($file);
193 }
194 else {
195 0 $self->source($distribution->get_file_onto_local_disk);
196 }
197 0 return 1;
198 }
199  
200 3 1;
201  
202 __END__
« blib/lib/Shipwright/Source/Shipyard.pm ↑ Summary blib/lib/Shipwright/Script/Ktf.pm »