diff options
-rw-r--r-- | scripts/Dpkg/Changelog/Parse.pm | 2 | ||||
-rw-r--r-- | scripts/Dpkg/Control/Hash.pm | 27 | ||||
-rw-r--r-- | scripts/Dpkg/Control/Info.pm | 43 | ||||
-rw-r--r-- | scripts/Dpkg/Index.pm | 2 | ||||
-rw-r--r-- | scripts/Dpkg/Source/Package.pm | 4 | ||||
-rw-r--r-- | scripts/Dpkg/Vendor.pm | 4 | ||||
-rwxr-xr-x | scripts/dpkg-genchanges.pl | 4 | ||||
-rwxr-xr-x | scripts/dpkg-name.pl | 2 | ||||
-rwxr-xr-x | scripts/dpkg-scanpackages.pl | 2 | ||||
-rwxr-xr-x | scripts/dpkg-scansources.pl | 2 | ||||
-rw-r--r-- | scripts/t/700_Dpkg_Control.t | 2 |
11 files changed, 40 insertions, 54 deletions
diff --git a/scripts/Dpkg/Changelog/Parse.pm b/scripts/Dpkg/Changelog/Parse.pm index 6f7dd6ce4..554d5985f 100644 --- a/scripts/Dpkg/Changelog/Parse.pm +++ b/scripts/Dpkg/Changelog/Parse.pm @@ -144,7 +144,7 @@ sub changelog_parse { my (@res, $fields); while (1) { $fields = Dpkg::Control::Changelog->new(); - last unless $fields->parse_fh(\*P, _g("output of changelog parser")); + last unless $fields->parse(\*P, _g("output of changelog parser")); push @res, $fields; } close(P) or subprocerr(_g("changelog parser %s"), $parser); diff --git a/scripts/Dpkg/Control/Hash.pm b/scripts/Dpkg/Control/Hash.pm index 75fbc8957..f42525f9d 100644 --- a/scripts/Dpkg/Control/Hash.pm +++ b/scripts/Dpkg/Control/Hash.pm @@ -26,10 +26,11 @@ use Dpkg::ErrorHandling; # Dpkg::Control::Fields itself (Dpkg::Vendor) # That's why field_capitalize is duplicated +use base qw(Dpkg::Interface::Storable); + use overload '%{}' => sub { ${$_[0]}->{'fields'} }, - 'eq' => sub { "$_[0]" eq "$_[1]" }, - '""' => \&output; + 'eq' => sub { "$_[0]" eq "$_[1]" }; =head1 NAME @@ -136,22 +137,12 @@ sub get_option { return $$self->{$k}; } -=item $c->parse($file) +=item $c->load($file) Parse the content of $file. Exits in case of errors. Returns true if some fields have been parsed. -=cut - -sub parse { - my ($self, $file) = @_; - open(CDATA, "<", $file) || syserr(_g("cannot read %s"), $file); - my $res = $self->parse_fh(\*CDATA, $file); - close(CDATA); - return $res; -} - -=item $c->parse_fh($fh, $description) +=item $c->parse($fh, $description) Parse a control file from the given filehandle. Exits in case of errors. $description is used to describe the filehandle, ideally it's a filename @@ -160,7 +151,7 @@ messages. Returns true if some fields have been parsed. =cut -sub parse_fh { +sub parse { my ($self, $fh, $desc) = @_; my $paraborder = 1; @@ -256,7 +247,13 @@ sub get_custom_field { return undef; } +=item $c->save($filename) + +Write the string representation of the control information to a +file. + =item my $str = $c->output() + =item "$c" Get a string representation of the control information. The fields diff --git a/scripts/Dpkg/Control/Info.pm b/scripts/Dpkg/Control/Info.pm index 72fd9abae..14bdad149 100644 --- a/scripts/Dpkg/Control/Info.pm +++ b/scripts/Dpkg/Control/Info.pm @@ -22,6 +22,8 @@ use Dpkg::Control; use Dpkg::ErrorHandling; use Dpkg::Gettext; +use base qw(Dpkg::Interface::Storable); + =head1 NAME Dpkg::Control::Info - parse files like debian/control @@ -37,8 +39,8 @@ syntax than debian/control. =item $c = Dpkg::Control::Info->new($file) -Create a new Dpkg::Control::Info object for $file. If $file is omitted, it parses -debian/control. If file is "-", it parses the standard input. +Create a new Dpkg::Control::Info object for $file. If $file is omitted, it +loads debian/control. If file is "-", it parses the standard input. =cut @@ -52,12 +54,12 @@ sub new { bless $self, $class; if ($arg) { if ($arg eq "-") { - $self->parse_fh(\*STDIN, _g("<standard input>")); + $self->parse(\*STDIN, _g("<standard input>")); } else { - $self->parse($arg); + $self->load($arg); } } else { - $self->parse("debian/control"); + $self->load("debian/control"); } return $self; } @@ -74,20 +76,11 @@ sub reset { $self->{packages} = []; } -=item $c->parse($file) +=item $c->load($file) -Parse the content of $file. Exits in case of errors. +Load the content of $file. Exits in case of errors. -=cut - -sub parse { - my ($self, $file) = @_; - open(CDATA, "<", $file) || syserr(_g("cannot read %s"), $file); - $self->parse_fh(\*CDATA, $file); - close(CDATA); -} - -=item $c->parse_fh($fh, $description) +=item $c->parse($fh, $description) Parse a control file from the given filehandle. Exits in case of errors. $description is used to describe the filehandle, ideally it's a filename @@ -96,18 +89,18 @@ messages. =cut -sub parse_fh { +sub parse { my ($self, $fh, $desc) = @_; $self->reset(); my $cdata = Dpkg::Control->new(type => CTRL_INFO_SRC); - return if not $cdata->parse_fh($fh, $desc); + return if not $cdata->parse($fh, $desc); $self->{source} = $cdata; unless (exists $cdata->{Source}) { syntaxerr($desc, _g("first block lacks a source field")); } while (1) { $cdata = Dpkg::Control->new(type => CTRL_INFO_PKG); - last if not $cdata->parse_fh($fh, $desc); + last if not $cdata->parse($fh, $desc); push @{$self->{packages}}, $cdata; unless (exists $cdata->{Package}) { syntaxerr($desc, _g("block lacks a package field")); @@ -166,19 +159,21 @@ sub get_packages { return @{$self->{packages}}; } -=item $c->dump($filehandle) +=item $c->output($filehandle) Dump the content into a filehandle. =cut -sub dump { +sub output { my ($self, $fh) = @_; - $self->{source}->output($fh); + my $str; + $str .= $self->{source}->output($fh); foreach my $pkg (@{$self->{packages}}) { print $fh "\n"; - $pkg->output($fh); + $str .= "\n" . $pkg->output($fh); } + return $str; } =back diff --git a/scripts/Dpkg/Index.pm b/scripts/Dpkg/Index.pm index c7bccf19f..f010f8b40 100644 --- a/scripts/Dpkg/Index.pm +++ b/scripts/Dpkg/Index.pm @@ -163,7 +163,7 @@ sub parse { my ($self, $fh, $desc) = @_; my $item = $self->new_item(); my $i = 0; - while ($item->parse_fh($fh, $desc)) { + while ($item->parse($fh, $desc)) { $self->add($item); $item = $self->new_item(); $i++; diff --git a/scripts/Dpkg/Source/Package.pm b/scripts/Dpkg/Source/Package.pm index 61f00a94d..9fe3df989 100644 --- a/scripts/Dpkg/Source/Package.pm +++ b/scripts/Dpkg/Source/Package.pm @@ -137,10 +137,8 @@ sub initialize { } close(DSC); # Read the fields - open(CDATA, "<", $filename) || syserr(_g("cannot open %s"), $filename); my $fields = Dpkg::Control->new(type => CTRL_PKG_SRC); - $fields->parse_fh(\*CDATA, sprintf(_g("source control file %s"), $filename)); - close(CDATA); + $fields->load($filename); $self->{'fields'} = $fields; foreach my $f (qw(Source Format Version Files)) { diff --git a/scripts/Dpkg/Vendor.pm b/scripts/Dpkg/Vendor.pm index 41672e638..22f40fea9 100644 --- a/scripts/Dpkg/Vendor.pm +++ b/scripts/Dpkg/Vendor.pm @@ -60,10 +60,8 @@ sub get_vendor_info(;$) { my $vendor = shift || "default"; my $file = get_vendor_file($vendor); return undef unless $file; - open(my $fh, "<", $file) || syserr(_g("cannot read %s"), $file); my $fields = Dpkg::Control::Hash->new(); - $fields->parse_fh($fh, $file) || error(_g("%s is empty"), $file); - close($fh); + $fields->load($file) || error(_g("%s is empty"), $file); return $fields; } diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl index d83623206..df5557641 100755 --- a/scripts/dpkg-genchanges.pl +++ b/scripts/dpkg-genchanges.pl @@ -393,12 +393,10 @@ if (!is_binaryonly) { (my $sversion = $substvars->get('source:Version')) =~ s/^\d+://; $dsc= "$uploadfilesdir/${sourcepackage}_${sversion}.dsc"; - open(CDATA, "<", $dsc) || syserr(_g("cannot open .dsc file %s"), $dsc); push(@sourcefiles,"${sourcepackage}_${sversion}.dsc"); my $dsc_fields = Dpkg::Control->new(type => CTRL_PKG_SRC); - $dsc_fields->parse_fh(\*CDATA, sprintf(_g("source control file %s"), $dsc)) || - error(_g("%s is empty", $dsc)); + $dsc_fields->load($dsc) || error(_g("%s is empty", $dsc)); readallchecksums($dsc_fields, \%checksum, \%size); diff --git a/scripts/dpkg-name.pl b/scripts/dpkg-name.pl index 6b9f4c117..bdeaf6e64 100755 --- a/scripts/dpkg-name.pl +++ b/scripts/dpkg-name.pl @@ -95,7 +95,7 @@ sub getfields($) open(CDATA, '-|', "dpkg-deb", "-f", "--", $filename) || syserr(_g("cannot open %s"), $filename); my $fields = Dpkg::Control->new(type => CTRL_PKG_DEB); - $fields->parse_fh(\*CDATA, sprintf(_g("binary control file %s"), $filename)); + $fields->parse(\*CDATA, sprintf(_g("binary control file %s"), $filename)); close(CDATA); return $fields; diff --git a/scripts/dpkg-scanpackages.pl b/scripts/dpkg-scanpackages.pl index 9318864ab..a2099130a 100755 --- a/scripts/dpkg-scanpackages.pl +++ b/scripts/dpkg-scanpackages.pl @@ -189,7 +189,7 @@ FILE: my $pid = spawn('exec' => [ "dpkg-deb", "-I", $fn, "control" ], 'to_pipe' => \$output); my $fields = Dpkg::Control->new(type => CTRL_INDEX_PKG); - $fields->parse_fh($output, $fn) + $fields->parse($output, $fn) or error(_g("couldn't parse control information from %s."), $fn); wait_child($pid, no_check => 1); if ($?) { diff --git a/scripts/dpkg-scansources.pl b/scripts/dpkg-scansources.pl index 8339233e4..bfe73b27c 100755 --- a/scripts/dpkg-scansources.pl +++ b/scripts/dpkg-scansources.pl @@ -224,7 +224,7 @@ sub process_dsc { # Parse ‘.dsc’ file. my $fields = Dpkg::Control->new(type => CTRL_PKG_SRC); - $fields->parse($file); + $fields->load($file); $fields->set_options(type => CTRL_INDEX_SRC); # Get checksums diff --git a/scripts/t/700_Dpkg_Control.t b/scripts/t/700_Dpkg_Control.t index 73c31c05d..269de5d84 100644 --- a/scripts/t/700_Dpkg_Control.t +++ b/scripts/t/700_Dpkg_Control.t @@ -27,7 +27,7 @@ my $datadir = $srcdir . '/t/700_Dpkg_Control'; my $c = Dpkg::Control::Info->new("$datadir/control-1"); my $io = IO::String->new(); -$c->dump($io); +$c->output($io); my $value = ${$io->string_ref()}; my $expected = 'Source: mysource My-Field-One: myvalue1 |