use IPC::Cmd qw/run can_run/;
-use CPANPLUS::Error;
+use CPANPLUS::Error ();
use base qw/CPANPLUS::Dist::Base/;
for my $prog (qw/emerge ebuild/) {
unless (can_run($prog)) {
- error "$prog is required to write ebuilds -- aborting";
+ __PACKAGE__->_abort("$prog is required to write ebuilds");
return $format_available = 0;
}
}
$main_portdir = abs_path($unquote->($1));
}
} else {
- error $errmsg;
+ __PACKAGE__->_abort($errmsg);
}
}
my %opts = @_;
my $OK = sub { $stat->prepared(1); 1 };
- my $FAIL = sub { $stat->prepared(0); 0 };
+ my $FAIL = sub { $stat->prepared(0); $self->_abort(@_) if @_; 0 };
my $keywords = delete $opts{'keywords'};
if (defined $keywords) {
$stat->distdir($distdir);
if ($stat->do_manifest && !-w $stat->distdir) {
- error 'distdir isn\'t writable -- aborting';
- return $FAIL->();
+ return $FAIL->('distdir isn\'t writable');
}
$stat->fetched_arch($mod->status->fetch);
$forced{$file} = 1;
$skip = 0;
} else {
- error "Can't force rewriting of $file -- skipping";
+ $self->_skip("Can't force rewriting of $file");
}
} else {
- msg 'Ebuild already generated for ' . $stat->distribution . ' -- skipping';
+ $self->_skip('Ebuild already generated for', $stat->distribution);
}
if ($skip) {
$stat->prepared(1);
$stat->uri('http://search.cpan.org/dist/' . $name);
unless ($author =~ /^(.)(.)/) {
- error 'Wrong author name -- aborting';
- return $FAIL->();
+ return $FAIL->('Wrong author name');
}
$stat->src("mirror://cpan/modules/by-authors/id/$1/$1$2/$author/"
. $mod->package);
for my $prereq (sort keys %$prereqs) {
next if $prereq =~ /^perl(?:-|\z)/;
my $obj = $int->module_tree($prereq);
- unless ($obj) {
- error 'Wrong module object -- aborting';
- return $FAIL->();
- }
+ return $FAIL->('Wrong module object') unless $obj;
next if $obj->package_is_perl_core;
{
my $version;
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 };
+ my $FAIL = sub { $stat->created(0); $stat->dist(undef); $self->_abort(@_) if @_; 0 };
unless ($stat->prepared) {
- error 'Can\'t create ' . $stat->distribution . ' since it was never prepared -- aborting';
- return $FAIL->();
+ return $FAIL->(
+ 'Can\'t create', $stat->distribution, 'since it was never prepared'
+ );
}
if ($stat->created) {
- msg $stat->distribution . ' was already created -- skipping';
+ $self->_skip($stat->distribution, 'was already created');
return $OK->();
}
my $dir = $stat->eb_dir;
unless (-d $dir) {
eval { File::Path::mkpath($dir) };
- if ($@) {
- error "mkpath($dir): $@";
- return $FAIL->();
- }
+ return $FAIL->("mkpath($dir): $@") if $@;
}
my %seen;
$d .= $stat->footer;
my $file = $stat->eb_file;
- open my $eb, '>', $file or do {
- error "open($file): $! -- aborting";
- return $FAIL->();
- };
+ open my $eb, '>', $file or return $FAIL->("open($file): $!");
print $eb $d;
close $eb;
my $file = $stat->eb_file;
unless ($file and -e $file) {
- error 'The ebuild file is invalid or does not exist -- aborting';
- return 0;
+ return $self->_abort('The ebuild file is invalid or does not exist');
}
unless (File::Copy::copy($stat->fetched_arch => $stat->distdir)) {
- error "Couldn\'t copy the distribution file to distdir ($!) -- aborting";
- return 0;
+ return $self->_abort("Couldn\'t copy the distribution file to distdir ($!)");
}
- msg 'Adding Manifest entry for ' . $stat->distribution;
+ $self->_notify('Adding Manifest entry for', $stat->distribution);
+
return $self->_run([ 'ebuild', $stat->eb_file, 'manifest' ], 0);
}
}
- error "Couldn't find an appropriate ebuild for $name in the portage tree -- skipping";
+ $self->_skip(
+ "Couldn't find an appropriate ebuild for $name in the portage tree"
+ );
+
return '';
}
};
unless ($success) {
- error "$errmsg -- aborting";
+ $self->_abort($errmsg);
if (not $verbose and defined $output and $stat->verbose) {
my $msg = join '', @$output;
1 while chomp $msg;
- error $msg;
+ CPANPLUS::Error::error($msg);
}
}
return $success;
}
+sub _abort {
+ my $self = shift;
+
+ CPANPLUS::Error::error("@_ -- aborting");
+
+ return 0;
+}
+
+sub _notify {
+ my $self = shift;
+
+ CPANPLUS::Error::msg("@_");
+
+ return 1;
+}
+
+sub _skip { shift->_notify(@_, '-- skipping') }
+
=head1 DEPENDENCIES
Gentoo (L<http://gentoo.org>).