Hi gregor!

> And then I found the following d/changelog entry for 0.95:
> 
>   [ Alex Muntada ]
>   * Debian::Control::Stanza: accept case-insensitive field names in new()
>     as required by Debian Policy while retaining the canonical accessors.
>     Thanks to Ben Finney for the bug report. (Closes: #860023)

Wow, I totally forgot that :)

> But yeah, it's not only a déjà-vu, apparently we need to take a look
> at this part of the code again …

Here's a proof of concept:

```
#!perl
use strict;
use warnings;
use v5.30;

use Debian::Control::Stanza::Source;
#use Debian::Control::Stanza::Binary;
my %stanza = (
    'Source' => 'package-name',
    'VCS-GIT' => 'test-vcs-git',
);
my $s = Debian::Control::Stanza::Source->new(\%stanza);
say $s->Vcs_Git;
```

It works as expected unless you uncomment the use of the
Stanza::Binary package. Then it fails:

```
Invalid field given (VCS_GIT) at case-insensitive.pl line 12.
```

That's because the import in D::C::Stanza is called twice and
the $class->fields is different for ::Source than ::Binary.
I think we need to move the canonicalization to the constructor
instead (see the patch attached, that seems to work and passes
t/Control.t too).

HTH

--
  ⢀⣴⠾⠻⢶⣦⠀
  ⣾⠁⢠⠒⠀⣿⡁   Alex Muntada <al...@debian.org>
  ⢿⡄⠘⠷⠚⠋   Debian Developer 🍥 log.alexm.org
  ⠈⠳⣄⠀⠀⠀⠀

diff --git a/lib/Debian/Control/Stanza.pm b/lib/Debian/Control/Stanza.pm
index f534c19..3be0d2a 100644
--- a/lib/Debian/Control/Stanza.pm
+++ b/lib/Debian/Control/Stanza.pm
@@ -63,12 +63,6 @@ my %canonical;
 sub import {
     my( $class ) = @_;
 
-    # map the accessor name for the lower case equivalent
-    %canonical = map (
-        ( lc($_) => $_ ),
-        $class->fields,
-    );
-
     $class->mk_accessors( $class->fields );
 }
 
@@ -99,6 +93,12 @@ sub new {
     my $class = shift;
     my $init = shift || {};
 
+    # map the accessor name for the lower case equivalent
+    my %canonical = map (
+        ( lc($_) => $_ ),
+        $class->fields,
+    );
+
     my $self = Tie::IxHash->new;
 
     bless $self, $class;

Attachment: signature.asc
Description: PGP signature

Reply via email to