summaryrefslogtreecommitdiff
path: root/scripts/Dpkg/Control
diff options
context:
space:
mode:
authorRaphaël Hertzog <hertzog@debian.org>2010-02-18 23:57:01 +0100
committerRaphaël Hertzog <hertzog@debian.org>2010-02-20 22:28:18 +0100
commit6c8369aee32b5c99f45e60f62e6e07d26b2b42b8 (patch)
tree1df7f73c01b546f76a0b17249d163162a8fb0ca1 /scripts/Dpkg/Control
parent9e7dfecce74f4d58de5be46b387b899489869876 (diff)
downloaddpkg-6c8369aee32b5c99f45e60f62e6e07d26b2b42b8.tar.gz
Update Dpkg::Control::* to use Dpkg::Interface::Storable
This implies renaming parse_fh() into parse() and parse() into load(). Update all scripts and modules using those methods.
Diffstat (limited to 'scripts/Dpkg/Control')
-rw-r--r--scripts/Dpkg/Control/Hash.pm27
-rw-r--r--scripts/Dpkg/Control/Info.pm43
2 files changed, 31 insertions, 39 deletions
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