1 package CPANPLUS::Dist::Gentoo;
6 use File::Copy qw/copy/;
7 use File::Path qw/mkpath/;
8 use File::Spec::Functions qw/catdir catfile/;
10 use IPC::Cmd qw/run can_run/;
14 use base qw/CPANPLUS::Dist::Base/;
18 CPANPLUS::Dist::Gentoo - CPANPLUS backend generating Gentoo ebuilds.
26 our $VERSION = '0.02_01';
30 cpan2dist --format=CPANPLUS::Dist::Gentoo \
31 --dist-opts overlay=/usr/local/portage \
32 --dist-opts distdir=/usr/portage/distfiles \
33 --dist-opts manifest=yes \
34 --dist-opts keywords=x86 \
39 This module is a CPANPLUS backend that recursively generates Gentoo ebuilds for a given package in the specified overlay (defaults to C</usr/local/portage>), update the manifest, and even emerge it (together with its dependencies) if the user requires it. You need write permissions on the directory where Gentoo fetches its source files (usually C</usr/portage/distfiles>).
41 The generated ebuilds are placed into the section C<perl-gcpanp>. They favour depending on C<perl-core> or C<dev-perl> rather than C<perl-gcpanp>.
45 After installing this module, you should append C<perl-gcpanp> to your F</etc/portage/categories> file.
49 All the methods are inherited from L<CPANPLUS::Dist::Base>. Please refer to its perldoc for precise information on what's done at each step.
53 use constant CATEGORY => 'perl-gcpanp';
55 sub format_available {
56 for my $prog (qw/emerge ebuild/) {
57 unless (can_run($prog)) {
58 error "$prog is required to write ebuilds -- aborting";
67 my $stat = $self->status;
68 $stat->mk_accessors(qw/name version dist desc uri src license deps
69 eb_name eb_version eb_dir eb_file distdir fetched_arch
70 keywords do_manifest/);
76 'Digest' => 'digest-base',
77 'Locale-Maketext' => 'locale-maketext',
78 'Net-Ping' => 'net-ping',
79 'PathTools' => 'File-Spec',
80 'PodParser' => 'Pod-Parser',
81 'Set-Scalar' => 'set-scalar',
82 'Tie-EncryptedHash' => 'tie-encryptedhash',
87 my $mod = $self->parent;
88 my $stat = $self->status;
89 my $int = $mod->parent;
90 my $conf = $int->configure_object;
94 my $keywords = delete $opts{'keywords'};
95 $keywords = 'x86' unless defined $keywords;
96 $keywords = [ split ' ', $keywords ];
97 $stat->keywords($keywords);
99 my $manifest = delete $opts{'manifest'};
100 $manifest = 1 unless defined $manifest;
101 $manifest = 0 if $manifest =~ /^\s*no?\s*$/i;
102 $stat->do_manifest($manifest);
104 my $overlay = catdir(delete($opts{'overlay'}) || '/usr/local/portage',
107 $stat->distdir(delete($opts{'distdir'}) || '/usr/portage/distfiles');
108 if ($stat->do_manifest && !-w $stat->distdir) {
109 error 'distdir isn\'t writable -- aborting';
112 $stat->fetched_arch($mod->status->fetch);
114 my $name = $mod->package_name;
117 my $version = $mod->package_version;
118 $stat->version($version);
119 $stat->dist($name . '-' . $version);
121 $version =~ s/_+/$f ? do { $f = 0; '_p' } : ''/ge;
122 1 while $version =~ s/(_p[^.]*)\.+/$1/;
123 $stat->eb_version($version);
125 $stat->eb_name($gentooism{$stat->name} || $stat->name);
126 $stat->eb_dir(catdir($overlay, $stat->eb_name));
127 $stat->eb_file(catfile($stat->eb_dir,
128 $stat->eb_name . '-' . $stat->eb_version . '.ebuild'));
129 if (-r $stat->eb_file) {
130 msg 'Ebuild already generated for ' . $stat->dist . ' -- skipping';
136 $self->SUPER::prepare(%opts);
138 my $desc = $mod->description;
139 ($desc = $name) =~ s/-+/::/g unless $desc;
141 $stat->uri('http://search.cpan.org/dist/' . $name);
142 unless ($name =~ /^([^-]+)/) {
143 error 'Wrong distribution name -- aborting';
146 $stat->src('mirror://cpan/modules/by-module/' . $1 . '/' . $mod->package);
147 $stat->license([ qw/Artistic GPL-2/ ]);
149 my $prereqs = $mod->status->prereqs;
151 for my $prereq (sort keys %$prereqs) {
152 next if $prereq =~ /^perl(?:-|\z)/;
153 my $obj = $int->module_tree($prereq);
155 error 'Wrong module object -- aborting';
158 next if $obj->package_is_perl_core;
161 if ($prereqs->{$prereq}) {
162 if ($obj->installed_version && $obj->installed_version < $obj->version) {
163 $version = $obj->installed_version;
165 $version = $obj->package_version;
168 push @depends, [ $obj , $version ];
171 $stat->deps(\@depends);
178 my $stat = $self->status;
180 unless ($stat->prepared) {
181 error 'Can\'t create ' . $stat->dist . ' since it was never prepared -- aborting';
185 if ($stat->created) {
186 msg $stat->dist . ' was already created -- skipping';
190 $self->SUPER::create(@_);
192 my $dir = $stat->eb_dir;
194 eval { mkpath $dir };
196 error "mkpath($dir): $@";
201 my $d = "# Generated by CPANPLUS::Dist::Gentoo\n\ninherit perl-module\n\n";
202 $d .= 'S="${WORKDIR}/' . $stat->dist . "\"\n";
203 $d .= 'DESCRIPTION="' . $stat->desc . "\"\n";
204 $d .= 'HOMEPAGE="' . $stat->uri . "\"\n";
205 $d .= 'SRC_URI="' . $stat->src . "\"\n";
206 $d .= "SLOT=\"0\"\n";
207 $d .= 'LICENSE="|| ( ' . join(' ', sort @{$stat->license}) . " )\"\n";
208 $d .= 'KEYWORDS="' . join(' ', sort @{$stat->keywords}) . "\"\n";
209 $d .= 'DEPEND="' . join "\n",
212 my $a = $_->[0]->package_name;
214 if (defined $_->[1]) {
218 '|| ( ' . join(' ', map "$x$_/$a",
219 qw/perl-core dev-perl perl-gcpan/, CATEGORY)
224 my $file = $stat->eb_file;
225 open my $eb, '>', $file or do {
226 error "open($file): $! -- aborting";
232 if ($stat->do_manifest) {
233 unless (copy $stat->fetched_arch, $stat->distdir) {
234 error "Couldn\'t copy the distribution file to distdir ($!) -- aborting";
235 1 while unlink $file;
239 msg 'Adding Manifest entry for ' . $stat->dist;
240 unless (scalar run command => [ 'ebuild', $file, 'manifest' ], verbose => 0) {
241 error 'ebuild manifest failed -- aborting';
242 1 while unlink $file;
252 my $stat = $self->status;
253 my $conf = $self->parent->parent->configure_object;
255 my $sudo = $conf->get_program('sudo');
256 my @cmd = ('emerge', '=' . $stat->eb_name . '-' . $stat->eb_version);
257 unshift @cmd, $sudo if $sudo;
259 unless (run command => \@cmd, verbose => 1) {
260 error 'emerge failed -- aborting';
269 my $stat = $self->status;
270 my $conf = $self->parent->parent->configure_object;
272 my $sudo = $conf->get_program('sudo');
273 my @cmd = ('emerge', '-C', '=' . $stat->eb_name . '-' . $stat->eb_version);
274 unshift @cmd, $sudo if $sudo;
276 unless (run command => \@cmd, verbose => 1) {
277 error 'emerge -C failed -- aborting';
286 Gentoo (L<http://gentoo.org>).
288 L<CPANPLUS>, L<IPC::Cmd> (core modules since 5.9.5).
290 L<File::Path> (since 5.001), L<File::Copy> (5.002), L<File::Spec::Functions> (5.00504).
296 L<CPANPLUS::Dist::Base>, L<CPANPLUS::Dist::Deb>, L<CPANPLUS::Dist::Mdv>.
300 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
302 You can contact me by mail or on C<irc.perl.org> (vincent).
306 Please report any bugs or feature requests to C<bug-cpanplus-dist-gentoo at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPANPLUS-Dist-Gentoo>. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
310 You can find documentation for this module with the perldoc command.
312 perldoc CPANPLUS::Dist::Gentoo
314 =head1 ACKNOWLEDGEMENTS
316 The module is to some extend cargo-culted from L<CPANPLUS::Dist::Deb> and L<CPANPLUS::Dist::Mdv>.
318 =head1 COPYRIGHT & LICENSE
320 Copyright 2008 Vincent Pit, all rights reserved.
322 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
326 1; # End of CPANPLUS::Dist::Gentoo