From: Vincent Pit Date: Sat, 15 Aug 2009 09:36:19 +0000 (+0200) Subject: Properly asset the situation at the end of prepare()/create() X-Git-Tag: v0.08~17 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=88382900dcd1a7b94384f5bebf6f6c47bf610613;p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git Properly asset the situation at the end of prepare()/create() --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 5c4dd8e..7fab73a 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -138,7 +138,8 @@ sub prepare { my %opts = @_; - $stat->prepared(0); + my $OK = sub { $stat->prepared(1); 1 }; + my $FAIL = sub { $stat->prepared(0); 0 }; my $keywords = delete $opts{'keywords'}; if (defined $keywords) { @@ -180,7 +181,7 @@ sub prepare { if ($stat->do_manifest && !-w $stat->distdir) { error 'distdir isn\'t writable -- aborting'; - return 0; + return $FAIL->(); } $stat->fetched_arch($mod->status->fetch); @@ -255,7 +256,7 @@ sub prepare { unless ($author =~ /^(.)(.)/) { error 'Wrong author name -- aborting'; - return 0; + return $FAIL->(); } $stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/" . $mod->package); @@ -269,7 +270,7 @@ sub prepare { my $obj = $int->module_tree($prereq); unless ($obj) { error 'Wrong module object -- aborting'; - return 0; + return $FAIL->(); } next if $obj->package_is_perl_core; { @@ -286,25 +287,24 @@ sub prepare { } $stat->deps(\@depends); - $stat->prepared(1); - return 1; + return $OK->(); } sub create { my $self = shift; my $stat = $self->status; + my $OK = sub { $stat->created(1); $stat->dist($stat->eb_file); 1 }; + my $FAIL = sub { $stat->created(0); $stat->dist(undef); 0 }; + unless ($stat->prepared) { error 'Can\'t create ' . $stat->distribution . ' since it was never prepared -- aborting'; - $stat->created(0); - $stat->dist(undef); - return 0; + return $FAIL->(); } if ($stat->created) { msg $stat->distribution . ' was already created -- skipping'; - $stat->dist($stat->eb_file); - return 1; + return $OK->(); } my $dir = $stat->eb_dir; @@ -312,7 +312,7 @@ sub create { eval { File::Path::mkpath($dir) }; if ($@) { error "mkpath($dir): $@"; - return 0; + return $FAIL->(); } } @@ -338,7 +338,7 @@ sub create { my $file = $stat->eb_file; open my $eb, '>', $file or do { error "open($file): $! -- aborting"; - return 0; + return $FAIL->(); }; print $eb $d; close $eb; @@ -348,26 +348,21 @@ sub create { $self->SUPER::create(@_); - $stat->created(0); - $stat->dist(undef); - if ($stat->do_manifest) { unless (File::Copy::copy($stat->fetched_arch => $stat->distdir)) { error "Couldn\'t copy the distribution file to distdir ($!) -- aborting"; 1 while unlink $file; - return 0; + return $FAIL->(); } msg 'Adding Manifest entry for ' . $stat->distribution; unless ($self->_run([ 'ebuild', $file, 'manifest' ], 0)) { 1 while unlink $file; - return 0; + return $FAIL->(); } } - $stat->created(1); - $stat->dist($file); - return 1; + return $OK->(); } sub _cpan2portage {