Made the spec parser more configurable (and a little more efficient).
This commit is contained in:
parent
eda3f47208
commit
2256f515aa
1 changed files with 32 additions and 14 deletions
|
@ -57,21 +57,39 @@ sub parse_file {
|
||||||
|
|
||||||
open my $fh, $file or croak "Cannot open $file: $!\n";
|
open my $fh, $file or croak "Cannot open $file: $!\n";
|
||||||
|
|
||||||
while (<$fh>) {
|
my %strings = (
|
||||||
/^Name:\s*(\S+)/ and $self->{name} = $1;
|
name => qr[^Name:\s*(\S+)],
|
||||||
/^Version:\s*(\S+)/ and $self->{version} = $1;
|
version => qr[^Version:\s*(\S+)],
|
||||||
/^Epoch:\s*(\S+)/ and $self->{epoch} = $1;
|
epoch => qr[^Epoch:\s*(\S+)],
|
||||||
/^Release:\s*(\S+)/ and $self->{release} = $1;
|
release => qr[^Release:\s*(\S+)],
|
||||||
/^Summary:\s*(.+)/ and $self->{summary} = $1;
|
summary => qr[^Summary:\s*(.+)],
|
||||||
/^License:\s*(.+)/ and $self->{license} = $1;
|
license => qr[^License:\s*(.+)],
|
||||||
/^Group:\s*(\S+)/ and $self->{group} = $1;
|
group => qr[^Group:\s*(\S+)],
|
||||||
/^URL:\s*(\S+)/ and $self->{url} = $1;
|
url => qr[^URL:\s*(\S+)],
|
||||||
/^Source\d*:\s*(\S+)/ and push @{$self->{source}}, $1;
|
buildroot => qr[^BuildRoot:\s*(\S+)],
|
||||||
/^BuildRoot:\s*(\S+)/ and $self->{buildroot} = $1;
|
buildarch => qr[^BuildArch:\s*(\S+)],
|
||||||
/^BuildArch:\s*(\S+)/ and $self->{buildarch} = $1;
|
);
|
||||||
|
|
||||||
/^BuildRequires:\s*(.+)/ and push @{$self->{buildrequires}}, $1;
|
my %arrays = (
|
||||||
/^Requires:\s*(.+)/ and push @{$self->{requires}}, $1;
|
source => qr[^Source\d*:\s*(\S+)],
|
||||||
|
buildrequires => qr[^BuildRequires:\s*(.+)],
|
||||||
|
requires => qr[^Requires:\s*(.+)],
|
||||||
|
);
|
||||||
|
|
||||||
|
LINE: while (<$fh>) {
|
||||||
|
foreach my $attr (keys %strings) {
|
||||||
|
if (/$strings{$attr}/) {
|
||||||
|
$self->{$attr} = $1;
|
||||||
|
next LINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach my $attr (keys %arrays) {
|
||||||
|
if (/$arrays{$attr}/) {
|
||||||
|
push @{$self->{$attr}}, $1;
|
||||||
|
next LINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
|
Loading…
Add table
Reference in a new issue