Explorar o código

Dpkg::Substvars: Rename no_warn() member function to mark_as_used()

Keep the old name for backwards compatibility, but make it issue a
warning.
Guillem Jover %!s(int64=14) %!d(string=hai) anos
pai
achega
bb486d9e26
Modificáronse 3 ficheiros con 22 adicións e 7 borrados
  1. 2 0
      debian/changelog
  2. 19 6
      scripts/Dpkg/Substvars.pm
  3. 1 1
      scripts/t/750_Dpkg_Substvars.t

+ 2 - 0
debian/changelog

@@ -32,6 +32,8 @@ dpkg (1.16.4) UNRELEASED; urgency=low
     error message. Thanks to Thomas Adam <thomas.adam@smoothwall.net> and
     Jonathan Nieder <jrnieder@gmail.com>.
   * Add new Dpkg::Substvars::set_as_used() member function.
+  * Rename Dpkg::Substvars no_warn() member function to mark_as_used(), keep
+    the old name aliased to the new one producing a deprecation warning.
 
   [ Updated man page translations ]
   * German (Helge Kreutzmann).

+ 19 - 6
scripts/Dpkg/Substvars.pm

@@ -25,6 +25,7 @@ use Dpkg::Arch qw(get_host_arch);
 use Dpkg::ErrorHandling;
 use Dpkg::Gettext;
 
+use Carp;
 use POSIX qw(:errno_h);
 
 use base qw(Dpkg::Interface::Storable);
@@ -76,7 +77,7 @@ sub new {
     };
     $self->{'vars'}{'dpkg:Upstream-Version'} =~ s/-[^-]+$//;
     bless $self, $class;
-    $self->no_warn($_) foreach keys %{$self->{'vars'}};
+    $self->mark_as_used($_) foreach keys %{$self->{'vars'}};
     if ($arg) {
         $self->load($arg) if -e $arg;
     }
@@ -104,7 +105,7 @@ even if unused).
 sub set_as_used {
     my ($self, $key, $value) = @_;
     $self->set($key, $value);
-    $self->no_warn($key);
+    $self->mark_as_used($key);
 }
 
 =item $s->get($key)
@@ -130,18 +131,30 @@ sub delete {
     return delete $self->{'vars'}{$key};
 }
 
-=item $s->no_warn($key)
+=item $s->mark_as_used($key)
 
 Prevents warnings about a unused substitution, for example if it is provided by
 default.
 
 =cut
 
-sub no_warn {
+sub mark_as_used {
     my ($self, $key) = @_;
     $self->{'used'}{$key}++;
 }
 
+=item $s->no_warn($key)
+
+Obsolete function, use mark_as_used() instead.
+
+=cut
+
+sub no_warn {
+    my ($self, $key) = @_;
+    carp "obsolete no_warn() function, use mark_as_used() instead";
+    $self->mark_as_used($key);
+}
+
 =item $s->load($file)
 
 Add new substitutions read from $file.
@@ -187,7 +200,7 @@ sub set_version_substvars {
     # XXX: Source-Version is now deprecated, remove in the future.
     $self->{'vars'}{'Source-Version'} = $version;
 
-    $self->no_warn($_) foreach qw/binary:Version source:Version source:Upstream-Version Source-Version/;
+    $self->mark_as_used($_) foreach qw/binary:Version source:Version source:Upstream-Version Source-Version/;
 }
 
 =item $s->set_arch_substvars()
@@ -230,7 +243,7 @@ sub substvars {
         $lhs = $1; $vn = $2; $rhs = $3;
         if (defined($self->{'vars'}{$vn})) {
             $v = $lhs . $self->{'vars'}{$vn} . $rhs;
-	    $self->no_warn($vn);
+            $self->mark_as_used($vn);
             $count++;
         } else {
             warning($opts{msg_prefix} . _g("unknown substitution variable \${%s}"),

+ 1 - 1
scripts/t/750_Dpkg_Substvars.t

@@ -95,7 +95,7 @@ is($output, "750_Dpkg_Substvars.t: warning: unused substitution variable \${var2
           , 'unused variables warnings');
 
 # Disable warnings for a certain variable
-$s->no_warn('var2');
+$s->mark_as_used('var2');
 $output = '';
 $SIG{'__WARN__'} = sub { $output .= $_[0] };
 $s->warn_about_unused();