[devel] cpan2spec

Alexey Tourbin =?iso-8859-1?q?at_=CE=C1_altlinux=2Eru?=
Чт Апр 29 00:37:40 MSD 2004


Здравствуйте.
У кого-нибудь есть любимые перловые модули, которых нет в сизифе?
Нарисовал скрипт для упрощенной генерации spec-файла (наподобие
cpan2rpm, но окончательно джина из бутылки выпускать нельзя:)).

$ cpan2spec ~/RPM/SOURCES/Bloom-Filter-0.02.tar.bz2
%define dist Bloom-Filter
Name: perl-%dist
Version: 0.02
Release: alt1

Summary: Sample Perl Bloom filter implementation
License: GPL or Artistic
Group: Development/Perl

URL: %CPAN %dist
Source: %dist-%version.tar.bz2

BuildArch: noarch

%description
A Bloom filter is a probabilistic algorithm for doing existence tests
in less memory than a full list of keys would require.  The tradeoff to
using Bloom filters is a certain configurable risk of false positives. 
This module implements a simple Bloom filter with configurable capacity
and false positive rate. Bloom filters were first described in a 1970 
paper by Burton Bloom, see http://portal.acm.org/citation.cfm?id=362692&dl=ACM&coll=portal.


%prep
%setup -q -n %dist-%version

%build
%perl_vendor_build

%install
%perl_vendor_install

%files
%doc README Changes
%perl_vendor_privlib/Bloom*
%perl_vendor_man3dir/Bloom*
$
----------- следующая часть -----------
#!/usr/bin/perl
# $Id$

use Switch;
use Cwd qw(realpath);
use ExtUtils::MakeMaker;
use File::Find qw(find);
use File::Temp qw(tempdir);
use sigtrap qw(die normal-signals);
use strict;

my %spec = (
	Name => 'perl-%dist',
	Release => 'alt1',
	License => 'GPL or Artistic',
	Group => 'Development/Perl',
	URL => '%CPAN %dist',
	Source => '%dist-%version.tar.bz2',
	BuildArch => 'noarch',
	prep => '%setup -q -n %dist-%version',
	build => '%perl_vendor_build',
	install => '%perl_vendor_install',
);

my @order = (
# name, type, optional
	[qw[ dist macro ]],
	[qw[ Name tag ]],
	[qw[ Version tag ]],
	[qw[ Release tag ]],
	[qw[ ]],
	[qw[ Summary tag ]],
	[qw[ License tag ]],
	[qw[ Group tag ]],
	[qw[ ]],
	[qw[ URL tag ]],
	[qw[ Source tag ]],
	[qw[ ]],
	[qw[ BuildArch tag 1 ]],
	[qw[ ]],
	[qw[ description section ]],
	[qw[ ]],
	[qw[ prep section ]],
	[qw[ ]],
	[qw[ build section ]],
	[qw[ ]],
	[qw[ install section ]],
	[qw[ ]],
	[qw[ files section ]],
);

@ARGV == 1 or print STDERR <<EOF and exit(1);
Usage:
1) go get your module at http://search.cpan.org/
2) zme <module>.tar.gz
3) $0 <module>.tar.*z* > ~/RPM/SOURES/perl-<module>.spec
4) vim ~/RPM/SOURES/perl-<module>.spec
5) buildreq ~/RPM/SOURES/perl-<module>.spec
6) add_changelog -e 'initial revision' ~/RPM/SOURES/perl-<module>.spec
7) rpm -ba ~/RPM/SOURES/perl-<module>.spec
EOF

{
	my $tarball = realpath $ARGV[0];
	my $dir = tempdir "cpan2spec.XXXXXXXXXX", TMPDIR => 1, CLEANUP => 1;
	chdir $dir;
	my $z	=	$tarball =~ /\.tar.bz2$/	&&	'j'
		||	$tarball =~ /\.tar.gz$/		&&	'z'
		||	do {	my $exhort = q(shpx gneonyy);
				$exhort =~ tr/A-Za-z/N-ZA-Mn-za-m/;
				die "$exhort $tarball\n";
			};
	system "tar", "xf$z", $tarball;
	chdir <*>;

	my $makefile;
	system $^X, qw(-pi -e s/\bexit\b/return/g Makefile.PL);
	*ExtUtils::MakeMaker::WriteMakefile = 
		sub { $makefile = { @_ }; bless $makefile, 'MM' }
		and do './Makefile.PL';
	$$makefile{DISTNAME} ||= $$makefile{NAME} and $$makefile{DISTNAME} =~ s/::/-/g;
	$spec{dist} ||= $$makefile{DISTNAME};

	find { wanted => sub { $$makefile{VERSION_FROM} ||= $_ if /\.pm$/ } 
		=> no_chdir => 1 } => ".";
		
	$spec{Version} ||= $$makefile{VERSION} ||
		$makefile->parse_version($$makefile{VERSION_FROM});
	$spec{Summary} ||= $$makefile{ABSTRACT}	|| 
		$makefile->parse_abstract($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
	$spec{Summary} ||= do {
		open my $fh, ($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
		my @lines = <$fh>;
		shift @lines while grep { /^=head1\s+name/i } @lines;
		shift @lines; local $_ = shift @lines;
		s/^[\w:-]+\s+[^\w\s]+\s+//;
		$_;
	};
	$spec{description} ||= do {
		open my $fh, ($$makefile{ABSTRACT_FROM} || $$makefile{VERSION_FROM});
		my @lines = <$fh>;
		shift @lines while grep { /^=head1\s+descr/i } @lines;
		shift @lines; local $_ = shift @lines;
		for my $line (@lines) {
			last unless $line =~ /\S/;
			$_ .= $line;
		}
		$_;
	};
	
	my $xs;
	find sub { ++$xs if /\.(xs|c)$/ } => ".";
	delete $spec{BuildArch} if $xs;
	
	my @doc = (<README*>, <Change*>);
	$spec{files} .= "\%doc @doc\n" if @doc;
	
	my %glob;
	find sub { /\.pm$/ and do {
			open my $fh, $_; 
			map { /^package\s+(\w+)/ && ++$glob{$1} } <$fh>; 
		}} => ".";
	foreach my $glob (sort keys %glob) {
		$spec{files} .= $xs
		? "\%perl_vendor_archlib/$glob*\n\%perl_vendor_autolib/$glob*\n"
		: "\%perl_vendor_privlib/$glob*\n";
		$spec{files} .= "\%perl_vendor_man3dir/$glob*\n";
	}
}

for (@order) {
	print "\n" and next unless @$_;
	next if not $spec{$$_[0]} and $$_[2];
	switch ($$_[1]) {
		case 'macro'	{ print "\%define $$_[0] " }
		case 'tag'	{ print "$$_[0]: " }
		case 'section'	{ print "\%$$_[0]\n" }
		else 		{ die "$$_[1] \n" }
	}
	print $spec{$$_[0]} . "\n";
}
----------- следующая часть -----------
Было удалено вложение не в текстовом формате...
Имя     : =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Тип     : application/pgp-signature
Размер  : 189 байтов
Описание: =?iso-8859-1?q?=CF=D4=D3=D5=D4=D3=D4=D7=D5=C5=D4?=
Url     : <http://lists.altlinux.org/pipermail/devel/attachments/20040429/0a41e140/attachment-0001.bin>


Подробная информация о списке рассылки Devel