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=78cdc923b56bf37fd97ada6bf80030448616b586

commit 78cdc923b56bf37fd97ada6bf80030448616b586
Author: Guillem Jover <[email protected]>
AuthorDate: Fri Sep 27 05:34:15 2024 +0200

    scripts: Fix module loading
    
    Load the module, and if that does not fail, then construct the object.
    Otherwise we get very confusing errors.
    
    Prompted-by: Holger Levsen <[email protected]>
    Prompted-by: Niels Thykier <[email protected]>
---
 scripts/Dpkg/BuildDriver.pm     | 7 +++----
 scripts/Dpkg/Changelog/Parse.pm | 5 +++--
 scripts/Dpkg/Vendor.pm          | 9 +++++----
 3 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/scripts/Dpkg/BuildDriver.pm b/scripts/Dpkg/BuildDriver.pm
index fabb6fbef..98f84a90b 100644
--- a/scripts/Dpkg/BuildDriver.pm
+++ b/scripts/Dpkg/BuildDriver.pm
@@ -95,14 +95,13 @@ sub _load_driver {
     # Normalize the driver name.
     $name = join q{}, map { ucfirst lc } split /-/, $name;
 
-    my $driver;
+    my $module = "Dpkg::BuildDriver::$name";
     eval qq{
-        require Dpkg::BuildDriver::$name;
-        \$driver = Dpkg::BuildDriver::$name->new(%opts);
+        require $module;
     };
     error(g_('build driver %s is unknown: %s'), $name, $@) if $@;
 
-    return $driver;
+    return $module->new(%opts);
 }
 
 sub new {
diff --git a/scripts/Dpkg/Changelog/Parse.pm b/scripts/Dpkg/Changelog/Parse.pm
index dff7ddaa6..a1c35ccf1 100644
--- a/scripts/Dpkg/Changelog/Parse.pm
+++ b/scripts/Dpkg/Changelog/Parse.pm
@@ -152,11 +152,12 @@ sub changelog_parse {
     # Find the right changelog parser.
     my $format = ucfirst lc $opts{changelogformat};
     my $changes;
+    my $module = "Dpkg::Changelog::$format";
     eval qq{
-        require Dpkg::Changelog::$format;
-        \$changes = Dpkg::Changelog::$format->new();
+        require $module;
     };
     error(g_('changelog format %s is unknown: %s'), $format, $@) if $@;
+    $changes = $module->new();
     error(g_('changelog format %s is not a Dpkg::Changelog class'), $format)
         unless $changes->isa('Dpkg::Changelog');
     $changes->set_options(reportfile => $opts{label},
diff --git a/scripts/Dpkg/Vendor.pm b/scripts/Dpkg/Vendor.pm
index feec75cd7..e40211718 100644
--- a/scripts/Dpkg/Vendor.pm
+++ b/scripts/Dpkg/Vendor.pm
@@ -211,9 +211,9 @@ sub get_vendor_object {
     state %OBJECT_CACHE;
     return $OBJECT_CACHE{$vendor_key} if exists $OBJECT_CACHE{$vendor_key};
 
-    my ($obj, @names);
-
     my @vendor_parts = split m{$vendor_sep_regex}, $vendor;
+
+    my @names;
     push @names, join q{}, map { ucfirst } @vendor_parts;
     push @names, join q{}, map { ucfirst lc } @vendor_parts;
 
@@ -228,11 +228,12 @@ sub get_vendor_object {
     push @names, @obsolete_names;
 
     foreach my $name (uniq @names) {
+        my $module = "Dpkg::Vendor::$name";
         eval qq{
-            require Dpkg::Vendor::$name;
-            \$obj = Dpkg::Vendor::$name->new();
+            require $module;
         };
         unless ($@) {
+            my $obj = $module->new();
             $OBJECT_CACHE{$vendor_key} = $obj;
             if (exists $obsolete_name{$name}) {
                 warning(g_('%s module name is deprecated; ' .

-- 
Dpkg.Org's dpkg

Reply via email to