summaryrefslogtreecommitdiffstats
path: root/preps/perl
diff options
context:
space:
mode:
authorJustin Davis <jrcd83@gmail.com>2012-04-16 01:03:20 +0200
committerJustin Davis <jrcd83@gmail.com>2012-04-16 01:03:20 +0200
commit690e3e9a39e2691b483474725ee1a17d44231401 (patch)
tree9919cf2319fa08b8392659b63465c5c1434357c6 /preps/perl
parent10ef1c3abeb88af473c34f8ddd18da3148796823 (diff)
downloadgenpkg-690e3e9a39e2691b483474725ee1a17d44231401.tar.gz
genpkg-690e3e9a39e2691b483474725ee1a17d44231401.tar.xz
Rename the metas/ directory to preps/.
This matches the prepkg script name.
Diffstat (limited to 'preps/perl')
-rwxr-xr-xpreps/perl106
1 files changed, 106 insertions, 0 deletions
diff --git a/preps/perl b/preps/perl
new file mode 100755
index 0000000..9f8bb35
--- /dev/null
+++ b/preps/perl
@@ -0,0 +1,106 @@
+#!/usr/bin/env perl
+
+use warnings 'FATAL' => 'all';
+use strict;
+
+use File::Fetch;
+use IO::Handle; # for autoflush
+use Cwd;
+
+my $PROG = 'preps/perl';
+my %BADNAMES = ('perl-libwww' => 'libwww-perl');
+
+sub err
+{
+ print STDERR "$PROG: ", @_, "\n";
+ exit 1;
+}
+
+sub matchdist
+{
+ my($dist) = @_;
+
+ # Refresh our local list of distributions if needed.
+ my $var = $ENV{'PKGVAR'}
+ or err('PKGVAR env variable is unset');
+
+ if(!-f "$var/cpandists" || -M "$var/cpandists" > 1) {
+ print STDERR "$PROG: Refreshing local CPAN data... ";
+ my $cwd = getcwd();
+ chdir $var or die "chdir: $!";
+ system 'fetchcpan';
+ die "FAILED\n" unless($? == 0);
+ print STDERR "OK\n";
+ chdir $cwd or die "chdir: $!";
+ }
+
+ open(DISTS, '<', "$var/cpandists") or err("open: $!");
+ while(<DISTS>) {
+ my @f = split;
+ my $d = lc $f[0]; $d =~ tr/-_/--/s;
+ next unless($d eq lc($dist));
+ close(DISTS);
+ return ($f[0], $f[2]);
+ }
+ close(DISTS);
+ return ();
+}
+
+sub fetchdist
+{
+ my($cpath) = @_;
+ my $file = $cpath; $file =~ s{^.*/}{};
+ if(-f $file) {
+ print STDERR "$file already downloaded.\n";
+ return;
+ }
+
+ my $mirror = $ENV{'CPANMIRROR'} || 'ftp://cpan.pair.com';
+ my $url = "${mirror}/authors/id/${cpath}";
+
+ print STDERR "Downloading $file... ";
+ my $ff = File::Fetch->new('uri' => $url);
+ die "FAILED\n" unless($ff->fetch());
+ print STDERR "OK\n";
+}
+
+sub main
+{
+ my $dist = shift or die "usage: $PROG [package name]\n";
+
+ my $guess;
+ if($BADNAMES{$dist}){
+ $dist = $BADNAMES{$dist};
+ }elsif($dist =~ s/^perl-// == 0){
+ $guess = 1;
+ $dist = "app-$dist";
+ }
+
+ STDERR->autoflush(1);
+ my ($realname, $cpath) = matchdist($dist);
+ unless($realname){
+ if($guess){
+ return 2
+ }else{
+ ## Return a hard error to makepkgmeta if perl- package.
+ err(qq{failed to find perl dist similar to '$dist'});
+ return 1
+ }
+ }
+ fetchdist($cpath);
+
+ print <<"END_META";
+url
+https://metacpan.org/release/$realname
+
+source
+http://search.cpan.org/CPAN/authors/id/$cpath
+
+END_META
+
+ my $file = $cpath; $file =~ s{.*/}{};
+ system 'perl-dist' => $file;
+ return $? >> 8;
+}
+
+exit main(@ARGV);