The following commit has been merged in the master branch:
commit aba76e6de21438ada3d6df542021d341fb499dcc
Author: Raphaël Hertzog <[email protected]>
Date:   Fri Feb 19 19:45:40 2010 +0100

    Update Dpkg::Substvars to use Dpkg::Interface::Storable
    
    The parse() function is replaced by load() for most users.

diff --git a/scripts/Dpkg/Substvars.pm b/scripts/Dpkg/Substvars.pm
index 0ec04ba..8ef3158 100644
--- a/scripts/Dpkg/Substvars.pm
+++ b/scripts/Dpkg/Substvars.pm
@@ -1,4 +1,4 @@
-# Copyright © 2007,2009 Raphaël Hertzog <[email protected]>
+# Copyright © 2007-2010 Raphaël Hertzog <[email protected]>
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,6 +25,8 @@ use Dpkg::Gettext;
 
 use POSIX qw(:errno_h);
 
+use base qw(Dpkg::Interface::Storable);
+
 my $maxsubsts = 50;
 
 =head1 NAME
@@ -71,7 +73,7 @@ sub new {
     bless $self, $class;
     $self->no_warn($_) foreach keys %{$self->{'vars'}};
     if ($arg) {
-        $self->parse($arg);
+        $self->load($arg) if -e $arg;
     }
     return $self;
 }
@@ -122,28 +124,27 @@ sub no_warn {
     $self->{'used'}{$key}++;
 }
 
-=item $s->parse($file)
+=item $s->load($file)
 
 Add new substitutions read from $file.
 
+=item $s->parse($fh, $desc)
+
+Add new substitutions read from the filehandle. $desc is used to identify
+the filehandle in error messages.
+
 =cut
 
 sub parse {
-    my ($self, $varlistfile) = @_;
-    $varlistfile = "./$varlistfile" if $varlistfile =~ m/\s/;
-    if (open(SV, "<", $varlistfile)) {
-       binmode(SV);
-       while (<SV>) {
-           next if m/^\s*\#/ || !m/\S/;
-           s/\s*\n$//;
-           m/^(\w[-:0-9A-Za-z]*)\=(.*)$/ ||
-               error(_g("bad line in substvars file %s at line %d"),
-                     $varlistfile, $.);
-           $self->{'vars'}{$1} = $2;
-       }
-       close(SV);
-    } elsif ($! != ENOENT) {
-       error(_g("unable to open substvars file %s: %s"), $varlistfile, $!);
+    my ($self, $fh, $varlistfile) = @_;
+    binmode($fh);
+    while (<$fh>) {
+       next if m/^\s*\#/ || !m/\S/;
+       s/\s*\n$//;
+       m/^(\w[-:0-9A-Za-z]*)\=(.*)$/ ||
+           error(_g("bad line in substvars file %s at line %d"),
+                 $varlistfile, $.);
+       $self->{'vars'}{$1} = $2;
     }
 }
 
@@ -238,6 +239,36 @@ sub warn_about_unused {
     }
 }
 
+=item $s->save($file)
+
+Store all substitutions variables except the automatic ones in the
+indicated file.
+
+=item "$s"
+
+Return a string representation of all substitutions variables except the
+automatic ones.
+
+=item $str = $s->output($fh)
+
+Print all substitutions variables except the automatic ones in the
+filehandle and return the content written.
+
+=cut
+
+sub output {
+    my ($self, $fh) = @_;
+    my $str = "";
+    # Store all non-automatic substitutions only
+    foreach my $vn (sort keys %{$self->{'vars'}}) {
+       next if 
/^(?:(?:dpkg|source|binary):(?:Source-)?Version|Space|Tab|Newline|Arch|Source-Version|F:.+)$/;
+       my $line = "$vn=" . $self->{vars}{$vn} . "\n";
+       print $fh $line if defined $fh;
+       $str .= $line;
+    }
+    return $str;
+}
+
 =back
 
 =head1 AUTHOR
diff --git a/scripts/dpkg-genchanges.pl b/scripts/dpkg-genchanges.pl
index df55576..5493a95 100755
--- a/scripts/dpkg-genchanges.pl
+++ b/scripts/dpkg-genchanges.pl
@@ -210,7 +210,7 @@ my $control = Dpkg::Control::Info->new($controlfile);
 my $fields = Dpkg::Control->new(type => CTRL_FILE_CHANGES);
 $substvars->set_version_substvars($changelog->{"Version"});
 $substvars->set_arch_substvars();
-$substvars->parse($varlistfile) if -e $varlistfile;
+$substvars->load($varlistfile) if -e $varlistfile;
 
 if (defined($prev_changelog) and
     version_compare_relation($changelog->{"Version"}, REL_LT,
diff --git a/scripts/dpkg-gencontrol.pl b/scripts/dpkg-gencontrol.pl
index f135036..605fe84 100755
--- a/scripts/dpkg-gencontrol.pl
+++ b/scripts/dpkg-gencontrol.pl
@@ -138,7 +138,7 @@ $options{"changelogformat"} = $changelogformat if 
$changelogformat;
 my $changelog = changelog_parse(%options);
 $substvars->set_version_substvars($changelog->{"Version"});
 $substvars->set_arch_substvars();
-$substvars->parse($varlistfile) if -e $varlistfile;
+$substvars->load($varlistfile) if -e $varlistfile;
 $substvars->set("binary:Version", $forceversion) if defined $forceversion;
 my $control = Dpkg::Control::Info->new($controlfile);
 my $fields = Dpkg::Control->new(type => CTRL_PKG_DEB);
diff --git a/scripts/dpkg-source.pl b/scripts/dpkg-source.pl
index 7a7517a..1c01511 100755
--- a/scripts/dpkg-source.pl
+++ b/scripts/dpkg-source.pl
@@ -325,7 +325,7 @@ if ($options{'opmode'} =~ /^(-b|--print-format)$/) {
     # Write the .dsc
     my $dscname = $srcpkg->get_basename(1) . ".dsc";
     info(_g("building %s in %s"), $sourcepackage, $dscname);
-    $substvars->parse($varlistfile) if $varlistfile && -e $varlistfile;
+    $substvars->load($varlistfile) if $varlistfile && -e $varlistfile;
     $srcpkg->write_dsc(filename => $dscname,
                       remove => \%remove,
                       override => \%override,
diff --git a/scripts/t/750_Dpkg_Substvars.t b/scripts/t/750_Dpkg_Substvars.t
index ae4609f..f7e03a5 100644
--- a/scripts/t/750_Dpkg_Substvars.t
+++ b/scripts/t/750_Dpkg_Substvars.t
@@ -28,7 +28,7 @@ my $datadir = $srcdir . '/t/750_Dpkg_Substvars';
 
 my $s = Dpkg::Substvars->new();
 
-$s->parse("$datadir/substvars1");
+$s->load("$datadir/substvars1");
 
 # simple value tests
 is($s->get('var1'), 'Some value', 'var1');

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to