+ return $FAIL->() unless $stat->created;
+
+ {
+ open my $eb, '>', $file or return $FAIL->("open($file): $!");
+ my $source = $self->ebuild_source;
+ return $FAIL->() unless defined $source;
+ print $eb $source;
+ }
+
+ return $FAIL->() if $stat->do_manifest and not $self->update_manifest;
+
+ return $OK->();
+}
+
+=head2 C<update_manifest>
+
+Updates the F<Manifest> file for the ebuild associated to the current dist object.
+
+=cut
+
+sub update_manifest {
+ my $self = shift;
+ my $stat = $self->status;
+
+ my $file = $stat->ebuild_file;
+ unless (defined $file and -e $file) {
+ return $self->_abort('The ebuild file is invalid or does not exist');
+ }
+
+ unless (File::Copy::copy($stat->fetched_arch => $stat->distdir)) {
+ return $self->_abort("Couldn\'t copy the distribution file to distdir ($!)");
+ }
+
+ $self->_notify('Adding Manifest entry for', $stat->distribution);
+
+ return $self->_run([ 'ebuild', $file, 'manifest' ], 0);
+}
+
+=head2 C<ebuild_source>
+
+Returns the source of the ebuild for the current dist object, or C<undef> when one of the dependencies couldn't be mapped to an existing ebuild.
+
+=cut
+
+sub ebuild_source {
+ my $self = shift;
+ my $stat = $self->status;
+
+ # We must resolve the deps now and not inside prepare because _cpan2portage
+ # has to see the ebuilds already generated for the dependencies of the current
+ # dist.
+ my @deps;
+ for (@{$stat->deps}) {
+ my $dep = $self->_cpan2portage(@$_);
+ unless (defined $dep) {
+ $self->_abort(
+ "Couldn't find an appropriate ebuild for $_->[0] in the portage tree"
+ );
+ return;