From: Vincent Pit Date: Sat, 29 Nov 2008 16:08:44 +0000 (+0100) Subject: Move all the "command running" logic into a _run private method X-Git-Tag: v0.03~10 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FCPANPLUS-Dist-Gentoo.git;a=commitdiff_plain;h=410770eb10e4a998b5393317b9da84e19054eb35 Move all the "command running" logic into a _run private method --- diff --git a/lib/CPANPLUS/Dist/Gentoo.pm b/lib/CPANPLUS/Dist/Gentoo.pm index 34a27a0..d7c1a7f 100644 --- a/lib/CPANPLUS/Dist/Gentoo.pm +++ b/lib/CPANPLUS/Dist/Gentoo.pm @@ -243,16 +243,7 @@ sub create { } msg 'Adding Manifest entry for ' . $stat->dist; - my ($success, $errmsg, $output) = run - command => [ 'ebuild', $file, 'manifest' ], - verbose => 0; - unless ($success) { - error "$errmsg -- aborting"; - if (defined $output and $stat->verbose) { - my $msg = join '', @$output; - 1 while chomp $msg; - error $msg; - } + unless ($self->_run([ 'ebuild', $file, 'manifest' ], 0)) { 1 while unlink $file; return 0; } @@ -270,14 +261,7 @@ sub install { my @cmd = ('emerge', '=' . $stat->eb_name . '-' . $stat->eb_version); unshift @cmd, $sudo if $sudo; - my ($success, $errmsg) = run command => \@cmd, - verbose => 1; - unless ($success) { - error "$errmsg -- aborting"; - return 0; - } - - return 1; + return $self->_run(\@cmd, 1); } sub uninstall { @@ -289,14 +273,23 @@ sub uninstall { my @cmd = ('emerge', '-C', '=' . $stat->eb_name . '-' . $stat->eb_version); unshift @cmd, $sudo if $sudo; - my ($success, $errmsg) = run command => \@cmd, - verbose => 1; + return $self->_run(\@cmd, 1); +} + +sub _run { + my ($self, $cmd, $verbose) = @_; + + my ($success, $errmsg, $output) = run command => $cmd, verbose => $verbose; unless ($success) { error "$errmsg -- aborting"; - return 0; + if (not $verbose and defined $output and $self->status->verbose) { + my $msg = join '', @$output; + 1 while chomp $msg; + error $msg; + } } - return 1; + return $success; } =head1 DEPENDENCIES