This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=38c1e43897ae9f4647b94bc55625a1f4eeff3936

commit 38c1e43897ae9f4647b94bc55625a1f4eeff3936
Author: Guillem Jover <[email protected]>
AuthorDate: Sat Dec 20 19:56:34 2025 +0100

    Dpkg::Shlibs::SymbolFile: Refactor metavariable substitution into a function
    
    We are repeating the same handling in multiple places. Refactor so that
    we can add new metavariables and only modify a single place for it.
---
 scripts/Dpkg/Shlibs/SymbolFile.pm | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/scripts/Dpkg/Shlibs/SymbolFile.pm 
b/scripts/Dpkg/Shlibs/SymbolFile.pm
index e5d637959..6d25fdf06 100644
--- a/scripts/Dpkg/Shlibs/SymbolFile.pm
+++ b/scripts/Dpkg/Shlibs/SymbolFile.pm
@@ -295,6 +295,15 @@ sub merge_object_from_symfile {
     }
 }
 
+sub replace_metavars($self, $var, %opts)
+{
+    return if $opts{template_mode};
+
+    if (exists $opts{package}) {
+        $var->$* =~ s/#PACKAGE#/$opts{package}/g;
+    }
+}
+
 sub output {
     my ($self, $fh, %opts) = @_;
     $opts{template_mode} //= 0;
@@ -304,25 +313,19 @@ sub output {
     foreach my $soname (sort $self->get_sonames()) {
         my @deps = $self->get_dependencies($soname);
         my $dep_first = shift @deps;
-        if (exists $opts{package} and not $opts{template_mode}) {
-            $dep_first =~ s/#PACKAGE#/$opts{package}/g;
-        }
+        $self->replace_metavars(\$dep_first, %opts);
         print { $fh } "$soname $dep_first\n" if defined $fh;
         $res .= "$soname $dep_first\n" if defined wantarray;
 
         foreach my $dep_next (@deps) {
-            if (exists $opts{package} and not $opts{template_mode}) {
-                $dep_next =~ s/#PACKAGE#/$opts{package}/g;
-            }
+            $self->replace_metavars(\$dep_next, %opts);
             print { $fh } "| $dep_next\n" if defined $fh;
             $res .= "| $dep_next\n" if defined wantarray;
         }
         my $f = $self->{objects}{$soname}{fields};
         foreach my $field (sort keys %{$f}) {
             my $value = $f->{$field};
-            if (exists $opts{package} and not $opts{template_mode}) {
-                $value =~ s/#PACKAGE#/$opts{package}/g;
-            }
+            $self->replace_metavars(\$value, %opts);
             print { $fh } "* $field: $value\n" if defined $fh;
             $res .= "* $field: $value\n" if defined wantarray;
         }

-- 
Dpkg.Org's dpkg

Reply via email to