commit 598503e669f997688d34c9f754fdbbce63981696 Author: Dave Cross Date: Mon Aug 25 11:37:19 2008 +0000 Initial revision diff --git a/Build.PL b/Build.PL new file mode 100644 index 0000000..36862f4 --- /dev/null +++ b/Build.PL @@ -0,0 +1,22 @@ +use Module::Build; +use 5.006000; + +my $build = Module::Build->new( + license => 'perl', + dist_version => '0.01', + dist_author => 'Dave Cross ', + module_name => 'Parse::RPM::Spec', + requires => { + perl => '5.6.0', + }, + build_requires => { + 'Test::More' => 0, + }, + build_recommends => { + 'Test::Pod' => 0, + 'Test::Pod::Coverage' => 0, + }, + create_makefile_pl => 'traditional', +); + +$build->create_build_script; diff --git a/Changes b/Changes new file mode 100644 index 0000000..930747b --- /dev/null +++ b/Changes @@ -0,0 +1,6 @@ +Revision history for Perl extension Parse::RPM::Spec. + +0.01 Mon Aug 25 11:41:00 2008 + - original version; created by h2xs 1.23 with options + -X -n Parse::RPM::Spec + diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000..2a531a9 --- /dev/null +++ b/MANIFEST @@ -0,0 +1,6 @@ +Changes +Build.PL +MANIFEST +README +t/Parse-RPM-Spec.t +lib/Parse/RPM/Spec.pm diff --git a/README b/README new file mode 100644 index 0000000..ecc02d8 --- /dev/null +++ b/README @@ -0,0 +1,40 @@ +Parse-RPM-Spec version 0.01 +=========================== + +The README is used to introduce the module and provide instructions on +how to install the module, any machine dependencies it may have (for +example C compilers and installed libraries) and any other information +that should be provided before the module is installed. + +A README file is required for CPAN modules since CPAN extracts the +README file from a module distribution so that people browsing the +archive can use it get an idea of the modules uses. It is usually a +good idea to provide version information here so that people can +decide whether fixes for the module are worth downloading. + +INSTALLATION + +To install this module type the following: + + perl Makefile.PL + make + make test + make install + +DEPENDENCIES + +This module requires these other modules and libraries: + + blah blah blah + +COPYRIGHT AND LICENCE + +Put the correct copyright and licence information here. + +Copyright (C) 2008 by Dave Cross + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.10.0 or, +at your option, any later version of Perl 5 you may have available. + + diff --git a/lib/Parse/RPM/Spec.pm b/lib/Parse/RPM/Spec.pm new file mode 100644 index 0000000..9a4e84d --- /dev/null +++ b/lib/Parse/RPM/Spec.pm @@ -0,0 +1,153 @@ +package Parse::RPM::Spec; + +use 5.006000; +use strict; +use warnings; + +use Carp; + +our @ISA = qw(Exporter); + +our $VERSION = '0.01'; + +my @attr = qw(name version release summary license gropu url source + buildroot buildarch buildrequires requires); + +my %attr = map { $_ => 1 } @attr; + +sub new { + my $class = shift; + + my $args = shift; + my $self = {}; + + if (my $type = ref $args) { + if ($type eq 'HASH') { + $self = $args; + } else { + croak "Unknown reference of type $type passed to ${class}::new\n"; + } + } else { + $self->{file} = $args; + } + + $self = bless $self, $class; + + $self->parse_file; + + return $self; +} + +sub parse_file { + my $self = shift; + + my $file = shift || $self->{file}; + + unless (defined $file) { + croak "No spec file to parse\n"; + } + + unless (-e $file) { + croak "Spec file $file doesn't exist\n"; + } + + unless (-r $file) { + croak "Cannot read spec file $file\n"; + } + + unless (-s $file) { + croak "Spec file $file is empty\n"; + } + + open my $fh, $file or croak "Cannot open $file: $!\n"; + + while (<$fh>) { + /^Name:\s*(\S+)/ and $self->{name} = $1; + /^Version:\s*(\S+)/ and $self->{version} = $1; + /^Release:\s*(\S+)/ and $self->{release} = $1; + /^Summary:\s*(\S+)/ and $self->{summary} = $1; + /^License:\s*(.+)/ and $self->{license} = $1; + /^Group:\s*(\S+)/ and $self->{group} = $1; + /^URL:\s*(\S+)/ and $self->{url} = $1; + /^Source0:\s*(\S+)/ and $self->{source} = $1; + /^BuildRoot:\s*(\S+)/ and $self->{buildroot} = $1; + + /^BuildRequires:\s*(.+)/ and push @{$self->{buildrequires}}, $1; + /^Requires:\s*(.+)/ and push @{$self->{requires}}, $1; + } + + return $self; +} + +sub AUTOLOAD { + our $AUTOLOAD; + + my $self = shift; + + my ($attr) = $AUTOLOAD =~ /.*::(.*)/; + + unless ($attr{$attr}) { + croak "Invalid attribute: $attr\n"; + } + + my $val = $self->{$attr}; + + if (@_) { + $self->{$attr} = shift; + } + + return $val; +} + +1; +__END__ +# Below is stub documentation for your module. You'd better edit it! + +=head1 NAME + +Parse::RPM::Spec - Perl extension for blah blah blah + +=head1 SYNOPSIS + + use Parse::RPM::Spec; + blah blah blah + +=head1 DESCRIPTION + +Stub documentation for Parse::RPM::Spec, created by h2xs. It looks like the +author of the extension was negligent enough to leave the stub +unedited. + +Blah blah blah. + +=head2 EXPORT + +None by default. + + + +=head1 SEE ALSO + +Mention other useful documentation such as the documentation of +related modules or operating system documentation (such as man pages +in UNIX), or any relevant external documentation such as RFCs or +standards. + +If you have a mailing list set up for your module, mention it here. + +If you have a web site set up for your module, mention it here. + +=head1 AUTHOR + +Dave Cross, Edave@localdomainE + +=head1 COPYRIGHT AND LICENSE + +Copyright (C) 2008 by Dave Cross + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself, either Perl version 5.10.0 or, +at your option, any later version of Perl 5 you may have available. + + +=cut diff --git a/t/Parse-RPM-Spec.t b/t/Parse-RPM-Spec.t new file mode 100644 index 0000000..ada2049 --- /dev/null +++ b/t/Parse-RPM-Spec.t @@ -0,0 +1,19 @@ +use Test::More tests => 12; +BEGIN { use_ok('Parse::RPM::Spec') }; + +eval { my $spec = Parse::RPM::Spec->new(\'t/file.spec') }; +ok($@); +like($@, qr/SCALAR/); + +ok($spec = Parse::RPM::Spec->new('t/file.spec')); +isa_ok($spec, 'Parse::RPM::Spec'); + +ok($spec = Parse::RPM::Spec->new({ file => 't/file.spec' })); +isa_ok($spec, 'Parse::RPM::Spec'); + +is($spec->name, 'perl-Array-Compare'); +is($spec->version, '1.16'); +$spec->version('1.17'); +is($spec->version, '1.17'); +is(@{$spec->buildrequires}, 2); +is($spec->buildrequires->[0], 'perl >= 1:5.6.0'); diff --git a/t/file.spec b/t/file.spec new file mode 100644 index 0000000..0987611 --- /dev/null +++ b/t/file.spec @@ -0,0 +1,48 @@ +Name: perl-Array-Compare +Version: 1.16 +Release: 1%{?dist} +Summary: Perl extension for comparing arrays +License: GPL+ or Artistic +Group: Development/Libraries +URL: http://search.cpan.org/dist/Array-Compare/ +Source0: http://www.cpan.org/authors/id/D/DA/DAVECROSS/Array-Compare-%{version}.tar.gz +BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) +BuildArch: noarch +BuildRequires: perl >= 1:5.6.0 +BuildRequires: perl(Module::Build) +Requires: perl(:MODULE_COMPAT_%(eval "`%{__perl} -V:version`"; echo $version)) + +%description +If you have two arrays and you want to know if they are the same or +different, then Array::Compare will be useful to you. + +%prep +%setup -q -n Array-Compare-%{version} + +%build +%{__perl} Build.PL installdirs=vendor +./Build + +%install +rm -rf $RPM_BUILD_ROOT + +./Build install destdir=$RPM_BUILD_ROOT create_packlist=0 +find $RPM_BUILD_ROOT -depth -type d -exec rmdir {} 2>/dev/null \; + +%{_fixperms} $RPM_BUILD_ROOT/* + +%check +./Build test + +%clean +rm -rf $RPM_BUILD_ROOT + +%files +%defattr(-,root,root,-) +%doc Changes README +%{perl_vendorlib}/* +%{_mandir}/man3/* + +%changelog +* Tue Aug 19 2008 Dave Cross 1.16-1 +- Specfile autogenerated by cpanspec 1.77.