Просмотр исходного кода

Dpkg::Substvars: Add new method set_field_substvars()

Refactor the ad-code in Dpkg::Control::HashCore to use this new method.
Guillem Jover лет назад: 10
Родитель
Сommit
a8abe4885f
3 измененных файлов с 21 добавлено и 3 удалено
  1. 1 0
      debian/changelog
  2. 1 3
      scripts/Dpkg/Control/HashCore.pm
  3. 19 0
      scripts/Dpkg/Substvars.pm

+ 1 - 0
debian/changelog

@@ -32,6 +32,7 @@ dpkg (1.18.11) UNRELEASED; urgency=medium
       hooks. Prompted by Johannes Schauer <josch@debian.org>.
       hooks. Prompted by Johannes Schauer <josch@debian.org>.
     - Make the Dpkg::Substavars parse() method return the number of substvars
     - Make the Dpkg::Substavars parse() method return the number of substvars
       parsed.
       parsed.
+    - Add new set_field_substvars() method to Dpkg::Substvars.
   * Packaging:
   * Packaging:
     - Add liblocale-gettext-perl to libdpkg-perl Recommends.
     - Add liblocale-gettext-perl to libdpkg-perl Recommends.
     - Wrap and document dependency relationships.
     - Wrap and document dependency relationships.

+ 1 - 3
scripts/Dpkg/Control/HashCore.pm

@@ -402,9 +402,7 @@ sub apply_substvars {
     my ($self, $substvars, %opts) = @_;
     my ($self, $substvars, %opts) = @_;
 
 
     # Add substvars to refer to other fields
     # Add substvars to refer to other fields
-    foreach my $f (keys %$self) {
-        $substvars->set_as_auto("F:$f", $self->{$f});
-    }
+    $substvars->set_field_substvars($self, 'F');
 
 
     foreach my $f (keys %$self) {
     foreach my $f (keys %$self) {
         my $v = $substvars->substvars($self->{$f}, %opts);
         my $v = $substvars->substvars($self->{$f}, %opts);

+ 19 - 0
scripts/Dpkg/Substvars.pm

@@ -270,6 +270,23 @@ sub set_arch_substvars {
     $self->set('Arch', get_host_arch(), $attr);
     $self->set('Arch', get_host_arch(), $attr);
 }
 }
 
 
+=item $s->set_field_substvars($ctrl, $prefix)
+
+Defines field variables from a Dpkg::Control object, with each variable
+having the form "${$prefix:$field}".
+
+They will never be warned about when unused.
+
+=cut
+
+sub set_field_substvars {
+    my ($self, $ctrl, $prefix) = @_;
+
+    foreach my $field (keys %{$ctrl}) {
+        $self->set_as_auto("$prefix:$field", $ctrl->{$field});
+    }
+}
+
 =item $newstring = $s->substvars($string)
 =item $newstring = $s->substvars($string)
 
 
 Substitutes variables in $string and return the result in $newstring.
 Substitutes variables in $string and return the result in $newstring.
@@ -407,6 +424,8 @@ Obsolete substvar: Emit an error on Source-Version substvar usage.
 
 
 New return: $s->parse() now returns the number of parsed substvars.
 New return: $s->parse() now returns the number of parsed substvars.
 
 
+New method: $s->set_field_substvars().
+
 =head2 Version 1.04 (dpkg 1.18.0)
 =head2 Version 1.04 (dpkg 1.18.0)
 
 
 New method: $s->filter().
 New method: $s->filter().