Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Rewrote examples/cpanpkgbuild.pl.
Instead of writing to a file we print the PKGBUILD to stdout.
Removed strict and warnings because the script is so short.
Rewrote the style to match my latest.
  • Loading branch information
juster committed Aug 18, 2013
1 parent e97f10a commit 71b7311
Showing 1 changed file with 23 additions and 71 deletions.
94 changes: 23 additions & 71 deletions examples/cpanpkgbuild.pl
@@ -1,81 +1,33 @@
#!/usr/bin/perl

use warnings;
use strict;

use CPANPLUS::Backend;
use Getopt::Long;
use Pod::Usage;
use English '-no_match_vars';

BEGIN {
eval { require CPANPLUS::Dist::Arch; }
or die 'CPANPLUS::Dist::Arch must be installed for this script to work.'
if(@ARGV < 1){
print STDERR "usage: cpanpkgbuild.pl [module]\n";
exit 2;
}

my $force;
GetOptions( force => \$force ); # must be before messing with @ARGV

my $modname = shift @ARGV or pod2usage;

# Check if a PKGBUILD already exists...
die << 'END_ERROR' if ( -f 'PKGBUILD' && !$force );
PKGBUILD already exists in current directory. Use -f to force overwrite.
END_ERROR

my $cb = CPANPLUS::Backend->new;
my $modobj = $cb->module_tree($modname)
or die qq{module '$modname' not found in CPANPLUS};

# Try to avoid interactive requests...
$cb->configure_object->set_conf( 'prereqs', 0 );
$ENV{PERL_AUTOINSTALL} = '--skipdeps';

# Prepare the package, but don't install it...
$modobj->fetch ( verbose => 0 );
$modobj->extract( verbose => 0 );
my $distobj = $modobj->dist( target => 'prepare',
format => 'CPANPLUS::Dist::Arch' )
or die q{failed to prepare distribution object};

# Get the PKGBUILD from CPANPLUS::Dist::Arch and print to a file...
my $pkgbuild_txt = $distobj->get_pkgbuild()
or die q{ERROR get_pkgbuild() returned an empty string};
$m = shift;
if(!eval { require CPANPLUS::Dist::Arch; }){
print STDERR "error: failed to load CPANPLUS::Dist::Arch\n";
exit 1;
}

open my $pkgbuild_file, '>', 'PKGBUILD'
or die qq{ERROR creating PKGBUILD: $OS_ERROR};
print $pkgbuild_file $pkgbuild_txt;
close $pkgbuild_file
or die qq{ERROR closing new PKGBUILD: $OS_ERROR};
$cb = new CPANPLUS::Backend;
$x = $cb->module_tree($m);
if(!$x){
print STDERR "error: module not found: $m\n";
exit 100;
}

print "Created PKGBUILD.\n";
$cb->configure_object->set_conf('prereqs' => 0);
$x->fetch('verbose' => 0);
$x->extract('verbose' => 0);
$y = $x->dist('target' => 'prepare', 'format' => 'CPANPLUS::Dist::Arch');
if(!$y){
print STDERR "error: failed to prepare distribution\n";
exit 1;
}

print $y->get_pkgbuild();
exit 0;

__END__
=head1 NAME
cpanpkgbuild.pl - Create a PKGBUILD file for a perl module
=head1 SYNOPSIS
cpanpkgbuild.pl [-f] DBD::SQLite
Will create a PKGBUILD in the current directory for DBD::SQLite. Then
use your favorite editor to customize PKGBUILD, run makepkg on it,
etc. etc. The -f or -force flag forces overwriting any existing PKGBUILD.
=head1 AUTHOR
Justin Davis, C<< <jrcd83 at gmail.com> >>, juster on
L<http://bbs.archlinux.org>
=head1 COPYRIGHT & LICENSE
Copyright 2009 Justin Davis, all rights reserved.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut

0 comments on commit 71b7311

Please sign in to comment.